Initial commit

This commit is contained in:
mareksebera 2014-09-10 20:20:58 +02:00
commit 3b93da31de
1004 changed files with 265840 additions and 0 deletions

View file

@ -0,0 +1,240 @@
<?php
/**
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command
* @since CakePHP v 2.5
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CommandTask', 'Console/Command/Task');
/**
* CommandTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class CommandTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
App::build(array(
'Plugin' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
),
'Console/Command' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
)
), App::RESET);
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->CommandTask = $this->getMock(
'CommandTask',
array('in', '_stop', 'clear'),
array($out, $out, $in)
);
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->CommandTask);
CakePlugin::unload();
}
/**
* Test the resulting list of shells
*
* @return void
*/
public function testGetShellList() {
$result = $this->CommandTask->getShellList();
$expected = array(
'CORE' => array(
'acl',
'api',
'bake',
'command_list',
'completion',
'console',
'i18n',
'schema',
'server',
'test',
'testsuite',
'upgrade'
),
'TestPlugin' => array(
'example'
),
'TestPluginTwo' => array(
'example',
'welcome'
),
'app' => array(
'sample'
),
);
$this->assertEquals($expected, $result);
}
/**
* Test the resulting list of commands
*
* @return void
*/
public function testCommands() {
$result = $this->CommandTask->commands();
$expected = array(
'TestPlugin.example',
'TestPluginTwo.example',
'TestPluginTwo.welcome',
'acl',
'api',
'bake',
'command_list',
'completion',
'console',
'i18n',
'schema',
'server',
'test',
'testsuite',
'upgrade',
'sample'
);
$this->assertEquals($expected, $result);
}
/**
* Test the resulting list of subcommands for the given command
*
* @return void
*/
public function testSubCommands() {
$result = $this->CommandTask->subCommands('acl');
$expected = array(
'check',
'create',
'db_config',
'delete',
'deny',
'getPath',
'grant',
'inherit',
'initdb',
'nodeExists',
'parseIdentifier',
'setParent',
'view'
);
$this->assertEquals($expected, $result);
}
/**
* Test that unknown commands return an empty array
*
* @return void
*/
public function testSubCommandsUnknownCommand() {
$result = $this->CommandTask->subCommands('yoghurt');
$expected = array();
$this->assertEquals($expected, $result);
}
/**
* Test that getting a existing shell returns the shell instance
*
* @return void
*/
public function testGetShell() {
$result = $this->CommandTask->getShell('acl');
$this->assertInstanceOf('AclShell', $result);
}
/**
* Test that getting a non-existing shell returns false
*
* @return void
*/
public function testGetShellNonExisting() {
$result = $this->CommandTask->getShell('strawberry');
$this->assertFalse($result);
}
/**
* Test that getting a existing core shell with 'core.' prefix returns the correct shell instance
*
* @return void
*/
public function testGetShellCore() {
$result = $this->CommandTask->getShell('core.bake');
$this->assertInstanceOf('BakeShell', $result);
}
/**
* Test the options array for a known command
*
* @return void
*/
public function testOptions() {
$result = $this->CommandTask->options('bake');
$expected = array(
'--help',
'-h',
'--verbose',
'-v',
'--quiet',
'-q',
'--connection',
'-c',
'--theme',
'-t'
);
$this->assertEquals($expected, $result);
}
/**
* Test the options array for an unknown command
*
* @return void
*/
public function testOptionsUnknownCommand() {
$result = $this->CommandTask->options('pie');
$expected = array(
'--help',
'-h',
'--verbose',
'-v',
'--quiet',
'-q'
);
$this->assertEquals($expected, $result);
}
}

View file

