Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Making HtmlHelper not use ClassRegistry to access the View instance. …
…Updating test cases.
  • Loading branch information
markstory committed Aug 11, 2010
1 parent e0acd21 commit 7efe163
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
6 changes: 2 additions & 4 deletions cake/libs/view/helpers/html.php
Expand Up @@ -379,8 +379,7 @@ public function css($path, $rel = null, $options = array()) {
if ($options['inline']) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
$this->_View->addScript($out);
}
}

Expand Down Expand Up @@ -445,8 +444,7 @@ public function script($url, $options = array()) {
if ($options['inline']) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
$this->_View->addScript($out);
}
}

Expand Down
31 changes: 13 additions & 18 deletions cake/tests/cases/libs/view/helpers/html.test.php
Expand Up @@ -108,10 +108,9 @@ class HtmlHelperTest extends CakeTestCase {
* @return void
*/
function startTest() {
$view = new View(new TheHtmlTestController());
$this->Html = new HtmlHelper($view);
$this->View = $this->getMock('View', array('addScript'), array(new TheHtmlTestController()));
$this->Html = new HtmlHelper($this->View);

ClassRegistry::addObject('view', $view);
$this->_appEncoding = Configure::read('App.encoding');
$this->_asset = Configure::read('Asset');
$this->_debug = Configure::read('debug');
Expand All @@ -128,7 +127,7 @@ function endTest() {
Configure::write('Asset', $this->_asset);
Configure::write('debug', $this->_debug);
ClassRegistry::flush();
unset($this->Html);
unset($this->Html, $this->View);
}

/**
Expand Down Expand Up @@ -472,19 +471,16 @@ function testCssLink() {
$this->assertTags($result[1], $expected);
$this->assertEqual(count($result), 2);

ClassRegistry::removeObject('view');
$view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$view->expects($this->any())->method('addScript')->with($this->matchesRegularExpression('/css_in_head.css/'));
$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);
$this->View->expects($this->at(0))->method('addScript')
->with($this->matchesRegularExpression('/css_in_head.css/'));

ClassRegistry::removeObject('view');
$view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$view->expects($this->any())
$this->View->expects($this->at(1))
->method('addScript')
->with($this->matchesRegularExpression('/more_css_in_head.css/'));

$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);

$result = $this->Html->css('more_css_in_head', null, array('inline' => false));
$this->assertNull($result);
}
Expand Down Expand Up @@ -610,10 +606,9 @@ function testScript() {
);
$this->assertTags($result, $expected);

ClassRegistry::removeObject('view');
$view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$view->expects($this->any())->method('addScript')->with($this->matchesRegularExpression('/script_in_head.js/'));

$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/script_in_head.js/'));
$result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result);
}
Expand Down

0 comments on commit 7efe163

Please sign in to comment.