Skip to content

Commit

Permalink
Adding test cases for the helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 10, 2010
1 parent b7f79a0 commit 1e8805f
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion tests/cases/helpers/asset_compress.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class AssetCompressHelperTestCase extends CakeTestCase {
* @return void
**/
function startTest() {
$this->Helper = new AssetCompressHelper();
$this->_pluginPath = App::pluginPath('AssetCompress');
$testFile = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini';

$this->Helper = new AssetCompressHelper(array('iniFile' => $testFile));
$this->Helper->Html = new HtmlHelper();
Router::reload();
}
Expand All @@ -31,6 +34,89 @@ function testIncludeAssets() {
$result = $this->Helper->includeAssets();
$this->assertPattern('#"/some/dir/asset_compress#', $result, 'double dir set %s');
}

/**
* test css addition
*
* @return void
*/
function testCssOrderPreserving() {
$this->Helper->css('base');
$this->Helper->css('reset');

$result = $this->Helper->includeAssets();
$expected = array(
'link' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => '/asset_compress/css_files/get/default.css?file[]=base&file[]=reset'
)
);
$this->assertTags($result, $expected);
}

/**
* test script addition
*
* @return void
*/
function testScriptOrderPreserving() {
$this->Helper->script('libraries');
$this->Helper->script('thing');

$result = $this->Helper->includeAssets();
$expected = array(
'script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/default.js?file[]=libraries&file[]=thing'
),
'/script'
);
$this->assertTags($result, $expected);
}


/**
* test generating two script files.
*
* @return void
*/
function testMultipleScriptFiles() {
$this->Helper->script('libraries', 'default');
$this->Helper->script('thing', 'second');

$result = $this->Helper->includeAssets();
$expected = array(
array('script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/default.js?file[]=libraries'
)),
'/script',
array('script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/second.js?file[]=thing'
)),
'/script'
);
$this->assertTags($result, $expected);
}

/**
* test timestamping assets.
*
* @return void
*/
function testTimestampping() {
Configure::write('debug', 1);
$this->Helper->script('libraries', 'default');
$result = $this->Helper->includeAssets();
$this->assertPattern('/default\.\d+\.js/', $result);

Configure::write('debug', 2);
}



/**
* end a test
*
Expand Down

0 comments on commit 1e8805f

Please sign in to comment.