8
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
9
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
11
* Licensed under The MIT License
12
* Redistributions of files must retain the above copyright notice.
14
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
15
* @link http://cakephp.org CakePHP(tm) Project
17
* @subpackage cake.tests.cases.console.libs.tasks
18
* @since CakePHP(tm) v 1.3
19
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
21
App::import('Shell', 'Shell', false);
23
if (!defined('DISABLE_AUTO_DISPATCH')) {
24
define('DISABLE_AUTO_DISPATCH', true);
27
if (!class_exists('ShellDispatcher')) {
30
require CAKE . 'console' . DS . 'cake.php';
34
require_once CAKE . 'console' . DS . 'libs' . DS . 'bake.php';
35
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
36
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
37
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
39
Mock::generatePartial(
40
'ShellDispatcher', 'BakeShellMockShellDispatcher',
41
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
43
Mock::generatePartial(
44
'BakeShell', 'MockBakeShell',
45
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
48
Mock::generate('DbConfigTask', 'BakeShellMockDbConfigTask');
49
Mock::generate('ModelTask', 'BakeShellMockModelTask');
50
Mock::generate('ControllerTask', 'BakeShellMockControllerTask');
52
if (!class_exists('UsersController')) {
53
class UsersController extends Controller {
58
class BakeShellTestCase extends CakeTestCase {
66
var $fixtures = array('core.user');
74
function startTest() {
75
$this->Dispatch =& new BakeShellMockShellDispatcher();
76
$this->Shell =& new MockBakeShell();
77
$this->Shell->Dispatch =& $this->Dispatch;
78
$this->Shell->Dispatch->shellPaths = App::path('shells');
88
unset($this->Dispatch, $this->Shell);
97
function testAllWithModelName() {
98
App::import('Model', 'User');
99
$userExists = class_exists('User');
100
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
103
$this->Shell->Model =& new BakeShellMockModelTask();
104
$this->Shell->Controller =& new BakeShellMockControllerTask();
105
$this->Shell->View =& new BakeShellMockModelTask();
106
$this->Shell->DbConfig =& new BakeShellMockDbConfigTask();
108
$this->Shell->DbConfig->expectOnce('getConfig');
109
$this->Shell->DbConfig->setReturnValue('getConfig', 'test_suite');
111
$this->Shell->Model->setReturnValue('bake', true);
112
$this->Shell->Model->expectNever('getName');
113
$this->Shell->Model->expectOnce('bake');
115
$this->Shell->Controller->expectOnce('bake');
116
$this->Shell->Controller->setReturnValue('bake', true);
118
$this->Shell->View->expectOnce('execute');
120
$this->Shell->expectAt(0, 'out', array('Bake All'));
121
$this->Shell->expectAt(1, 'out', array('User Model was baked.'));
122
$this->Shell->expectAt(2, 'out', array('User Controller was baked.'));
123
$this->Shell->expectAt(3, 'out', array('User Views were baked.'));
124
$this->Shell->expectAt(4, 'out', array('Bake All complete'));
126
$this->Shell->params = array();
127
$this->Shell->args = array('User');