2009-05-15 03:17:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ControllerTask Test Case
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-05-15 03:17:42 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-05-15 03:17:42 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-15 03:17:42 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-05-15 03:17:42 +00:00
|
|
|
*/
|
|
|
|
|
2012-05-25 16:27:40 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
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');
|
2009-06-07 00:25:57 +00:00
|
|
|
|
2011-03-08 05:55:01 +00:00
|
|
|
App::uses('BakeArticle', 'Model');
|
|
|
|
App::uses('BakeComment', 'Model');
|
|
|
|
App::uses('BakeTags', 'Model');
|
|
|
|
$imported = class_exists('BakeArticle') || class_exists('BakeComment') || class_exists('BakeTag');
|
|
|
|
|
|
|
|
if (!$imported) {
|
2009-05-19 03:46:20 +00:00
|
|
|
define('ARTICLE_MODEL_CREATED', true);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-05-31 14:37:20 +00:00
|
|
|
/**
|
|
|
|
* Class BakeArticle
|
|
|
|
*/
|
2010-07-09 03:25:39 +00:00
|
|
|
class BakeArticle extends Model {
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
public $hasMany = array('BakeComment');
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
public $hasAndBelongsToMany = array('BakeTag');
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2009-05-19 03:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-15 03:17:42 +00:00
|
|
|
/**
|
|
|
|
* ControllerTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-15 03:17:42 +00:00
|
|
|
*/
|
|
|
|
class ControllerTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 03:17:42 +00:00
|
|
|
/**
|
|
|
|
* fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-07-09 03:25:39 +00:00
|
|
|
public $fixtures = array('core.bake_article', 'core.bake_articles_bake_tag', 'core.bake_comment', 'core.bake_tag');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 03:17:42 +00:00
|
|
|
/**
|
2010-09-21 03:42:35 +00:00
|
|
|
* setUp method
|
2009-05-15 03:17:42 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-21 03:42:35 +00:00
|
|
|
public function setUp() {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2011-03-19 17:46:00 +00:00
|
|
|
$this->Task = $this->getMock('ControllerTask',
|
2010-05-30 04:59:36 +00:00
|
|
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-05-26 03:51:48 +00:00
|
|
|
);
|
2010-10-19 03:09:23 +00:00
|
|
|
$this->Task->name = 'Controller';
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->Template = new TemplateTask($out, $out, $in);
|
2009-07-07 03:11:57 +00:00
|
|
|
$this->Task->Template->params['theme'] = 'default';
|
2010-05-26 03:51:48 +00:00
|
|
|
|
2011-03-19 17:46:00 +00:00
|
|
|
$this->Task->Model = $this->getMock('ModelTask',
|
|
|
|
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-05-26 03:54:28 +00:00
|
|
|
);
|
2011-03-19 17:46:00 +00:00
|
|
|
$this->Task->Project = $this->getMock('ProjectTask',
|
|
|
|
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-05-26 03:54:28 +00:00
|
|
|
);
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->Test = $this->getMock('TestTask', array(), array($out, $out, $in));
|
2013-01-16 17:59:13 +00:00
|
|
|
|
|
|
|
if (!defined('ARTICLE_MODEL_CREATED')) {
|
|
|
|
$this->markTestSkipped('Could not run as an Article, Tag or Comment model was already loaded.');
|
|
|
|
}
|
2009-05-15 03:17:42 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 03:17:42 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown method
|
2009-05-15 03:17:42 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function tearDown() {
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2009-05-15 03:17:42 +00:00
|
|
|
ClassRegistry::flush();
|
2011-04-21 23:27:21 +00:00
|
|
|
App::build();
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::tearDown();
|
2009-05-15 03:17:42 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 03:17:42 +00:00
|
|
|
/**
|
|
|
|
* test ListAll
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testListAll() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:19:32 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-15 03:17:42 +00:00
|
|
|
$this->Task->interactive = true;
|
2012-07-26 05:12:55 +00:00
|
|
|
$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');
|
2010-05-26 03:51:48 +00:00
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
$expected = array('BakeArticles', 'BakeArticlesBakeTags', 'BakeComments', 'BakeTags');
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->listAll('test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-15 03:17:42 +00:00
|
|
|
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
$result = $this->Task->listAll();
|
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
$expected = array('bake_articles', 'bake_articles_bake_tags', 'bake_comments', 'bake_tags');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-15 03:17:42 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 03:28:27 +00:00
|
|
|
/**
|
|
|
|
* Test that getName interacts with the user and returns the controller name.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-27 01:59:56 +00:00
|
|
|
public function testGetNameValidIndex() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:19:32 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
2010-03-05 02:57:48 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-09-21 03:42:35 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will(
|
|
|
|
$this->onConsecutiveCalls(3, 1)
|
|
|
|
);
|
2011-03-19 17:46:00 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->getName('test');
|
2010-07-09 03:25:39 +00:00
|
|
|
$expected = 'BakeComments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-03-19 17:46:00 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->getName('test');
|
2010-07-09 03:25:39 +00:00
|
|
|
$expected = 'BakeArticles';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-05-27 01:59:56 +00:00
|
|
|
}
|
2009-05-15 03:28:27 +00:00
|
|
|
|
2010-05-27 01:59:56 +00:00
|
|
|
/**
|
|
|
|
* test getting invalid indexes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetNameInvalidIndex() {
|
2010-05-27 01:59:56 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-07-10 04:19:32 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls(50, 'q'));
|
|
|
|
|
2010-05-27 01:59:56 +00:00
|
|
|
$this->Task->expects($this->once())->method('err');
|
|
|
|
$this->Task->expects($this->once())->method('_stop');
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->getName('test');
|
2009-05-15 03:28:27 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 04:04:57 +00:00
|
|
|
/**
|
|
|
|
* test helper interactions
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-27 03:01:14 +00:00
|
|
|
public function testDoHelpersNo() {
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
2009-05-15 04:04:57 +00:00
|
|
|
$result = $this->Task->doHelpers();
|
2012-10-26 22:18:05 +00:00
|
|
|
$this->assertSame(array(), $result);
|
2010-05-27 03:01:14 +00:00
|
|
|
}
|
2009-05-15 04:04:57 +00:00
|
|
|
|
2010-05-27 03:01:14 +00:00
|
|
|
/**
|
|
|
|
* test getting helper values
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDoHelpersTrailingSpace() {
|
2010-05-27 03:01:14 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
2012-09-30 07:38:57 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne '));
|
2009-05-15 04:04:57 +00:00
|
|
|
$result = $this->Task->doHelpers();
|
2012-09-30 07:38:57 +00:00
|
|
|
$expected = array('Text', 'Number', 'CustomOne');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-05-27 03:01:14 +00:00
|
|
|
}
|
2009-06-07 16:22:43 +00:00
|
|
|
|
2010-05-27 03:01:14 +00:00
|
|
|
/**
|
|
|
|
* test doHelpers with extra commas
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDoHelpersTrailingCommas() {
|
2010-05-27 03:01:14 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
2012-09-30 07:38:57 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
|
2009-06-07 16:22:43 +00:00
|
|
|
$result = $this->Task->doHelpers();
|
2012-09-30 07:38:57 +00:00
|
|
|
$expected = array('Text', 'Number', 'CustomOne');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-15 04:04:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-15 04:04:57 +00:00
|
|
|
/**
|
|
|
|
* test component interactions
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-27 03:01:14 +00:00
|
|
|
public function testDoComponentsNo() {
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
2009-05-15 04:04:57 +00:00
|
|
|
$result = $this->Task->doComponents();
|
2013-07-20 14:59:39 +00:00
|
|
|
$this->assertSame(array('Paginator'), $result);
|
2010-05-27 03:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test components with spaces
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDoComponentsTrailingSpaces() {
|
2010-05-27 03:01:14 +00:00
|
|
|
$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 '));
|
2009-05-15 04:04:57 +00:00
|
|
|
|
|
|
|
$result = $this->Task->doComponents();
|
2013-07-20 14:59:39 +00:00
|
|
|
$expected = array('Paginator', 'RequestHandler', 'Security');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-05-27 03:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test components with commas
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDoComponentsTrailingCommas() {
|
2010-05-27 03:01:14 +00:00
|
|
|
$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, , '));
|
2009-06-07 16:22:43 +00:00
|
|
|
|
|
|
|
$result = $this->Task->doComponents();
|
2013-07-20 14:59:39 +00:00
|
|
|
$expected = array('Paginator', 'RequestHandler', 'Security');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-15 04:04:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-17 03:17:40 +00:00
|
|
|
/**
|
|
|
|
* test Confirming controller user interaction
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:07:43 +00:00
|
|
|
public function testConfirmController() {
|
2009-05-17 03:17:40 +00:00
|
|
|
$controller = 'Posts';
|
|
|
|
$scaffold = false;
|
2012-09-30 07:38:57 +00:00
|
|
|
$helpers = array('Js', 'Time');
|
2009-05-17 03:17:40 +00:00
|
|
|
$components = array('Acl', 'Auth');
|
|
|
|
|
2010-05-30 04:07:43 +00:00
|
|
|
$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
|
2012-09-30 07:38:57 +00:00
|
|
|
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
|
2010-05-30 04:07:43 +00:00
|
|
|
$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
|
2009-05-19 02:26:16 +00:00
|
|
|
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
|
2009-05-17 03:17:40 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-17 04:04:33 +00:00
|
|
|
/**
|
|
|
|
* test the bake method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:07:43 +00:00
|
|
|
public function testBake() {
|
2012-09-30 07:38:57 +00:00
|
|
|
$helpers = array('Js', 'Time');
|
2009-05-17 04:04:33 +00:00
|
|
|
$components = array('Acl', 'Auth');
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
|
2009-05-17 04:04:33 +00:00
|
|
|
|
2013-08-09 21:06:15 +00:00
|
|
|
$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);
|
2009-05-17 04:04:33 +00:00
|
|
|
|
2009-06-07 00:25:57 +00:00
|
|
|
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
|
2013-08-09 21:06:15 +00:00
|
|
|
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'Scaffold.ctp');
|
|
|
|
$this->assertTextEquals($expected, $result);
|
2009-05-19 02:26:16 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-07 00:25:57 +00:00
|
|
|
/**
|
|
|
|
* test bake() with a -plugin param
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:07:43 +00:00
|
|
|
public function testBakeWithPlugin() {
|
2009-06-07 00:25:57 +00:00
|
|
|
$this->Task->plugin = 'ControllerTest';
|
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
//fake plugin path
|
2012-03-11 04:32:02 +00:00
|
|
|
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
|
2011-05-13 07:53:53 +00:00
|
|
|
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
|
2010-05-26 03:51:48 +00:00
|
|
|
|
2010-11-21 17:47:49 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('createFile')->with(
|
2010-05-30 04:07:43 +00:00
|
|
|
$path,
|
|
|
|
new PHPUnit_Framework_Constraint_IsAnything()
|
|
|
|
);
|
2010-11-21 17:47:49 +00:00
|
|
|
$this->Task->expects($this->at(3))->method('createFile')->with(
|
2010-05-30 04:07:43 +00:00
|
|
|
$path,
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ArticlesController extends ControllerTestAppController')
|
2011-09-10 00:40:32 +00:00
|
|
|
)->will($this->returnValue(true));
|
2011-03-19 17:46:00 +00:00
|
|
|
|
2009-06-07 00:25:57 +00:00
|
|
|
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
$this->Task->plugin = 'ControllerTest';
|
2011-05-13 07:53:53 +00:00
|
|
|
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
|
2011-09-10 00:40:32 +00:00
|
|
|
$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']);
|
2010-09-03 16:33:59 +00:00
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::unload();
|
2009-06-07 00:25:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-19 03:46:20 +00:00
|
|
|
/**
|
|
|
|
* test that bakeActions is creating the correct controller Code. (Using sessions)
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testBakeActionsUsingSessions() {
|
2010-07-09 03:25:39 +00:00
|
|
|
$result = $this->Task->bakeActions('BakeArticles', null, true);
|
2013-08-09 21:06:15 +00:00
|
|
|
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsUsingSessions.ctp');
|
|
|
|
$this->assertTextEquals($expected, $result);
|
2009-05-19 03:46:20 +00:00
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
$result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
|
2010-07-09 03:38:11 +00:00
|
|
|
$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);
|
2009-05-19 03:46:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-19 03:46:20 +00:00
|
|
|
/**
|
|
|
|
* Test baking with Controller::flash() or no sessions.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testBakeActionsWithNoSessions() {
|
2010-07-09 03:25:39 +00:00
|
|
|
$result = $this->Task->bakeActions('BakeArticles', null, false);
|
2013-08-09 21:06:15 +00:00
|
|
|
$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsWithNoSessions.ctp');
|
|
|
|
$this->assertTextEquals($expected, $result);
|
2009-05-19 03:46:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-07 00:25:57 +00:00
|
|
|
/**
|
|
|
|
* test baking a test
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testBakeTest() {
|
2009-06-07 00:25:57 +00:00
|
|
|
$this->Task->plugin = 'ControllerTest';
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-03-05 03:02:49 +00:00
|
|
|
$this->Task->interactive = false;
|
2009-06-07 00:25:57 +00:00
|
|
|
|
2010-07-09 03:25:39 +00:00
|
|
|
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'BakeArticles');
|
|
|
|
$this->Task->bakeTest('BakeArticles');
|
2009-06-07 00:25:57 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$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);
|
2009-06-07 00:25:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-19 04:18:59 +00:00
|
|
|
/**
|
|
|
|
* test Interactive mode.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testInteractive() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:19:32 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2011-03-19 17:46:00 +00:00
|
|
|
|
2010-06-12 20:10:16 +00:00
|
|
|
$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?
|
|
|
|
));
|
2009-05-19 04:18:59 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-03-19 17:46:00 +00:00
|
|
|
$filename,
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('class BakeArticlesController')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
|
|
|
$this->Task->execute();
|
2009-05-19 04:18:59 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-05 03:27:41 +00:00
|
|
|
/**
|
|
|
|
* test Interactive mode.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInteractiveAdminMethodsNotInteractive() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:19:32 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-05-05 03:27:41 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-05-05 03:27:41 +00:00
|
|
|
|
2010-06-12 20:10:16 +00:00
|
|
|
$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?
|
|
|
|
));
|
|
|
|
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->Project->expects($this->any())
|
|
|
|
->method('getPrefix')
|
|
|
|
->will($this->returnValue('admin_'));
|
2010-05-05 03:27:41 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-03-19 17:46:00 +00:00
|
|
|
$filename,
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('class BakeArticlesController')
|
2010-05-30 04:59:36 +00:00
|
|
|
)->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$result = $this->Task->execute();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/admin_index/', $result);
|
2010-05-05 03:27:41 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 02:26:16 +00:00
|
|
|
/**
|
|
|
|
* test that execute runs all when the first arg == all
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteIntoAll() {
|
2010-09-21 03:42:35 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
2013-01-16 17:57:18 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-19 02:26:16 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
|
|
|
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->Test->expects($this->once())->method('bake');
|
2009-07-15 14:14:16 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-03-19 17:46:00 +00:00
|
|
|
$filename,
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('class BakeArticlesController')
|
2010-05-30 04:59:36 +00:00
|
|
|
)->will($this->returnValue(true));
|
2009-05-19 02:26:16 +00:00
|
|
|
|
2009-05-20 04:31:59 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-01-16 17:57:18 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2009-05-20 04:31:59 +00:00
|
|
|
/**
|
2009-07-29 16:47:25 +00:00
|
|
|
* test that `cake bake controller foos` works.
|
2009-05-20 04:31:59 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteWithController() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-20 04:31:59 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-07-09 03:25:39 +00:00
|
|
|
$this->Task->args = array('BakeArticles');
|
2009-05-20 04:31:59 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-03-19 17:46:00 +00:00
|
|
|
$filename,
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('$scaffold')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
2009-05-20 04:31:59 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-30 04:59:36 +00:00
|
|
|
/**
|
|
|
|
* data provider for testExecuteWithControllerNameVariations
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:32:02 +00:00
|
|
|
public static function nameVariations() {
|
2010-05-30 04:59:36 +00:00
|
|
|
return array(
|
2010-07-09 03:25:39 +00:00
|
|
|
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
|
|
|
}
|
2010-06-12 21:43:12 +00:00
|
|
|
|
2010-03-06 02:30:58 +00:00
|
|
|
/**
|
|
|
|
* test that both plural and singular forms work for controller baking.
|
|
|
|
*
|
2010-05-30 04:59:36 +00:00
|
|
|
* @dataProvider nameVariations
|
2010-03-06 02:30:58 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteWithControllerNameVariations($name) {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->args = array($name);
|
2010-03-06 02:30:58 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-09-29 04:35:15 +00:00
|
|
|
$filename, $this->stringContains('$scaffold')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-05-20 04:31:59 +00:00
|
|
|
/**
|
2009-07-29 16:47:25 +00:00
|
|
|
* test that `cake bake controller foo scaffold` works.
|
2009-05-20 04:31:59 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteWithPublicParam() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-07-29 02:53:29 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-10-13 03:23:18 +00:00
|
|
|
$this->Task->args = array('BakeArticles');
|
|
|
|
$this->Task->params = array('public' => true);
|
2009-07-29 02:53:29 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2011-09-29 04:35:15 +00:00
|
|
|
$expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
|
|
|
$filename, $expected
|
|
|
|
);
|
2009-07-29 02:53:29 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that `cake bake controller foos both` works.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteWithControllerAndBoth() {
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-07-29 02:53:29 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-10-13 03:23:18 +00:00
|
|
|
$this->Task->args = array('BakeArticles');
|
|
|
|
$this->Task->params = array('public' => true, 'admin' => true);
|
2009-07-29 02:53:29 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-09-29 04:35:15 +00:00
|
|
|
$filename, $this->stringContains('admin_index')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
2009-07-29 02:53:29 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that `cake bake controller foos admin` works.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-05-30 04:59:36 +00:00
|
|
|
public function testExecuteWithControllerAndAdmin() {
|
2010-05-26 03:51:48 +00:00
|
|
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-20 04:31:59 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-10-13 03:23:18 +00:00
|
|
|
$this->Task->args = array('BakeArticles');
|
|
|
|
$this->Task->params = array('admin' => true);
|
2009-05-20 04:31:59 +00:00
|
|
|
|
2011-03-16 02:23:51 +00:00
|
|
|
$filename = '/my/path/BakeArticlesController.php';
|
2010-05-30 04:59:36 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->with(
|
2011-09-29 04:35:15 +00:00
|
|
|
$filename, $this->stringContains('admin_index')
|
2010-05-30 04:59:36 +00:00
|
|
|
);
|
2009-05-19 02:26:16 +00:00
|
|
|
$this->Task->execute();
|
2009-05-17 04:04:33 +00:00
|
|
|
}
|
2011-05-16 22:49:00 +00:00
|
|
|
}
|