This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from elboletaire/f/tests
Adding tests + some fixes thanks to them
- Loading branch information
Showing
9 changed files
with
256 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
vendor/* | ||
tests/test_files/webroot/css/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
bootstrap="./tests/bootstrap.php" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Less Test Cases"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
namespace Less\Test\TestCase\View\Helper; | ||
|
||
use Less\View\Helper\LessHelper; | ||
use Cake\TestSuite\TestCase; | ||
use Cake\View\View; | ||
|
||
class LessHelperTest extends TestCase | ||
{ | ||
private $Less; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$View = new View(); | ||
$this->Less = new LessHelper($View); | ||
} | ||
|
||
public function testLess() | ||
{ | ||
$options = [ | ||
'cache' => false | ||
]; | ||
|
||
// [Less.php] Basic compiling | ||
$result = $this->Less->less('less/test.less', $options, ['bgcolor' => 'red']); | ||
$this->assertHtml([ | ||
['style' => true], | ||
'body{background-color: #f00}', | ||
'/style' | ||
], $result); | ||
|
||
// [Less.php] Compiling using cache (here we only check for the | ||
// resulting tag, as the compilation checks are made in testCompile) | ||
$result = $this->Less->less('less/test.less'); | ||
$this->assertHtml([ | ||
'link' => [ | ||
'rel' => 'stylesheet', | ||
'href' => 'preg:/\/css\/lessphp_[0-9a-z]+\.css/' | ||
] | ||
], $result); | ||
|
||
// Trying the js fallback | ||
$result = $this->Less->less('less/test_error.less'); | ||
$this->assertHtml([ | ||
'link' => [ | ||
'rel' => 'stylesheet/less', | ||
'href' => '/less/test_error.less' | ||
], | ||
/*['script' => true], | ||
// Need some help here :p | ||
'/script', | ||
'script' => [ | ||
'src' => '/less/js/less.min.js' | ||
]*/ | ||
], $result); | ||
} | ||
|
||
// public function testJsBlock() | ||
// { | ||
|
||
// } | ||
|
||
public function testCompile() | ||
{ | ||
$options = [ | ||
'compress' => true | ||
]; | ||
|
||
// Basic compiling | ||
$result = $this->Less->compile(['less/test.less'], $options, [], false); | ||
$this->assertTextEquals('body{background-color: #000}', $result); | ||
|
||
// Changing the bgcolor var | ||
$result = $this->Less->compile(['less/test.less'], $options, ['bgcolor' => 'magenta'], false); | ||
$this->assertTextEquals('body{background-color: #f0f}', $result); | ||
|
||
// Compiling with cache | ||
$result = $this->Less->compile(['less/test.less'], $options); | ||
$this->assertRegExp('/lessphp_[a-z0-9]+\.css/', $result); | ||
$result = file_get_contents(WWW_ROOT . 'css' . DS . $result); | ||
$this->assertTextEquals('body{background-color: #000}', $result); | ||
|
||
// Compiling with cache and modify_vars | ||
$result = $this->Less->compile(['less/test.less'], $options, ['bgcolor' => 'darkorange']); | ||
$this->assertRegExp('/lessphp_[a-z0-9]+\.css/', $result); | ||
$result = file_get_contents(WWW_ROOT . 'css' . DS . $result); | ||
$this->assertTextEquals('body{background-color: #ff8c00}', $result); | ||
} | ||
|
||
public function testAssetBaseUrl() | ||
{ | ||
$assetBaseUrl = self::getProtectedMethod('assetBaseUrl'); | ||
$result = $assetBaseUrl->invokeArgs($this->Less, [ | ||
'less/styles.less', | ||
'Less' | ||
]); | ||
$this->assertEquals('http://localhost/Less/less', $result); | ||
|
||
$result = $assetBaseUrl->invokeArgs($this->Less, [ | ||
'css/whatever.less', | ||
'Bootstrap' | ||
]); | ||
$this->assertEquals('http://localhost/Bootstrap/css', $result); | ||
|
||
$result = $assetBaseUrl->invokeArgs($this->Less, [ | ||
'whatever.less', | ||
'Less' | ||
]); | ||
$this->assertEquals('http://localhost/Less', $result); | ||
} | ||
|
||
protected static function getProtectedMethod($name) { | ||
$class = new \ReflectionClass('Less\View\Helper\LessHelper'); | ||
$method = $class->getMethod($name); | ||
$method->setAccessible(true); | ||
return $method; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
use Cake\Cache\Cache; | ||
use Cake\Core\Configure; | ||
use Cake\Core\Plugin; | ||
use Cake\Datasource\ConnectionManager; | ||
use Cake\I18n\I18n; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
if (!defined('DS')) { | ||
define('DS', DIRECTORY_SEPARATOR); | ||
} | ||
|
||
define('ROOT', dirname(__DIR__) . DS); | ||
define('CAKE_CORE_INCLUDE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp'); | ||
define('CORE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS); | ||
define('CAKE', CORE_PATH . 'src' . DS); | ||
define('TESTS', ROOT . 'tests'); | ||
define('APP', ROOT . 'tests' . DS . 'test_files' . DS . 'app' . DS); | ||
define('APP_DIR', 'app'); | ||
define('WEBROOT_DIR', 'webroot'); | ||
define('WWW_ROOT', dirname(APP) . DS . 'webroot' . DS); | ||
define('TMP', sys_get_temp_dir() . DS); | ||
define('CONFIG', APP . 'config' . DS); | ||
define('CACHE', TMP); | ||
define('LOGS', TMP); | ||
|
||
require_once CORE_PATH . 'config/bootstrap.php'; | ||
|
||
date_default_timezone_set('UTC'); | ||
mb_internal_encoding('UTF-8'); | ||
|
||
Configure::write('debug', true); | ||
Configure::write('App', [ | ||
'namespace' => 'App', | ||
'encoding' => 'UTF-8', | ||
'base' => false, | ||
'baseUrl' => false, | ||
'dir' => 'src', | ||
'webroot' => WEBROOT_DIR, | ||
'www_root' => WWW_ROOT, | ||
'fullBaseUrl' => 'http://localhost', | ||
'imageBaseUrl' => 'img/', | ||
'jsBaseUrl' => 'js/', | ||
'cssBaseUrl' => 'css/', | ||
'paths' => [ | ||
'plugins' => [dirname(APP) . DS . 'plugins' . DS], | ||
'templates' => [APP . 'Template' . DS] | ||
] | ||
]); | ||
|
||
Cache::config([ | ||
'_cake_core_' => [ | ||
'engine' => 'File', | ||
'prefix' => 'cake_core_', | ||
'serialize' => true | ||
], | ||
'_cake_model_' => [ | ||
'engine' => 'File', | ||
'prefix' => 'cake_model_', | ||
'serialize' => true | ||
] | ||
]); | ||
|
||
Plugin::load('Less', ['path' => ROOT]); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@bgcolor: black; | ||
|
||
body { | ||
background-color: @bgcolor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
buggy { | ||
|
||
|