Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?php
2
/**
3
 * BakeShell Test Case
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.Test.Case.Console.Command
15
 * @since         CakePHP(tm) v 1.3
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('ConsoleOutput', 'Console');
20
App::uses('ConsoleInput', 'Console');
21
App::uses('ShellDispatcher', 'Console');
22
App::uses('Shell', 'Console');
23
App::uses('BakeShell', 'Console/Command');
24
App::uses('ModelTask', 'Console/Command/Task');
25
App::uses('ControllerTask', 'Console/Command/Task');
26
App::uses('DbConfigTask', 'Console/Command/Task');
27
App::uses('Controller', 'Controller');
28
 
29
if (!class_exists('UsersController')) {
30
	class UsersController extends Controller {
31
	}
32
}
33
 
34
class BakeShellTest extends CakeTestCase {
35
 
36
/**
37
 * fixtures
38
 *
39
 * @var array
40
 */
41
	public $fixtures = array('core.user');
42
 
43
/**
44
 * setup test
45
 *
46
 * @return void
47
 */
48
	public function setUp() {
49
		parent::setUp();
50
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
51
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
52
 
53
		$this->Shell = $this->getMock(
54
			'BakeShell',
55
			array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
56
			array($out, $out, $in)
57
		);
58
	}
59
 
60
/**
61
 * tearDown method
62
 *
63
 * @return void
64
 */
65
	public function tearDown() {
66
		parent::tearDown();
67
		unset($this->Dispatch, $this->Shell);
68
	}
69
 
70
/**
71
 * test bake all
72
 *
73
 * @return void
74
 */
75
	public function testAllWithModelName() {
76
		App::uses('User', 'Model');
77
		$userExists = class_exists('User');
78
		$this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');
79
 
80
		$this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
81
		$this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
82
		$this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
83
		$this->Shell->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher));
84
 
85
		$this->Shell->DbConfig->expects($this->once())
86
			->method('getConfig')
87
			->will($this->returnValue('test'));
88
 
89
		$this->Shell->Model->expects($this->never())
90
			->method('getName');
91
 
92
		$this->Shell->Model->expects($this->once())
93
			->method('bake')
94
			->will($this->returnValue(true));
95
 
96
		$this->Shell->Controller->expects($this->once())
97
			->method('bake')
98
			->will($this->returnValue(true));
99
 
100
		$this->Shell->View->expects($this->once())
101
			->method('execute');
102
 
103
		$this->Shell->expects($this->once())->method('_stop');
104
		$this->Shell->expects($this->at(0))
105
			->method('out')
106
			->with('Bake All');
107
 
108
		$this->Shell->expects($this->at(5))
109
			->method('out')
110
			->with('<success>Bake All complete</success>');
111
 
112
		$this->Shell->connection = '';
113
		$this->Shell->params = array();
114
		$this->Shell->args = array('User');
115
		$this->Shell->all();
116
 
117
		$this->assertEquals('User', $this->Shell->View->args[0]);
118
	}
119
}