2010-10-04 03:42:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-10-10 21:18:48 +00:00
|
|
|
* CommandListShellTest file
|
2010-10-04 03:42:24 +00:00
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 12:28:17 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-10-04 03:42:24 +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-04 03:42:24 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 12:28:17 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-10-04 03:42:24 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command
|
2010-10-04 03:42:24 +00:00
|
|
|
* @since CakePHP v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-10-04 03:42:24 +00:00
|
|
|
*/
|
2010-12-09 05:13:11 +00:00
|
|
|
|
|
|
|
App::uses('CommandListShell', 'Console/Command');
|
2011-03-08 18:45:44 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
|
|
|
* Class TestStringOutput
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Console.Command
|
|
|
|
*/
|
2010-10-04 03:42:24 +00:00
|
|
|
class TestStringOutput extends ConsoleOutput {
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
public $output = '';
|
|
|
|
|
|
|
|
protected function _write($message) {
|
|
|
|
$this->output .= $message;
|
|
|
|
}
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
|
|
|
* Class CommandListShellTest
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Console.Command
|
|
|
|
*/
|
2011-09-13 03:00:35 +00:00
|
|
|
class CommandListShellTest extends CakeTestCase {
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
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
|
2010-10-04 03:42:24 +00:00
|
|
|
),
|
2011-03-08 18:45:44 +00:00
|
|
|
'Console/Command' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
|
2010-10-04 03:42:24 +00:00
|
|
|
)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2010-10-06 03:51:08 +00:00
|
|
|
$out = new TestStringOutput();
|
2010-10-07 02:52:42 +00:00
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$this->Shell = $this->getMock(
|
|
|
|
'CommandListShell',
|
2010-10-06 03:51:08 +00:00
|
|
|
array('in', '_stop', 'clear'),
|
2010-10-24 19:11:30 +00:00
|
|
|
array($out, $out, $in)
|
2010-10-04 03:42:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2010-10-04 03:42:24 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-10-17 21:32:37 +00:00
|
|
|
parent::tearDown();
|
2010-10-24 19:11:30 +00:00
|
|
|
unset($this->Shell);
|
2011-05-12 04:54:45 +00:00
|
|
|
CakePlugin::unload();
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that main finds core shells.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMain() {
|
2010-10-04 03:42:24 +00:00
|
|
|
$this->Shell->main();
|
2010-10-06 03:51:08 +00:00
|
|
|
$output = $this->Shell->stdout->output;
|
2010-10-24 19:11:30 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$expected = "/\[.*TestPlugin.*\] example/";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2012-07-27 01:19:20 +00:00
|
|
|
$expected = "/\[.*CORE.*\] acl, api, bake, command_list, console, i18n, schema, server, test, testsuite, upgrade/";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$expected = "/\[.*app.*\] sample/";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($expected, $output);
|
2010-10-27 02:34:27 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 03:21:24 +00:00
|
|
|
/**
|
|
|
|
* test xml output.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMainXml() {
|
2010-10-20 03:21:24 +00:00
|
|
|
$this->Shell->params['xml'] = true;
|
|
|
|
$this->Shell->main();
|
|
|
|
|
|
|
|
$output = $this->Shell->stdout->output;
|
|
|
|
|
2011-10-28 05:01:17 +00:00
|
|
|
$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
|
2010-10-20 03:21:24 +00:00
|
|
|
$this->assertContains($find, $output);
|
|
|
|
|
|
|
|
$find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
|
|
|
|
$this->assertContains($find, $output);
|
2011-05-12 04:54:45 +00:00
|
|
|
|
|
|
|
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
|
2010-10-20 03:21:24 +00:00
|
|
|
$this->assertContains($find, $output);
|
|
|
|
}
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|