Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * DBConfigTask 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.Task
15
 * @since         CakePHP(tm) v 1.3
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('ShellDispatcher', 'Console');
20
App::uses('ConsoleOutput', 'Console');
21
App::uses('ConsoleInput', 'Console');
22
App::uses('Shell', 'Console');
23
App::uses('DbConfigTask', 'Console/Command/Task');
24
 
25
/**
26
 * DbConfigTest class
27
 *
28
 * @package       Cake.Test.Case.Console.Command.Task
29
 */
30
class DbConfigTaskTest extends CakeTestCase {
31
 
32
/**
33
 * setUp method
34
 *
35
 * @return void
36
 */
37
	public function setUp() {
38
		parent::setUp();
39
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
40
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
41
 
42
		$this->Task = $this->getMock('DbConfigTask',
43
			array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
44
			array($out, $out, $in)
45
		);
46
 
47
		$this->Task->path = APP . 'Config' . DS;
48
	}
49
 
50
/**
51
 * tearDown method
52
 *
53
 * @return void
54
 */
55
	public function tearDown() {
56
		parent::tearDown();
57
		unset($this->Task);
58
	}
59
 
60
/**
61
 * Test the getConfig method.
62
 *
63
 * @return void
64
 */
65
	public function testGetConfig() {
66
		$this->Task->expects($this->any())
67
			->method('in')
68
			->will($this->returnValue('test'));
69
 
70
		$result = $this->Task->getConfig();
71
		$this->assertEquals('test', $result);
72
	}
73
 
74
/**
75
 * test that initialize sets the path up.
76
 *
77
 * @return void
78
 */
79
	public function testInitialize() {
80
		$this->Task->initialize();
81
		$this->assertFalse(empty($this->Task->path));
82
		$this->assertEquals(APP . 'Config' . DS, $this->Task->path);
83
	}
84
 
85
/**
86
 * test execute and by extension _interactive
87
 *
88
 * @return void
89
 */
90
	public function testExecuteIntoInteractive() {
91
		$this->Task->initialize();
92
 
93
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
94
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
95
		$this->Task = $this->getMock(
96
			'DbConfigTask',
97
			array('in', '_stop', 'createFile', 'bake'), array($out, $out, $in)
98
		);
99
 
100
		$this->Task->expects($this->once())->method('_stop');
101
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
102
		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
103
		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistent
104
		$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
105
		$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
106
		$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
107
		$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
108
		$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
109
		$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
110
		$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
111
		$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
112
		$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
113
		$this->Task->expects($this->at(15))->method('bake')
114
			->with(array(
115
				array(
116
					'name' => 'default',
117
					'datasource' => 'mysql',
118
					'persistent' => 'false',
119
					'host' => 'localhost',
120
					'login' => 'root',
121
					'password' => 'password',
122
					'database' => 'cake_test',
123
					'prefix' => null,
124
					'encoding' => null,
125
					'port' => '',
126
					'schema' => null
127
				)
128
			));
129
 
130
		$this->Task->execute();
131
	}
132
}