Skip to content

Commit

Permalink
Updating HtmlHelper and its tests to use View::append().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 18, 2011
1 parent bd4ee41 commit 4606ea3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
29 changes: 17 additions & 12 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -144,7 +144,7 @@ class HtmlHelperTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->View = $this->getMock('View', array('addScript'), array(new TheHtmlTestController()));
$this->View = $this->getMock('View', array('append'), array(new TheHtmlTestController()));
$this->Html = new TestHtmlHelper($this->View);
$this->Html->request = new CakeRequest(null, false);
$this->Html->request->webroot = '';
Expand Down Expand Up @@ -508,12 +508,13 @@ public function testCssLink() {
$this->assertTags($result[1], $expected);
$this->assertEquals(count($result), 2);

$this->View->expects($this->at(0))->method('addScript')
->with($this->matchesRegularExpression('/css_in_head.css/'));
$this->View->expects($this->at(0))
->method('append')
->with('css', $this->matchesRegularExpression('/css_in_head.css/'));

$this->View->expects($this->at(1))
->method('addScript')
->with($this->matchesRegularExpression('/more_css_in_head.css/'));
->method('append')
->with('css', $this->matchesRegularExpression('/more_css_in_head.css/'));

$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);
Expand Down Expand Up @@ -654,8 +655,9 @@ public function testScript() {
);
$this->assertTags($result, $expected);

$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/script_in_head.js/'));
$this->View->expects($this->any())
->method('append')
->with('script', $this->matchesRegularExpression('/script_in_head.js/'));
$result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result);
}
Expand Down Expand Up @@ -751,8 +753,9 @@ public function testScriptBlock() {
$this->assertTags($result, $expected);


$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
$this->View->expects($this->any())
->method('append')
->with('script', $this->matchesRegularExpression('/window\.foo\s\=\s2;/'));

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

$this->View->expects($this->once())->method('addScript');
$this->View->expects($this->once())
->method('append');
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
$this->assertNull($result);
echo 'this is some javascript';
Expand Down Expand Up @@ -1245,8 +1249,9 @@ public function testMeta() {
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));


$this->View->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/^<meta/'));
$this->View->expects($this->any())
->method('append')
->with('meta', $this->matchesRegularExpression('/^<meta/'));

$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false));
$this->assertNull($result);
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -281,7 +281,7 @@ public function meta($type, $url = null, $options = array()) {
if ($inline) {
return $out;
} else {
$this->_View->addScript($out);
$this->_View->append('meta', $out);
}
}

Expand Down Expand Up @@ -436,7 +436,7 @@ public function css($path, $rel = null, $options = array()) {
if ($options['inline']) {
return $out;
} else {
$this->_View->addScript($out);
$this->_View->append(__FUNCTION__, $out);
}
}

Expand Down Expand Up @@ -513,7 +513,7 @@ public function script($url, $options = array()) {
if ($options['inline']) {
return $out;
} else {
$this->_View->addScript($out);
$this->_View->append(__FUNCTION__, $out);
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ public function scriptBlock($script, $options = array()) {
if ($inline) {
return sprintf($this->_tags['javascriptblock'], $attributes, $script);
} else {
$this->_View->addScript(sprintf($this->_tags['javascriptblock'], $attributes, $script));
$this->_View->append('script', sprintf($this->_tags['javascriptblock'], $attributes, $script));
return null;
}
}
Expand Down

0 comments on commit 4606ea3

Please sign in to comment.