@ -0,0 +1,618 @@
<?php
/**
* ControllerTask Test Case
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('CakeSchema', 'Model');
App::uses('ClassRegistry', 'Utility');
App::uses('Helper', 'View/Helper');
App::uses('ProjectTask', 'Console/Command/Task');
App::uses('ControllerTask', 'Console/Command/Task');
App::uses('ModelTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('TestTask', 'Console/Command/Task');
App::uses('Model', 'Model');
App::uses('BakeArticle', 'Model');
App::uses('BakeComment', 'Model');
App::uses('BakeTags', 'Model');
$imported = class_exists('BakeArticle') || class_exists('BakeComment') || class_exists('BakeTag');
if (!$imported) {
define('ARTICLE_MODEL_CREATED', true);
/**
* Class BakeArticle
*/
class BakeArticle extends Model {
public $hasMany = array('BakeComment');
public $hasAndBelongsToMany = array('BakeTag');
}
}
/**
* ControllerTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ControllerTaskTest extends CakeTestCase {
/**
* fixtures
*
* @var array
*/
public $fixtures = array('core.bake_article', 'core.bake_articles_bake_tag', 'core.bake_comment', 'core.bake_tag');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ControllerTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array($out, $out, $in)
);
$this->Task->name = 'Controller';
$this->Task->Template = new TemplateTask($out, $out, $in);
$this->Task->Template->params['theme'] = 'default';
$this->Task->Model = $this->getMock('ModelTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
array($out, $out, $in)
);
$this->Task->Project = $this->getMock('ProjectTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
array($out, $out, $in)
);
$this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in));
if (!defined('ARTICLE_MODEL_CREATED')) {
$this->markTestSkipped('Could not run as an Article, Tag or Comment model was already loaded.');
}
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->Task);
ClassRegistry::flush();
App::build();
parent::tearDown();
}
/**
* test ListAll
*
* @return void
*/
public function testListAll() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->connection = 'test';
$this->Task->interactive = true;
$this->Task->expects($this->at(2))->method('out')->with(' 1. BakeArticles');
$this->Task->expects($this->at(3))->method('out')->with(' 2. BakeArticlesBakeTags');
$this->Task->expects($this->at(4))->method('out')->with(' 3. BakeComments');
$this->Task->expects($this->at(5))->method('out')->with(' 4. BakeTags');
$expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');
$result = $this->Task->listAll('test');
$this->assertEquals($expected, $result);
$this->Task->interactive = false;
$result = $this->Task->listAll();
$expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');
$this->assertEquals($expected, $result);
}
/**
* Test that getName interacts with the user and returns the controller name.
*
* @return void
*/
public function testGetNameValidIndex() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')->will(
$this->onConsecutiveCalls(3, 1)
);
$result = $this->Task->getName('test');
$expected = 'BakeComments';
$this->assertEquals($expected, $result);
$result = $this->Task->getName('test');
$expected = 'BakeArticles';
$this->assertEquals($expected, $result);
}
/**
* test getting invalid indexes.
*
* @return void
*/
public function testGetNameInvalidIndex() {
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls(50, 'q'));
$this->Task->expects($this->once())->method('err');
$this->Task->expects($this->once())->method('_stop');
$this->Task->getName('test');
}
/**
* test helper interactions
*
* @return void
*/
public function testDoHelpersNo() {
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
$result = $this->Task->doHelpers();
$this->assertSame(array(), $result);
}
/**
* test getting helper values
*
* @return void
*/
public function testDoHelpersTrailingSpace() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne '));
$result = $this->Task->doHelpers();
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}
/**
* test doHelpers with extra commas
*
* @return void
*/
public function testDoHelpersTrailingCommas() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
$result = $this->Task->doHelpers();
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}
/**
* test component interactions
*
* @return void
*/
public function testDoComponentsNo() {
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
$result = $this->Task->doComponents();
$this->assertSame(array('Paginator'), $result);
}
/**
* test components with spaces
*
* @return void
*/
public function testDoComponentsTrailingSpaces() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security '));
$result = $this->Task->doComponents();
$expected = array('Paginator', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}
/**
* test components with commas
*
* @return void
*/
public function testDoComponentsTrailingCommas() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
$result = $this->Task->doComponents();
$expected = array('Paginator', 'RequestHandler', 'Security');
$this->assertEquals($expected, $result);
}
/**
* test Confirming controller user interaction
*
* @return void
*/
public function testConfirmController() {
$controller = 'Posts';
$scaffold = false;
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');
$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
}
/**
* test the bake method
*
* @return void
*/
public function testBake() {
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
$result = $this->Task->bake('Articles', null, $helpers, $components);
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'NoActions.ctp');
$this->assertTextEquals($expected, $result);
$result = $this->Task->bake('Articles', null, array(), array());
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'NoHelpersOrComponents.ctp');
$this->assertTextEquals($expected, $result);
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'Scaffold.ctp');
$this->assertTextEquals($expected, $result);
}
/**
* test bake() with a -plugin param
*
* @return void
*/
public function testBakeWithPlugin() {
$this->Task->plugin = 'ControllerTest';
//fake plugin path
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
$this->Task->expects($this->at(1))->method('createFile')->with(
$path,
new PHPUnit_Framework_Constraint_IsAnything()
);
$this->Task->expects($this->at(3))->method('createFile')->with(
$path,
$this->stringContains('ArticlesController extends ControllerTestAppController')
)->will($this->returnValue(true));
$this->Task->bake('Articles', '--actions--', array(), array(), array());
$this->Task->plugin = 'ControllerTest';
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
$result = $this->Task->bake('Articles', '--actions--', array(), array(), array());
$this->assertContains("App::uses('ControllerTestAppController', 'ControllerTest.Controller');", $result);
$this->assertEquals('ControllerTest', $this->Task->Template->templateVars['plugin']);
$this->assertEquals('ControllerTest.', $this->Task->Template->templateVars['pluginPath']);
CakePlugin::unload();
}
/**
* test that bakeActions is creating the correct controller Code. (Using sessions)
*
* @return void
*/
public function testBakeActionsUsingSessions() {
$result = $this->Task->bakeActions('BakeArticles', null, true);
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsUsingSessions.ctp');
$this->assertTextEquals($expected, $result);
$result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
$this->assertContains('function admin_index() {', $result);
$this->assertContains('function admin_add()', $result);
$this->assertContains('function admin_view($id = null)', $result);
$this->assertContains('function admin_edit($id = null)', $result);
$this->assertContains('function admin_delete($id = null)', $result);
}
/**
* Test baking with Controller::flash() or no sessions.
*
* @return void
*/
public function testBakeActionsWithNoSessions() {
$result = $this->Task->bakeActions('BakeArticles', null, false);
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsWithNoSessions.ctp');
$this->assertTextEquals($expected, $result);
}
/**
* test baking a test
*
* @return void
*/
public function testBakeTest() {
$this->Task->plugin = 'ControllerTest';
$this->Task->connection = 'test';
$this->Task->interactive = false;
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');
$this->Task->bakeTest('BakeArticles');
$this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
$this->assertEquals($this->Task->connection, $this->Task->Test->connection);
$this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
}
/**
* test Interactive mode.
*
* @return void
*/
public function testInteractive() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls(
'1',
'y', // build interactive
'n', // build no scaffolds
'y', // build normal methods
'n', // build admin methods
'n', // helpers?
'n', // components?
'y', // sessions ?
'y' // looks good?
));
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('class BakeArticlesController')
);
$this->Task->execute();
}
/**
* test Interactive mode.
*
* @return void
*/
public function testInteractiveAdminMethodsNotInteractive() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->connection = 'test';
$this->Task->interactive = true;
$this->Task->path = '/my/path/';
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls(
'1',
'y', // build interactive
'n', // build no scaffolds
'y', // build normal methods
'y', // build admin methods
'n', // helpers?
'n', // components?
'y', // sessions ?
'y' // looks good?
));
$this->Task->Project->expects($this->any())
->method('getPrefix')
->will($this->returnValue('admin_'));
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('class BakeArticlesController')
)->will($this->returnValue(true));
$result = $this->Task->execute();
$this->assertRegExp('/admin_index/', $result);
}
/**
* test that execute runs all when the first arg == all
*
* @return void
*/
public function testExecuteIntoAll() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
$this->Task->Test->expects($this->once())->method('bake');
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('class BakeArticlesController')
)->will($this->returnValue(true));
$this->Task->execute();
}
/**
* Test execute() with all and --admin
*
* @return void
*/
public function testExecuteIntoAllAdmin() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->params['admin'] = true;
$this->Task->Project->expects($this->any())
->method('getPrefix')
->will($this->returnValue('admin_'));
$this->Task->expects($this->any())
->method('_checkUnitTest')
->will($this->returnValue(true));
$this->Task->Test->expects($this->once())->method('bake');
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('function admin_index')
)->will($this->returnValue(true));
$this->Task->execute();
}
/**
* test that `cake bake controller foos` works.
*
* @return void
*/
public function testExecuteWithController() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('$scaffold')
);
$this->Task->execute();
}
/**
* data provider for testExecuteWithControllerNameVariations
*
* @return void
*/
public static function nameVariations() {
return array(
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
);
}
/**
* test that both plural and singular forms work for controller baking.
*
* @dataProvider nameVariations
* @return void
*/
public function testExecuteWithControllerNameVariations($name) {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array($name);
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $this->stringContains('$scaffold')
);
$this->Task->execute();
}
/**
* test that `cake bake controller foo scaffold` works.
*
* @return void
*/
public function testExecuteWithPublicParam() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
$this->Task->params = array('public' => true);
$filename = '/my/path/BakeArticlesController.php';
$expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $expected
);
$this->Task->execute();
}
/**
* test that `cake bake controller foos both` works.
*
* @return void
*/
public function testExecuteWithControllerAndBoth() {
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
$this->Task->params = array('public' => true, 'admin' => true);
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $this->stringContains('admin_index')
);
$this->Task->execute();
}
/**
* test that `cake bake controller foos admin` works.
*
* @return void
*/
public function testExecuteWithControllerAndAdmin() {
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticles');
$this->Task->params = array('admin' => true);
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $this->stringContains('admin_index')
);
$this->Task->execute();
}
}

View file

@ -0,0 +1,132 @@
<?php
/**
* DBConfigTask Test Case
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('DbConfigTask', 'Console/Command/Task');
/**
* DbConfigTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class DbConfigTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('DbConfigTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
array($out, $out, $in)
);
$this->Task->path = APP . 'Config' . DS;
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
}
/**
* Test the getConfig method.
*
* @return void
*/
public function testGetConfig() {
$this->Task->expects($this->any())
->method('in')
->will($this->returnValue('test'));
$result = $this->Task->getConfig();
$this->assertEquals('test', $result);
}
/**
* test that initialize sets the path up.
*
* @return void
*/
public function testInitialize() {
$this->Task->initialize();
$this->assertFalse(empty($this->Task->path));
$this->assertEquals(APP . 'Config' . DS, $this->Task->path);
}
/**
* test execute and by extension _interactive
*
* @return void
*/
public function testExecuteIntoInteractive() {
$this->Task->initialize();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock(
'DbConfigTask',
array('in', '_stop', 'createFile', 'bake'), array($out, $out, $in)
);
$this->Task->expects($this->once())->method('_stop');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistent
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
$this->Task->expects($this->at(15))->method('bake')
->with(array(
array(
'name' => 'default',
'datasource' => 'mysql',
'persistent' => 'false',
'host' => 'localhost',
'login' => 'root',
'password' => 'password',
'database' => 'cake_test',
'prefix' => null,
'encoding' => null,
'port' => '',
'schema' => null
)
));
$this->Task->execute();
}
}

View file

