2009-05-15 03:17:42 +00:00
< ? php
/**
* ControllerTask Test Case
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) : Rapid Development Framework ( http :// cakephp . org )
* Copyright 2005 - 2009 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice .
*
* @ copyright Copyright 2005 - 2009 , Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2010-01-26 22:03:03 +00:00
* @ link http :// cakephp . org CakePHP ( tm ) Project
2009-05-15 03:17:42 +00:00
* @ package cake
* @ subpackage cake . tests . cases . console . libs . tasks
* @ since CakePHP ( tm ) v 1.3
* @ license MIT License ( http :// www . opensource . org / licenses / mit - license . php )
*/
2009-07-26 01:27:02 +00:00
App :: import ( 'Core' , 'ClassRegistry' );
App :: import ( 'View' , 'Helper' , false );
App :: import ( 'Shell' , 'Shell' , false );
2009-05-15 03:17:42 +00:00
if ( ! defined ( 'DISABLE_AUTO_DISPATCH' )) {
define ( 'DISABLE_AUTO_DISPATCH' , true );
}
if ( ! class_exists ( 'ShellDispatcher' )) {
ob_start ();
$argv = false ;
require CAKE . 'console' . DS . 'cake.php' ;
ob_end_clean ();
}
2009-07-01 00:49:58 +00:00
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php' ;
2009-05-15 03:17:42 +00:00
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php' ;
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php' ;
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php' ;
2009-06-07 00:25:57 +00:00
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php' ;
2009-05-15 03:17:42 +00:00
Mock :: generatePartial (
'ShellDispatcher' , 'TestControllerTaskMockShellDispatcher' ,
array ( 'getInput' , 'stdout' , 'stderr' , '_stop' , '_initEnvironment' )
);
Mock :: generatePartial (
'ControllerTask' , 'MockControllerTask' ,
2009-05-17 03:17:40 +00:00
array ( 'in' , 'hr' , 'out' , 'err' , 'createFile' , '_stop' , '_checkUnitTest' )
2009-05-15 03:17:42 +00:00
);
Mock :: generatePartial (
'ModelTask' , 'ControllerMockModelTask' ,
array ( 'in' , 'out' , 'err' , 'createFile' , '_stop' , '_checkUnitTest' )
);
2009-07-01 00:49:58 +00:00
Mock :: generatePartial (
'ProjectTask' , 'ControllerMockProjectTask' ,
2009-10-07 04:46:13 +00:00
array ( 'in' , 'out' , 'err' , 'createFile' , '_stop' , '_checkUnitTest' , 'getPrefix' )
2009-07-01 00:49:58 +00:00
);
2009-06-07 00:25:57 +00:00
Mock :: generate ( 'TestTask' , 'ControllerMockTestTask' );
2009-05-24 02:56:54 +00:00
$imported = App :: import ( 'Model' , 'Article' );
$imported = $imported || App :: import ( 'Model' , 'Comment' );
$imported = $imported || App :: import ( 'Model' , 'Tag' );
if ( ! $imported ) {
2009-05-19 03:46:20 +00:00
define ( 'ARTICLE_MODEL_CREATED' , true );
App :: import ( 'Core' , 'Model' );
2009-07-24 19:18:37 +00:00
2009-05-19 03:46:20 +00:00
class Article extends Model {
2010-04-04 07:14:00 +00:00
public $name = 'Article' ;
public $hasMany = array ( 'Comment' );
public $hasAndBelongsToMany = array ( 'Tag' );
2009-05-19 03:46:20 +00:00
}
}
2009-05-15 03:17:42 +00:00
/**
* ControllerTaskTest class
*
* @ package cake
* @ subpackage cake . tests . cases . console . libs . tasks
*/
class ControllerTaskTest extends CakeTestCase {
2009-07-24 19:18:37 +00:00
2009-05-15 03:17:42 +00:00
/**
* fixtures
*
* @ var array
2009-11-14 12:18:31 +00:00
* @ access public
*/
2010-04-04 07:14:00 +00:00
public $fixtures = array ( 'core.article' , 'core.comment' , 'core.articles_tag' , 'core.tag' );
2009-07-24 19:18:37 +00:00
2009-05-15 03:17:42 +00:00
/**
2009-07-17 03:55:41 +00:00
* startTest method
2009-05-15 03:17:42 +00:00
*
* @ return void
* @ access public
*/
function startTest () {
$this -> Dispatcher =& new TestControllerTaskMockShellDispatcher ();
$this -> Task =& new MockControllerTask ( $this -> Dispatcher );
2010-03-05 02:57:48 +00:00
$this -> Task -> name = 'ControllerTask' ;
2009-08-02 22:17:31 +00:00
$this -> Task -> Dispatch =& $this -> Dispatcher ;
2009-07-07 03:11:57 +00:00
$this -> Task -> Dispatch -> shellPaths = App :: path ( 'shells' );
2009-05-15 03:17:42 +00:00
$this -> Task -> Template =& new TemplateTask ( $this -> Task -> Dispatch );
2009-07-07 03:11:57 +00:00
$this -> Task -> Template -> params [ 'theme' ] = 'default' ;
2009-05-15 03:17:42 +00:00
$this -> Task -> Model =& new ControllerMockModelTask ( $this -> Task -> Dispatch );
2009-07-01 00:49:58 +00:00
$this -> Task -> Project =& new ControllerMockProjectTask ( $this -> Task -> Dispatch );
2009-07-15 14:14:16 +00:00
$this -> Task -> Test =& new ControllerMockTestTask ();
2009-05-15 03:17:42 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-15 03:17:42 +00:00
/**
2009-07-17 03:55:41 +00:00
* endTest method
2009-05-15 03:17:42 +00:00
*
* @ return void
* @ access public
*/
function endTest () {
unset ( $this -> Task , $this -> Dispatcher );
ClassRegistry :: flush ();
}
2009-07-24 19:18:37 +00:00
2009-05-15 03:17:42 +00:00
/**
* test ListAll
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-15 03:17:42 +00:00
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' );
2009-07-24 19:18:37 +00:00
$this -> assertEqual ( $result , $expected );
2009-05-15 03:17:42 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-15 03:28:27 +00:00
/**
* Test that getName interacts with the user and returns the controller name .
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-15 03:28:27 +00:00
function testGetName () {
2010-03-05 02:57:48 +00:00
$this -> Task -> interactive = true ;
2009-05-15 03:28:27 +00:00
$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' );
}
2009-07-24 19:18:37 +00:00
2009-05-15 04:04:57 +00:00
/**
* test helper interactions
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-15 04:04:57 +00:00
function testDoHelpers () {
2009-06-04 01:35:11 +00:00
$this -> Task -> setReturnValue ( 'in' , 'n' );
2009-05-15 04:04:57 +00:00
$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 );
2009-06-07 16:22:43 +00:00
$this -> Task -> setReturnValueAt ( 3 , 'in' , 'y' );
$this -> Task -> setReturnValueAt ( 4 , 'in' , ' Javascript, Ajax, CustomOne, , ' );
$result = $this -> Task -> doHelpers ();
$expected = array ( 'Javascript' , 'Ajax' , 'CustomOne' );
$this -> assertEqual ( $result , $expected );
2009-05-15 04:04:57 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-15 04:04:57 +00:00
/**
* test component interactions
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-15 04:04:57 +00:00
function testDoComponents () {
2009-06-04 01:35:11 +00:00
$this -> Task -> setReturnValue ( 'in' , 'n' );
2009-05-15 04:04:57 +00:00
$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 );
2009-06-07 16:22:43 +00:00
$this -> Task -> setReturnValueAt ( 3 , 'in' , 'y' );
$this -> Task -> setReturnValueAt ( 4 , 'in' , ' RequestHandler, Security, , ' );
$result = $this -> Task -> doComponents ();
$expected = array ( 'RequestHandler' , 'Security' );
$this -> assertEqual ( $result , $expected );
2009-05-15 04:04:57 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-17 03:17:40 +00:00
/**
* test Confirming controller user interaction
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-17 03:17:40 +00:00
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 \t Ajax, Time " ));
$this -> Task -> expectAt ( 4 , 'out' , array ( " Components: \n \t Acl, Auth " ));
2009-05-19 02:26:16 +00:00
$this -> Task -> confirmController ( $controller , $scaffold , $helpers , $components );
2009-05-17 03:17:40 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-17 04:04:33 +00:00
/**
* test the bake method
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-17 04:04:33 +00:00
function testBake () {
$helpers = array ( 'Ajax' , 'Time' );
$components = array ( 'Acl' , 'Auth' );
$this -> Task -> setReturnValue ( 'createFile' , true );
2009-06-07 00:25:57 +00:00
$result = $this -> Task -> bake ( 'Articles' , '--actions--' , $helpers , $components );
2009-05-17 04:04:33 +00:00
$this -> assertPattern ( '/class ArticlesController extends AppController/' , $result );
$this -> assertPattern ( '/\$components \= array\(\'Acl\', \'Auth\'\)/' , $result );
2009-12-07 20:11:52 +00:00
$this -> assertPattern ( '/\$helpers \= array\(\'Ajax\', \'Time\'\)/' , $result );
2009-05-17 04:04:33 +00:00
$this -> assertPattern ( '/\-\-actions\-\-/' , $result );
2009-06-07 00:25:57 +00:00
$result = $this -> Task -> bake ( 'Articles' , 'scaffold' , $helpers , $components );
2009-05-17 04:04:33 +00:00
$this -> assertPattern ( '/class ArticlesController extends AppController/' , $result );
$this -> assertPattern ( '/var \$scaffold/' , $result );
$this -> assertNoPattern ( '/helpers/' , $result );
$this -> assertNoPattern ( '/components/' , $result );
2009-12-07 20:11:52 +00:00
$result = $this -> Task -> bake ( 'Articles' , '--actions--' , array (), array ());
$this -> assertPattern ( '/class ArticlesController extends AppController/' , $result );
$this -> assertNoPattern ( '/components/' , $result );
$this -> assertNoPattern ( '/helpers/' , $result );
$this -> assertPattern ( '/\-\-actions\-\-/' , $result );
2009-05-19 02:26:16 +00:00
}
2009-07-24 19:18:37 +00:00
2009-06-07 00:25:57 +00:00
/**
* test bake () with a - plugin param
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-06-07 00:25:57 +00:00
function testBakeWithPlugin () {
$this -> Task -> plugin = 'ControllerTest' ;
$helpers = array ( 'Ajax' , 'Time' );
$components = array ( 'Acl' , 'Auth' );
$uses = array ( 'Comment' , 'User' );
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array ( $path , '*' ));
$this -> Task -> bake ( 'Articles' , '--actions--' , array (), array (), array ());
2009-07-24 19:18:37 +00:00
2009-06-17 02:29:48 +00:00
$this -> Task -> plugin = 'controllerTest' ;
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php' ;
$this -> Task -> expectAt ( 1 , 'createFile' , array (
$path , new PatternExpectation ( '/ArticlesController extends ControllerTestAppController/' )));
$this -> Task -> bake ( 'Articles' , '--actions--' , array (), array (), array ());
2009-06-07 00:25:57 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-19 03:46:20 +00:00
/**
* test that bakeActions is creating the correct controller Code . ( Using sessions )
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-19 03:46:20 +00:00
function testBakeActionsUsingSessions () {
2009-07-24 19:18:37 +00:00
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
2009-05-24 02:56:54 +00:00
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s' );
2009-05-19 03:49:44 +00:00
if ( $skip ) {
return ;
}
2009-05-19 03:46:20 +00:00
$result = $this -> Task -> bakeActions ( 'Articles' , null , true );
$this -> assertTrue ( strpos ( $result , 'function index() {' ) !== false );
$this -> assertTrue ( strpos ( $result , '$this->Article->recursive = 0;' ) !== false );
$this -> assertTrue ( strpos ( $result , " \$ this->set('articles', \$ this->paginate()); " ) !== false );
$this -> assertTrue ( strpos ( $result , 'function view($id = null)' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->Session->setFlash(sprintf(__('Invalid %s', true), 'article')); " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->set('article', \$ this->Article->read(null, \$ id) " ) !== false );
$this -> assertTrue ( strpos ( $result , 'function add()' ) !== false );
$this -> assertTrue ( strpos ( $result , 'if (!empty($this->data))' ) !== false );
$this -> assertTrue ( strpos ( $result , 'if ($this->Article->save($this->data))' ) !== false );
2010-03-06 02:30:58 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->Session->setFlash(sprintf(__('The %s has been saved', true), 'article')); " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , 'function edit($id = null)' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.', true), 'article')); " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , 'function delete($id = null)' ) !== false );
2009-08-07 20:27:13 +00:00
$this -> assertTrue ( strpos ( $result , 'if ($this->Article->delete($id))' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->Session->setFlash(sprintf(__('%s deleted', true), 'Article')); " ) !== false );
2009-05-19 03:46:20 +00:00
$result = $this -> Task -> bakeActions ( 'Articles' , 'admin_' , true );
$this -> assertTrue ( strpos ( $result , 'function admin_index() {' ) !== false );
$this -> assertTrue ( strpos ( $result , 'function admin_add()' ) !== false );
$this -> assertTrue ( strpos ( $result , 'function admin_view($id = null)' ) !== false );
$this -> assertTrue ( strpos ( $result , 'function admin_edit($id = null)' ) !== false );
$this -> assertTrue ( strpos ( $result , 'function admin_delete($id = null)' ) !== false );
}
2009-07-24 19:18:37 +00:00
2009-05-19 03:46:20 +00:00
/**
* Test baking with Controller :: flash () or no sessions .
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-19 03:46:20 +00:00
function testBakeActionsWithNoSessions () {
2009-07-24 19:18:37 +00:00
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
2009-05-24 02:56:54 +00:00
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s' );
2009-05-19 03:49:44 +00:00
if ( $skip ) {
return ;
}
2009-05-19 03:46:20 +00:00
$result = $this -> Task -> bakeActions ( 'Articles' , null , false );
$this -> assertTrue ( strpos ( $result , 'function index() {' ) !== false );
$this -> assertTrue ( strpos ( $result , '$this->Article->recursive = 0;' ) !== false );
$this -> assertTrue ( strpos ( $result , " \$ this->set('articles', \$ this->paginate()); " ) !== false );
$this -> assertTrue ( strpos ( $result , 'function view($id = null)' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->flash(sprintf(__('Invalid %s', true), 'article'), array('action' => 'index')) " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->set('article', \$ this->Article->read(null, \$ id) " ) !== false );
$this -> assertTrue ( strpos ( $result , 'function add()' ) !== false );
$this -> assertTrue ( strpos ( $result , 'if (!empty($this->data))' ) !== false );
$this -> assertTrue ( strpos ( $result , 'if ($this->Article->save($this->data))' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->flash(sprintf(__('The %s has been saved.', true), 'article'), array('action' => 'index')) " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , 'function edit($id = null)' ) !== false );
2009-05-19 03:49:44 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->Article->Tag->find('list') " ) !== false );
2009-05-19 04:18:59 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->set(compact('tags')) " ) !== false );
2009-05-19 03:46:20 +00:00
$this -> assertTrue ( strpos ( $result , 'function delete($id = null)' ) !== false );
2009-08-07 20:27:13 +00:00
$this -> assertTrue ( strpos ( $result , 'if ($this->Article->delete($id))' ) !== false );
2010-02-22 03:37:18 +00:00
$this -> assertTrue ( strpos ( $result , " \$ this->flash(sprintf(__('%s deleted', true), 'Article'), array('action' => 'index')) " ) !== false );
2009-05-19 03:46:20 +00:00
}
2009-07-24 19:18:37 +00:00
2009-06-07 00:25:57 +00:00
/**
* test baking a test
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-06-07 00:25:57 +00:00
function testBakeTest () {
$this -> Task -> plugin = 'ControllerTest' ;
$this -> Task -> connection = 'test_suite' ;
2010-03-05 03:02:49 +00:00
$this -> Task -> interactive = false ;
2009-06-07 00:25:57 +00:00
$this -> Task -> Test -> expectOnce ( 'bake' , array ( 'Controller' , 'Articles' ));
$this -> Task -> bakeTest ( 'Articles' );
$this -> assertEqual ( $this -> Task -> plugin , $this -> Task -> Test -> plugin );
$this -> assertEqual ( $this -> Task -> connection , $this -> Task -> Test -> connection );
2010-03-05 03:02:49 +00:00
$this -> assertEqual ( $this -> Task -> interactive , $this -> Task -> Test -> interactive );
2009-06-07 00:25:57 +00:00
}
2009-07-24 19:18:37 +00:00
2009-05-19 04:18:59 +00:00
/**
* test Interactive mode .
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-19 04:18:59 +00:00
function testInteractive () {
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path' ;
2009-06-04 01:35:11 +00:00
$this -> Task -> setReturnValue ( 'in' , '1' );
2009-05-19 04:18:59 +00:00
$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' , 'n' ); // 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 -> execute ();
$filename = '/my/path/articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array ( $filename , new PatternExpectation ( '/class ArticlesController/' )));
}
2009-07-24 19:18:37 +00:00
2009-05-19 02:26:16 +00:00
/**
* test that execute runs all when the first arg == all
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-05-19 02:26:16 +00:00
function testExecuteIntoAll () {
2009-06-04 01:35:11 +00:00
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
2009-05-24 02:56:54 +00:00
'Execute into all could not be run as an Article, Tag or Comment model was already loaded. %s' );
2009-05-19 03:46:20 +00:00
if ( $skip ) {
return ;
}
2009-05-19 02:26:16 +00:00
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path/' ;
$this -> Task -> args = array ( 'all' );
2009-07-15 14:14:16 +00:00
$this -> Task -> setReturnValue ( 'createFile' , true );
$this -> Task -> setReturnValue ( '_checkUnitTest' , true );
$this -> Task -> Test -> expectCallCount ( 'bake' , 1 );
2009-05-19 02:26:16 +00:00
$filename = '/my/path/articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array ( $filename , new PatternExpectation ( '/class ArticlesController/' )));
2009-05-20 04:31:59 +00:00
$this -> Task -> execute ();
}
2009-07-24 19:18:37 +00:00
2009-05-20 04:31:59 +00:00
/**
2009-07-29 16:47:25 +00:00
* test that `cake bake controller foos` works .
2009-05-20 04:31:59 +00:00
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-07-29 16:47:25 +00:00
function testExecuteWithController () {
2009-06-04 01:35:11 +00:00
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
2009-05-24 02:56:54 +00:00
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s' );
2009-05-20 04:31:59 +00:00
if ( $skip ) {
return ;
}
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path/' ;
2009-07-29 16:47:25 +00:00
$this -> Task -> args = array ( 'Articles' );
2009-05-20 04:31:59 +00:00
$filename = '/my/path/articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array (
2009-07-29 16:47:25 +00:00
$filename , new PatternExpectation ( '/\$scaffold/' )
2009-05-20 04:31:59 +00:00
));
$this -> Task -> execute ();
}
2009-07-24 19:18:37 +00:00
2010-03-06 02:30:58 +00:00
/**
* test that both plural and singular forms work for controller baking .
*
* @ return void
* @ access public
*/
function testExecuteWithControllerNameVariations () {
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s' );
if ( $skip ) {
return ;
}
$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 -> 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 -> execute ();
}
2009-05-20 04:31:59 +00:00
/**
2009-07-29 16:47:25 +00:00
* test that `cake bake controller foo scaffold` works .
2009-05-20 04:31:59 +00:00
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-07-29 16:47:25 +00:00
function testExecuteWithPublicParam () {
2009-07-24 19:18:37 +00:00
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
2009-07-29 02:53:29 +00:00
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s' );
if ( $skip ) {
return ;
}
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path/' ;
2009-07-29 16:47:25 +00:00
$this -> Task -> args = array ( 'Articles' , 'public' );
2009-07-29 02:53:29 +00:00
$filename = '/my/path/articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array (
2009-07-29 16:47:25 +00:00
$filename , new NoPatternExpectation ( '/var \$scaffold/' )
2009-07-29 02:53:29 +00:00
));
$this -> Task -> execute ();
}
/**
* test that `cake bake controller foos both` works .
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-07-29 02:53:29 +00:00
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 ) {
return ;
}
2009-10-07 04:46:13 +00:00
$this -> Task -> Project -> setReturnValue ( 'getPrefix' , 'admin_' );
2009-07-29 02:53:29 +00:00
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path/' ;
2009-07-29 16:47:25 +00:00
$this -> Task -> args = array ( 'Articles' , 'public' , 'admin' );
2009-07-29 02:53:29 +00:00
$filename = '/my/path/articles_controller.php' ;
$this -> Task -> expectAt ( 0 , 'createFile' , array (
$filename , new PatternExpectation ( '/admin_index/' )
));
$this -> Task -> execute ();
}
/**
* test that `cake bake controller foos admin` works .
*
* @ return void
2009-11-14 12:18:31 +00:00
* @ access public
*/
2009-07-29 02:53:29 +00:00
function testExecuteWithControllerAndAdmin () {
$skip = $this -> skipIf ( ! defined ( 'ARTICLE_MODEL_CREATED' ),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s' );
2009-05-20 04:31:59 +00:00
if ( $skip ) {
return ;
}
2009-10-07 04:46:13 +00:00
$this -> Task -> Project -> setReturnValue ( 'getPrefix' , 'admin_' );
2009-05-20 04:31:59 +00:00
$this -> Task -> connection = 'test_suite' ;
$this -> Task -> path = '/my/path/' ;
2009-07-29 02:53:29 +00:00
$this -> Task -> args = array ( 'Articles' , 'admin' );
2009-05-20 04:31:59 +00:00
$filename = '/my/path/articles_controller.php' ;
2009-07-29 02:53:29 +00:00
$this -> Task -> expectAt ( 0 , 'createFile' , array (
2009-05-20 04:31:59 +00:00
$filename , new PatternExpectation ( '/admin_index/' )
));
2009-05-19 02:26:16 +00:00
$this -> Task -> execute ();
2009-05-17 04:04:33 +00:00
}
2009-05-15 03:17:42 +00:00
}
?>