2009-05-21 03:15:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DBConfigTask Test Case
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2009-05-21 03:15:31 +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);
|
2009-05-21 03:15:31 +00:00
|
|
|
|
|
|
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
|
|
|
define('DISABLE_AUTO_DISPATCH', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('ShellDispatcher')) {
|
|
|
|
ob_start();
|
|
|
|
$argv = false;
|
|
|
|
require CAKE . 'console' . DS . 'cake.php';
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
|
|
|
|
|
|
|
|
|
|
|
|
class TEST_DATABASE_CONFIG {
|
2010-04-04 07:14:00 +00:00
|
|
|
public $default = array(
|
2009-05-21 03:15:31 +00:00
|
|
|
'driver' => 'mysql',
|
|
|
|
'persistent' => false,
|
|
|
|
'host' => 'localhost',
|
|
|
|
'login' => 'user',
|
|
|
|
'password' => 'password',
|
|
|
|
'database' => 'database_name',
|
|
|
|
'prefix' => '',
|
|
|
|
);
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2010-04-04 07:14:00 +00:00
|
|
|
public $otherOne = array(
|
2009-05-21 03:15:31 +00:00
|
|
|
'driver' => 'mysql',
|
|
|
|
'persistent' => false,
|
|
|
|
'host' => 'localhost',
|
|
|
|
'login' => 'user',
|
|
|
|
'password' => 'password',
|
|
|
|
'database' => 'other_one',
|
|
|
|
'prefix' => '',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DbConfigTest class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
|
|
|
class DbConfigTaskTest extends CakeTestCase {
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* startTest method
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function startTest() {
|
2010-06-08 04:54:42 +00:00
|
|
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
2010-09-21 02:41:25 +00:00
|
|
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
|
2010-06-08 04:54:42 +00:00
|
|
|
));
|
|
|
|
$this->Task = $this->getMock('DbConfigTask',
|
|
|
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
|
|
|
|
array(&$this->Dispatcher)
|
|
|
|
);
|
2009-07-07 03:11:57 +00:00
|
|
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
2009-05-21 03:15:31 +00:00
|
|
|
|
2009-08-06 18:59:47 +00:00
|
|
|
$this->Task->params['working'] = rtrim(APP, DS);
|
2009-05-21 03:15:31 +00:00
|
|
|
$this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* endTest method
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function endTest() {
|
2009-05-21 03:15:31 +00:00
|
|
|
unset($this->Task, $this->Dispatcher);
|
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
|
|
|
* Test the getConfig method.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetConfig() {
|
2010-06-08 04:54:42 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('otherOne'));
|
2009-05-21 03:15:31 +00:00
|
|
|
$result = $this->Task->getConfig();
|
|
|
|
$this->assertEqual($result, 'otherOne');
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
|
|
|
* test that initialize sets the path up.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInitialize() {
|
2009-05-21 03:15:31 +00:00
|
|
|
$this->assertTrue(empty($this->Task->path));
|
|
|
|
$this->Task->initialize();
|
|
|
|
$this->assertFalse(empty($this->Task->path));
|
|
|
|
$this->assertEqual($this->Task->path, APP . 'config' . DS);
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2010-04-24 02:03:11 +00:00
|
|
|
* test execute and by extension _interactive
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoInteractive() {
|
2009-05-21 03:15:31 +00:00
|
|
|
$this->Task->initialize();
|
2010-06-09 02:14:48 +00:00
|
|
|
$this->Task = $this->getMock('DbConfigTask', array('in', '_stop', 'createFile'), array(&$this->Dispatcher));
|
2009-05-21 03:15:31 +00:00
|
|
|
|
2010-06-08 04:54:42 +00:00
|
|
|
$this->Task->expects($this->once())->method('_stop');
|
2010-06-09 02:14:48 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
|
|
|
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
|
|
|
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
|
|
|
|
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
|
|
|
|
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
|
|
|
|
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
|
|
|
|
$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
|
|
|
|
$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
|
|
|
|
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
|
|
|
|
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
|
|
|
|
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
|
2009-05-21 03:15:31 +00:00
|
|
|
|
|
|
|
$result = $this->Task->execute();
|
|
|
|
}
|
|
|
|
}
|