2010-10-04 03:42:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CommandList file
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs
|
2010-10-04 03:42:24 +00:00
|
|
|
* @since CakePHP v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
|
|
class TestStringOutput extends ConsoleOutput {
|
|
|
|
public $output = '';
|
|
|
|
|
|
|
|
protected function _write($message) {
|
|
|
|
$this->output .= $message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CommandListTest extends CakeTestCase {
|
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => 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
|
|
|
)
|
|
|
|
), true);
|
2011-05-12 04:54:45 +00:00
|
|
|
CakePlugin::loadAll();
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* teardown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
function testMain() {
|
|
|
|
$this->Shell->main();
|
2010-10-06 03:51:08 +00:00
|
|
|
$output = $this->Shell->stdout->output;
|
2010-10-24 19:11:30 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/welcome \[.*TestPluginTwo.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2011-03-08 18:45:44 +00:00
|
|
|
|
2010-10-04 03:42:24 +00:00
|
|
|
$expected = "/acl \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/api \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/bake \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/console \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/i18n \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/schema \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
|
|
|
$expected = "/testsuite \[.*CORE.*\]/";
|
2010-10-17 21:32:37 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
2010-10-04 03:42:24 +00:00
|
|
|
|
2010-10-17 21:32:37 +00:00
|
|
|
$expected = "/sample \[.*app.*\]/";
|
2010-10-04 03:42:24 +00:00
|
|
|
$this->assertPattern($expected, $output);
|
|
|
|
}
|
2010-10-20 03:21:24 +00:00
|
|
|
|
2010-10-27 02:34:27 +00:00
|
|
|
/**
|
|
|
|
* Test the sort param
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testSortPlugin() {
|
|
|
|
$this->Shell->params['sort'] = true;
|
|
|
|
$this->Shell->main();
|
|
|
|
|
|
|
|
$output = $this->Shell->stdout->output;
|
|
|
|
|
|
|
|
$expected = "/\[.*App.*\]\n[ ]+sample/";
|
|
|
|
$this->assertPattern($expected, $output);
|
|
|
|
|
|
|
|
$expected = "/\[.*TestPluginTwo.*\]\n[ ]+example, welcome/";
|
|
|
|
$this->assertPattern($expected, $output);
|
|
|
|
|
|
|
|
$expected = "/\[.*TestPlugin.*\]\n[ ]+example/";
|
|
|
|
$this->assertPattern($expected, $output);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-27 02:34:27 +00:00
|
|
|
$expected = "/\[.*Core.*\]\n[ ]+acl, api, bake, command_list, console, i18n, schema, testsuite/";
|
|
|
|
$this->assertPattern($expected, $output);
|
|
|
|
}
|
|
|
|
|
2010-10-20 03:21:24 +00:00
|
|
|
/**
|
|
|
|
* test xml output.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMainXml() {
|
|
|
|
$this->Shell->params['xml'] = true;
|
|
|
|
$this->Shell->main();
|
|
|
|
|
|
|
|
$output = $this->Shell->stdout->output;
|
|
|
|
|
|
|
|
$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
|
|
|
|
$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
|
|
|
}
|