Skip to content

Commit

Permalink
Updating HtmlHelper test to use request object.
Browse files Browse the repository at this point in the history
Removing reference operators.
  • Loading branch information
markstory committed May 15, 2010
1 parent 3983bf3 commit 0eebda9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/html.php
Expand Up @@ -235,7 +235,7 @@ public function meta($type, $url = null, $options = array()) {
if ($inline) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view = ClassRegistry::getObject('view');
$view->addScript($out);
}
}
Expand Down
52 changes: 24 additions & 28 deletions cake/tests/cases/libs/view/helpers/html.test.php
Expand Up @@ -17,7 +17,7 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller', 'Model'));
App::import('Core', array('Helper', 'AppHelper', 'ClassRegistry', 'Controller'));
App::import('Helper', array('Html', 'Form'));

if (!defined('FULL_BASE_URL')) {
Expand Down Expand Up @@ -110,8 +110,11 @@ class HtmlHelperTest extends CakeTestCase {
* @return void
*/
function startTest() {
$this->Html =& new HtmlHelper();
$view =& new View(new TheHtmlTestController());
$this->Html = new HtmlHelper();
$this->Html->request = new CakeRequest(null, false);
$this->Html->request->webroot = '';

$view = new View(new TheHtmlTestController());
ClassRegistry::addObject('view', $view);
$this->_appEncoding = Configure::read('App.encoding');
$this->_asset = Configure::read('Asset');
Expand Down Expand Up @@ -157,6 +160,8 @@ function testDocType() {
* @return void
*/
function testLink() {
$this->Html->request->webroot = '';

$result = $this->Html->link('/home');
$expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a');
$this->assertTags($result, $expected);
Expand Down Expand Up @@ -289,6 +294,7 @@ function testLink() {
* @return void
*/
function testImageTag() {
$this->Html->request->webroot = '';
Configure::write('Asset.timestamp', false);

$result = $this->Html->image('test.gif');
Expand All @@ -312,7 +318,7 @@ function testImageTag() {
function testImageWithTimestampping() {
Configure::write('Asset.timestamp', 'force');

$this->Html->webroot = '/';
$this->Html->request->webroot = '/';
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));

Expand All @@ -322,14 +328,12 @@ function testImageWithTimestampping() {
$result = $this->Html->image('cake.icon.png');
$this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '')));

$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/longer/';
$this->Html->request->webroot = '/testing/longer/';
$result = $this->Html->image('cake.icon.png');
$expected = array(
'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '')
);
$this->assertTags($result, $expected);
$this->Html->webroot = $webroot;
}

/**
Expand All @@ -346,15 +350,15 @@ function testImageTagWithTheme() {
App::import('Core', 'File');

$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
$file =& new File($testfile, true);
$file = new File($testfile, true);

App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
Configure::write('Asset.timestamp', true);
Configure::write('debug', 1);

$this->Html->webroot = '/';
$this->Html->request->webroot = '/';
$this->Html->theme = 'test_theme';
$result = $this->Html->image('__cake_test_image.gif');
$this->assertTags($result, array(
Expand All @@ -363,18 +367,16 @@ function testImageTagWithTheme() {
'alt' => ''
)));

$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/';
$this->Html->request->webroot = '/testing/';
$result = $this->Html->image('__cake_test_image.gif');

$this->assertTags($result, array(
'img' => array(
'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
)));
$this->Html->webroot = $webroot;

$dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$dir = new Folder(WWW_ROOT . 'theme' . DS . 'test_theme');
$dir->delete();
}

Expand All @@ -392,15 +394,13 @@ function testThemeAssetsInMainWebrootPath() {
$webRoot = Configure::read('App.www_root');
Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS);

$webroot = $this->Html->webroot;
$this->Html->theme = 'test_theme';
$result = $this->Html->css('webroot_test');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/')
);
$this->assertTags($result, $expected);

$webroot = $this->Html->webroot;
$this->Html->theme = 'test_theme';
$result = $this->Html->css('theme_webroot');
$expected = array(
Expand Down Expand Up @@ -474,13 +474,13 @@ function testCssLink() {
$this->assertEqual(count($result), 2);

ClassRegistry::removeObject('view');
$view =& new HtmlHelperMockView();
$view = new HtmlHelperMockView();
ClassRegistry::addObject('view', $view);
$view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/')));
$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);

$view =& ClassRegistry::getObject('view');
$view = ClassRegistry::getObject('view');
$view->expectAt(1, 'addScript', array(new NoPatternExpectation('/inline=""/')));
$result = $this->Html->css('more_css_in_head', null, array('inline' => false));
$this->assertNull($result);
Expand Down Expand Up @@ -515,19 +515,15 @@ function testCssTimestamping() {
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);

$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/';
$this->Html->request->webroot = '/testing/';
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
$this->Html->webroot = $webroot;

$webroot = $this->Html->webroot;
$this->Html->webroot = '/testing/longer/';
$this->Html->request->webroot = '/testing/longer/';
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
$this->Html->webroot = $webroot;
}

/**
Expand Down Expand Up @@ -607,8 +603,8 @@ function testScript() {
);
$this->assertTags($result, $expected);

$view =& ClassRegistry::getObject('view');
$view =& new HtmlHelperMockView();
$view = ClassRegistry::getObject('view');
$view = new HtmlHelperMockView();
$view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/')));
$result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result);
Expand Down Expand Up @@ -648,8 +644,8 @@ function testScriptBlock() {
);
$this->assertTags($result, $expected);

$view =& ClassRegistry::getObject('view');
$view =& new HtmlHelperMockView();
$view = ClassRegistry::getObject('view');
$view = new HtmlHelperMockView();
$view->expectAt(0, 'addScript', array(new PatternExpectation('/window\.foo\s\=\s2;/')));

$result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
Expand Down Expand Up @@ -698,7 +694,7 @@ function testScriptStartAndScriptEnd() {
$this->assertTags($result, $expected);

ClassRegistry::removeObject('view');
$View =& new HtmlHelperMockView();
$View = new HtmlHelperMockView();

$View->expectOnce('addScript');
ClassRegistry::addObject('view', $View);
Expand Down

0 comments on commit 0eebda9

Please sign in to comment.