@ -0,0 +1,494 @@
<?php
/**
* ExtractTaskTest file
*
* Test Case for i18n extraction shell task
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP v 1.2.0.7726
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Folder', 'Utility');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('ExtractTask', 'Console/Command/Task');
/**
* ExtractTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ExtractTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock(
'ExtractTask',
array('in', 'out', 'err', '_stop'),
array($out, $out, $in)
);
$this->path = TMP . 'tests' . DS . 'extract_task_test';
new Folder($this->path . DS . 'locale', true);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
$Folder = new Folder($this->path);
$Folder->delete();
CakePlugin::unload();
}
/**
* testExecute method
*
* @return void
*/
public function testExecute() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));
$this->Task->expects($this->never())->method('_stop');
$this->Task->execute();
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertFalse(file_exists($this->path . DS . 'cake.pot'));
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
$this->assertRegExp($pattern, $result);
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
$this->assertRegExp($pattern, $result);
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
$this->assertRegExp($pattern, $result);
// home.ctp
$pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "The %s is being used for caching. To change the config edit ';
$pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Your cache is NOT working. Please check ';
$pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Rename config\/database.php.default to ';
$pattern .= 'config\/database.php"\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "To change the content of this page, create: APP\/views\/pages\/home\.ctp/';
$this->assertRegExp($pattern, $result);
$pattern = '/To change its layout, create: APP\/views\/layouts\/default\.ctp\./s';
$this->assertRegExp($pattern, $result);
// extract.ctp
$pattern = '/\#: (\\\\|\/)extract\.ctp:15;6\n';
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "You have %d new message."\nmsgstr ""/';
$this->assertNotRegExp($pattern, $result, 'No duplicate msgid');
$pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
$this->assertRegExp($pattern, $result);
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
$pattern .= '\#: (\\\\|\/)home\.ctp:68\n';
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
$this->assertRegExp($pattern, $result);
$pattern = '/\#: (\\\\|\/)extract\.ctp:22\nmsgid "';
$pattern .= 'Hot features!';
$pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin';
$pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake';
$pattern .= '\\\n - Active, Friendly Community: Join us #cakephp on IRC. We\'d love to help you get started';
$pattern .= '"\nmsgstr ""/';
$this->assertRegExp($pattern, $result);
$this->assertContains('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly');
$this->assertContains("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly');
// extract.ctp - reading the domain.pot
$result = file_get_contents($this->path . DS . 'domain.pot');
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
$this->assertNotRegExp($pattern, $result);
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
$this->assertNotRegExp($pattern, $result);
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
$this->assertRegExp($pattern, $result);
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
$this->assertRegExp($pattern, $result);
}
/**
* testExtractCategory method
*
* @return void
*/
public function testExtractCategory() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->params['merge'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));
$this->Task->expects($this->never())->method('_stop');
$this->Task->execute();
$this->assertTrue(file_exists($this->path . DS . 'LC_TIME' . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');
$pattern = '/\#: .*extract\.ctp:31\n/';
$this->assertNotRegExp($pattern, $result);
}
/**
* test exclusions
*
* @return void
*/
public function testExtractWithExclude() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['exclude'] = 'Pages,Layouts';
$this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));
$this->Task->execute();
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');
$pattern = '/\#: .*extract\.ctp:6\n/';
$this->assertNotRegExp($pattern, $result);
$pattern = '/\#: .*default\.ctp:26\n/';
$this->assertNotRegExp($pattern, $result);
}
/**
* test extract can read more than one path.
*
* @return void
*/
public function testExtractMultiplePaths() {
$this->Task->interactive = false;
$this->Task->params['paths'] =
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages,' .
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Posts';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->never())->method('_stop');
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot');
$pattern = '/msgid "Add User"/';
$this->assertRegExp($pattern, $result);
}
/**
* Tests that it is possible to exclude plugin paths by enabling the param option for the ExtractTask
*
* @return void
*/
public function testExtractExcludePlugins() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['exclude-plugins'] = true;
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotRegExp('#TestPlugin#', $result);
}
/**
* Test that is possible to extract messages form a single plugin
*
* @return void
*/
public function testExtractPlugin() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['plugin'] = 'TestPlugin';
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotRegExp('#Pages#', $result);
$this->assertContains('translate.ctp:1', $result);
$this->assertContains('This is a translatable string', $result);
$this->assertContains('I can haz plugin model validation message', $result);
}
/**
* Tests that the task will inspect application models and extract the validation messages from them
*
* @return void
*/
public function testExtractModelValidation() {
App::build(array(
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), App::RESET);
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->params['exclude-plugins'] = true;
$this->Task->params['ignore-model-validation'] = false;
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot');
$pattern = preg_quote('#Model/PersisterOne.php:validation for field title#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = preg_quote('#Model/PersisterOne.php:validation for field body#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post title is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "You may enter up to %s chars \(minimum is %s chars\)"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is super required"#';
$this->assertRegExp($pattern, $result);
$this->assertContains('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly');
$this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly');
}
/**
* Tests that the task will inspect application models and extract the validation messages from them
* while using a custom validation domain for the messages set on the model itself
*
* @return void
*/
public function testExtractModelValidationWithDomainInModel() {
App::build(array(
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS)
));
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->params['exclude-plugins'] = true;
$this->Task->params['ignore-model-validation'] = false;
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post title is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is super required"#';
$this->assertRegExp($pattern, $result);
}
/**
* Test that the extract shell can obtain validation messages from models inside a specific plugin
*
* @return void
*/
public function testExtractModelValidationInPlugin() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['ignore-model-validation'] = false;
$this->Task->params['plugin'] = 'TestPlugin';
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field title#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field body#', '\\');
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post title is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#msgid "Post body is super required"#';
$this->assertRegExp($pattern, $result);
$pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#';
$this->assertNotRegExp($pattern, $result);
}
/**
* Test that the extract shell overwrites existing files with the overwrite parameter
*
* @return void
*/
public function testExtractOverwrite() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->params['overwrite'] = true;
file_put_contents($this->path . DS . 'default.pot', 'will be overwritten');
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$original = file_get_contents($this->path . DS . 'default.pot');
$this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotEquals($original, $result);
}
/**
* Test that the extract shell scans the core libs
*
* @return void
*/
public function testExtractCore() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'yes';
$this->Task->execute();
$this->assertTrue(file_exists($this->path . DS . 'cake.pot'));
$result = file_get_contents($this->path . DS . 'cake.pot');
$pattern = '/msgid "Yesterday, %s"\nmsgstr ""\n/';
$this->assertRegExp($pattern, $result);
$this->assertTrue(file_exists($this->path . DS . 'cake_dev.pot'));
$result = file_get_contents($this->path . DS . 'cake_dev.pot');
$pattern = '/#: Console\/Templates\//';
$this->assertNotRegExp($pattern, $result);
$pattern = '/#: Test\//';
$this->assertNotRegExp($pattern, $result);
}
}

View file

