diff --git a/cake/tests/cases/console/libs/tasks/controller.test.php b/cake/tests/cases/console/libs/tasks/controller.test.php index ec341d3f05f..abb8e56b501 100644 --- a/cake/tests/cases/console/libs/tasks/controller.test.php +++ b/cake/tests/cases/console/libs/tasks/controller.test.php @@ -81,7 +81,7 @@ public function startTest() { 'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment' )); $this->Task = $this->getMock('ControllerTask', - array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'), + array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'), array(&$this->Dispatcher) ); $this->Task->name = 'ControllerTask'; @@ -94,7 +94,7 @@ public function startTest() { array(&$this->Dispatcher) ); $this->Task->Project = $this->getMock('ProjectTask', - array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'), + array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'), array(&$this->Dispatcher) ); $this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher)); @@ -324,7 +324,7 @@ public function testBakeWithPlugin() { * * @return void */ - public function xxtestBakeActionsUsingSessions() { + public function testBakeActionsUsingSessions() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s'); if ($skip) { @@ -350,7 +350,7 @@ public function xxtestBakeActionsUsingSessions() { $this->assertTrue(strpos($result, 'function delete($id = null)') !== false); $this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false); - $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Article deleted', true));") !== false); + $this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Article deleted'));") !== false); $result = $this->Task->bakeActions('Articles', 'admin_', true); @@ -366,7 +366,7 @@ public function xxtestBakeActionsUsingSessions() { * * @return void */ - public function xxtestBakeActionsWithNoSessions() { + public function testBakeActionsWithNoSessions() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s'); if ($skip) { @@ -402,7 +402,7 @@ public function xxtestBakeActionsWithNoSessions() { * * @return void */ - public function xxtestBakeTest() { + public function testBakeTest() { $this->Task->plugin = 'ControllerTest'; $this->Task->connection = 'test_suite'; $this->Task->interactive = false; @@ -420,23 +420,26 @@ public function xxtestBakeTest() { * * @return void */ - public function xxtestInteractive() { + public function testInteractive() { $this->Task->connection = 'test_suite'; - $this->Task->path = '/my/path'; - $this->Task->expects($this->any())->method('in')->will($this->returnValue('1')); - $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); // build interactive - $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); // build no scaffolds - $this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y')); // build normal methods - $this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); // build admin methods - $this->Task->expects($this->at(5))->method('in')->will($this->returnValue('n')); // helpers? - $this->Task->expects($this->at(6))->method('in')->will($this->returnValue('n')); // components? - $this->Task->expects($this->at(7))->method('in')->will($this->returnValue('y')); // use sessions - $this->Task->expects($this->at(8))->method('in')->will($this->returnValue('y')); // looks good - - $this->Task->execute(); + $this->Task->path = '/my/path/'; + + $this->Task->expects($this->at(8))->method('in')->will($this->returnValue('1')); + $this->Task->expects($this->at(12))->method('in')->will($this->returnValue('y')); // build interactive + $this->Task->expects($this->at(13))->method('in')->will($this->returnValue('n')); // build no scaffolds + $this->Task->expects($this->at(14))->method('in')->will($this->returnValue('y')); // build normal methods + $this->Task->expects($this->at(15))->method('in')->will($this->returnValue('n')); // build admin methods + $this->Task->expects($this->at(16))->method('in')->will($this->returnValue('n')); // helpers? + $this->Task->expects($this->at(17))->method('in')->will($this->returnValue('n')); // components? + $this->Task->expects($this->at(18))->method('in')->will($this->returnValue('y')); // use sessions + $this->Task->expects($this->at(25))->method('in')->will($this->returnValue('y')); // looks good $filename = '/my/path/articles_controller.php'; - $this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/')); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, + new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/') + ); + $this->Task->execute(); } /** @@ -445,27 +448,32 @@ public function xxtestInteractive() { * @return void * @access public */ - function xxtestInteractiveAdminMethodsNotInteractive() { + function testInteractiveAdminMethodsNotInteractive() { $this->Task->connection = 'test_suite'; $this->Task->interactive = true; - $this->Task->path = '/my/path'; - $this->Task->setReturnValue('in', '1'); - $this->Task->setReturnValueAt(1, 'in', 'y'); // build interactive - $this->Task->setReturnValueAt(2, 'in', 'n'); // build no scaffolds - $this->Task->setReturnValueAt(3, 'in', 'y'); // build normal methods - $this->Task->setReturnValueAt(4, 'in', 'y'); // build admin methods - $this->Task->setReturnValueAt(5, 'in', 'n'); // helpers? - $this->Task->setReturnValueAt(6, 'in', 'n'); // components? - $this->Task->setReturnValueAt(7, 'in', 'y'); // use sessions - $this->Task->setReturnValueAt(8, 'in', 'y'); // looks good - $this->Task->setReturnValue('createFile', true); - $this->Task->Project->setReturnValue('getPrefix', 'admin_'); + $this->Task->path = '/my/path/'; - $result = $this->Task->execute(); - $this->assertPattern('/admin_index/', $result); + $this->Task->expects($this->at(8))->method('in')->will($this->returnValue('1')); + $this->Task->expects($this->at(12))->method('in')->will($this->returnValue('y')); // build interactive + $this->Task->expects($this->at(13))->method('in')->will($this->returnValue('n')); // build no scaffolds + $this->Task->expects($this->at(14))->method('in')->will($this->returnValue('y')); // build normal methods + $this->Task->expects($this->at(15))->method('in')->will($this->returnValue('y')); // build admin methods + $this->Task->expects($this->at(16))->method('in')->will($this->returnValue('n')); // helpers? + $this->Task->expects($this->at(17))->method('in')->will($this->returnValue('n')); // components? + $this->Task->expects($this->at(18))->method('in')->will($this->returnValue('y')); // use sessions + $this->Task->expects($this->at(25))->method('in')->will($this->returnValue('y')); // looks good + $this->Task->Project->expects($this->any()) + ->method('getPrefix') + ->will($this->returnValue('admin_')); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/'))); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, + new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/') + )->will($this->returnValue(true)); + + $result = $this->Task->execute(); + $this->assertPattern('/admin_index/', $result); } /** @@ -473,7 +481,7 @@ function xxtestInteractiveAdminMethodsNotInteractive() { * * @return void */ - public function xxtestExecuteIntoAll() { + public function testExecuteIntoAll() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute into all could not be run as an Article, Tag or Comment model was already loaded. %s'); if ($skip) { @@ -483,12 +491,14 @@ public function xxtestExecuteIntoAll() { $this->Task->path = '/my/path/'; $this->Task->args = array('all'); - $this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true)); $this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true)); - $this->Task->Test->expectCallCount('bake', 1); + $this->Task->Test->expects($this->once())->method('bake'); $filename = '/my/path/articles_controller.php'; - $this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/')); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, + new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesController/') + )->will($this->returnValue(true)); $this->Task->execute(); } @@ -498,7 +508,7 @@ public function xxtestExecuteIntoAll() { * * @return void */ - public function xxtestExecuteWithController() { + public function testExecuteWithController() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s'); if ($skip) { @@ -509,19 +519,31 @@ public function xxtestExecuteWithController() { $this->Task->args = array('Articles'); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array( - $filename, new PatternExpectation('/\$scaffold/') - )); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, + new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/') + ); $this->Task->execute(); } +/** + * data provider for testExecuteWithControllerNameVariations + * + * @return void + */ + static function nameVariations() { + return array( + array('Articles'), array('Article'), array('article'), array('articles') + ); + } /** * test that both plural and singular forms work for controller baking. * + * @dataProvider nameVariations * @return void */ - public function xxtestExecuteWithControllerNameVariations() { + public function testExecuteWithControllerNameVariations($name) { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s'); if ($skip) { @@ -529,41 +551,12 @@ public function xxtestExecuteWithControllerNameVariations() { } $this->Task->connection = 'test_suite'; $this->Task->path = '/my/path/'; - $this->Task->args = array('Articles'); - - $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array( - $filename, new PatternExpectation('/\$scaffold/') - )); + $this->Task->args = array($name); - $this->Task->execute(); - - $this->Task->args = array('Article'); - $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(1, 'createFile', array( - $filename, new PatternExpectation('/class ArticlesController/') - )); - $this->Task->execute(); - - $this->Task->args = array('article'); - $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(2, 'createFile', array( - $filename, new PatternExpectation('/class ArticlesController/') - )); - - $this->Task->args = array('articles'); - $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(3, 'createFile', array( - $filename, new PatternExpectation('/class ArticlesController/') - )); - $this->Task->execute(); - - $this->Task->args = array('Articles'); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(4, 'createFile', array( - $filename, new PatternExpectation('/class ArticlesController/') - )); - $this->Task->execute(); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/') + ); $this->Task->execute(); } @@ -572,7 +565,7 @@ public function xxtestExecuteWithControllerNameVariations() { * * @return void */ - public function xxtestExecuteWithPublicParam() { + public function testExecuteWithPublicParam() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s'); if ($skip) { @@ -583,10 +576,10 @@ public function xxtestExecuteWithPublicParam() { $this->Task->args = array('Articles', 'public'); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array( - $filename, new NoPatternExpectation('/var \$scaffold/') - )); - + $expected = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')); + $this->Task->expects($this->once())->method('createFile')->with( + $filename, $expected + ); $this->Task->execute(); } @@ -595,7 +588,7 @@ public function xxtestExecuteWithPublicParam() { * * @return void */ - public function xxtestExecuteWithControllerAndBoth() { + public function testExecuteWithControllerAndBoth() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s'); if ($skip) { @@ -607,10 +600,9 @@ public function xxtestExecuteWithControllerAndBoth() { $this->Task->args = array('Articles', 'public', 'admin'); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array( - $filename, new PatternExpectation('/admin_index/') - )); - + $this->Task->expects($this->once())->method('createFile')->with( + $filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/') + ); $this->Task->execute(); } @@ -619,7 +611,7 @@ public function xxtestExecuteWithControllerAndBoth() { * * @return void */ - public function xxtestExecuteWithControllerAndAdmin() { + public function testExecuteWithControllerAndAdmin() { $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s'); if ($skip) { @@ -631,10 +623,9 @@ public function xxtestExecuteWithControllerAndAdmin() { $this->Task->args = array('Articles', 'admin'); $filename = '/my/path/articles_controller.php'; - $this->Task->expectAt(0, 'createFile', array( - $filename, new PatternExpectation('/admin_index/') - )); - + $this->Task->expects($this->once())->method('createFile')->with( + $filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/') + ); $this->Task->execute(); } }