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