Dispatcher =& new TestControllerTaskMockShellDispatcher(); $this->Task =& new MockControllerTask($this->Dispatcher); $this->Task->Dispatch =& new $this->Dispatcher; $this->Task->Dispatch->shellPaths = Configure::read('shellPaths'); $this->Task->Template =& new TemplateTask($this->Task->Dispatch); $this->Task->Model =& new ControllerMockModelTask($this->Task->Dispatch); } /** * tearDown method * * @return void * @access public */ function endTest() { unset($this->Task, $this->Dispatcher); ClassRegistry::flush(); } /** * test ListAll * * @return void **/ function testListAll() { $this->Task->connection = 'test_suite'; $this->Task->interactive = true; $this->Task->expectAt(1, 'out', array('1. Articles')); $this->Task->expectAt(2, 'out', array('2. ArticlesTags')); $this->Task->expectAt(3, 'out', array('3. Comments')); $this->Task->expectAt(4, 'out', array('4. Tags')); $expected = array('Articles', 'ArticlesTags', 'Comments', 'Tags'); $result = $this->Task->listAll('test_suite'); $this->assertEqual($result, $expected); $this->Task->expectAt(6, 'out', array('1. Articles')); $this->Task->expectAt(7, 'out', array('2. ArticlesTags')); $this->Task->expectAt(8, 'out', array('4. Comments')); $this->Task->expectAt(9, 'out', array('5. Tags')); $this->Task->interactive = false; $result = $this->Task->listAll(); $expected = array('articles', 'articles_tags', 'comments', 'tags'); $this->assertEqual($result, $expected); } /** * Test that getName interacts with the user and returns the controller name. * * @return void **/ function testGetName() { $this->Task->setReturnValue('in', 1); $this->Task->setReturnValueAt(0, 'in', 'q'); $this->Task->expectOnce('_stop'); $this->Task->getName('test_suite'); $this->Task->setReturnValueAt(1, 'in', 1); $result = $this->Task->getName('test_suite'); $expected = 'Articles'; $this->assertEqual($result, $expected); $this->Task->setReturnValueAt(2, 'in', 3); $result = $this->Task->getName('test_suite'); $expected = 'Comments'; $this->assertEqual($result, $expected); $this->Task->setReturnValueAt(3, 'in', 10); $result = $this->Task->getName('test_suite'); $this->Task->expectOnce('err'); } /** * test helper interactions * * @return void **/ function testDoHelpers() { $this->Task->setReturnValueAt(0, 'in', 'n'); $result = $this->Task->doHelpers(); $this->assertEqual($result, array()); $this->Task->setReturnValueAt(1, 'in', 'y'); $this->Task->setReturnValueAt(2, 'in', ' Javascript, Ajax, CustomOne '); $result = $this->Task->doHelpers(); $expected = array('Javascript', 'Ajax', 'CustomOne'); $this->assertEqual($result, $expected); } /** * test component interactions * * @return void **/ function testDoComponents() { $this->Task->setReturnValueAt(0, 'in', 'n'); $result = $this->Task->doComponents(); $this->assertEqual($result, array()); $this->Task->setReturnValueAt(1, 'in', 'y'); $this->Task->setReturnValueAt(2, 'in', ' RequestHandler, Security '); $result = $this->Task->doComponents(); $expected = array('RequestHandler', 'Security'); $this->assertEqual($result, $expected); } /** * test Confirming controller user interaction * * @return void **/ function testConfirmController() { $controller = 'Posts'; $scaffold = false; $helpers = array('Ajax', 'Time'); $components = array('Acl', 'Auth'); $uses = array('Comment', 'User'); $this->Task->expectAt(2, 'out', array("Controller Name:\n\t$controller")); $this->Task->expectAt(3, 'out', array("Helpers:\n\tAjax, Time")); $this->Task->expectAt(4, 'out', array("Components:\n\tAcl, Auth")); $this->Task->expectAt(5, 'out', array("Uses:\n\tComment, User")); $this->Task->confirmController($controller, $scaffold, $uses, $helpers, $components); } /** * test the bake method * * @return void **/ function testBake() { $helpers = array('Ajax', 'Time'); $components = array('Acl', 'Auth'); $uses = array('Comment', 'User'); $this->Task->setReturnValue('createFile', true); $result = $this->Task->bake('Articles', '--actions--', $helpers, $components, $uses); $this->assertPattern('/class ArticlesController extends AppController/', $result); $this->assertPattern('/\$components \= array\(\'Acl\', \'Auth\'\)/', $result); $this->assertPattern('/\$uses \= array\(\'Article\', \'Comment\', \'User\'\)/', $result); $this->assertPattern('/\$helpers \= array\(\'Html\', \'Form\', \'Ajax\', \'Time\'\)/', $result); $this->assertPattern('/\-\-actions\-\-/', $result); $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components, $uses); $this->assertPattern('/class ArticlesController extends AppController/', $result); $this->assertPattern('/var \$scaffold/', $result); $this->assertNoPattern('/helpers/', $result); $this->assertNoPattern('/components/', $result); $this->assertNoPattern('/uses/', $result); } } ?>