comparison cake/tests/cases/console/libs/tasks/db_config.test.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * DBConfigTask Test Case
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
9 *
10 * Licensed under The MIT License
11 * Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://cakephp.org CakePHP(tm) Project
15 * @package cake
16 * @subpackage cake.tests.cases.console.libs.tasks
17 * @since CakePHP(tm) v 1.3
18 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
19 */
20 App::import('Shell', 'Shell', false);
21
22 if (!defined('DISABLE_AUTO_DISPATCH')) {
23 define('DISABLE_AUTO_DISPATCH', true);
24 }
25
26 if (!class_exists('ShellDispatcher')) {
27 ob_start();
28 $argv = false;
29 require CAKE . 'console' . DS . 'cake.php';
30 ob_end_clean();
31 }
32
33 require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
34 //require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
35
36 Mock::generatePartial(
37 'ShellDispatcher', 'TestDbConfigTaskMockShellDispatcher',
38 array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
39 );
40
41 Mock::generatePartial(
42 'DbConfigTask', 'MockDbConfigTask',
43 array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
44 );
45
46 class TEST_DATABASE_CONFIG {
47 var $default = array(
48 'driver' => 'mysql',
49 'persistent' => false,
50 'host' => 'localhost',
51 'login' => 'user',
52 'password' => 'password',
53 'database' => 'database_name',
54 'prefix' => '',
55 );
56
57 var $otherOne = array(
58 'driver' => 'mysql',
59 'persistent' => false,
60 'host' => 'localhost',
61 'login' => 'user',
62 'password' => 'password',
63 'database' => 'other_one',
64 'prefix' => '',
65 );
66 }
67
68 /**
69 * DbConfigTest class
70 *
71 * @package cake
72 * @subpackage cake.tests.cases.console.libs.tasks
73 */
74 class DbConfigTaskTest extends CakeTestCase {
75
76 /**
77 * startTest method
78 *
79 * @return void
80 * @access public
81 */
82 function startTest() {
83 $this->Dispatcher =& new TestDbConfigTaskMockShellDispatcher();
84 $this->Task =& new MockDbConfigTask($this->Dispatcher);
85 $this->Task->Dispatch =& $this->Dispatcher;
86 $this->Task->Dispatch->shellPaths = App::path('shells');
87
88 $this->Task->params['working'] = rtrim(APP, DS);
89 $this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
90 }
91
92 /**
93 * endTest method
94 *
95 * @return void
96 * @access public
97 */
98 function endTest() {
99 unset($this->Task, $this->Dispatcher);
100 ClassRegistry::flush();
101 }
102
103 /**
104 * Test the getConfig method.
105 *
106 * @return void
107 * @access public
108 */
109 function testGetConfig() {
110 $this->Task->setReturnValueAt(0, 'in', 'otherOne');
111 $result = $this->Task->getConfig();
112 $this->assertEqual($result, 'otherOne');
113 }
114
115 /**
116 * test that initialize sets the path up.
117 *
118 * @return void
119 * @access public
120 */
121 function testInitialize() {
122 $this->assertTrue(empty($this->Task->path));
123 $this->Task->initialize();
124 $this->assertFalse(empty($this->Task->path));
125 $this->assertEqual($this->Task->path, APP . 'config' . DS);
126
127 }
128
129 /**
130 * test execute and by extension __interactive
131 *
132 * @return void
133 * @access public
134 */
135 function testExecuteIntoInteractive() {
136 $this->Task->initialize();
137
138 $this->Task->expectOnce('_stop');
139 $this->Task->setReturnValue('in', 'y');
140 $this->Task->setReturnValueAt(0, 'in', 'default');
141 $this->Task->setReturnValueAt(1, 'in', 'n');
142 $this->Task->setReturnValueAt(2, 'in', 'localhost');
143 $this->Task->setReturnValueAt(3, 'in', 'n');
144 $this->Task->setReturnValueAt(4, 'in', 'root');
145 $this->Task->setReturnValueAt(5, 'in', 'password');
146 $this->Task->setReturnValueAt(6, 'in', 'cake_test');
147 $this->Task->setReturnValueAt(7, 'in', 'n');
148 $this->Task->setReturnValueAt(8, 'in', 'y');
149 $this->Task->setReturnValueAt(9, 'in', 'y');
150 $this->Task->setReturnValueAt(10, 'in', 'y');
151 $this->Task->setReturnValueAt(11, 'in', 'n');
152
153 $result = $this->Task->execute();
154 }
155 }