@ -0,0 +1,453 @@
<?php
/**
* FixtureTask Test case
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('ModelTask', 'Console/Command/Task');
App::uses('FixtureTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('DbConfigTask', 'Console/Command/Task');
/**
* FixtureTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class FixtureTaskTest extends CakeTestCase {
/**
* fixtures
*
* @var array
*/
public $fixtures = array('core.article', 'core.comment', 'core.datatype', 'core.binary_test', 'core.user');
/**
* Whether backup global state for each test method or not
*
* @var bool
*/
public $backupGlobals = false;
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('FixtureTask',
array('in', 'err', 'createFile', '_stop', 'clear'),
array($out, $out, $in)
);
$this->Task->Model = $this->getMock('ModelTask',
array('in', 'out', 'err', 'createFile', 'getName', 'getTable', 'listAll'),
array($out, $out, $in)
);
$this->Task->Template = new TemplateTask($out, $out, $in);
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array($out, $out, $in));
$this->Task->Template->initialize();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
}
/**
* test that initialize sets the path
*
* @return void
*/
public function testConstruct() {
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$Task = new FixtureTask($out, $out, $in);
$this->assertEquals(APP . 'Test' . DS . 'Fixture' . DS, $Task->path);
}
/**
* test import option array generation
*
* @return void
*/
public function testImportOptionsSchemaRecords() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$result = $this->Task->importOptions('Article');
$expected = array('schema' => 'Article', 'records' => true);
$this->assertEquals($expected, $result);
}
/**
* test importOptions choosing nothing.
*
* @return void
*/
public function testImportOptionsNothing() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n'));
$result = $this->Task->importOptions('Article');
$expected = array();
$this->assertEquals($expected, $result);
}
/**
* test importOptions with overwriting command line options.
*
* @return void
*/
public function testImportOptionsWithCommandLineOptions() {
$this->Task->params = array('schema' => true, 'records' => true);
$result = $this->Task->importOptions('Article');
$expected = array('schema' => 'Article', 'records' => true);
$this->assertEquals($expected, $result);
}
/**
* test importOptions with schema.
*
* @return void
*/
public function testImportOptionsWithSchema() {
$this->Task->params = array('schema' => true);
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
$result = $this->Task->importOptions('Article');
$expected = array('schema' => 'Article');
$this->assertEquals($expected, $result);
}
/**
* test importOptions with records.
*
* @return void
*/
public function testImportOptionsWithRecords() {
$this->Task->params = array('records' => true);
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
$result = $this->Task->importOptions('Article');
$expected = array('records' => true);
$this->assertEquals($expected, $result);
}
/**
* test importOptions choosing from Table.
*
* @return void
*/
public function testImportOptionsTable() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
$result = $this->Task->importOptions('Article');
$expected = array('fromTable' => true);
$this->assertEquals($expected, $result);
}
/**
* test generating a fixture with database conditions.
*
* @return void
*/
public function testImportRecordsFromDatabaseWithConditionsPoo() {
$this->Task->interactive = true;
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue('WHERE 1=1'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$result = $this->Task->bake('Article', false, array(
'fromTable' => true, 'schema' => 'Article', 'records' => false
));
$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('public $records', $result);
$this->assertContains('public $import', $result);
$this->assertContains("'title' => 'First Article'", $result, 'Missing import data %s');
$this->assertContains('Second Article', $result, 'Missing import data %s');
$this->assertContains('Third Article', $result, 'Missing import data %s');
}
/**
* test that connection gets set to the import options when a different connection is used.
*
* @return void
*/
public function testImportOptionsAlternateConnection() {
$this->Task->connection = 'test';
$result = $this->Task->bake('Article', false, array('schema' => 'Article'));
$this->assertContains("'connection' => 'test'", $result);
}
/**
* Ensure that fixture data doesn't get overly escaped.
*
* @return void
*/
public function testImportRecordsNoEscaping() {
$db = ConnectionManager::getDataSource('test');
if ($db instanceof Sqlserver) {
$this->markTestSkipped('This test does not run on SQLServer');
}
$Article = ClassRegistry::init('Article');
$Article->updateAll(array('body' => "'Body \"value\"'"));
$this->Task->interactive = true;
$this->Task->expects($this->at(0))
->method('in')
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$result = $this->Task->bake('Article', false, array(
'fromTable' => true,
'schema' => 'Article',
'records' => false
));
$this->assertContains("'body' => 'Body \"value\"'", $result, 'Data has bad escaping');
}
/**
* test that execute passes runs bake depending with named model.
*
* @return void
*/
public function testExecuteWithNamedModel() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('article');
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));
$this->Task->execute();
}
/**
* test that execute runs all() when args[0] = all
*
* @return void
*/
public function testExecuteIntoAll() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->Model->expects($this->any())
->method('listAll')
->will($this->returnValue(array('articles', 'comments')));
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));
$filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains('class CommentFixture'));
$this->Task->execute();
}
/**
* test using all() with -count and -records
*
* @return void
*/
public function testAllWithCountAndRecordsFlags() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->params = array('count' => 10, 'records' => true);
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('Articles', 'comments')));
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains("'title' => 'Third Article'"));
$filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
$this->Task->expects($this->exactly(2))->method('createFile');
$this->Task->all();
}
/**
* test using all() with -schema
*
* @return void
*/
public function testAllWithSchemaImport() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->params = array('schema' => true);
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('Articles', 'comments')));
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('public $import = array(\'model\' => \'Article\''));
$filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains('public $import = array(\'model\' => \'Comment\''));
$this->Task->expects($this->exactly(2))->method('createFile');
$this->Task->all();
}
/**
* test interactive mode of execute
*
* @return void
*/
public function testExecuteInteractive() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->expects($this->any())->method('in')->will($this->returnValue('y'));
$this->Task->Model->expects($this->any())->method('getName')->will($this->returnValue('Article'));
$this->Task->Model->expects($this->any())->method('getTable')
->with('Article')
->will($this->returnValue('articles'));
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->once())->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));
$this->Task->execute();
}
/**
* Test that bake works
*
* @return void
*/
public function testBake() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$result = $this->Task->bake('Article');
$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('public $fields', $result);
$this->assertContains('public $records', $result);
$this->assertNotContains('public $import', $result);
$result = $this->Task->bake('Article', 'comments');
$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('public $table = \'comments\';', $result);
$this->assertContains('public $fields = array(', $result);
$result = $this->Task->bake('Article', 'comments', array('records' => true));
$this->assertContains("public \$import = array('records' => true, 'connection' => 'test');", $result);
$this->assertNotContains('public $records', $result);
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article'));
$this->assertContains("public \$import = array('model' => 'Article', 'connection' => 'test');", $result);
$this->assertNotContains('public $fields', $result);
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true));
$this->assertContains("public \$import = array('model' => 'Article', 'records' => true, 'connection' => 'test');", $result);
$this->assertNotContains('public $fields', $result);
$this->assertNotContains('public $records', $result);
}
/**
* test record generation with float and binary types
*
* @return void
*/
public function testRecordGenerationForBinaryAndFloat() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$result = $this->Task->bake('Article', 'datatypes');
$this->assertContains("'float_field' => 1", $result);
$this->assertContains("'bool' => 1", $result);
$result = $this->Task->bake('Article', 'binary_tests');
$this->assertContains("'data' => 'Lorem ipsum dolor sit amet'", $result);
}
/**
* Test that file generation includes headers and correct path for plugins.
*
* @return void
*/
public function testGenerateFixtureFile() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('ArticleFixture'));
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains('<?php'));
$this->Task->generateFixtureFile('Article', array());
$this->Task->generateFixtureFile('Article', array());
}
/**
* test generating files into plugins.
*
* @return void
*/
public function testGeneratePluginFixtureFile() {
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->plugin = 'TestFixture';
$filename = APP . 'Plugin' . DS . 'TestFixture' . DS . 'Test' . DS . 'Fixture' . DS . 'ArticleFixture.php';
//fake plugin path
CakePlugin::load('TestFixture', array('path' => APP . 'Plugin' . DS . 'TestFixture' . DS));
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('class Article'));
$this->Task->generateFixtureFile('Article', array());
CakePlugin::unload();
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,208 @@
<?php
/**
* PluginTask Test file
*
* Test Case for plugin generation shell task
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP v 1.3.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('PluginTask', 'Console/Command/Task');
App::uses('ModelTask', 'Console/Command/Task');
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
/**
* PluginTaskPlugin class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class PluginTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('PluginTask',
array('in', 'err', 'createFile', '_stop', 'clear'),
array($this->out, $this->out, $this->in)
);
$this->Task->path = TMP . 'tests' . DS;
$this->Task->bootstrap = TMP . 'tests' . DS . 'bootstrap.php';
touch($this->Task->bootstrap);
$this->_paths = $paths = App::path('plugins');
foreach ($paths as $i => $p) {
if (!is_dir($p)) {
array_splice($paths, $i, 1);
}
}
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
App::build(array('plugins' => $paths));
}
/**
* tearDown()
*
* @return void
*/
public function tearDown() {
if (file_exists($this->Task->bootstrap)) {
unlink($this->Task->bootstrap);
}
parent::tearDown();
}
/**
* test bake()
*
* @return void
*/
public function testBakeFoldersAndFiles() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$path = $this->Task->path . 'BakeTestPlugin';
$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->bake('BakeTestPlugin');
$path = $this->Task->path . 'BakeTestPlugin';
$this->assertTrue(is_dir($path), 'No plugin dir %s');
$directories = array(
'Config' . DS . 'Schema',
'Model' . DS . 'Behavior',
'Model' . DS . 'Datasource',
'Console' . DS . 'Command' . DS . 'Task',
'Controller' . DS . 'Component',
'Lib',
'View' . DS . 'Helper',
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
'Test' . DS . 'Fixture',
'Vendor',
'webroot'
);
foreach ($directories as $dir) {
$this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
}
$Folder = new Folder($this->Task->path . 'BakeTestPlugin');
$Folder->delete();
}
/**
* test execute with no args, flowing into interactive,
*
* @return void
*/
public function testExecuteWithNoArgs() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue($this->_testPath));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
$path = $this->Task->path . 'TestPlugin';
$file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'Model' . DS . 'TestPluginAppModel.php';
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->args = array();
$this->Task->execute();
$Folder = new Folder($path);
$Folder->delete();
}
/**
* Test Execute
*
* @return void
*/
public function testExecuteWithOneArg() {
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue($this->_testPath));
$this->Task->expects($this->at(1))->method('in')
->will($this->returnValue('y'));
$path = $this->Task->path . 'BakeTestPlugin';
$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$path = $this->Task->path . 'BakeTestPlugin';
$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->args = array('BakeTestPlugin');
$this->Task->execute();
$Folder = new Folder($this->Task->path . 'BakeTestPlugin');
$Folder->delete();
}
/**
* Test that findPath ignores paths that don't exist.
*
* @return void
*/
public function testFindPathNonExistant() {
$paths = App::path('plugins');
$last = count($paths);
array_unshift($paths, '/fake/path');
$paths[] = '/fake/path2';
$this->Task = $this->getMock('PluginTask',
array('in', 'out', 'err', 'createFile', '_stop'),
array($this->out, $this->out, $this->in)
);
$this->Task->path = TMP . 'tests' . DS;
// Make sure the added path is filtered out.
$this->Task->expects($this->exactly($last))
->method('out');
$this->Task->expects($this->once())
->method('in')
->will($this->returnValue($last));
$this->Task->findPath($paths);
}
}

View file

