2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ShellDispatcherTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +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
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-03-08 22:02:22 +00:00
|
|
|
|
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestShellDispatcher class
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestShellDispatcher extends ShellDispatcher {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* params property
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $params = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* stopped property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $stopped = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* TestShell
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $TestShell;
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* _initEnvironment method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _initEnvironment() {
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-26 01:27:02 +00:00
|
|
|
/**
|
|
|
|
* clear method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function clear() {
|
2009-07-26 01:27:02 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* _stop method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _stop($status = 0) {
|
2008-11-13 00:33:53 +00:00
|
|
|
$this->stopped = 'Stopped with status: ' . $status;
|
2009-04-30 17:25:58 +00:00
|
|
|
return $status;
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* getShell
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string $shell
|
2009-04-30 17:25:58 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-10-18 01:04:14 +00:00
|
|
|
public function getShell($shell) {
|
|
|
|
return $this->_getShell($shell);
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* _getShell
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string $plugin
|
2009-04-30 17:25:58 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-10-18 01:04:14 +00:00
|
|
|
protected function _getShell($shell) {
|
2009-04-30 17:25:58 +00:00
|
|
|
if (isset($this->TestShell)) {
|
|
|
|
return $this->TestShell;
|
|
|
|
}
|
2010-10-18 01:04:14 +00:00
|
|
|
return parent::_getShell($shell);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ShellDispatcherTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-04-30 17:25:58 +00:00
|
|
|
class ShellDispatcherTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
2009-06-11 16:13:16 +00:00
|
|
|
),
|
2011-03-08 22:02:22 +00:00
|
|
|
'Console/Command' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
|
2009-06-11 16:13:16 +00:00
|
|
|
)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2011-05-12 04:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2011-10-20 01:33:03 +00:00
|
|
|
parent::tearDown();
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::unload();
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParams method
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-08 09:03:46 +00:00
|
|
|
public function testParseParamsAppWorkingAbsolute() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array(
|
|
|
|
'/cake/1.2.x.x/cake/console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/var/www/htdocs'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('/', DS, '/var/www/htdocs/new'),
|
2013-06-09 15:39:48 +00:00
|
|
|
'root' => str_replace('/', DS, '/var/www/htdocs')
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2016-11-08 09:03:46 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2016-11-08 09:03:46 +00:00
|
|
|
/**
|
|
|
|
* testParseParams method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testParseParamsNone() {
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array('cake.php');
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'app'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2016-11-08 09:03:46 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2016-11-08 09:03:46 +00:00
|
|
|
/**
|
|
|
|
* testParseParams method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testParseParamsApp() {
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2016-11-08 09:03:46 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2016-11-08 09:03:46 +00:00
|
|
|
/**
|
|
|
|
* testParseParams method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testParseParamsAppWorkingRelative() {
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array(
|
|
|
|
'./cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake/console'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2016-11-08 09:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testParseParams method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testParseParams() {
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-dry',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
|
2010-05-22 17:10:01 +00:00
|
|
|
'webroot' => 'webroot'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2010-05-22 17:10:01 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake',
|
|
|
|
'schema',
|
|
|
|
'run',
|
|
|
|
'create',
|
|
|
|
'-dry',
|
|
|
|
'-f',
|
|
|
|
'-name',
|
|
|
|
'DbAcl'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'app'),
|
|
|
|
'root' => str_replace('\\', DS, dirname(CAKE_CORE_INCLUDE_PATH)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-10-10 03:09:19 +00:00
|
|
|
$expected = array(
|
|
|
|
'./console/cake.php', 'schema', 'run', 'create', '-dry', '-f', '-name', 'DbAcl'
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->args);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'/cake/1.2.x.x/cake/console/cake.php',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/app',
|
|
|
|
'schema',
|
|
|
|
'run',
|
|
|
|
'create',
|
|
|
|
'-dry',
|
|
|
|
'-name',
|
|
|
|
'DbAcl'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
2011-06-20 22:28:51 +00:00
|
|
|
'working' => str_replace('/', DS, '/cake/1.2.x.x/app'),
|
|
|
|
'root' => str_replace('/', DS, '/cake/1.2.x.x'),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:/wamp/www/cake/app',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'C:/wamp/www/apps/cake/app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake'
|
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:\wamp\www\cake\app',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'C:\wamp\www\apps\cake\app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake'
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-06-26 03:50:11 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:\wamp\www\apps',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'cake\app',
|
|
|
|
'-url',
|
|
|
|
'http://example.com/some/url/with/a/path'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake',
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-06-26 03:50:11 +00:00
|
|
|
$params = array(
|
|
|
|
'/home/amelo/dev/cake-common/cake/console/cake.php',
|
|
|
|
'-root',
|
|
|
|
'/home/amelo/dev/lsbu-vacancy',
|
|
|
|
'-working',
|
|
|
|
'/home/amelo/dev/lsbu-vacancy',
|
|
|
|
'-app',
|
|
|
|
'app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => '/home/amelo/dev/lsbu-vacancy/app',
|
|
|
|
'root' => '/home/amelo/dev/lsbu-vacancy',
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2011-10-21 10:20:31 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'/cake/1.2.x.x/cake/console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-app',
|
|
|
|
'old',
|
|
|
|
'-working',
|
|
|
|
'/var/www/htdocs'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'old',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => str_replace('/', DS, '/var/www/htdocs/old'),
|
2013-06-09 15:39:48 +00:00
|
|
|
'root' => str_replace('/', DS, '/var/www/htdocs')
|
2011-10-21 10:20:31 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2009-07-27 16:57:58 +00:00
|
|
|
|
2011-06-23 20:41:10 +00:00
|
|
|
if (DS === '\\') {
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'D:\www',
|
|
|
|
'bake',
|
|
|
|
'my_app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'working' => 'D:\\\\www',
|
|
|
|
'app' => 'www',
|
|
|
|
'root' => 'D:\\',
|
|
|
|
'webroot' => 'webroot'
|
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2011-06-23 20:41:10 +00:00
|
|
|
}
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
2009-04-30 17:25:58 +00:00
|
|
|
* Verify loading of (plugin-) shells
|
2008-11-13 00:33:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetShell() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(class_exists('SampleShell'), 'SampleShell Class already loaded.');
|
|
|
|
$this->skipIf(class_exists('ExampleShell'), 'ExampleShell Class already loaded.');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-10-18 01:04:14 +00:00
|
|
|
$result = $Dispatcher->getShell('sample');
|
|
|
|
$this->assertInstanceOf('SampleShell', $result);
|
2011-10-20 01:33:03 +00:00
|
|
|
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
|
|
|
$result = $Dispatcher->getShell('test_plugin.example');
|
|
|
|
$this->assertInstanceOf('ExampleShell', $result);
|
2011-12-11 02:31:21 +00:00
|
|
|
$this->assertEquals('TestPlugin', $result->plugin);
|
|
|
|
$this->assertEquals('Example', $result->name);
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2011-05-12 04:58:39 +00:00
|
|
|
$result = $Dispatcher->getShell('TestPlugin.example');
|
2010-10-18 01:04:14 +00:00
|
|
|
$this->assertInstanceOf('ExampleShell', $result);
|
2015-01-16 13:30:28 +00:00
|
|
|
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
|
|
|
$result = $Dispatcher->getShell('test_plugin');
|
|
|
|
$this->assertInstanceOf('TestPluginShell', $result);
|
|
|
|
|
|
|
|
$Dispatcher = new TestShellDispatcher();
|
|
|
|
$result = $Dispatcher->getShell('TestPlugin');
|
|
|
|
$this->assertInstanceOf('TestPluginShell', $result);
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of Shell subclasses with a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchShellWithMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2014-03-01 18:01:36 +00:00
|
|
|
$Shell = $this->getMock('Shell');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2014-03-01 18:01:36 +00:00
|
|
|
$Shell->expects($this->once())->method('initialize');
|
|
|
|
$Shell->expects($this->once())->method('runCommand')
|
2010-10-10 04:21:16 +00:00
|
|
|
->with(null, array())
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2014-03-01 18:01:36 +00:00
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $Dispatcher->args);
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of Shell subclasses without a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchShellWithoutMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2014-03-01 18:01:36 +00:00
|
|
|
$Shell = $this->getMock('Shell');
|
2010-10-10 04:21:16 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->once())->method('initialize');
|
2010-10-10 04:21:16 +00:00
|
|
|
$Shell->expects($this->once())->method('runCommand')
|
|
|
|
->with('initdb', array('initdb'))
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of custom classes with a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchNotAShellWithMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2016-04-08 12:33:26 +00:00
|
|
|
$methods = get_class_methods('CakeObject');
|
2010-05-22 17:10:01 +00:00
|
|
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
2016-04-08 12:33:26 +00:00
|
|
|
$Shell = $this->getMock('CakeObject', $methods);
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->never())->method('initialize');
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main_not_a');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $Dispatcher->args);
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2016-04-08 12:33:26 +00:00
|
|
|
$Shell = $this->getMock('CakeObject', $methods);
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main_not_a', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of custom classes without a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchNotAShellWithoutMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2016-04-08 12:33:26 +00:00
|
|
|
$methods = get_class_methods('CakeObject');
|
2010-05-22 17:10:01 +00:00
|
|
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
2016-04-08 12:33:26 +00:00
|
|
|
$Shell = $this->getMock('CakeObject', $methods);
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->never())->method('initialize');
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main_not_a');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
2010-05-22 17:10:01 +00:00
|
|
|
$this->assertTrue($result);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $Dispatcher->args);
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2016-04-08 12:33:26 +00:00
|
|
|
$Shell = $this->getMock('CakeObject', $methods);
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
2009-05-02 21:34:39 +00:00
|
|
|
$this->assertTrue($result);
|
2009-05-01 10:08:56 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-05-01 01:47:33 +00:00
|
|
|
/**
|
|
|
|
* Verify shifting of arguments
|
2008-11-13 00:33:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testShiftArgs() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2009-05-01 01:47:33 +00:00
|
|
|
|
|
|
|
$Dispatcher->args = array('a', 'b', 'c');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('a', $Dispatcher->shiftArgs());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($Dispatcher->args, array('b', 'c'));
|
2009-05-01 01:47:33 +00:00
|
|
|
|
|
|
|
$Dispatcher->args = array('a' => 'b', 'c', 'd');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('b', $Dispatcher->shiftArgs());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($Dispatcher->args, array('c', 'd'));
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2009-05-01 01:47:33 +00:00
|
|
|
$Dispatcher->args = array('a', 'b' => 'c', 'd');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('a', $Dispatcher->shiftArgs());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($Dispatcher->args, array('b' => 'c', 'd'));
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2012-11-21 14:39:03 +00:00
|
|
|
$Dispatcher->args = array(0 => 'a', 2 => 'b', 30 => 'c');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('a', $Dispatcher->shiftArgs());
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($Dispatcher->args, array(0 => 'b', 1 => 'c'));
|
2009-05-01 01:47:33 +00:00
|
|
|
|
|
|
|
$Dispatcher->args = array();
|
|
|
|
$this->assertNull($Dispatcher->shiftArgs());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame(array(), $Dispatcher->args);
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|