Converting HtmlHelperTest to phpunit

This commit is contained in:
José Lorenzo Rodríguez 2010-05-15 21:05:22 -04:30
parent 67e32e292d
commit 32a46e9eda

View file

@ -49,8 +49,6 @@ class TheHtmlTestController extends Controller {
public $uses = null; public $uses = null;
} }
Mock::generate('View', 'HtmlHelperMockView');
/** /**
* HtmlHelperTest class * HtmlHelperTest class
* *
@ -474,14 +472,18 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertEqual(count($result), 2); $this->assertEqual(count($result), 2);
ClassRegistry::removeObject('view'); ClassRegistry::removeObject('view');
$view =& new HtmlHelperMockView(); $view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view); ClassRegistry::addObject('view', $view);
$view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/'))); $view->expects($this->any())->method('addScript')->with($this->matchesRegularExpression('/css_in_head.css/'));
$result = $this->Html->css('css_in_head', null, array('inline' => false)); $result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result); $this->assertNull($result);
$view =& ClassRegistry::getObject('view'); ClassRegistry::removeObject('view');
$view->expectAt(1, 'addScript', array(new NoPatternExpectation('/inline=""/'))); $view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$view->expects($this->any())
->method('addScript')
->with($this->matchesRegularExpression('/more_css_in_head.css/'));
$result = $this->Html->css('more_css_in_head', null, array('inline' => false)); $result = $this->Html->css('more_css_in_head', null, array('inline' => false));
$this->assertNull($result); $this->assertNull($result);
} }
@ -607,9 +609,10 @@ class HtmlHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$view =& ClassRegistry::getObject('view'); ClassRegistry::removeObject('view');
$view =& new HtmlHelperMockView(); $view = $this->getMock('View', array(), array(), '', false);
$view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/'))); ClassRegistry::addObject('view', $view);
$view->expects($this->any())->method('addScript')->with($this->matchesRegularExpression('/script_in_head.js/'));
$result = $this->Html->script('script_in_head', array('inline' => false)); $result = $this->Html->script('script_in_head', array('inline' => false));
$this->assertNull($result); $this->assertNull($result);
} }
@ -648,9 +651,11 @@ class HtmlHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$view =& ClassRegistry::getObject('view'); ClassRegistry::removeObject('view');
$view =& new HtmlHelperMockView(); $view = $this->getMock('View', array(), array(), '', false);
$view->expectAt(0, 'addScript', array(new PatternExpectation('/window\.foo\s\=\s2;/'))); ClassRegistry::addObject('view', $view);
$view->expects($this->any())->method('addScript')
->with($this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
$result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false)); $result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false));
$this->assertNull($result); $this->assertNull($result);
@ -698,10 +703,10 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
ClassRegistry::removeObject('view'); ClassRegistry::removeObject('view');
$View =& new HtmlHelperMockView(); $view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$View->expectOnce('addScript'); $view->expects($this->once())->method('addScript');
ClassRegistry::addObject('view', $View);
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false)); $result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
$this->assertNull($result); $this->assertNull($result);
@ -1121,10 +1126,10 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL')); $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL'))); $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
$viewMock = new HtmlHelperMockView();
$viewMock->expectOnce('addScript', array(new PatternExpectation('/^<meta/')));
ClassRegistry::removeObject('view'); ClassRegistry::removeObject('view');
ClassRegistry::addObject('view', $viewMock); $view = $this->getMock('View', array(), array(), '', false);
ClassRegistry::addObject('view', $view);
$view->expects($this->any())->method('addScript')->with($this->matchesRegularExpression('/^<meta/'));
$this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false))); $this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false)));
} }