@ -0,0 +1,386 @@
<?php
/**
* ProjectTask Test file
*
* Test Case for project generation shell task
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP v 1.3.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('ProjectTask', 'Console/Command/Task');
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
/**
* ProjectTask Test class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ProjectTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ProjectTask',
array('in', 'err', 'createFile', '_stop'),
array($out, $out, $in)
);
$this->Task->path = TMP . 'tests' . DS;
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
$Folder = new Folder($this->Task->path . 'bake_test_app');
$Folder->delete();
unset($this->Task);
}
/**
* creates a test project that is used for testing project task.
*
* @return void
*/
protected function _setupTestProject() {
$skel = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
}
/**
* test bake() method and directory creation.
*
* @return void
*/
public function testBake() {
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app';
$this->assertTrue(is_dir($path), 'No project dir %s');
$dirs = array(
'Config',
'Config' . DS . 'Schema',
'Console',
'Console' . DS . 'Command',
'Console' . DS . 'Templates',
'Console' . DS . 'Command' . DS . 'Task',
'Controller',
'Controller' . DS . 'Component',
'Locale',
'Model',
'Model' . DS . 'Behavior',
'Model' . DS . 'Datasource',
'Plugin',
'Test',
'Test' . DS . 'Case',
'Test' . DS . 'Case' . DS . 'Controller',
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
'Test' . DS . 'Case' . DS . 'Model',
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
'Test' . DS . 'Fixture',
'Vendor',
'View',
'View' . DS . 'Helper',
'tmp',
'tmp' . DS . 'cache',
'tmp' . DS . 'cache' . DS . 'models',
'tmp' . DS . 'cache' . DS . 'persistent',
'tmp' . DS . 'cache' . DS . 'views',
'tmp' . DS . 'logs',
'tmp' . DS . 'sessions',
'tmp' . DS . 'tests',
'webroot',
'webroot' . DS . 'css',
'webroot' . DS . 'files',
'webroot' . DS . 'img',
'webroot' . DS . 'js',
);
foreach ($dirs as $dir) {
$this->assertTrue(is_dir($path . DS . $dir), 'Missing ' . $dir);
}
}
/**
* test bake with an absolute path.
*
* @return void
*/
public function testExecuteWithAbsolutePath() {
$path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app';
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$File = new File($path . DS . 'webroot' . DS . 'index.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
$File = new File($path . DS . 'webroot' . DS . 'test.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
}
/**
* test bake with CakePHP on the include path. The constants should remain commented out.
*
* @return void
*/
public function testExecuteWithCakeOnIncludePath() {
if (!function_exists('ini_set')) {
$this->markTestAsSkipped('Not access to ini_set, cannot proceed.');
}
$restore = ini_get('include_path');
ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . $restore);
$path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app';
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$contents = file_get_contents($path . DS . 'webroot' . DS . 'index.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
$contents = file_get_contents($path . DS . 'webroot' . DS . 'test.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
ini_set('include_path', $restore);
}
/**
* test bake() method with -empty flag, directory creation and empty files.
*
* @return void
*/
public function testBakeEmptyFlag() {
$this->Task->params['empty'] = true;
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app';
$empty = array(
'Console' . DS . 'Command' . DS . 'Task' => 'empty',
'Controller' . DS . 'Component' => 'empty',
'Lib' => 'empty',
'Model' . DS . 'Behavior' => 'empty',
'Model' . DS . 'Datasource' => 'empty',
'Plugin' => 'empty',
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior' => 'empty',
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component' => 'empty',
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' => 'empty',
'Test' . DS . 'Fixture' => 'empty',
'Vendor' => 'empty',
'View' . DS . 'Elements' => 'empty',
'View' . DS . 'Scaffolds' => 'empty',
'tmp' . DS . 'cache' . DS . 'models' => 'empty',
'tmp' . DS . 'cache' . DS . 'persistent' => 'empty',
'tmp' . DS . 'cache' . DS . 'views' => 'empty',
'tmp' . DS . 'logs' => 'empty',
'tmp' . DS . 'sessions' => 'empty',
'tmp' . DS . 'tests' => 'empty',
'webroot' . DS . 'js' => 'empty',
'webroot' . DS . 'files' => 'empty'
);
foreach ($empty as $dir => $file) {
$this->assertTrue(is_file($path . DS . $dir . DS . $file), sprintf('Missing %s file in %s', $file, $dir));
}
}
/**
* test generation of Security.salt
*
* @return void
*/
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->assertNotRegExp('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
}
/**
* test generation of Security.cipherSeed
*
* @return void
*/
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->assertNotRegExp('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
}
/**
* test generation of cache prefix
*
* @return void
*/
public function testCachePrefixGeneration() {
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app' . DS;
$result = $this->Task->cachePrefix($path);
$this->assertTrue($result);
$File = new File($path . 'Config' . DS . 'core.php');
$contents = $File->read();
$this->assertRegExp('/\$prefix = \'.+\';/', $contents, '$prefix is not defined');
$this->assertNotRegExp('/\$prefix = \'myapp_\';/', $contents, 'Default cache prefix left behind. %s');
}
/**
* Test that index.php is generated correctly.
*
* @return void
*/
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->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
$File = new File($path . 'webroot' . DS . 'test.php');
$contents = $File->read();
$this->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
}
/**
* test getPrefix method, and that it returns Routing.prefix or writes to config file.
*
* @return void
*/
public function testGetPrefix() {
Configure::write('Routing.prefixes', array('admin'));
$result = $this->Task->getPrefix();
$this->assertEquals('admin_', $result);
Configure::write('Routing.prefixes', null);
$this->_setupTestProject();
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'Config' . DS;
$this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
$result = $this->Task->getPrefix();
$this->assertEquals('super_duper_admin_', $result);
$File = new File($this->Task->configPath . 'core.php');
$File->delete();
}
/**
* test cakeAdmin() writing core.php
*
* @return void
*/
public function testCakeAdmin() {
$File = new File(APP . 'Config' . DS . '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->assertEquals(Configure::read('Routing.prefixes'), array('my_prefix'));
$File->delete();
}
/**
* test getting the prefix with more than one prefix setup
*
* @return void
*/
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->expects($this->once())->method('in')->will($this->returnValue(2));
$result = $this->Task->getPrefix();
$this->assertEquals('ninja_', $result);
}
/**
* Test execute method with one param to destination folder.
*
* @return void
*/
public function testExecute() {
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
$this->Task->params['working'] = TMP . 'tests' . DS;
$path = $this->Task->path . 'bake_test_app';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($path));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$this->Task->execute();
$this->assertTrue(is_dir($path), 'No project dir');
$this->assertTrue(is_dir($path . DS . 'Controller'), 'No controllers dir ');
$this->assertTrue(is_dir($path . DS . 'Controller' . DS . 'Component'), 'No components dir ');
$this->assertTrue(is_dir($path . DS . 'Model'), 'No models dir');
$this->assertTrue(is_dir($path . DS . 'View'), 'No views dir');
$this->assertTrue(is_dir($path . DS . 'View' . DS . 'Helper'), 'No helpers dir');
$this->assertTrue(is_dir($path . DS . 'Test'), 'No tests dir');
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Case'), 'No cases dir');
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Fixture'), 'No fixtures dir');
}
/**
* test console path
*
* @return void
*/
public function testConsolePath() {
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app' . DS;
$result = $this->Task->consolePath($path);
$this->assertTrue($result);
$File = new File($path . 'Console' . DS . 'cake.php');
$contents = $File->read();
$this->assertNotRegExp('/__CAKE_PATH__/', $contents, 'Console path placeholder left behind.');
}
}

View file

