2009-05-30 04:28:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-07-17 03:12:47 +00:00
|
|
|
* ViewTask Test file
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
2009-07-17 03:12:47 +00:00
|
|
|
* Test Case for view generation shell task
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc.
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-30 04:28:18 +00:00
|
|
|
* @since CakePHP v 1.2.0.7726
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2009-05-30 04:28:18 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-07 05:15:00 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 05:13:11 +00:00
|
|
|
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');
|
2011-03-07 05:15:00 +00:00
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('Controller', 'Controller');
|
2009-06-04 03:18:14 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test View Task Comment Model
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-06-04 01:59:46 +00:00
|
|
|
class ViewTaskComment extends Model {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Model name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ViewTaskComment';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-06-05 03:35:36 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Belongs To Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array(
|
2009-06-05 03:35:36 +00:00
|
|
|
'Article' => array(
|
2011-10-13 01:09:19 +00:00
|
|
|
'className' => 'TestTest.ViewTaskArticle',
|
2009-06-05 03:35:36 +00:00
|
|
|
'foreignKey' => 'article_id'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test View Task Article Model
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-06-05 03:35:36 +00:00
|
|
|
class ViewTaskArticle extends Model {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Model name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ViewTaskArticle';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'articles';
|
2009-06-04 01:59:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
2010-02-13 22:51:49 +00:00
|
|
|
* Test View Task Comments Controller
|
2009-11-14 12:18:31 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-06-04 01:59:46 +00:00
|
|
|
class ViewTaskCommentsController extends Controller {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ViewTaskComments';
|
2009-06-05 03:35:36 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Testing public controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2009-06-05 03:35:36 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Testing public controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function add() {
|
2009-06-05 03:35:36 +00:00
|
|
|
}
|
2009-06-04 01:59:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test View Task Articles Controller
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-07-17 03:12:47 +00:00
|
|
|
class ViewTaskArticlesController extends Controller {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ViewTaskArticles';
|
2009-07-17 03:12:47 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test public controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function index() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test public controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function add() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test admin prefixed controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_index() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test admin prefixed controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_add() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test admin prefixed controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_view() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test admin prefixed controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_edit() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test admin prefixed controller action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function admin_delete() {
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-04 01:59:46 +00:00
|
|
|
|
2009-05-30 04:28:18 +00:00
|
|
|
/**
|
|
|
|
* ViewTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-30 04:28:18 +00:00
|
|
|
*/
|
|
|
|
class ViewTaskTest extends CakeTestCase {
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-30 04:28:18 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
2009-08-18 08:14:39 +00:00
|
|
|
* Ensure that the default theme is used
|
|
|
|
*
|
2009-05-30 04:28:18 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task = $this->getMock('ViewTask',
|
|
|
|
array('in', 'err', 'createFile', '_stop'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2010-10-24 19:27:04 +00:00
|
|
|
$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));
|
2010-06-12 19:03:00 +00:00
|
|
|
|
2009-07-01 01:50:28 +00:00
|
|
|
$this->Task->path = TMP;
|
2009-08-18 08:14:39 +00:00
|
|
|
$this->Task->Template->params['theme'] = 'default';
|
2009-05-30 04:28:18 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-30 04:28:18 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* tearDown method
|
2009-05-30 04:28:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
unset($this->Task, $this->Dispatch);
|
2009-05-30 04:28:18 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-30 04:28:18 +00:00
|
|
|
/**
|
|
|
|
* Test getContent and parsing of Templates.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetContent() {
|
2009-05-30 04:28:18 +00:00
|
|
|
$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);
|
|
|
|
|
2010-05-07 01:38:14 +00:00
|
|
|
$this->assertPattern('/Delete Test View Model/', $result);
|
|
|
|
$this->assertPattern('/Edit Test View Model/', $result);
|
|
|
|
$this->assertPattern('/List Test View Models/', $result);
|
|
|
|
$this->assertPattern('/New Test View Model/', $result);
|
2009-05-30 04:28:18 +00:00
|
|
|
|
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
|
2009-06-04 01:59:46 +00:00
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
|
2009-05-30 04:28:18 +00:00
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-02 03:21:41 +00:00
|
|
|
/**
|
|
|
|
* test getContent() using an admin_prefixed action.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetContentWithAdminAction() {
|
2009-10-07 05:35:29 +00:00
|
|
|
$_back = Configure::read('Routing');
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2009-07-02 03:21:41 +00:00
|
|
|
$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);
|
|
|
|
|
2010-05-07 01:38:14 +00:00
|
|
|
$this->assertPattern('/Delete Test View Model/', $result);
|
|
|
|
$this->assertPattern('/Edit Test View Model/', $result);
|
|
|
|
$this->assertPattern('/List Test View Models/', $result);
|
|
|
|
$this->assertPattern('/New Test View Model/', $result);
|
2009-07-02 03:21:41 +00:00
|
|
|
|
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
|
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
|
|
|
|
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
|
|
|
|
|
2009-11-26 14:52:15 +00:00
|
|
|
$result = $this->Task->getContent('admin_add', $vars);
|
|
|
|
$this->assertPattern("/input\('name'\)/", $result);
|
|
|
|
$this->assertPattern("/input\('body'\)/", $result);
|
2010-05-07 01:38:14 +00:00
|
|
|
$this->assertPattern('/List Test View Models/', $result);
|
2009-11-26 14:52:15 +00:00
|
|
|
|
2009-10-07 05:35:29 +00:00
|
|
|
Configure::write('Routing', $_back);
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-04 01:59:46 +00:00
|
|
|
/**
|
|
|
|
* test Bake method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-06-12 19:03:00 +00:00
|
|
|
public function testBakeView() {
|
2009-06-04 01:59:46 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'view.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('View Task Articles')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
2009-06-04 01:59:46 +00:00
|
|
|
$this->Task->bake('view', true);
|
2010-06-12 19:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test baking an edit file
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBakeEdit() {
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
2009-06-04 01:59:46 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
|
2010-06-12 19:03:00 +00:00
|
|
|
new PHPUnit_Framework_Constraint_IsAnything()
|
|
|
|
);
|
2009-06-04 01:59:46 +00:00
|
|
|
$this->Task->bake('edit', true);
|
2010-06-12 19:03:00 +00:00
|
|
|
}
|
2009-06-04 01:59:46 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
/**
|
|
|
|
* test baking an index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBakeIndex() {
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains("\$viewTaskComment['Article']['title']")
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2009-06-04 01:59:46 +00:00
|
|
|
$this->Task->bake('index', true);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-08-24 01:49:30 +00:00
|
|
|
/**
|
|
|
|
* test that baking a view with no template doesn't make a file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBakeWithNoTemplate() {
|
2010-08-24 01:49:30 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
|
2010-09-21 03:42:35 +00:00
|
|
|
$this->Task->expects($this->never())->method('createFile');
|
2010-08-24 01:49:30 +00:00
|
|
|
$this->Task->bake('delete', true);
|
|
|
|
}
|
|
|
|
|
2009-06-07 01:18:34 +00:00
|
|
|
/**
|
|
|
|
* test bake() with a -plugin param
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeWithPlugin() {
|
2009-06-07 01:18:34 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
$this->Task->plugin = 'TestTest';
|
2010-10-19 03:09:23 +00:00
|
|
|
$this->Task->name = 'View';
|
2009-06-07 01:18:34 +00:00
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
//fake plugin path
|
2011-05-13 07:53:53 +00:00
|
|
|
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
|
2011-05-22 18:42:43 +00:00
|
|
|
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'View' . DS . 'ViewTaskComments' . DS . 'view.ctp';
|
2011-10-13 01:09:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->getContent('index');
|
|
|
|
$this->assertNotContains('List Test Test.view Task Articles', $result);
|
|
|
|
|
|
|
|
$this->Task->expects($this->once())
|
|
|
|
->method('createFile')
|
2011-10-13 01:00:47 +00:00
|
|
|
->with($path, $this->anything());
|
2010-06-12 19:03:00 +00:00
|
|
|
|
2009-06-07 01:18:34 +00:00
|
|
|
$this->Task->bake('view', true);
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::unload();
|
2009-06-07 01:18:34 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-04 02:03:57 +00:00
|
|
|
/**
|
|
|
|
* test bake actions baking multiple actions.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeActions() {
|
2009-06-04 02:03:57 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'view.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('View Task Comments')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('Edit View Task Comment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(2))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2009-06-04 02:03:57 +00:00
|
|
|
|
|
|
|
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-04 03:18:14 +00:00
|
|
|
/**
|
|
|
|
* test baking a customAction (non crud)
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testCustomAction() {
|
2009-06-04 03:18:14 +00:00
|
|
|
$this->Task->controllerName = 'ViewTaskComments';
|
|
|
|
$this->Task->params['app'] = APP;
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls('', 'my_action', 'y'));
|
|
|
|
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'my_action.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2009-06-04 03:18:14 +00:00
|
|
|
|
|
|
|
$this->Task->customAction();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-04 03:18:14 +00:00
|
|
|
/**
|
|
|
|
* Test all()
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoAll() {
|
2009-06-04 03:18:14 +00:00
|
|
|
$this->Task->args[0] = 'all';
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->Controller->expects($this->once())->method('listAll')
|
|
|
|
->will($this->returnValue(array('view_task_comments')));
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'add.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
2009-06-04 03:18:14 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-02-10 02:13:20 +00:00
|
|
|
/**
|
|
|
|
* Test all() with action parameter
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoAllWithActionName() {
|
2010-02-10 02:13:20 +00:00
|
|
|
$this->Task->args = array('all', 'index');
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->Controller->expects($this->once())->method('listAll')
|
|
|
|
->will($this->returnValue(array('view_task_comments')));
|
2010-02-10 02:13:20 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2010-02-10 02:13:20 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-06-05 03:35:36 +00:00
|
|
|
/**
|
|
|
|
* test `cake bake view $controller view`
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithActionParam() {
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->args[0] = 'ViewTaskComments';
|
|
|
|
$this->Task->args[1] = 'view';
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'view.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-05 03:35:36 +00:00
|
|
|
/**
|
2009-07-24 19:18:37 +00:00
|
|
|
* test `cake bake view $controller`
|
2009-07-17 03:12:47 +00:00
|
|
|
* Ensure that views are only baked for actions that exist in the controller.
|
2009-06-05 03:35:36 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithController() {
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->args[0] = 'ViewTaskComments';
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'add.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
2009-07-17 03:12:47 +00:00
|
|
|
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-03-06 02:30:58 +00:00
|
|
|
/**
|
2010-06-12 19:03:00 +00:00
|
|
|
* static dataprovider for test cases
|
2010-03-06 02:30:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-12 19:03:00 +00:00
|
|
|
public static function nameVariations() {
|
|
|
|
return array(array('ViewTaskComments'), array('ViewTaskComment'), array('view_task_comment'));
|
|
|
|
}
|
2010-03-06 02:30:58 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
/**
|
|
|
|
* 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(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'add.ctp',
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-07-17 03:12:47 +00:00
|
|
|
/**
|
|
|
|
* test `cake bake view $controller -admin`
|
|
|
|
* Which only bakes admin methods, not non-admin methods.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithControllerAndAdminFlag() {
|
2009-10-07 05:35:29 +00:00
|
|
|
$_back = Configure::read('Routing');
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2009-07-17 03:12:47 +00:00
|
|
|
$this->Task->args[0] = 'ViewTaskArticles';
|
|
|
|
$this->Task->params['admin'] = 1;
|
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
|
|
|
|
|
|
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
2009-06-05 03:35:36 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$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(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskArticles' . DS . $view,
|
2011-10-13 01:00:47 +00:00
|
|
|
$this->anything()
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
}
|
2009-07-17 03:12:47 +00:00
|
|
|
$this->Task->execute();
|
2009-10-07 05:35:29 +00:00
|
|
|
Configure::write('Routing', $_back);
|
2009-07-17 03:12:47 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-05 03:35:36 +00:00
|
|
|
/**
|
|
|
|
* test execute into interactive.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteInteractive() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->args = array();
|
2009-07-17 03:12:47 +00:00
|
|
|
$this->Task->params = array();
|
2009-06-05 03:35:36 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$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(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'index.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(4))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'view.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(5))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'add.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('Add View Task Comment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(6))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('Edit View Task Comment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
2009-06-05 03:35:36 +00:00
|
|
|
$this->Task->execute();
|
2009-07-01 01:50:28 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-09-23 17:27:47 +00:00
|
|
|
/**
|
|
|
|
* test `cake bake view posts index list`
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithAlternateTemplates() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-09-23 17:27:47 +00:00
|
|
|
$this->Task->args = array('ViewTaskComments', 'index', 'list');
|
|
|
|
$this->Task->params = array();
|
2010-02-13 22:51:49 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'list.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
2009-09-23 17:27:47 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:50:28 +00:00
|
|
|
/**
|
|
|
|
* test execute into interactive() with admin methods.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteInteractiveWithAdmin() {
|
2009-10-07 05:35:29 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-07-01 01:50:28 +00:00
|
|
|
$this->Task->args = array();
|
2009-07-17 03:12:47 +00:00
|
|
|
|
2010-06-12 19:03:00 +00:00
|
|
|
$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(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'admin_index.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(4))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'admin_view.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('ViewTaskComment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(5))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'admin_add.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('Add View Task Comment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(6))->method('createFile')
|
|
|
|
->with(
|
2011-05-22 18:42:43 +00:00
|
|
|
TMP . 'ViewTaskComments' . DS . 'admin_edit.ctp',
|
2011-09-29 04:35:15 +00:00
|
|
|
$this->stringContains('Edit View Task Comment')
|
2010-06-12 19:03:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->expects($this->exactly(4))->method('createFile');
|
2009-07-01 01:50:28 +00:00
|
|
|
$this->Task->execute();
|
2009-06-05 03:35:36 +00:00
|
|
|
}
|
2010-02-13 22:51:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test getting templates, make sure noTemplateActions works
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetTemplate() {
|
2010-02-13 22:51:49 +00:00
|
|
|
$result = $this->Task->getTemplate('delete');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $this->Task->getTemplate('add');
|
|
|
|
$this->assertEqual($result, 'form');
|
|
|
|
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
|
|
|
|
|
|
|
$result = $this->Task->getTemplate('admin_add');
|
|
|
|
$this->assertEqual($result, 'form');
|
|
|
|
}
|
2010-05-07 01:38:14 +00:00
|
|
|
|
2009-05-30 04:28:18 +00:00
|
|
|
}
|