a grand renaming so that the most significant portion of the name comes first
This commit is contained in:
@@ -0,0 +1,633 @@
|
||||
<?php
|
||||
/**
|
||||
* ControllerTask Test Case
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @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)
|
||||
*/
|
||||
App::import('Core', 'ClassRegistry');
|
||||
App::import('View', 'Helper', false);
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
||||
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';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestControllerTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ControllerTask', 'MockControllerTask',
|
||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ModelTask', 'ControllerMockModelTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ProjectTask', 'ControllerMockProjectTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix')
|
||||
);
|
||||
|
||||
Mock::generate('TestTask', 'ControllerMockTestTask');
|
||||
|
||||
$imported = App::import('Model', 'Article');
|
||||
$imported = $imported || App::import('Model', 'Comment');
|
||||
$imported = $imported || App::import('Model', 'Tag');
|
||||
|
||||
if (!$imported) {
|
||||
define('ARTICLE_MODEL_CREATED', true);
|
||||
App::import('Core', 'Model');
|
||||
|
||||
class Article extends Model {
|
||||
var $name = 'Article';
|
||||
var $hasMany = array('Comment');
|
||||
var $hasAndBelongsToMany = array('Tag');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ControllerTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ControllerTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestControllerTaskMockShellDispatcher();
|
||||
$this->Task =& new MockControllerTask($this->Dispatcher);
|
||||
$this->Task->name = 'ControllerTask';
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||
$this->Task->Template->params['theme'] = 'default';
|
||||
$this->Task->Model =& new ControllerMockModelTask($this->Task->Dispatch);
|
||||
$this->Task->Project =& new ControllerMockProjectTask($this->Task->Dispatch);
|
||||
$this->Task->Test =& new ControllerMockTestTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Task, $this->Dispatcher);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test ListAll
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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
|
||||
* @access public
|
||||
*/
|
||||
function testGetName() {
|
||||
$this->Task->interactive = true;
|
||||
$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
|
||||
* @access public
|
||||
*/
|
||||
function testDoHelpers() {
|
||||
$this->Task->setReturnValue('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);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* test component interactions
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testDoComponents() {
|
||||
$this->Task->setReturnValue('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);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Confirming controller user interaction
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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->confirmController($controller, $scaffold, $helpers, $components);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the bake method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBake() {
|
||||
$helpers = array('Ajax', 'Time');
|
||||
$components = array('Acl', 'Auth');
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
|
||||
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
|
||||
$this->assertPattern('/class ArticlesController extends AppController/', $result);
|
||||
$this->assertPattern('/\$components \= array\(\'Acl\', \'Auth\'\)/', $result);
|
||||
$this->assertPattern('/\$helpers \= array\(\'Ajax\', \'Time\'\)/', $result);
|
||||
$this->assertPattern('/\-\-actions\-\-/', $result);
|
||||
|
||||
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
|
||||
$this->assertPattern('/class ArticlesController extends AppController/', $result);
|
||||
$this->assertPattern('/var \$scaffold/', $result);
|
||||
$this->assertNoPattern('/helpers/', $result);
|
||||
$this->assertNoPattern('/components/', $result);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() with a -plugin param
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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());
|
||||
|
||||
$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());
|
||||
|
||||
$this->assertEqual($this->Task->Template->templateVars['plugin'], 'ControllerTest');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that bakeActions is creating the correct controller Code. (Using sessions)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeActionsUsingSessions() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s');
|
||||
if ($skip) {
|
||||
return;
|
||||
}
|
||||
$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);
|
||||
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('Invalid article', true));") !== false);
|
||||
$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);
|
||||
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article has been saved', true));") !== false);
|
||||
|
||||
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
|
||||
$this->assertTrue(strpos($result, "\$this->Session->setFlash(__('The article could not be saved. Please, try again.', true));") !== false);
|
||||
|
||||
$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);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test baking with Controller::flash() or no sessions.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeActionsWithNoSessions() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s');
|
||||
if ($skip) {
|
||||
return;
|
||||
}
|
||||
$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);
|
||||
$this->assertTrue(strpos($result, "\$this->flash(__('Invalid article', true), array('action' => 'index'))") !== false);
|
||||
$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);
|
||||
$this->assertTrue(strpos($result, "\$this->flash(__('The article has been saved.', true), array('action' => 'index'))") !== false);
|
||||
|
||||
$this->assertTrue(strpos($result, 'function edit($id = null)') !== false);
|
||||
$this->assertTrue(strpos($result, "\$this->Article->Tag->find('list')") !== false);
|
||||
$this->assertTrue(strpos($result, "\$this->set(compact('tags'))") !== false);
|
||||
|
||||
$this->assertTrue(strpos($result, 'function delete($id = null)') !== false);
|
||||
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
|
||||
$this->assertTrue(strpos($result, "\$this->flash(__('Article deleted', true), array('action' => 'index'))") !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking a test
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeTest() {
|
||||
$this->Task->plugin = 'ControllerTest';
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->interactive = false;
|
||||
|
||||
$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);
|
||||
$this->assertEqual($this->Task->interactive, $this->Task->Test->interactive);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Interactive mode.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$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', '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/')));
|
||||
}
|
||||
|
||||
/**
|
||||
* test Interactive mode.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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_');
|
||||
|
||||
$result = $this->Task->execute();
|
||||
$this->assertPattern('/admin_index/', $result);
|
||||
|
||||
$filename = '/my/path/articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute runs all when the first arg == all
|
||||
*
|
||||
* @return void
|
||||
* @access 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) {
|
||||
return;
|
||||
}
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
||||
$this->Task->Test->expectCallCount('bake', 1);
|
||||
|
||||
$filename = '/my/path/articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that `cake bake controller foos` works.
|
||||
*
|
||||
* @return void
|
||||
* @access 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) {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that `cake bake controller foo scaffold` works.
|
||||
*
|
||||
* @return void
|
||||
* @access 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) {
|
||||
return;
|
||||
}
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('Articles', 'public');
|
||||
|
||||
$filename = '/my/path/articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
$filename, new NoPatternExpectation('/var \$scaffold/')
|
||||
));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that `cake bake controller foos both` works.
|
||||
*
|
||||
* @return void
|
||||
* @access 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) {
|
||||
return;
|
||||
}
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$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->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that `cake bake controller foos admin` works.
|
||||
*
|
||||
* @return void
|
||||
* @access 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) {
|
||||
return;
|
||||
}
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$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->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* DBConfigTask Test Case
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @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)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
||||
//require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestDbConfigTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'DbConfigTask', 'MockDbConfigTask',
|
||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
class TEST_DATABASE_CONFIG {
|
||||
var $default = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'database_name',
|
||||
'prefix' => '',
|
||||
);
|
||||
|
||||
var $otherOne = array(
|
||||
'driver' => 'mysql',
|
||||
'persistent' => false,
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'other_one',
|
||||
'prefix' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* DbConfigTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class DbConfigTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestDbConfigTaskMockShellDispatcher();
|
||||
$this->Task =& new MockDbConfigTask($this->Dispatcher);
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
|
||||
$this->Task->params['working'] = rtrim(APP, DS);
|
||||
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Task, $this->Dispatcher);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getConfig method.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetConfig() {
|
||||
$this->Task->setReturnValueAt(0, 'in', 'otherOne');
|
||||
$result = $this->Task->getConfig();
|
||||
$this->assertEqual($result, 'otherOne');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that initialize sets the path up.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testInitialize() {
|
||||
$this->assertTrue(empty($this->Task->path));
|
||||
$this->Task->initialize();
|
||||
$this->assertFalse(empty($this->Task->path));
|
||||
$this->assertEqual($this->Task->path, APP . 'config' . DS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute and by extension __interactive
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoInteractive() {
|
||||
$this->Task->initialize();
|
||||
|
||||
$this->Task->expectOnce('_stop');
|
||||
$this->Task->setReturnValue('in', 'y');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'default');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'localhost');
|
||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(4, 'in', 'root');
|
||||
$this->Task->setReturnValueAt(5, 'in', 'password');
|
||||
$this->Task->setReturnValueAt(6, 'in', 'cake_test');
|
||||
$this->Task->setReturnValueAt(7, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(8, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(9, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(10, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(11, 'in', 'n');
|
||||
|
||||
$result = $this->Task->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* ExtractTaskTest file
|
||||
*
|
||||
* Test Case for i18n extraction shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.2.0.7726
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', 'Folder');
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
|
||||
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
/**
|
||||
* ExtractTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ExtractTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setUp() {
|
||||
$this->Dispatcher =& new TestExtractTaskMockShellDispatcher();
|
||||
$this->Task =& new ExtractTask($this->Dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function tearDown() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* testExecute method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecute() {
|
||||
$path = TMP . 'tests' . DS . 'extract_task_test';
|
||||
new Folder($path . DS . 'locale', true);
|
||||
|
||||
$this->Task->interactive = false;
|
||||
|
||||
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
||||
$this->Task->params['output'] = $path . DS;
|
||||
$this->Task->Dispatch->expectNever('stderr');
|
||||
$this->Task->Dispatch->expectNever('_stop');
|
||||
$this->Task->execute();
|
||||
$this->assertTrue(file_exists($path . DS . 'default.pot'));
|
||||
$result = file_get_contents($path . DS . 'default.pot');
|
||||
|
||||
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// home.ctp
|
||||
$pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "The %s is being used for caching. To change the config edit ';
|
||||
$pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Your cache is NOT working. Please check ';
|
||||
$pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Rename config\/database.php.default to ';
|
||||
$pattern .= 'config\/database.php"\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
|
||||
$pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// extract.ctp
|
||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
|
||||
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
|
||||
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
||||
$pattern .= '\#: (\\\\|\/)home\.ctp:74\n';
|
||||
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
// extract.ctp - reading the domain.pot
|
||||
$result = file_get_contents($path . DS . 'domain.pot');
|
||||
|
||||
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
||||
$this->assertNoPattern($pattern, $result);
|
||||
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
||||
$this->assertNoPattern($pattern, $result);
|
||||
|
||||
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
|
||||
$Folder = new Folder($path);
|
||||
$Folder->delete();
|
||||
}
|
||||
function getTests() {
|
||||
return array('start', 'startCase', 'testExtractMultiplePaths', 'endCase', 'end');
|
||||
}
|
||||
|
||||
/**
|
||||
* test extract can read more than one path.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testExtractMultiplePaths() {
|
||||
$path = TMP . 'tests' . DS . 'extract_task_test';
|
||||
new Folder($path . DS . 'locale', true);
|
||||
|
||||
$this->Task->interactive = false;
|
||||
|
||||
$this->Task->params['paths'] =
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
|
||||
|
||||
$this->Task->params['output'] = $path . DS;
|
||||
$this->Task->Dispatch->expectNever('stderr');
|
||||
$this->Task->Dispatch->expectNever('_stop');
|
||||
$this->Task->execute();
|
||||
|
||||
$result = file_get_contents($path . DS . 'default.pot');
|
||||
|
||||
$pattern = '/msgid "Add User"/';
|
||||
$this->assertPattern($pattern, $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* FixtureTask Test case
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @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)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestFixtureTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'FixtureTask', 'MockFixtureTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'Shell', 'MockFixtureModelTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', 'getName', 'getTable', 'listAll')
|
||||
);
|
||||
|
||||
/**
|
||||
* FixtureTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class FixtureTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.comment', 'core.datatype', 'core.binary_test');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestFixtureTaskMockShellDispatcher();
|
||||
$this->Task =& new MockFixtureTask();
|
||||
$this->Task->Model =& new MockFixtureModelTask();
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
$this->Task->Template->initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Task, $this->Dispatcher);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that initialize sets the path
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testConstruct() {
|
||||
$this->Dispatch->params['working'] = DS . 'my' . DS . 'path';
|
||||
$Task =& new FixtureTask($this->Dispatch);
|
||||
|
||||
$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
|
||||
$this->assertEqual($Task->path, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test import option array generation
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testImportOptions() {
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
|
||||
$result = $this->Task->importOptions('Article');
|
||||
$expected = array('schema' => 'Article', 'records' => true);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(4, 'in', 'n');
|
||||
|
||||
$result = $this->Task->importOptions('Article');
|
||||
$expected = array();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(5, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(6, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(7, 'in', 'y');
|
||||
$result = $this->Task->importOptions('Article');
|
||||
$expected = array('fromTable' => true);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test generating a fixture with database conditions.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testImportRecordsFromDatabaseWithConditions() {
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', 'WHERE 1=1 LIMIT 10');
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$result = $this->Task->bake('Article', false, array('fromTable' => true, 'schema' => 'Article', 'records' => false));
|
||||
|
||||
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
|
||||
$this->assertPattern('/var \$records/', $result);
|
||||
$this->assertPattern('/var \$import/', $result);
|
||||
$this->assertPattern("/'title' => 'First Article'/", $result, 'Missing import data %s');
|
||||
$this->assertPattern('/Second Article/', $result, 'Missing import data %s');
|
||||
$this->assertPattern('/Third Article/', $result, 'Missing import data %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute passes runs bake depending with named model.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNamedModel() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('article');
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute passes runs bake depending with named model.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNamedModelVariations() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
|
||||
$this->Task->args = array('article');
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('articles');
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('Articles');
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('Article');
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute runs all() when args[0] = all
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoAll() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));
|
||||
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$filename = '/my/path/comment_fixture.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test using all() with -count and -records
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testAllWithCountAndRecordsFlags() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
$this->Task->params = array('count' => 10, 'records' => true);
|
||||
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));
|
||||
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/title\' => \'Third Article\'/')));
|
||||
|
||||
$filename = '/my/path/comment_fixture.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/comment\' => \'First Comment for First Article/')));
|
||||
$this->Task->expectCallCount('createFile', 2);
|
||||
$this->Task->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* test interactive mode of execute
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
|
||||
$this->Task->setReturnValue('in', 'y');
|
||||
$this->Task->Model->setReturnValue('getName', 'Article');
|
||||
$this->Task->Model->setReturnValue('getTable', 'articles', array('Article'));
|
||||
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that bake works
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBake() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
|
||||
$result = $this->Task->bake('Article');
|
||||
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
|
||||
$this->assertPattern('/var \$fields/', $result);
|
||||
$this->assertPattern('/var \$records/', $result);
|
||||
$this->assertNoPattern('/var \$import/', $result);
|
||||
|
||||
$result = $this->Task->bake('Article', 'comments');
|
||||
$this->assertPattern('/class ArticleFixture extends CakeTestFixture/', $result);
|
||||
$this->assertPattern('/var \$name \= \'Article\';/', $result);
|
||||
$this->assertPattern('/var \$table \= \'comments\';/', $result);
|
||||
$this->assertPattern('/var \$fields = array\(/', $result);
|
||||
|
||||
$result = $this->Task->bake('Article', 'comments', array('records' => true));
|
||||
$this->assertPattern("/var \\\$import \= array\('records' \=\> true\);/", $result);
|
||||
$this->assertNoPattern('/var \$records/', $result);
|
||||
|
||||
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article'));
|
||||
$this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\);/", $result);
|
||||
$this->assertNoPattern('/var \$fields/', $result);
|
||||
|
||||
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true));
|
||||
$this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true\);/", $result);
|
||||
$this->assertNoPattern('/var \$fields/', $result);
|
||||
$this->assertNoPattern('/var \$records/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test record generation with float and binary types
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testRecordGenerationForBinaryAndFloat() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
|
||||
$result = $this->Task->bake('Article', 'datatypes');
|
||||
$this->assertPattern("/'float_field' => 1/", $result);
|
||||
|
||||
$result = $this->Task->bake('Article', 'binary_tests');
|
||||
$this->assertPattern("/'data' => 'Lorem ipsum dolor sit amet'/", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that file generation includes headers and correct path for plugins.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGenerateFixtureFile() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$filename = '/my/path/article_fixture.php';
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/Article/')));
|
||||
$result = $this->Task->generateFixtureFile('Article', array());
|
||||
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/\<\?php(.*)\?\>/ms')));
|
||||
$result = $this->Task->generateFixtureFile('Article', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* test generating files into plugins.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGeneratePluginFixtureFile() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->plugin = 'TestFixture';
|
||||
$filename = APP . 'plugins' . DS . 'test_fixture' . DS . 'tests' . DS . 'fixtures' . DS . 'article_fixture.php';
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/Article/')));
|
||||
$result = $this->Task->generateFixtureFile('Article', array());
|
||||
}
|
||||
}
|
@@ -0,0 +1,909 @@
|
||||
<?php
|
||||
/**
|
||||
* ModelTaskTest file
|
||||
*
|
||||
* Test Case for test generation shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.2.6
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'ModelTask', 'MockModelTask',
|
||||
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
Mock::generate(
|
||||
'Model', 'MockModelTaskModel'
|
||||
);
|
||||
|
||||
Mock::generate(
|
||||
'FixtureTask', 'MockModelTaskFixtureTask'
|
||||
);
|
||||
|
||||
/**
|
||||
* ModelTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ModelTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag', 'core.category_thread');
|
||||
|
||||
/**
|
||||
* starTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
|
||||
$this->Task =& new MockModelTask($this->Dispatcher);
|
||||
$this->Task->name = 'ModelTask';
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||
$this->Task->Fixture =& new MockModelTaskFixtureTask();
|
||||
$this->Task->Test =& new MockModelTaskFixtureTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Task, $this->Dispatcher);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that listAll scans the database connection and lists all the tables in it.s
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testListAll() {
|
||||
$this->Task->expectAt(1, 'out', array('1. Article'));
|
||||
$this->Task->expectAt(2, 'out', array('2. ArticlesTag'));
|
||||
$this->Task->expectAt(3, 'out', array('3. CategoryThread'));
|
||||
$this->Task->expectAt(4, 'out', array('4. Comment'));
|
||||
$this->Task->expectAt(5, 'out', array('5. Tag'));
|
||||
$result = $this->Task->listAll('test_suite');
|
||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->expectAt(7, 'out', array('1. Article'));
|
||||
$this->Task->expectAt(8, 'out', array('2. ArticlesTag'));
|
||||
$this->Task->expectAt(9, 'out', array('3. CategoryThread'));
|
||||
$this->Task->expectAt(10, 'out', array('4. Comment'));
|
||||
$this->Task->expectAt(11, 'out', array('5. Tag'));
|
||||
|
||||
$this->Task->connection = 'test_suite';
|
||||
$result = $this->Task->listAll();
|
||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that getName interacts with the user and returns the model name.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
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 = 'Article';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(2, 'in', 4);
|
||||
$result = $this->Task->getName('test_suite');
|
||||
$expected = 'Comment';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(3, 'in', 10);
|
||||
$result = $this->Task->getName('test_suite');
|
||||
$this->Task->expectOnce('err');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test table name interactions
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetTableName() {
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$result = $this->Task->getTable('Article', 'test_suite');
|
||||
$expected = 'articles';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'my_table');
|
||||
$result = $this->Task->getTable('Article', 'test_suite');
|
||||
$expected = 'my_table';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that initializing the validations works.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testInitValidations() {
|
||||
$result = $this->Task->initValidations();
|
||||
$this->assertTrue(in_array('notempty', $result));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that individual field validation works, with interactive = false
|
||||
* tests the guessing features of validation
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFieldValidationGuessing() {
|
||||
$this->Task->interactive = false;
|
||||
$this->Task->initValidations();
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
$expected = array('notempty' => 'notempty');
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
|
||||
$expected = array('date' => 'date');
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
|
||||
$expected = array('time' => 'time');
|
||||
|
||||
$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
$expected = array('email' => 'email');
|
||||
|
||||
$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
|
||||
$expected = array('numeric' => 'numeric');
|
||||
|
||||
$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
|
||||
$expected = array('numeric' => 'numeric');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that interactive field validation works and returns multiple validators.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testInteractiveFieldValidation() {
|
||||
$this->Task->initValidations();
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', '19');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', '15');
|
||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that a bogus response doesn't cause errors to bubble up.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testInteractiveFieldValidationWithBogusResponse() {
|
||||
$this->Task->initValidations();
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', '999999');
|
||||
$this->Task->setReturnValueAt(1, 'in', '19');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
||||
$this->Task->expectAt(4, 'out', array(new PatternExpectation('/make a valid/')));
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
$expected = array('notempty' => 'notempty');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that a regular expression can be used for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testInteractiveFieldValidationWithRegexp() {
|
||||
$this->Task->initValidations();
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', '/^[a-z]{0,9}$/');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
||||
|
||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the validation Generation routine
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testNonInteractiveDoValidation() {
|
||||
$Model =& new MockModelTaskModel();
|
||||
$Model->primaryKey = 'id';
|
||||
$Model->setReturnValue('schema', array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'length' => 11,
|
||||
'null' => false,
|
||||
'key' => 'primary',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'string',
|
||||
'length' => 20,
|
||||
'null' => false,
|
||||
),
|
||||
'email' => array(
|
||||
'type' => 'string',
|
||||
'length' => 255,
|
||||
'null' => false,
|
||||
),
|
||||
'some_date' => array(
|
||||
'type' => 'date',
|
||||
'length' => '',
|
||||
'null' => false,
|
||||
),
|
||||
'some_time' => array(
|
||||
'type' => 'time',
|
||||
'length' => '',
|
||||
'null' => false,
|
||||
),
|
||||
'created' => array(
|
||||
'type' => 'datetime',
|
||||
'length' => '',
|
||||
'null' => false,
|
||||
)
|
||||
));
|
||||
$this->Task->interactive = false;
|
||||
|
||||
$result = $this->Task->doValidation($Model);
|
||||
$expected = array(
|
||||
'name' => array(
|
||||
'notempty' => 'notempty'
|
||||
),
|
||||
'email' => array(
|
||||
'email' => 'email',
|
||||
),
|
||||
'some_date' => array(
|
||||
'date' => 'date'
|
||||
),
|
||||
'some_time' => array(
|
||||
'time' => 'time'
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that finding primary key works
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFindPrimaryKey() {
|
||||
$fields = array(
|
||||
'one' => array(),
|
||||
'two' => array(),
|
||||
'key' => array('key' => 'primary')
|
||||
);
|
||||
$this->Task->expectAt(0, 'in', array('*', null, 'key'));
|
||||
$this->Task->setReturnValue('in', 'my_field');
|
||||
$result = $this->Task->findPrimaryKey($fields);
|
||||
$expected = 'my_field';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test finding Display field
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFindDisplayField() {
|
||||
$fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
|
||||
'created' => array(), 'modified' => array());
|
||||
|
||||
$this->Task->setReturnValue('in', 'n');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'n');
|
||||
$result = $this->Task->findDisplayField($fields);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', 2);
|
||||
$result = $this->Task->findDisplayField($fields);
|
||||
$this->assertEqual($result, 'tagname');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that belongsTo generation works.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBelongsToGeneration() {
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'Comment'));
|
||||
$result = $this->Task->findBelongsTo($model, array());
|
||||
$expected = array(
|
||||
'belongsTo' => array(
|
||||
array(
|
||||
'alias' => 'Article',
|
||||
'className' => 'Article',
|
||||
'foreignKey' => 'article_id',
|
||||
),
|
||||
array(
|
||||
'alias' => 'User',
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
||||
$result = $this->Task->findBelongsTo($model, array());
|
||||
$expected = array(
|
||||
'belongsTo' => array(
|
||||
array(
|
||||
'alias' => 'ParentCategoryThread',
|
||||
'className' => 'CategoryThread',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that hasOne and/or hasMany relations are generated properly.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testHasManyHasOneGeneration() {
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->listAll();
|
||||
$result = $this->Task->findHasOneAndMany($model, array());
|
||||
$expected = array(
|
||||
'hasMany' => array(
|
||||
array(
|
||||
'alias' => 'Comment',
|
||||
'className' => 'Comment',
|
||||
'foreignKey' => 'article_id',
|
||||
),
|
||||
),
|
||||
'hasOne' => array(
|
||||
array(
|
||||
'alias' => 'Comment',
|
||||
'className' => 'Comment',
|
||||
'foreignKey' => 'article_id',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
||||
$result = $this->Task->findHasOneAndMany($model, array());
|
||||
$expected = array(
|
||||
'hasOne' => array(
|
||||
array(
|
||||
'alias' => 'ChildCategoryThread',
|
||||
'className' => 'CategoryThread',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
),
|
||||
'hasMany' => array(
|
||||
array(
|
||||
'alias' => 'ChildCategoryThread',
|
||||
'className' => 'CategoryThread',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that HABTM generation works
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testHasAndBelongsToManyGeneration() {
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->listAll();
|
||||
$result = $this->Task->findHasAndBelongsToMany($model, array());
|
||||
$expected = array(
|
||||
'hasAndBelongsToMany' => array(
|
||||
array(
|
||||
'alias' => 'Tag',
|
||||
'className' => 'Tag',
|
||||
'foreignKey' => 'article_id',
|
||||
'joinTable' => 'articles_tags',
|
||||
'associationForeignKey' => 'tag_id',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test non interactive doAssociations
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testDoAssociationsNonInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->interactive = false;
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'Article'));
|
||||
$result = $this->Task->doAssociations($model);
|
||||
$expected = array(
|
||||
'hasMany' => array(
|
||||
array(
|
||||
'alias' => 'Comment',
|
||||
'className' => 'Comment',
|
||||
'foreignKey' => 'article_id',
|
||||
),
|
||||
),
|
||||
'hasAndBelongsToMany' => array(
|
||||
array(
|
||||
'alias' => 'Tag',
|
||||
'className' => 'Tag',
|
||||
'foreignKey' => 'article_id',
|
||||
'joinTable' => 'articles_tags',
|
||||
'associationForeignKey' => 'tag_id',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the fixutre object is correctly called.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeFixture() {
|
||||
$this->Task->plugin = 'test_plugin';
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->Fixture->expectAt(0, 'bake', array('Article', 'articles'));
|
||||
$this->Task->bakeFixture('Article', 'articles');
|
||||
|
||||
$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
|
||||
$this->assertEqual($this->Task->connection, $this->Task->Fixture->connection);
|
||||
$this->assertEqual($this->Task->interactive, $this->Task->Fixture->interactive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the test object is correctly called.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeTest() {
|
||||
$this->Task->plugin = 'test_plugin';
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
|
||||
$this->Task->bakeTest('Article');
|
||||
|
||||
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
||||
$this->assertEqual($this->Task->connection, $this->Task->Test->connection);
|
||||
$this->assertEqual($this->Task->interactive, $this->Task->Test->interactive);
|
||||
}
|
||||
|
||||
/**
|
||||
* test confirming of associations, and that when an association is hasMany
|
||||
* a question for the hasOne is also not asked.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testConfirmAssociations() {
|
||||
$associations = array(
|
||||
'hasOne' => array(
|
||||
array(
|
||||
'alias' => 'ChildCategoryThread',
|
||||
'className' => 'CategoryThread',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
),
|
||||
'hasMany' => array(
|
||||
array(
|
||||
'alias' => 'ChildCategoryThread',
|
||||
'className' => 'CategoryThread',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
),
|
||||
'belongsTo' => array(
|
||||
array(
|
||||
'alias' => 'User',
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
),
|
||||
)
|
||||
);
|
||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$result = $this->Task->confirmAssociations($model, $associations);
|
||||
$this->assertTrue(empty($result['hasOne']));
|
||||
|
||||
$this->Task->setReturnValue('in', 'n');
|
||||
$result = $this->Task->confirmAssociations($model, $associations);
|
||||
$this->assertTrue(empty($result['hasMany']));
|
||||
$this->assertTrue(empty($result['hasOne']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that inOptions generates questions and only accepts a valid answer
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testInOptions() {
|
||||
$options = array('one', 'two', 'three');
|
||||
$this->Task->expectAt(0, 'out', array('1. one'));
|
||||
$this->Task->expectAt(1, 'out', array('2. two'));
|
||||
$this->Task->expectAt(2, 'out', array('3. three'));
|
||||
$this->Task->setReturnValueAt(0, 'in', 10);
|
||||
|
||||
$this->Task->expectAt(3, 'out', array('1. one'));
|
||||
$this->Task->expectAt(4, 'out', array('2. two'));
|
||||
$this->Task->expectAt(5, 'out', array('3. three'));
|
||||
$this->Task->setReturnValueAt(1, 'in', 2);
|
||||
$result = $this->Task->inOptions($options, 'Pick a number');
|
||||
$this->assertEqual($result, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking validation
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeValidation() {
|
||||
$validate = array(
|
||||
'name' => array(
|
||||
'notempty' => 'notempty'
|
||||
),
|
||||
'email' => array(
|
||||
'email' => 'email',
|
||||
),
|
||||
'some_date' => array(
|
||||
'date' => 'date'
|
||||
),
|
||||
'some_time' => array(
|
||||
'time' => 'time'
|
||||
)
|
||||
);
|
||||
$result = $this->Task->bake('Article', compact('validate'));
|
||||
$this->assertPattern('/class Article extends AppModel \{/', $result);
|
||||
$this->assertPattern('/\$name \= \'Article\'/', $result);
|
||||
$this->assertPattern('/\$validate \= array\(/', $result);
|
||||
$expected = <<< STRINGEND
|
||||
array(
|
||||
'notempty' => array(
|
||||
'rule' => array('notempty'),
|
||||
//'message' => 'Your custom message here',
|
||||
//'allowEmpty' => false,
|
||||
//'required' => false,
|
||||
//'last' => false, // Stop validation after this rule
|
||||
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
||||
),
|
||||
STRINGEND;
|
||||
$this->assertPattern('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking relations
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeRelations() {
|
||||
$associations = array(
|
||||
'belongsTo' => array(
|
||||
array(
|
||||
'alias' => 'SomethingElse',
|
||||
'className' => 'SomethingElse',
|
||||
'foreignKey' => 'something_else_id',
|
||||
),
|
||||
array(
|
||||
'alias' => 'User',
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
),
|
||||
),
|
||||
'hasOne' => array(
|
||||
array(
|
||||
'alias' => 'OtherModel',
|
||||
'className' => 'OtherModel',
|
||||
'foreignKey' => 'other_model_id',
|
||||
),
|
||||
),
|
||||
'hasMany' => array(
|
||||
array(
|
||||
'alias' => 'Comment',
|
||||
'className' => 'Comment',
|
||||
'foreignKey' => 'parent_id',
|
||||
),
|
||||
),
|
||||
'hasAndBelongsToMany' => array(
|
||||
array(
|
||||
'alias' => 'Tag',
|
||||
'className' => 'Tag',
|
||||
'foreignKey' => 'article_id',
|
||||
'joinTable' => 'articles_tags',
|
||||
'associationForeignKey' => 'tag_id',
|
||||
),
|
||||
)
|
||||
);
|
||||
$result = $this->Task->bake('Article', compact('associations'));
|
||||
$this->assertPattern('/\$hasAndBelongsToMany \= array\(/', $result);
|
||||
$this->assertPattern('/\$hasMany \= array\(/', $result);
|
||||
$this->assertPattern('/\$belongsTo \= array\(/', $result);
|
||||
$this->assertPattern('/\$hasOne \= array\(/', $result);
|
||||
$this->assertPattern('/Tag/', $result);
|
||||
$this->assertPattern('/OtherModel/', $result);
|
||||
$this->assertPattern('/SomethingElse/', $result);
|
||||
$this->assertPattern('/Comment/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() with a -plugin param
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeWithPlugin() {
|
||||
$this->Task->plugin = 'ControllerTest';
|
||||
|
||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
||||
$this->Task->bake('Article', array(), array());
|
||||
|
||||
$this->Task->plugin = 'controllerTest';
|
||||
|
||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
||||
$this->Task->expectAt(1, 'createFile', array(
|
||||
$path, new PatternExpectation('/Article extends ControllerTestAppModel/')));
|
||||
$this->Task->bake('Article', array(), array());
|
||||
|
||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute passes runs bake depending with named model.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNamedModel() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('article');
|
||||
$filename = '/my/path/article.php';
|
||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute passes with different inflections of the same name.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNamedModelVariations() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
||||
|
||||
$this->Task->args = array('article');
|
||||
$filename = '/my/path/article.php';
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('Articles');
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('articles');
|
||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute with a model name picks up hasMany associations.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNamedModelHasManyCreated() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('article');
|
||||
$filename = '/my/path/article.php';
|
||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation("/'Comment' \=\> array\(/")));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute runs all() when args[0] = all
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoAll() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
||||
|
||||
$this->Task->Fixture->expectCallCount('bake', 5);
|
||||
$this->Task->Test->expectCallCount('bake', 5);
|
||||
|
||||
$filename = '/my/path/article.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
||||
|
||||
$filename = '/my/path/articles_tag.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
||||
|
||||
$filename = '/my/path/category_thread.php';
|
||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
||||
|
||||
$filename = '/my/path/comment.php';
|
||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
||||
|
||||
$filename = '/my/path/tag.php';
|
||||
$this->Task->expectAt(4, 'createFile', array($filename, new PatternExpectation('/class Tag/')));
|
||||
|
||||
$this->Task->execute();
|
||||
|
||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that skipTables changes how all() works.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSkipTablesAndAll() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
||||
$this->Task->skipTables = array('tags');
|
||||
|
||||
$this->Task->Fixture->expectCallCount('bake', 4);
|
||||
$this->Task->Test->expectCallCount('bake', 4);
|
||||
|
||||
$filename = '/my/path/article.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
||||
|
||||
$filename = '/my/path/articles_tag.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
||||
|
||||
$filename = '/my/path/category_thread.php';
|
||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
||||
|
||||
$filename = '/my/path/comment.php';
|
||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the interactive side of bake.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->interactive = true;
|
||||
|
||||
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
|
||||
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
|
||||
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
|
||||
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
|
||||
$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
|
||||
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
|
||||
$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
|
||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
||||
|
||||
$this->Task->Test->expectOnce('bake');
|
||||
$this->Task->Fixture->expectOnce('bake');
|
||||
|
||||
$filename = '/my/path/article.php';
|
||||
$this->Task->expectOnce('createFile');
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test using bake interactively with a table that does not exist.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNonExistantTableName() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
|
||||
$this->Task->expectOnce('_stop');
|
||||
$this->Task->expectOnce('err');
|
||||
|
||||
$this->Task->setReturnValueAt(0, 'in', 'Foobar');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/**
|
||||
* PluginTask Test file
|
||||
*
|
||||
* Test Case for plugin generation shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.3.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestPluginTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'PluginTask', 'MockPluginTask',
|
||||
array('in', '_stop', 'err', 'out', 'createFile')
|
||||
);
|
||||
|
||||
Mock::generate('ModelTask', 'PluginTestMockModelTask');
|
||||
|
||||
/**
|
||||
* PluginTaskPlugin class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class PluginTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestPluginTaskMockShellDispatcher();
|
||||
$this->Dispatcher->shellPaths = App::path('shells');
|
||||
$this->Task =& new MockPluginTask($this->Dispatcher);
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->path = TMP . 'tests' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* startCase methods
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startCase() {
|
||||
$this->_paths = $paths = App::path('plugins');
|
||||
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
|
||||
App::build(array('plugins' => $paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* endCase
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endCase() {
|
||||
App::build(array('plugins' => $this->_paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake()
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeFoldersAndFiles() {
|
||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->bake('BakeTestPlugin');
|
||||
|
||||
$path = $this->Task->path . 'bake_test_plugin';
|
||||
$this->assertTrue(is_dir($path), 'No plugin dir %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'config'), 'No config dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'config' . DS . 'schema'), 'No schema dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'config' . DS . 'schema' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'controllers' . DS . 'components' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'models' . DS . 'datasources'), 'No datasources dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
||||
|
||||
$this->assertTrue(
|
||||
is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'components'), 'No components cases dir %s'
|
||||
);
|
||||
$this->assertTrue(
|
||||
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file %s'
|
||||
);
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors'), 'No behaviors cases dir %s');
|
||||
$this->assertTrue(
|
||||
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s'
|
||||
);
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'helpers'), 'No helpers cases dir %s');
|
||||
$this->assertTrue(
|
||||
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file %s'
|
||||
);
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'models'), 'No models cases dir %s');
|
||||
$this->assertTrue(
|
||||
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file %s'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'controllers'),
|
||||
'No controllers cases dir %s'
|
||||
);
|
||||
$this->assertTrue(
|
||||
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file %s'
|
||||
);
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'vendors'), 'No vendors dir %s');
|
||||
|
||||
$this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells'), 'No vendors shells dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks'), 'No vendors shells tasks dir %s');
|
||||
$this->assertTrue(file_exists($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
|
||||
|
||||
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
||||
|
||||
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
||||
|
||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute with no args, flowing into interactive,
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithNoArgs() {
|
||||
$this->Task->setReturnValueAt(0, 'in', 'TestPlugin');
|
||||
$this->Task->setReturnValueAt(1, 'in', '3');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
||||
|
||||
$path = $this->Task->path . 'test_plugin';
|
||||
$file = $path . DS . 'test_plugin_app_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
||||
|
||||
$file = $path . DS . 'test_plugin_app_model.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
||||
|
||||
$this->Task->args = array();
|
||||
$this->Task->execute();
|
||||
|
||||
$Folder =& new Folder($path);
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Execute
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithOneArg() {
|
||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->Dispatch->args = array('BakeTestPlugin');
|
||||
$this->Task->args =& $this->Task->Dispatch->args;
|
||||
|
||||
$path = $this->Task->path . 'bake_test_plugin';
|
||||
$file = $path . DS . 'bake_test_plugin_app_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
|
||||
|
||||
$file = $path . DS . 'bake_test_plugin_app_model.php';
|
||||
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
|
||||
|
||||
$this->Task->execute();
|
||||
|
||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin');
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute chaining into MVC parts
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithTwoArgs() {
|
||||
$this->Task->Model =& new PluginTestMockModelTask();
|
||||
$this->Task->setReturnValueAt(0, 'in', $this->_testPath);
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
|
||||
$Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);
|
||||
|
||||
$this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
|
||||
$this->Task->args =& $this->Task->Dispatch->args;
|
||||
|
||||
$this->Task->Model->expectOnce('loadTasks');
|
||||
$this->Task->Model->expectOnce('execute');
|
||||
$this->Task->execute();
|
||||
$Folder->delete();
|
||||
}
|
||||
}
|
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**
|
||||
* ProjectTask Test file
|
||||
*
|
||||
* Test Case for project generation shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.3.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'ProjectTask', 'MockProjectTask',
|
||||
array('in', '_stop', 'err', 'out', 'createFile')
|
||||
);
|
||||
|
||||
/**
|
||||
* ProjectTask Test class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ProjectTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
|
||||
$this->Dispatcher->shellPaths = App::path('shells');
|
||||
$this->Task =& new MockProjectTask($this->Dispatcher);
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->path = TMP . 'tests' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
|
||||
$Folder =& new Folder($this->Task->path . 'bake_test_app');
|
||||
$Folder->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a test project that is used for testing project task.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _setupTestProject() {
|
||||
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
||||
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() method and directory creation.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBake() {
|
||||
$this->_setupTestProject();
|
||||
|
||||
$path = $this->Task->path . 'bake_test_app';
|
||||
$this->assertTrue(is_dir($path), 'No project dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() method with -empty flag, directory creation and empty files.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeEmptyFlag() {
|
||||
$this->Task->params['empty'] = true;
|
||||
$this->_setupTestProject();
|
||||
$path = $this->Task->path . 'bake_test_app';
|
||||
$this->assertTrue(is_dir($path), 'No project dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
||||
|
||||
$this->assertTrue(is_file($path . DS . 'controllers' . DS .'components' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'locale' . DS . 'eng' . DS . 'LC_MESSAGES' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'plugins' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'shells' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'views' . DS . 'errors' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'views' . DS . 'scaffolds' . DS . 'empty'), 'No empty file in dir %s');
|
||||
$this->assertTrue(is_file($path . DS . 'webroot' . DS . 'js' . DS . 'empty'), 'No empty file in dir %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test generation of Security.salt
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSecuritySaltGeneration() {
|
||||
$this->_setupTestProject();
|
||||
|
||||
$path = $this->Task->path . 'bake_test_app' . DS;
|
||||
$result = $this->Task->securitySalt($path);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$file =& new File($path . 'config' . DS . 'core.php');
|
||||
$contents = $file->read();
|
||||
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test generation of Security.cipherSeed
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSecurityCipherSeedGeneration() {
|
||||
$this->_setupTestProject();
|
||||
|
||||
$path = $this->Task->path . 'bake_test_app' . DS;
|
||||
$result = $this->Task->securityCipherSeed($path);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$file =& new File($path . 'config' . DS . 'core.php');
|
||||
$contents = $file->read();
|
||||
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that index.php is generated correctly.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testIndexPhpGeneration() {
|
||||
$this->_setupTestProject();
|
||||
|
||||
$path = $this->Task->path . 'bake_test_app' . DS;
|
||||
$this->Task->corePath($path);
|
||||
|
||||
$file =& new File($path . 'webroot' . DS . 'index.php');
|
||||
$contents = $file->read();
|
||||
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
||||
|
||||
$file =& new File($path . 'webroot' . DS . 'test.php');
|
||||
$contents = $file->read();
|
||||
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getPrefix method, and that it returns Routing.prefix or writes to config file.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetPrefix() {
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$result = $this->Task->getPrefix();
|
||||
$this->assertEqual($result, 'admin_');
|
||||
|
||||
Configure::write('Routing.prefixes', null);
|
||||
$this->_setupTestProject();
|
||||
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
||||
$this->Task->setReturnValue('in', 'super_duper_admin');
|
||||
|
||||
$result = $this->Task->getPrefix();
|
||||
$this->assertEqual($result, 'super_duper_admin_');
|
||||
|
||||
$file =& new File($this->Task->configPath . 'core.php');
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* test cakeAdmin() writing core.php
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testCakeAdmin() {
|
||||
$file =& new File(CONFIGS . 'core.php');
|
||||
$contents = $file->read();;
|
||||
$file =& new File(TMP . 'tests' . DS . 'core.php');
|
||||
$file->write($contents);
|
||||
|
||||
Configure::write('Routing.prefixes', null);
|
||||
$this->Task->configPath = TMP . 'tests' . DS;
|
||||
$result = $this->Task->cakeAdmin('my_prefix');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->assertEqual(Configure::read('Routing.prefixes'), array('my_prefix'));
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting the prefix with more than one prefix setup
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetPrefixWithMultiplePrefixes() {
|
||||
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
|
||||
$this->_setupTestProject();
|
||||
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
||||
$this->Task->setReturnValue('in', 2);
|
||||
|
||||
$result = $this->Task->getPrefix();
|
||||
$this->assertEqual($result, 'ninja_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execute method with one param to destination folder.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecute() {
|
||||
$this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
|
||||
$this->Task->params['working'] = TMP . 'tests' . DS;
|
||||
|
||||
$path = $this->Task->path . 'bake_test_app';
|
||||
$this->Task->setReturnValue('in', 'y');
|
||||
$this->Task->setReturnValueAt(0, 'in', $path);
|
||||
|
||||
$this->Task->execute();
|
||||
$this->assertTrue(is_dir($path), 'No project dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
||||
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* TemplateTask file
|
||||
*
|
||||
* Test Case for TemplateTask generation shell task
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @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)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestTemplateTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'TemplateTask', 'MockTemplateTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop')
|
||||
);
|
||||
|
||||
/**
|
||||
* TemplateTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TemplateTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestTemplateTaskMockShellDispatcher();
|
||||
$this->Task =& new MockTemplateTask($this->Dispatcher);
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
unset($this->Task, $this->Dispatcher);
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that set sets variables
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testSet() {
|
||||
$this->Task->set('one', 'two');
|
||||
$this->assertTrue(isset($this->Task->templateVars['one']));
|
||||
$this->assertEqual($this->Task->templateVars['one'], 'two');
|
||||
|
||||
$this->Task->set(array('one' => 'three', 'four' => 'five'));
|
||||
$this->assertTrue(isset($this->Task->templateVars['one']));
|
||||
$this->assertEqual($this->Task->templateVars['one'], 'three');
|
||||
$this->assertTrue(isset($this->Task->templateVars['four']));
|
||||
$this->assertEqual($this->Task->templateVars['four'], 'five');
|
||||
|
||||
$this->Task->templateVars = array();
|
||||
$this->Task->set(array(3 => 'three', 4 => 'four'));
|
||||
$this->Task->set(array(1 => 'one', 2 => 'two'));
|
||||
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
|
||||
$this->assertEqual($this->Task->templateVars, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test finding themes installed in
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFindingInstalledThemesForBake() {
|
||||
$consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS;
|
||||
$this->Task->Dispatch->shellPaths = array($consoleLibs);
|
||||
$this->Task->initialize();
|
||||
$this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting the correct theme name. Ensure that with only one theme, or a theme param
|
||||
* that the user is not bugged. If there are more, find and return the correct theme name
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetThemePath() {
|
||||
$defaultTheme = CAKE_CORE_INCLUDE_PATH . DS . dirname(CONSOLE_LIBS) . 'templates' . DS . 'default' .DS;
|
||||
$this->Task->templatePaths = array('default' => $defaultTheme);
|
||||
$this->Task->expectCallCount('in', 1);
|
||||
|
||||
$result = $this->Task->getThemePath();
|
||||
$this->assertEqual($result, $defaultTheme);
|
||||
|
||||
$this->Task->templatePaths = array('default' => $defaultTheme, 'other' => '/some/path');
|
||||
$this->Task->params['theme'] = 'other';
|
||||
$result = $this->Task->getThemePath();
|
||||
$this->assertEqual($result, '/some/path');
|
||||
|
||||
$this->Task->params = array();
|
||||
$this->Task->setReturnValueAt(0, 'in', '1');
|
||||
$result = $this->Task->getThemePath();
|
||||
$this->assertEqual($result, $defaultTheme);
|
||||
$this->assertEqual($this->Dispatcher->params['theme'], 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGenerate() {
|
||||
App::build(array(
|
||||
'shells' => array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
|
||||
)
|
||||
));
|
||||
$this->Task->initialize();
|
||||
$this->Task->setReturnValue('in', 1);
|
||||
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
|
||||
$expected = "I got rendered\nfoo";
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test generate with a missing template in the chosen theme.
|
||||
* ensure fallback to default works.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGenerateWithTemplateFallbacks() {
|
||||
App::build(array(
|
||||
'shells' => array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'console' . DS
|
||||
)
|
||||
));
|
||||
$this->Task->initialize();
|
||||
$this->Task->params['theme'] = 'test';
|
||||
$this->Task->set(array(
|
||||
'model' => 'Article',
|
||||
'table' => 'articles',
|
||||
'import' => false,
|
||||
'records' => false,
|
||||
'schema' => ''
|
||||
));
|
||||
$result = $this->Task->generate('classes', 'fixture');
|
||||
$this->assertPattern('/ArticleFixture extends CakeTestFixture/', $result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,625 @@
|
||||
<?php
|
||||
/**
|
||||
* TestTaskTest file
|
||||
*
|
||||
* Test Case for test generation shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.2.0.7726
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
App::import('Controller', 'Controller', false);
|
||||
App::import('Model', 'Model', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestTestTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'TestTask', 'MockTestTask',
|
||||
array('in', '_stop', 'err', 'out', 'createFile', 'isLoadableClass')
|
||||
);
|
||||
|
||||
/**
|
||||
* Test Article model
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskArticle extends Model {
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'TestTaskArticle';
|
||||
|
||||
/**
|
||||
* Table name to use
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'articles';
|
||||
|
||||
/**
|
||||
* HasMany Associations
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasMany = array(
|
||||
'Comment' => array(
|
||||
'className' => 'TestTask.TestTaskComment',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Has and Belongs To Many Associations
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Tag' => array(
|
||||
'className' => 'TestTaskTag',
|
||||
'joinTable' => 'articles_tags',
|
||||
'foreignKey' => 'article_id',
|
||||
'associationForeignKey' => 'tag_id'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Example public method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function doSomething() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Example Secondary public method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function doSomethingElse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Example protected method
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _innerMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag Testing Model
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskTag extends Model {
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'TestTaskTag';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'tags';
|
||||
|
||||
/**
|
||||
* Has and Belongs To Many Associations
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Article' => array(
|
||||
'className' => 'TestTaskArticle',
|
||||
'joinTable' => 'articles_tags',
|
||||
'foreignKey' => 'tag_id',
|
||||
'associationForeignKey' => 'article_id'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulated plugin
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskAppModel extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing AppMode (TaskComment)
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskComment extends TestTaskAppModel {
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'TestTaskComment';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'comments';
|
||||
|
||||
/**
|
||||
* Belongs To Associations
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array(
|
||||
'Article' => array(
|
||||
'className' => 'TestTaskArticle',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Task Comments Controller
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskCommentsController extends Controller {
|
||||
|
||||
/**
|
||||
* Controller Name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'TestTaskComments';
|
||||
|
||||
/**
|
||||
* Models to use
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uses = array('TestTaskComment', 'TestTaskTag');
|
||||
}
|
||||
|
||||
/**
|
||||
* TestTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class TestTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestTestTaskMockShellDispatcher();
|
||||
$this->Dispatcher->shellPaths = App::path('shells');
|
||||
$this->Task =& new MockTestTask($this->Dispatcher);
|
||||
$this->Task->name = 'TestTask';
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that file path generation doesn't continuously append paths.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFilePathGeneration() {
|
||||
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php';
|
||||
|
||||
$this->Task->Dispatch->expectNever('stderr');
|
||||
$this->Task->Dispatch->expectNever('_stop');
|
||||
|
||||
$this->Task->setReturnValue('in', 'y');
|
||||
$this->Task->expectAt(0, 'createFile', array($file, '*'));
|
||||
$this->Task->bake('Model', 'MyClass');
|
||||
|
||||
$this->Task->expectAt(1, 'createFile', array($file, '*'));
|
||||
$this->Task->bake('Model', 'MyClass');
|
||||
|
||||
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.php';
|
||||
$this->Task->expectAt(2, 'createFile', array($file, '*'));
|
||||
$this->Task->bake('Controller', 'Comments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that method introspection pulls all relevant non parent class
|
||||
* methods into the test case.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMethodIntrospection() {
|
||||
$result = $this->Task->getTestableMethods('TestTaskArticle');
|
||||
$expected = array('dosomething', 'dosomethingelse');
|
||||
$this->assertEqual(array_map('strtolower', $result), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the generation of fixtures works correctly.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFixtureArrayGenerationFromModel() {
|
||||
$subject = ClassRegistry::init('TestTaskArticle');
|
||||
$result = $this->Task->generateFixtureList($subject);
|
||||
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
|
||||
'app.test_task_article', 'app.test_task_tag');
|
||||
|
||||
$this->assertEqual(sort($result), sort($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the generation of fixtures works correctly.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testFixtureArrayGenerationFromController() {
|
||||
$subject = new TestTaskCommentsController();
|
||||
$result = $this->Task->generateFixtureList($subject);
|
||||
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
|
||||
'app.test_task_article', 'app.test_task_tag');
|
||||
|
||||
$this->assertEqual(sort($result), sort($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* test user interaction to get object type
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetObjectType() {
|
||||
$this->Task->expectOnce('_stop');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
||||
$this->Task->getObjectType();
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 2);
|
||||
$result = $this->Task->getObjectType();
|
||||
$this->assertEqual($result, $this->Task->classTypes[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* creating test subjects should clear the registry so the registry is always fresh
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testRegistryClearWhenBuildingTestObjects() {
|
||||
ClassRegistry::flush();
|
||||
$model = ClassRegistry::init('TestTaskComment');
|
||||
$model->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
'Random' => array(
|
||||
'className' => 'TestTaskArticle',
|
||||
'foreignKey' => 'article_id',
|
||||
)
|
||||
)
|
||||
));
|
||||
$keys = ClassRegistry::keys();
|
||||
$this->assertTrue(in_array('random', $keys));
|
||||
$object =& $this->Task->buildTestSubject('Model', 'TestTaskComment');
|
||||
|
||||
$keys = ClassRegistry::keys();
|
||||
$this->assertFalse(in_array('random', $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that getClassName returns the user choice as a classname.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetClassName() {
|
||||
$objects = App::objects('model');
|
||||
$skip = $this->skipIf(empty($objects), 'No models in app, this test will fail. %s');
|
||||
if ($skip) {
|
||||
return;
|
||||
}
|
||||
$this->Task->setReturnValueAt(0, 'in', 'MyCustomClass');
|
||||
$result = $this->Task->getClassName('Model');
|
||||
$this->assertEqual($result, 'MyCustomClass');
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
||||
$result = $this->Task->getClassName('Model');
|
||||
$options = App::objects('model');
|
||||
$this->assertEqual($result, $options[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user interaction for defining additional fixtures.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetUserFixtures() {
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'app.pizza, app.topping, app.side_dish');
|
||||
$result = $this->Task->getUserFixtures();
|
||||
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that resolving classnames works
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetRealClassname() {
|
||||
$result = $this->Task->getRealClassname('Model', 'Post');
|
||||
$this->assertEqual($result, 'Post');
|
||||
|
||||
$result = $this->Task->getRealClassname('Controller', 'Posts');
|
||||
$this->assertEqual($result, 'PostsController');
|
||||
|
||||
$result = $this->Task->getRealClassname('Helper', 'Form');
|
||||
$this->assertEqual($result, 'FormHelper');
|
||||
|
||||
$result = $this->Task->getRealClassname('Behavior', 'Containable');
|
||||
$this->assertEqual($result, 'ContainableBehavior');
|
||||
|
||||
$result = $this->Task->getRealClassname('Component', 'Auth');
|
||||
$this->assertEqual($result, 'AuthComponent');
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking files. The conditionally run tests are known to fail in PHP4
|
||||
* as PHP4 classnames are all lower case, breaking the plugin path inflection.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeModelTest() {
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
$this->Task->setReturnValue('isLoadableClass', true);
|
||||
|
||||
$result = $this->Task->bake('Model', 'TestTaskArticle');
|
||||
|
||||
$this->assertPattern('/App::import\(\'Model\', \'TestTaskArticle\'\)/', $result);
|
||||
$this->assertPattern('/class TestTaskArticleTestCase extends CakeTestCase/', $result);
|
||||
|
||||
$this->assertPattern('/function startTest\(\)/', $result);
|
||||
$this->assertPattern("/\\\$this->TestTaskArticle \=\& ClassRegistry::init\('TestTaskArticle'\)/", $result);
|
||||
|
||||
$this->assertPattern('/function endTest\(\)/', $result);
|
||||
$this->assertPattern('/unset\(\$this->TestTaskArticle\)/', $result);
|
||||
|
||||
$this->assertPattern('/function testDoSomething\(\)/i', $result);
|
||||
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);
|
||||
|
||||
$this->assertPattern("/'app\.test_task_article'/", $result);
|
||||
if (PHP5) {
|
||||
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
||||
}
|
||||
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
||||
$this->assertPattern("/'app\.articles_tag'/", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking controller test files, ensure that the stub class is generated.
|
||||
* Conditional assertion is known to fail on PHP4 as classnames are all lower case
|
||||
* causing issues with inflection of path name from classname.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeControllerTest() {
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
$this->Task->setReturnValue('isLoadableClass', true);
|
||||
|
||||
$result = $this->Task->bake('Controller', 'TestTaskComments');
|
||||
|
||||
$this->assertPattern('/App::import\(\'Controller\', \'TestTaskComments\'\)/', $result);
|
||||
$this->assertPattern('/class TestTaskCommentsControllerTestCase extends CakeTestCase/', $result);
|
||||
|
||||
$this->assertPattern('/class TestTestTaskCommentsController extends TestTaskCommentsController/', $result);
|
||||
$this->assertPattern('/var \$autoRender = false/', $result);
|
||||
$this->assertPattern('/function redirect\(\$url, \$status = null, \$exit = true\)/', $result);
|
||||
|
||||
$this->assertPattern('/function startTest\(\)/', $result);
|
||||
$this->assertPattern("/\\\$this->TestTaskComments \=\& new TestTestTaskCommentsController\(\)/", $result);
|
||||
$this->assertPattern("/\\\$this->TestTaskComments->constructClasses\(\)/", $result);
|
||||
|
||||
$this->assertPattern('/function endTest\(\)/', $result);
|
||||
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);
|
||||
|
||||
$this->assertPattern("/'app\.test_task_article'/", $result);
|
||||
if (PHP5) {
|
||||
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
||||
}
|
||||
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
||||
$this->assertPattern("/'app\.articles_tag'/", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Constructor generation ensure that constructClasses is called for controllers
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGenerateConstructor() {
|
||||
$result = $this->Task->generateConstructor('controller', 'PostsController');
|
||||
$expected = "new TestPostsController();\n\t\t\$this->Posts->constructClasses();\n";
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->generateConstructor('model', 'Post');
|
||||
$expected = "ClassRegistry::init('Post');\n";
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->generateConstructor('helper', 'FormHelper');
|
||||
$expected = "new FormHelper();\n";
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that mock class generation works for the appropriate classes
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testMockClassGeneration() {
|
||||
$result = $this->Task->hasMockClass('controller');
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() with a -plugin param
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeWithPlugin() {
|
||||
$this->Task->plugin = 'TestTest';
|
||||
|
||||
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
||||
$this->Task->bake('Helper', 'Form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test filename generation for each type + plugins
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testTestCaseFileName() {
|
||||
$this->Task->path = '/my/path/tests/';
|
||||
|
||||
$result = $this->Task->testCaseFileName('Model', 'Post');
|
||||
$expected = $this->Task->path . 'cases' . DS . 'models' . DS . 'post.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->testCaseFileName('Helper', 'Form');
|
||||
$expected = $this->Task->path . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->testCaseFileName('Controller', 'Posts');
|
||||
$expected = $this->Task->path . 'cases' . DS . 'controllers' . DS . 'posts_controller.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->testCaseFileName('Behavior', 'Containable');
|
||||
$expected = $this->Task->path . 'cases' . DS . 'behaviors' . DS . 'containable.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Task->testCaseFileName('Component', 'Auth');
|
||||
$expected = $this->Task->path . 'cases' . DS . 'components' . DS . 'auth.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->plugin = 'TestTest';
|
||||
$result = $this->Task->testCaseFileName('Model', 'Post');
|
||||
$expected = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'post.test.php';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute with a type defined
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithOneArg() {
|
||||
$this->Task->args[0] = 'Model';
|
||||
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
||||
$this->Task->setReturnValue('isLoadableClass', true);
|
||||
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute with type and class name defined
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithTwoArgs() {
|
||||
$this->Task->args = array('Model', 'TestTaskTag');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
||||
$this->Task->setReturnValue('isLoadableClass', true);
|
||||
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
||||
$this->Task->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,677 @@
|
||||
<?php
|
||||
/**
|
||||
* ViewTask Test file
|
||||
*
|
||||
* Test Case for view generation shell task
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
* @since CakePHP v 1.2.0.7726
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'view.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestViewTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
Mock::generatePartial(
|
||||
'ViewTask', 'MockViewTask',
|
||||
array('in', '_stop', 'err', 'out', 'createFile')
|
||||
);
|
||||
|
||||
Mock::generate('ControllerTask', 'ViewTaskMockControllerTask');
|
||||
Mock::generate('ProjectTask', 'ViewTaskMockProjectTask');
|
||||
|
||||
/**
|
||||
* Test View Task Comment Model
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ViewTaskComment extends Model {
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ViewTaskComment';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'comments';
|
||||
|
||||
/**
|
||||
* Belongs To Associations
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array(
|
||||
'Article' => array(
|
||||
'className' => 'ViewTaskArticle',
|
||||
'foreignKey' => 'article_id'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test View Task Article Model
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ViewTaskArticle extends Model {
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ViewTaskArticle';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = 'articles';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test View Task Comments Controller
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ViewTaskCommentsController extends Controller {
|
||||
|
||||
/**
|
||||
* Controller name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ViewTaskComments';
|
||||
|
||||
/**
|
||||
* Testing public controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing public controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function add() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test View Task Articles Controller
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ViewTaskArticlesController extends Controller {
|
||||
|
||||
/**
|
||||
* Controller name
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ViewTaskArticles';
|
||||
|
||||
/**
|
||||
* Test public controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test public controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function add() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test admin prefixed controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function admin_index() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test admin prefixed controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function admin_add() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test admin prefixed controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function admin_view() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test admin prefixed controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function admin_edit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test admin prefixed controller action
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function admin_delete() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewTaskTest class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.console.libs.tasks
|
||||
*/
|
||||
class ViewTaskTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
|
||||
|
||||
/**
|
||||
* startTest method
|
||||
*
|
||||
* Ensure that the default theme is used
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function startTest() {
|
||||
$this->Dispatcher =& new TestViewTaskMockShellDispatcher();
|
||||
$this->Dispatcher->shellPaths = App::path('shells');
|
||||
$this->Task =& new MockViewTask($this->Dispatcher);
|
||||
$this->Task->name = 'ViewTask';
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
||||
$this->Task->Controller =& new ViewTaskMockControllerTask();
|
||||
$this->Task->Project =& new ViewTaskMockProjectTask();
|
||||
$this->Task->path = TMP;
|
||||
$this->Task->Template->params['theme'] = 'default';
|
||||
|
||||
$this->_routing = Configure::read('Routing');
|
||||
}
|
||||
|
||||
/**
|
||||
* endTest method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function endTest() {
|
||||
ClassRegistry::flush();
|
||||
Configure::write('Routing', $this->_routing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getContent and parsing of Templates.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetContent() {
|
||||
$vars = array(
|
||||
'modelClass' => 'TestViewModel',
|
||||
'schema' => array(),
|
||||
'primaryKey' => 'id',
|
||||
'displayField' => 'name',
|
||||
'singularVar' => 'testViewModel',
|
||||
'pluralVar' => 'testViewModels',
|
||||
'singularHumanName' => 'Test View Model',
|
||||
'pluralHumanName' => 'Test View Models',
|
||||
'fields' => array('id', 'name', 'body'),
|
||||
'associations' => array()
|
||||
);
|
||||
$result = $this->Task->getContent('view', $vars);
|
||||
|
||||
$this->assertPattern('/Delete Test View Model/', $result);
|
||||
$this->assertPattern('/Edit Test View Model/', $result);
|
||||
$this->assertPattern('/List Test View Models/', $result);
|
||||
$this->assertPattern('/New Test View Model/', $result);
|
||||
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getContent() using an admin_prefixed action.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testGetContentWithAdminAction() {
|
||||
$_back = Configure::read('Routing');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$vars = array(
|
||||
'modelClass' => 'TestViewModel',
|
||||
'schema' => array(),
|
||||
'primaryKey' => 'id',
|
||||
'displayField' => 'name',
|
||||
'singularVar' => 'testViewModel',
|
||||
'pluralVar' => 'testViewModels',
|
||||
'singularHumanName' => 'Test View Model',
|
||||
'pluralHumanName' => 'Test View Models',
|
||||
'fields' => array('id', 'name', 'body'),
|
||||
'associations' => array()
|
||||
);
|
||||
$result = $this->Task->getContent('admin_view', $vars);
|
||||
|
||||
$this->assertPattern('/Delete Test View Model/', $result);
|
||||
$this->assertPattern('/Edit Test View Model/', $result);
|
||||
$this->assertPattern('/List Test View Models/', $result);
|
||||
$this->assertPattern('/New Test View Model/', $result);
|
||||
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
|
||||
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
|
||||
|
||||
$result = $this->Task->getContent('admin_add', $vars);
|
||||
$this->assertPattern("/input\('name'\)/", $result);
|
||||
$this->assertPattern("/input\('body'\)/", $result);
|
||||
$this->assertPattern('/List Test View Models/', $result);
|
||||
|
||||
Configure::write('Routing', $_back);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Bake method
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBake() {
|
||||
$this->Task->controllerName = 'ViewTaskComments';
|
||||
$this->Task->controllerPath = 'view_task_comments';
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||
new PatternExpectation('/View Task Articles/')
|
||||
));
|
||||
$this->Task->bake('view', true);
|
||||
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
|
||||
$this->Task->bake('edit', true);
|
||||
|
||||
$this->Task->expectAt(2, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||
new PatternExpectation('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
|
||||
));
|
||||
$this->Task->bake('index', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that baking a view with no template doesn't make a file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testBakeWithNoTemplate() {
|
||||
$this->Task->controllerName = 'ViewTaskComments';
|
||||
$this->Task->controllerPath = 'view_task_comments';
|
||||
|
||||
$this->Task->expectNever('createFile');
|
||||
$this->Task->bake('delete', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake() with a -plugin param
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeWithPlugin() {
|
||||
$this->Task->controllerName = 'ViewTaskComments';
|
||||
$this->Task->controllerPath = 'view_task_comments';
|
||||
$this->Task->plugin = 'TestTest';
|
||||
|
||||
$path = APP . 'plugins' . DS . 'test_test' . DS . 'views' . DS . 'view_task_comments' . DS . 'view.ctp';
|
||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
||||
$this->Task->bake('view', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* test bake actions baking multiple actions.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBakeActions() {
|
||||
$this->Task->controllerName = 'ViewTaskComments';
|
||||
$this->Task->controllerPath = 'view_task_comments';
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||
new PatternExpectation('/View Task Comments/')
|
||||
));
|
||||
$this->Task->expectAt(1, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
||||
new PatternExpectation('/Edit View Task Comment/')
|
||||
));
|
||||
$this->Task->expectAt(2, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
|
||||
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
|
||||
}
|
||||
|
||||
/**
|
||||
* test baking a customAction (non crud)
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testCustomAction() {
|
||||
$this->Task->controllerName = 'ViewTaskComments';
|
||||
$this->Task->controllerPath = 'view_task_comments';
|
||||
$this->Task->params['app'] = APP;
|
||||
|
||||
$this->Task->setReturnValueAt(0, 'in', '');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'my_action');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'my_action.ctp', '*'));
|
||||
|
||||
$this->Task->customAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test all()
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoAll() {
|
||||
$this->Task->args[0] = 'all';
|
||||
|
||||
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
|
||||
$this->Task->Controller->expectOnce('listAll');
|
||||
|
||||
$this->Task->expectCallCount('createFile', 2);
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test all() with action parameter
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteIntoAllWithActionName() {
|
||||
$this->Task->args = array('all', 'index');
|
||||
|
||||
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
|
||||
$this->Task->Controller->expectOnce('listAll');
|
||||
|
||||
$this->Task->expectCallCount('createFile', 1);
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test `cake bake view $controller view`
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithActionParam() {
|
||||
$this->Task->args[0] = 'ViewTaskComments';
|
||||
$this->Task->args[1] = 'view';
|
||||
|
||||
$this->Task->expectCallCount('createFile', 1);
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test `cake bake view $controller`
|
||||
* Ensure that views are only baked for actions that exist in the controller.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithController() {
|
||||
$this->Task->args[0] = 'ViewTaskComments';
|
||||
|
||||
$this->Task->expectCallCount('createFile', 2);
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that both plural and singular forms can be used for baking views.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithControllerVariations() {
|
||||
$this->Task->args = array('ViewTaskComments');
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
||||
$this->Task->execute();
|
||||
|
||||
$this->Task->args = array('ViewTaskComment');
|
||||
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test `cake bake view $controller -admin`
|
||||
* Which only bakes admin methods, not non-admin methods.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithControllerAndAdminFlag() {
|
||||
$_back = Configure::read('Routing');
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$this->Task->args[0] = 'ViewTaskArticles';
|
||||
$this->Task->params['admin'] = 1;
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
|
||||
$this->Task->expectCallCount('createFile', 4);
|
||||
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_index.ctp', '*'));
|
||||
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_add.ctp', '*'));
|
||||
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_view.ctp', '*'));
|
||||
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_edit.ctp', '*'));
|
||||
|
||||
$this->Task->execute();
|
||||
Configure::write('Routing', $_back);
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute into interactive.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->args = array();
|
||||
$this->Task->params = array();
|
||||
|
||||
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
|
||||
$this->Task->setReturnValue('in', 'y');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
||||
|
||||
$this->Task->expectCallCount('createFile', 4);
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'index.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
$this->Task->expectAt(1, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'view.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
$this->Task->expectAt(2, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'add.ctp',
|
||||
new PatternExpectation('/Add View Task Comment/')
|
||||
));
|
||||
$this->Task->expectAt(3, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'edit.ctp',
|
||||
new PatternExpectation('/Edit View Task Comment/')
|
||||
));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test `cake bake view posts index list`
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteWithAlternateTemplates() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->args = array('ViewTaskComments', 'index', 'list');
|
||||
$this->Task->params = array();
|
||||
|
||||
$this->Task->expectCallCount('createFile', 1);
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'list.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test execute into interactive() with admin methods.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testExecuteInteractiveWithAdmin() {
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->args = array();
|
||||
|
||||
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
||||
$this->Task->setReturnValueAt(2, 'in', 'y');
|
||||
|
||||
$this->Task->expectCallCount('createFile', 4);
|
||||
$this->Task->expectAt(0, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'admin_index.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
$this->Task->expectAt(1, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'admin_view.ctp',
|
||||
new PatternExpectation('/ViewTaskComment/')
|
||||
));
|
||||
$this->Task->expectAt(2, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'admin_add.ctp',
|
||||
new PatternExpectation('/Add View Task Comment/')
|
||||
));
|
||||
$this->Task->expectAt(3, 'createFile', array(
|
||||
TMP . 'view_task_comments' . DS . 'admin_edit.ctp',
|
||||
new PatternExpectation('/Edit View Task Comment/')
|
||||
));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting templates, make sure noTemplateActions works
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetTemplate() {
|
||||
$result = $this->Task->getTemplate('delete');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->Task->getTemplate('add');
|
||||
$this->assertEqual($result, 'form');
|
||||
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
|
||||
$result = $this->Task->getTemplate('admin_add');
|
||||
$this->assertEqual($result, 'form');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user