@ -0,0 +1,164 @@
<?php
/**
* TemplateTask file
*
* Test Case for TemplateTask generation shell task
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('TemplateTask', 'Console/Command/Task');
/**
* TemplateTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TemplateTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('TemplateTask',
array('in', 'err', 'createFile', '_stop', 'clear'),
array($out, $out, $in)
);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
}
/**
* test that set sets variables
*
* @return void
*/
public function testSet() {
$this->Task->set('one', 'two');
$this->assertTrue(isset($this->Task->templateVars['one']));
$this->assertEquals('two', $this->Task->templateVars['one']);
$this->Task->set(array('one' => 'three', 'four' => 'five'));
$this->assertTrue(isset($this->Task->templateVars['one']));
$this->assertEquals('three', $this->Task->templateVars['one']);
$this->assertTrue(isset($this->Task->templateVars['four']));
$this->assertEquals('five', $this->Task->templateVars['four']);
$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->assertEquals($expected, $this->Task->templateVars);
}
/**
* test finding themes installed in
*
* @return void
*/
public function testFindingInstalledThemesForBake() {
$consoleLibs = CAKE . 'Console' . DS;
$this->Task->initialize();
$this->assertEquals($this->Task->templatePaths['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
*/
public function testGetThemePath() {
$defaultTheme = CAKE . 'Console' . DS . 'Templates' . DS . 'default' . DS;
$this->Task->templatePaths = array('default' => $defaultTheme);
$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
$result = $this->Task->getThemePath();
$this->assertEquals($defaultTheme, $result);
$this->Task->templatePaths = array('other' => '/some/path', 'default' => $defaultTheme);
$this->Task->params['theme'] = 'other';
$result = $this->Task->getThemePath();
$this->assertEquals('/some/path', $result);
$this->Task->params = array();
$result = $this->Task->getThemePath();
$this->assertEquals('/some/path', $result);
$this->assertEquals('other', $this->Task->params['theme']);
}
/**
* test generate
*
* @return void
*/
public function testGenerate() {
App::build(array(
'Console' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS
)
));
$this->Task->initialize();
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
$expected = "I got rendered\nfoo";
$this->assertTextEquals($expected, $result);
}
/**
* test generate with a missing template in the chosen theme.
* ensure fallback to default works.
*
* @return void
*/
public function testGenerateWithTemplateFallbacks() {
App::build(array(
'Console' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . 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->assertRegExp('/ArticleFixture extends CakeTestFixture/', $result);
}
}

View file

@ -0,0 +1,755 @@
<?php
/**
* TestTaskTest file
*
* Test Case for test generation shell task
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP v 1.2.0.7726
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('TestTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');
/**
* Test Article model
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskArticle extends Model {
/**
* Table name to use
*
* @var string
*/
public $useTable = 'articles';
/**
* HasMany Associations
*
* @var array
*/
public $hasMany = array(
'Comment' => array(
'className' => 'TestTask.TestTaskComment',
'foreignKey' => 'article_id',
)
);
/**
* Has and Belongs To Many Associations
*
* @var array
*/
public $hasAndBelongsToMany = array(
'Tag' => array(
'className' => 'TestTaskTag',
'joinTable' => 'articles_tags',
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id'
)
);
/**
* Example public method
*
* @return void
*/
public function doSomething() {
}
/**
* Example Secondary public method
*
* @return void
*/
public function doSomethingElse() {
}
/**
* Example protected method
*
* @return void
*/
protected function _innerMethod() {
}
}
/**
* Tag Testing Model
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskTag extends Model {
/**
* Table name
*
* @var string
*/
public $useTable = 'tags';
/**
* Has and Belongs To Many Associations
*
* @var array
*/
public $hasAndBelongsToMany = array(
'Article' => array(
'className' => 'TestTaskArticle',
'joinTable' => 'articles_tags',
'foreignKey' => 'tag_id',
'associationForeignKey' => 'article_id'
)
);
}
/**
* Simulated plugin
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskAppModel extends Model {
}
/**
* Testing AppMode (TaskComment)
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskComment extends TestTaskAppModel {
/**
* Table name
*
* @var string
*/
public $useTable = 'comments';
/**
* Belongs To Associations
*
* @var array
*/
public $belongsTo = array(
'Article' => array(
'className' => 'TestTaskArticle',
'foreignKey' => 'article_id',
)
);
}
/**
* Test Task Comments Controller
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskCommentsController extends Controller {
/**
* Models to use
*
* @var array
*/
public $uses = array('TestTaskComment', 'TestTaskTag');
}
/**
* TestTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TestTaskTest extends CakeTestCase {
/**
* Fixtures
*
* @var string
*/
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('TestTask',
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array($out, $out, $in)
);
$this->Task->name = 'Test';
$this->Task->Template = new TemplateTask($out, $out, $in);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
CakePlugin::unload();
}
/**
* Test that file path generation doesn't continuously append paths.
*
* @return void
*/
public function testFilePathGenerationModelRepeated() {
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->never())->method('_stop');
$file = TESTS . 'Case' . DS . 'Model' . DS . 'MyClassTest.php';
$this->Task->expects($this->at(1))->method('createFile')
->with($file, $this->anything());
$this->Task->expects($this->at(3))->method('createFile')
->with($file, $this->anything());
$file = TESTS . 'Case' . DS . 'Controller' . DS . 'CommentsControllerTest.php';
$this->Task->expects($this->at(5))->method('createFile')
->with($file, $this->anything());
$this->Task->bake('Model', 'MyClass');
$this->Task->bake('Model', 'MyClass');
$this->Task->bake('Controller', 'Comments');
}
/**
* Test that method introspection pulls all relevant non parent class
* methods into the test case.
*
* @return void
*/
public function testMethodIntrospection() {
$result = $this->Task->getTestableMethods('TestTaskArticle');
$expected = array('dosomething', 'dosomethingelse');
$this->assertEquals($expected, array_map('strtolower', $result));
}
/**
* test that the generation of fixtures works correctly.
*
* @return void
*/
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->assertEquals(sort($expected), sort($result));
}
/**
* test that the generation of fixtures works correctly.
*
* @return void
*/
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->assertEquals(sort($expected), sort($result));
}
/**
* test user interaction to get object type
*
* @return void
*/
public function testGetObjectType() {
$this->Task->expects($this->once())->method('_stop');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
$this->Task->getObjectType();
$result = $this->Task->getObjectType();
$this->assertEquals($this->Task->classTypes['Controller'], $result);
}
/**
* creating test subjects should clear the registry so the registry is always fresh
*
* @return void
*/
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('test_task_comment', $keys));
$this->Task->buildTestSubject('Model', 'TestTaskComment');
$keys = ClassRegistry::keys();
$this->assertFalse(in_array('random', $keys));
}
/**
* test that getClassName returns the user choice as a class name.
*
* @return void
*/
public function testGetClassName() {
$objects = App::objects('model');
$this->skipIf(empty($objects), 'No models in app.');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
$result = $this->Task->getClassName('Model');
$this->assertEquals('MyCustomClass', $result);
$result = $this->Task->getClassName('Model');
$options = App::objects('model');
$this->assertEquals($options[0], $result);
}
/**
* Test the user interaction for defining additional fixtures.
*
* @return void
*/
public function testGetUserFixtures() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')
->will($this->returnValue('app.pizza, app.topping, app.side_dish'));
$result = $this->Task->getUserFixtures();
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
$this->assertEquals($expected, $result);
}
/**
* test that resolving class names works
*
* @return void
*/
public function testGetRealClassname() {
$result = $this->Task->getRealClassname('Model', 'Post');
$this->assertEquals('Post', $result);
$result = $this->Task->getRealClassname('Controller', 'Posts');
$this->assertEquals('PostsController', $result);
$result = $this->Task->getRealClassname('Controller', 'PostsController');
$this->assertEquals('PostsController', $result);
$result = $this->Task->getRealClassname('Controller', 'AlertTypes');
$this->assertEquals('AlertTypesController', $result);
$result = $this->Task->getRealClassname('Helper', 'Form');
$this->assertEquals('FormHelper', $result);
$result = $this->Task->getRealClassname('Helper', 'FormHelper');
$this->assertEquals('FormHelper', $result);
$result = $this->Task->getRealClassname('Behavior', 'Containable');
$this->assertEquals('ContainableBehavior', $result);
$result = $this->Task->getRealClassname('Behavior', 'ContainableBehavior');
$this->assertEquals('ContainableBehavior', $result);
$result = $this->Task->getRealClassname('Component', 'Auth');
$this->assertEquals('AuthComponent', $result);
}
/**
* test baking files. The conditionally run tests are known to fail in PHP4
* as PHP4 class names are all lower case, breaking the plugin path inflection.
*
* @return void
*/
public function testBakeModelTest() {
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$result = $this->Task->bake('Model', 'TestTaskArticle');
$this->assertContains("App::uses('TestTaskArticle', 'Model')", $result);
$this->assertContains('class TestTaskArticleTest extends CakeTestCase', $result);
$this->assertContains('function setUp()', $result);
$this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
$this->assertContains('function tearDown()', $result);
$this->assertContains('unset($this->TestTaskArticle)', $result);
$this->assertContains('function testDoSomething()', $result);
$this->assertContains('function testDoSomethingElse()', $result);
$this->assertContains('$this->markTestIncomplete(\'testDoSomething not implemented.\')', $result);
$this->assertContains('$this->markTestIncomplete(\'testDoSomethingElse not implemented.\')', $result);
$this->assertContains("'app.test_task_article'", $result);
$this->assertContains("'app.test_task_comment'", $result);
$this->assertContains("'app.test_task_tag'", $result);
$this->assertContains("'app.articles_tag'", $result);
}
/**
* test baking controller test files
*
* @return void
*/
public function testBakeControllerTest() {
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$result = $this->Task->bake('Controller', 'TestTaskComments');
$this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
$this->assertContains('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
$this->assertNotContains('function setUp()', $result);
$this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
$this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
$this->assertNotContains('function tearDown()', $result);
$this->assertNotContains('unset($this->TestTaskComments)', $result);
$this->assertContains("'app.test_task_article'", $result);
$this->assertContains("'app.test_task_comment'", $result);
$this->assertContains("'app.test_task_tag'", $result);
$this->assertContains("'app.articles_tag'", $result);
}
/**
* test baking component test files,
*
* @return void
*/
public function testBakeComponentTest() {
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$result = $this->Task->bake('Component', 'Example');
$this->assertContains("App::uses('Component', 'Controller')", $result);
$this->assertContains("App::uses('ComponentCollection', 'Controller')", $result);
$this->assertContains("App::uses('ExampleComponent', 'Controller/Component')", $result);
$this->assertContains('class ExampleComponentTest extends CakeTestCase', $result);
$this->assertContains('function setUp()', $result);
$this->assertContains("\$Collection = new ComponentCollection()", $result);
$this->assertContains("\$this->Example = new ExampleComponent(\$Collection)", $result);
$this->assertContains('function tearDown()', $result);
$this->assertContains('unset($this->Example)', $result);
}
/**
* test baking behavior test files,
*
* @return void
*/
public function testBakeBehaviorTest() {
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$result = $this->Task->bake('Behavior', 'Example');
$this->assertContains("App::uses('ExampleBehavior', 'Model/Behavior')", $result);
$this->assertContains('class ExampleBehaviorTest extends CakeTestCase', $result);
$this->assertContains('function setUp()', $result);
$this->assertContains("\$this->Example = new ExampleBehavior()", $result);
$this->assertContains('function tearDown()', $result);
$this->assertContains('unset($this->Example)', $result);
}
/**
* test baking helper test files,
*
* @return void
*/
public function testBakeHelperTest() {
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
$result = $this->Task->bake('Helper', 'Example');
$this->assertContains("App::uses('ExampleHelper', 'View/Helper')", $result);
$this->assertContains('class ExampleHelperTest extends CakeTestCase', $result);
$this->assertContains('function setUp()', $result);
$this->assertContains("\$View = new View()", $result);
$this->assertContains("\$this->Example = new ExampleHelper(\$View)", $result);
$this->assertContains('function tearDown()', $result);
$this->assertContains('unset($this->Example)', $result);
}
/**
* test Constructor generation ensure that constructClasses is called for controllers
*
* @return void
*/
public function testGenerateConstructor() {
$result = $this->Task->generateConstructor('controller', 'PostsController', null);
$expected = array('', '', '');
$this->assertEquals($expected, $result);
$result = $this->Task->generateConstructor('model', 'Post', null);
$expected = array('', "ClassRegistry::init('Post');\n", '');
$this->assertEquals($expected, $result);
$result = $this->Task->generateConstructor('helper', 'FormHelper', null);
$expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
$this->assertEquals($expected, $result);
}
/**
* Test generateUses()
*
* @return void
*/
public function testGenerateUses() {
$result = $this->Task->generateUses('model', 'Model', 'Post');
$expected = array(
array('Post', 'Model')
);
$this->assertEquals($expected, $result);
$result = $this->Task->generateUses('controller', 'Controller', 'PostsController');
$expected = array(
array('PostsController', 'Controller')
);
$this->assertEquals($expected, $result);
$result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');
$expected = array(
array('View', 'View'),
array('Helper', 'View'),
array('FormHelper', 'View/Helper'),
);
$this->assertEquals($expected, $result);
$result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');
$expected = array(
array('ComponentCollection', 'Controller'),
array('Component', 'Controller'),
array('AuthComponent', 'Controller/Component')
);
$this->assertEquals($expected, $result);
}
/**
* Test that mock class generation works for the appropriate classes
*
* @return void
*/
public function testMockClassGeneration() {
$result = $this->Task->hasMockClass('controller');
$this->assertTrue($result);
}
/**
* test bake() with a -plugin param
*
* @return void
*/
public function testBakeWithPlugin() {
$this->Task->plugin = 'TestTest';
//fake plugin path
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
$this->Task->expects($this->once())->method('createFile')
->with($path, $this->anything());
$this->Task->bake('Helper', 'Form');
CakePlugin::unload();
}
/**
* test interactive with plugins lists from the plugin
*
* @return void
*/
public function testInteractiveWithPlugin() {
$testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
App::build(array(
'Plugin' => array($testApp)
), App::RESET);
CakePlugin::load('TestPlugin');
$this->Task->plugin = 'TestPlugin';
$path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';
$this->Task->expects($this->any())
->method('in')
->will($this->onConsecutiveCalls(
5, //helper
1 //OtherHelper
));
$this->Task->expects($this->once())
->method('createFile')
->with($path, $this->anything());
$this->Task->stdout->expects($this->at(21))
->method('write')
->with('1. OtherHelperHelper');
$this->Task->execute();
}
public static function caseFileNameProvider() {
return array(
array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
);
}
/**
* Test filename generation for each type + plugins
*
* @dataProvider caseFileNameProvider
* @return void
*/
public function testTestCaseFileName($type, $class, $expected) {
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
$result = $this->Task->testCaseFileName($type, $class);
$expected = $this->Task->path . $expected;
$this->assertEquals($expected, $result);
}
/**
* Test filename generation for plugins.
*
* @return void
*/
public function testTestCaseFileNamePlugin() {
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$this->Task->plugin = 'TestTest';
$result = $this->Task->testCaseFileName('Model', 'Post');
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
$this->assertEquals($expected, $result);
}
/**
* test execute with a type defined
*
* @return void
*/
public function testExecuteWithOneArg() {
$this->Task->args[0] = 'Model';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->expects($this->once())->method('createFile')
->with(
$this->anything(),
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
);
$this->Task->execute();
}
/**
* test execute with type and class name defined
*
* @return void
*/
public function testExecuteWithTwoArgs() {
$this->Task->args = array('Model', 'TestTaskTag');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
$this->Task->expects($this->once())->method('createFile')
->with(
$this->anything(),
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
);
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->execute();
}
/**
* test execute with type and class name defined and lower case.
*
* @return void
*/
public function testExecuteWithTwoArgsLowerCase() {
$this->Task->args = array('model', 'TestTaskTag');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
$this->Task->expects($this->once())->method('createFile')
->with(
$this->anything(),
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
);
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->execute();
}
/**
* Data provider for mapType() tests.
*
* @return array
*/
public static function mapTypeProvider() {
return array(
array('controller', null, 'Controller'),
array('Controller', null, 'Controller'),
array('component', null, 'Controller/Component'),
array('Component', null, 'Controller/Component'),
array('model', null, 'Model'),
array('Model', null, 'Model'),
array('behavior', null, 'Model/Behavior'),
array('Behavior', null, 'Model/Behavior'),
array('helper', null, 'View/Helper'),
array('Helper', null, 'View/Helper'),
array('Helper', 'DebugKit', 'DebugKit.View/Helper'),
);
}
/**
* Test that mapType returns the correct package names.
*
* @dataProvider mapTypeProvider
* @return void
*/
public function testMapType($original, $plugin, $expected) {
$this->assertEquals($expected, $this->Task->mapType($original, $plugin));
}
}

