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
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://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.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://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
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://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');
|
2013-09-28 15:42:28 +00:00
|
|
|
App::uses('CommandTask', 'Console/Command/Task');
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* TestStringOutput
|
2013-05-30 22:11:14 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* CommandListShellTest
|
2013-05-30 22:11:14 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2010-10-04 03:42:24 +00:00
|
|
|
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
|
|
|
);
|
2013-09-28 15:42:28 +00:00
|
|
|
|
|
|
|
$this->Shell->Command = $this->getMock(
|
|
|
|
'CommandTask',
|
|
|
|
array('in', '_stop', 'clear'),
|
|
|
|
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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
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/";
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2013-09-16 12:11:27 +00:00
|
|
|
$expected = "/\[.*CORE.*\] acl, api, bake, command_list, completion, console, i18n, schema, server, test, testsuite, upgrade/";
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2012-06-18 20:47:01 +00:00
|
|
|
$expected = "/\[.*app.*\] sample/";
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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"/>';
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($find, $output);
|
2010-10-20 03:21:24 +00:00
|
|
|
|
|
|
|
$find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($find, $output);
|
2011-05-12 04:54:45 +00:00
|
|
|
|
|
|
|
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($find, $output);
|
2010-10-20 03:21:24 +00:00
|
|
|
}
|
2010-10-04 03:42:24 +00:00
|
|
|
}
|