| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <?php
- /**
- * 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
- * @since 1.3.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Console\Command\Task;
- use Cake\Console\Command\Task\ControllerTask;
- use Cake\Console\Command\Task\TemplateTask;
- use Cake\Console\Shell;
- use Cake\Core\App;
- use Cake\Core\Plugin;
- use Cake\ORM\Table;
- use Cake\TestSuite\TestCase;
- use Cake\Utility\ClassRegistry;
- use Cake\View\Helper;
- /**
- * Class BakeArticle
- */
- class BakeArticlesTable extends Table {
- public function initialize(array $config) {
- $this->hasMany('BakeComments');
- $this->belongsToMany('BakeTags');
- }
- }
- class_alias(
- 'Cake\Test\TestCase\Console\Command\Task\BakeArticlesTable',
- 'TestApp\Model\Table\BakeArticlesTable'
- );
- /**
- * ControllerTaskTest class
- *
- */
- class ControllerTaskTest extends TestCase {
- /**
- * fixtures
- *
- * @var array
- */
- public $fixtures = ['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('Cake\Console\ConsoleOutput', array(), array(), '', false);
- $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
- $this->Task = $this->getMock('Cake\Console\Command\Task\ControllerTask',
- array('in', 'out', 'err', 'hr', 'createFile', '_stop'),
- array($out, $out, $in)
- );
- $this->Task->name = 'Controller';
- $this->Task->connection = 'test';
- $this->Task->Template = new TemplateTask($out, $out, $in);
- $this->Task->Template->params['theme'] = 'default';
- $this->Task->Model = $this->getMock('Cake\Console\Command\Task\ModelTask',
- array('in', 'out', 'err', 'createFile', '_stop'),
- array($out, $out, $in)
- );
- $this->Task->Project = $this->getMock('Cake\Console\Command\Task\ProjectTask',
- array('in', 'out', 'err', 'createFile', '_stop', 'getPrefix'),
- array($out, $out, $in)
- );
- $this->Task->Test = $this->getMock('Cake\Console\Command\Task\TestTask', array(), array($out, $out, $in));
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- unset($this->Task);
- 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.');
- }
- $result = $this->Task->listAll();
- $expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');
- $this->assertEquals($expected, $result);
- }
- /**
- * test helper interactions
- *
- * @return void
- */
- public function testDoHelpersNo() {
- $this->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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() {
- $this->markTestIncomplete();
- $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() {
- $this->markTestIncomplete();
- $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->markTestIncomplete();
- $this->Task->plugin = 'ControllerTest';
- //fake plugin path
- Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
- $path = APP . 'Plugin/ControllerTest/Controller/ArticlesController.php';
- $this->Task->expects($this->at(1))->method('createFile')->with(
- $path,
- $this->anything()
- );
- $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/ControllerTest/Controller/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->viewVars['plugin']);
- $this->assertEquals('ControllerTest.', $this->Task->Template->viewVars['pluginPath']);
- Plugin::unload();
- }
- /**
- * test that bakeActions is creating the correct controller Code. (Using sessions)
- *
- * @return void
- */
- public function testBakeActionsUsingSessions() {
- $this->markTestIncomplete();
- $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 a test
- *
- * @return void
- */
- public function testBakeTest() {
- $this->Task->plugin = 'ControllerTest';
- $this->Task->connection = 'test';
- $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);
- }
- /**
- * test baking a test
- *
- * @return void
- */
- public function testBakeTestDisabled() {
- $this->Task->plugin = 'ControllerTest';
- $this->Task->connection = 'test';
- $this->Task->params['no-test'] = true;
- $this->Task->Test->expects($this->never())
- ->method('bake');
- $this->Task->bakeTest('BakeArticles');
- }
- /**
- * test Interactive mode.
- *
- * @return void
- */
- public function testInteractive() {
- $this->markTestIncomplete();
- $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() {
- $this->markTestIncomplete();
- $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() {
- $this->markTestIncomplete();
- $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() {
- $this->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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->markTestIncomplete();
- $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();
- }
- }
|