View file

@ -0,0 +1,699 @@
<?php
/**
* ViewTask Test file
*
* Test Case for view generation shell task
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP v 1.2.0.7726
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ShellDispatcher', 'Console');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
App::uses('ViewTask', 'Console/Command/Task');
App::uses('ControllerTask', 'Console/Command/Task');
App::uses('TemplateTask', 'Console/Command/Task');
App::uses('ProjectTask', 'Console/Command/Task');
App::uses('DbConfigTask', 'Console/Command/Task');
App::uses('Model', 'Model');
App::uses('Controller', 'Controller');
App::uses('AppController', 'Controller');
/**
* Test View Task Comment Model
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ViewTaskComment extends Model {
/**
* Table name
*
* @var string
*/
public $useTable = 'comments';
/**
* Belongs To Associations
*
* @var array
*/
public $belongsTo = array(
'Article' => array(
'className' => 'TestTest.ViewTaskArticle',
'foreignKey' => 'article_id'
)
);
}
/**
* Test View Task Article Model
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ViewTaskArticle extends Model {
/**
* Table name
*
* @var string
*/
public $useTable = 'articles';
}
/**
* Test View Task Comments Controller
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ViewTaskCommentsController extends Controller {
/**
* Testing public controller action
*
* @return void
*/
public function index() {
}
/**
* Testing public controller action
*
* @return void
*/
public function add() {
}
}
/**
* Test View Task Articles Controller
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ViewTaskArticlesController extends Controller {
/**
* Test public controller action
*
* @return void
*/
public function index() {
}
/**
* Test public controller action
*
* @return void
*/
public function add() {
}
/**
* Test admin prefixed controller action
*
* @return void
*/
public function admin_index() {
}
/**
* Test admin prefixed controller action
*
* @return void
*/
public function admin_add() {
}
/**
* Test admin prefixed controller action
*
* @return void
*/
public function admin_view() {
}
/**
* Test admin prefixed controller action
*
* @return void
*/
public function admin_edit() {
}
/**
* Test admin prefixed controller action
*
* @return void
*/
public function admin_delete() {
}
}
/**
* ViewTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class ViewTaskTest extends CakeTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
/**
* setUp method
*
* Ensure that the default theme is used
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ViewTask',
array('in', 'err', 'createFile', '_stop'),
array($out, $out, $in)
);
$this->Task->Template = new TemplateTask($out, $out, $in);
$this->Task->Controller = $this->getMock('ControllerTask', array(), array($out, $out, $in));
$this->Task->Project = $this->getMock('ProjectTask', array(), array($out, $out, $in));
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array($out, $out, $in));
$this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default';
$this->Task->Template->templatePaths = array('default' => CAKE . 'Console' . DS . 'Templates' . DS . 'default' . DS);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatch);
}
/**
* Test getContent and parsing of Templates.
*
* @return void
*/
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->assertRegExp('/Delete Test View Model/', $result);
$this->assertRegExp('/Edit Test View Model/', $result);
$this->assertRegExp('/List Test View Models/', $result);
$this->assertRegExp('/New Test View Model/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
}
/**
* test getContent() using an admin_prefixed action.
*
* @return void
*/
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->assertRegExp('/Delete Test View Model/', $result);
$this->assertRegExp('/Edit Test View Model/', $result);
$this->assertRegExp('/List Test View Models/', $result);
$this->assertRegExp('/New Test View Model/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertRegExp('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
$result = $this->Task->getContent('admin_add', $vars);
$this->assertRegExp("/input\('name'\)/", $result);
$this->assertRegExp("/input\('body'\)/", $result);
$this->assertRegExp('/List Test View Models/', $result);
Configure::write('Routing', $_back);
}
/**
* test Bake method
*
* @return void
*/
public function testBakeView() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
$this->stringContains('View Task Articles')
);
$this->Task->bake('view', true);
}
/**
* test baking an edit file
*
* @return void
*/
public function testBakeEdit() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
new PHPUnit_Framework_Constraint_IsAnything()
);
$this->Task->bake('edit', true);
}
/**
* test baking an index
*
* @return void
*/
public function testBakeIndex() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->stringContains("\$viewTaskComment['Article']['title']")
);
$this->Task->bake('index', true);
}
/**
* test that baking a view with no template doesn't make a file.
*
* @return void
*/
public function testBakeWithNoTemplate() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->never())->method('createFile');
$this->Task->bake('delete', true);
}
/**
* test bake() with a -plugin param
*
* @return void
*/
public function testBakeWithPlugin() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->plugin = 'TestTest';
$this->Task->name = 'View';
//fake plugin path
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'View' . DS . 'ViewTaskComments' . DS . 'view.ctp';
$result = $this->Task->getContent('index');
$this->assertNotContains('List Test Test.view Task Articles', $result);
$this->Task->expects($this->once())
->method('createFile')
->with($path, $this->anything());
$this->Task->bake('view', true);
CakePlugin::unload();
}
/**
* test bake actions baking multiple actions.
*
* @return void
*/
public function testBakeActions() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
$this->stringContains('View Task Comments')
);
$this->Task->expects($this->at(1))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
$this->stringContains('Edit View Task Comment')
);
$this->Task->expects($this->at(2))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
}
/**
* test baking a customAction (non crud)
*
* @return void
*/
public function testCustomAction() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('', 'my_action', 'y'));
$this->Task->expects($this->once())->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'my_action.ctp',
$this->anything()
);
$this->Task->customAction();
}
/**
* Test all()
*
* @return void
*/
public function testExecuteIntoAll() {
$this->Task->args[0] = 'all';
$this->Task->Controller->expects($this->once())->method('listAll')
->will($this->returnValue(array('view_task_comments')));
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->anything()
);
$this->Task->expects($this->at(1))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'add.ctp',
$this->anything()
);
$this->Task->expects($this->exactly(2))->method('createFile');
$this->Task->execute();
}
/**
* Test all() with action parameter
*
* @return void
*/
public function testExecuteIntoAllWithActionName() {
$this->Task->args = array('all', 'index');
$this->Task->Controller->expects($this->once())->method('listAll')
->will($this->returnValue(array('view_task_comments')));
$this->Task->expects($this->once())->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->anything()
);
$this->Task->execute();
}
/**
* test `cake bake view $controller view`
*
* @return void
*/
public function testExecuteWithActionParam() {
$this->Task->args[0] = 'ViewTaskComments';
$this->Task->args[1] = 'view';
$this->Task->expects($this->once())->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
$this->anything()
);
$this->Task->execute();
}
/**
* test `cake bake view $controller`
* Ensure that views are only baked for actions that exist in the controller.
*
* @return void
*/
public function testExecuteWithController() {
$this->Task->args[0] = 'ViewTaskComments';
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->anything()
);
$this->Task->expects($this->at(1))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'add.ctp',
$this->anything()
);
$this->Task->expects($this->exactly(2))->method('createFile');
$this->Task->execute();
}
/**
* static dataprovider for test cases
*
* @return void
*/
public static function nameVariations() {
return array(array('ViewTaskComments'), array('ViewTaskComment'), array('view_task_comment'));
}
/**
* test that both plural and singular forms can be used for baking views.
*
* @dataProvider nameVariations
* @return void
*/
public function testExecuteWithControllerVariations($name) {
$this->Task->args = array($name);
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->anything()
);
$this->Task->expects($this->at(1))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'add.ctp',
$this->anything()
);
$this->Task->execute();
}
/**
* test `cake bake view $controller --admin`
* Which only bakes admin methods, not non-admin methods.
*
* @return void
*/
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->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
$this->Task->expects($this->exactly(4))->method('createFile');
$views = array('admin_index.ctp', 'admin_add.ctp', 'admin_view.ctp', 'admin_edit.ctp');
foreach ($views as $i => $view) {
$this->Task->expects($this->at($i))->method('createFile')
->with(
TMP . 'ViewTaskArticles' . DS . $view,
$this->anything()
);
}
$this->Task->execute();
Configure::write('Routing', $_back);
}
/**
* test execute into interactive.
*
* @return void
*/
public function testExecuteInteractive() {
$this->Task->connection = 'test';
$this->Task->args = array();
$this->Task->params = array();
$this->Task->Controller->expects($this->once())->method('getName')
->will($this->returnValue('ViewTaskComments'));
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('y', 'y', 'n'));
$this->Task->expects($this->at(3))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->expects($this->at(4))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->expects($this->at(5))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'add.ctp',
$this->stringContains('Add View Task Comment')
);
$this->Task->expects($this->at(6))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
$this->stringContains('Edit View Task Comment')
);
$this->Task->expects($this->exactly(4))->method('createFile');
$this->Task->execute();
}
/**
* test `cake bake view posts index list`
*
* @return void
*/
public function testExecuteWithAlternateTemplates() {
$this->Task->connection = 'test';
$this->Task->args = array('ViewTaskComments', 'index', 'list');
$this->Task->params = array();
$this->Task->expects($this->once())->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'list.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->execute();
}
/**
* test execute into interactive() with admin methods.
*
* @return void
*/
public function testExecuteInteractiveWithAdmin() {
Configure::write('Routing.prefixes', array('admin'));
$this->Task->connection = 'test';
$this->Task->args = array();
$this->Task->Controller->expects($this->once())->method('getName')
->will($this->returnValue('ViewTaskComments'));
$this->Task->Project->expects($this->once())->method('getPrefix')
->will($this->returnValue('admin_'));
$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls('y', 'n', 'y'));
$this->Task->expects($this->at(3))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_index.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->expects($this->at(4))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_view.ctp',
$this->stringContains('ViewTaskComment')
);
$this->Task->expects($this->at(5))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_add.ctp',
$this->stringContains('Add View Task Comment')
);
$this->Task->expects($this->at(6))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_edit.ctp',
$this->stringContains('Edit View Task Comment')
);
$this->Task->expects($this->exactly(4))->method('createFile');
$this->Task->execute();
}
/**
* test getting templates, make sure noTemplateActions works and prefixed template is used before generic one.
*
* @return void
*/
public function testGetTemplate() {
$result = $this->Task->getTemplate('delete');
$this->assertFalse($result);
$result = $this->Task->getTemplate('add');
$this->assertEquals('form', $result);
Configure::write('Routing.prefixes', array('admin'));
$result = $this->Task->getTemplate('admin_add');
$this->assertEquals('form', $result);
$this->Task->Template->templatePaths = array(
'test' => CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Templates' . DS . 'test' . DS
);
$this->Task->Template->params['theme'] = 'test';
$result = $this->Task->getTemplate('admin_edit');
$this->assertEquals('admin_edit', $result);
}
}