2009-07-16 12:51:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BakeShell Test Case
|
|
|
|
*
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-07-16 12:51:06 +00:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-10-24 20:58:22 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-07-16 12:51:06 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-10-24 20:58:22 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2009-07-16 12:51:06 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Shell', 'Shell', false);
|
2010-10-17 19:43:20 +00:00
|
|
|
App::import('Shell', 'Bake', false);
|
|
|
|
App::import('Shell', 'tasks/model', false);
|
|
|
|
App::import('Shell', 'tasks/controller', false);
|
|
|
|
App::import('Shell', 'tasks/db_config', false);
|
2009-07-16 12:51:06 +00:00
|
|
|
|
2010-10-17 19:43:20 +00:00
|
|
|
App::import('Core', 'Controller');
|
2010-10-03 05:53:42 +00:00
|
|
|
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
|
2009-07-16 12:51:06 +00:00
|
|
|
|
2009-07-17 03:55:41 +00:00
|
|
|
if (!class_exists('UsersController')) {
|
|
|
|
class UsersController extends Controller {
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Users';
|
2009-07-16 12:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 14:06:00 +00:00
|
|
|
class BakeShellTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-16 12:51:06 +00:00
|
|
|
/**
|
|
|
|
* fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:18:31 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.user');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-16 12:51:06 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setup test
|
2009-07-16 12:51:06 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
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-05-23 02:40:18 +00:00
|
|
|
$this->Shell = $this->getMock(
|
|
|
|
'BakeShell',
|
|
|
|
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
2010-10-24 19:11:30 +00:00
|
|
|
array($out, $out, $in)
|
2010-05-23 02:40:18 +00:00
|
|
|
);
|
2009-07-16 12:51:06 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-17 03:55:41 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* teardown method
|
2009-07-17 03:55:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2009-07-17 03:55:41 +00:00
|
|
|
unset($this->Dispatch, $this->Shell);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-16 12:51:06 +00:00
|
|
|
/**
|
|
|
|
* test bake all
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAllWithModelName() {
|
2009-12-20 01:01:59 +00:00
|
|
|
App::import('Model', 'User');
|
|
|
|
$userExists = class_exists('User');
|
|
|
|
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-08 03:51:39 +00:00
|
|
|
$this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
|
|
|
|
$this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
|
|
|
|
$this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
|
|
|
|
$this->Shell->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher));
|
2010-05-23 02:40:18 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Shell->DbConfig->expects($this->once())->method('getConfig')->will($this->returnValue('test'));
|
2010-05-23 02:40:18 +00:00
|
|
|
|
|
|
|
$this->Shell->Model->expects($this->never())->method('getName');
|
|
|
|
$this->Shell->Model->expects($this->once())->method('bake')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->Shell->Controller->expects($this->once())->method('bake')->will($this->returnValue(true));
|
|
|
|
$this->Shell->View->expects($this->once())->method('execute');
|
|
|
|
|
|
|
|
$this->Shell->expects($this->at(1))->method('out')->with('Bake All');
|
|
|
|
$this->Shell->expects($this->at(3))->method('out')->with('User Model was baked.');
|
|
|
|
$this->Shell->expects($this->at(5))->method('out')->with('User Controller was baked.');
|
|
|
|
$this->Shell->expects($this->at(7))->method('out')->with('User Views were baked.');
|
|
|
|
$this->Shell->expects($this->at(8))->method('out')->with('Bake All complete');
|
2009-07-16 12:51:06 +00:00
|
|
|
|
|
|
|
$this->Shell->params = array();
|
2009-07-17 03:55:41 +00:00
|
|
|
$this->Shell->args = array('User');
|
2009-07-16 12:51:06 +00:00
|
|
|
$this->Shell->all();
|
|
|
|
}
|
2009-11-14 12:18:31 +00:00
|
|
|
}
|