/
command_list.test.php
157 lines (126 loc) · 3.78 KB
/
command_list.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?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
* @package cake.tests.cases.console.libs
* @since CakePHP v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CommandListShell', 'Console/Command');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
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(
LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
),
'Console/Command' => array(
LIBS . 'tests' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
)
), true);
App::objects('plugin', null, false);
$out = new TestStringOutput();
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell = $this->getMock(
'CommandListShell',
array('in', '_stop', 'clear'),
array($out, $out, $in)
);
}
/**
* teardown
*
* @return void
*/
function tearDown() {
parent::tearDown();
unset($this->Shell);
}
/**
* test that main finds core shells.
*
* @return void
*/
function testMain() {
$this->Shell->main();
$output = $this->Shell->stdout->output;
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
$this->assertPattern($expected, $output);
$expected = "/welcome \[.*TestPluginTwo.*\]/";
$this->assertPattern($expected, $output);
$expected = "/acl \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/api \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/bake \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/console \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/i18n \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/schema \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/testsuite \[.*CORE.*\]/";
$this->assertPattern($expected, $output);
$expected = "/sample \[.*app.*\]/";
$this->assertPattern($expected, $output);
}
/**
* 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);
$expected = "/\[.*Core.*\]\n[ ]+acl, api, bake, command_list, console, i18n, schema, testsuite/";
$this->assertPattern($expected, $output);
}
/**
* 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);
$find = '<shell name="welcome" call_as="test_plugin_two.welcome" provider="TestPluginTwo" help="test_plugin_two.welcome -h"/>';
$this->assertContains($find, $output);
}
}