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)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-07-16 12:51:06 +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-07-16 12:51:06 +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
|
2009-07-16 12:51:06 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
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('BakeShell', 'Console/Command');
|
|
|
|
App::uses('ModelTask', 'Console/Command/Task');
|
|
|
|
App::uses('ControllerTask', 'Console/Command/Task');
|
|
|
|
App::uses('DbConfigTask', 'Console/Command/Task');
|
|
|
|
App::uses('Controller', 'Controller');
|
2009-07-16 12:51:06 +00:00
|
|
|
|
2009-07-17 03:55:41 +00:00
|
|
|
if (!class_exists('UsersController')) {
|
|
|
|
class UsersController extends Controller {
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Users';
|
2012-03-11 04:32:02 +00:00
|
|
|
|
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
|
|
|
*/
|
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
|
|
|
/**
|
2011-12-04 21:27:51 +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() {
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('User', 'Model');
|
2009-12-20 01:01:59 +00:00
|
|
|
$userExists = class_exists('User');
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');
|
|
|
|
|
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
|
|
|
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->DbConfig->expects($this->once())
|
|
|
|
->method('getConfig')
|
|
|
|
->will($this->returnValue('test'));
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->Model->expects($this->never())
|
|
|
|
->method('getName');
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->Model->expects($this->once())
|
|
|
|
->method('bake')
|
|
|
|
->will($this->returnValue(true));
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->Controller->expects($this->once())
|
|
|
|
->method('bake')
|
|
|
|
->will($this->returnValue(true));
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->View->expects($this->once())
|
|
|
|
->method('execute');
|
2010-05-23 02:40:18 +00:00
|
|
|
|
2010-12-13 01:55:33 +00:00
|
|
|
$this->Shell->expects($this->once())->method('_stop');
|
2011-12-02 01:41:17 +00:00
|
|
|
$this->Shell->expects($this->at(0))
|
|
|
|
->method('out')
|
|
|
|
->with('Bake All');
|
|
|
|
|
|
|
|
$this->Shell->expects($this->at(5))
|
|
|
|
->method('out')
|
|
|
|
->with('<success>Bake All complete</success>');
|
2009-07-16 12:51:06 +00:00
|
|
|
|
2010-12-13 01:55:33 +00:00
|
|
|
$this->Shell->connection = '';
|
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();
|
2011-12-02 01:41:17 +00:00
|
|
|
|
|
|
|
$this->assertEquals('User', $this->Shell->View->args[0]);
|
2009-07-16 12:51:06 +00:00
|
|
|
}
|
2009-11-14 12:18:31 +00:00
|
|
|
}
|