Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * CommandListShellTest file
4
 *
5
 * CakePHP :  Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP Project
14
 * @package       Cake.Test.Case.Console.Command
15
 * @since         CakePHP v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('CommandListShell', 'Console/Command');
20
App::uses('ConsoleOutput', 'Console');
21
App::uses('ConsoleInput', 'Console');
22
App::uses('Shell', 'Console');
23
 
24
/**
25
 * Class TestStringOutput
26
 *
27
 * @package       Cake.Test.Case.Console.Command
28
 */
29
class TestStringOutput extends ConsoleOutput {
30
 
31
	public $output = '';
32
 
33
	protected function _write($message) {
34
		$this->output .= $message;
35
	}
36
 
37
}
38
 
39
/**
40
 * Class CommandListShellTest
41
 *
42
 * @package       Cake.Test.Case.Console.Command
43
 */
44
class CommandListShellTest extends CakeTestCase {
45
 
46
/**
47
 * setUp method
48
 *
49
 * @return void
50
 */
51
	public function setUp() {
52
		parent::setUp();
53
		App::build(array(
54
			'Plugin' => array(
55
				CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
56
			),
57
			'Console/Command' => array(
58
				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
59
			)
60
		), App::RESET);
61
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
62
 
63
		$out = new TestStringOutput();
64
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
65
 
66
		$this->Shell = $this->getMock(
67
			'CommandListShell',
68
			array('in', '_stop', 'clear'),
69
			array($out, $out, $in)
70
		);
71
	}
72
 
73
/**
74
 * tearDown
75
 *
76
 * @return void
77
 */
78
	public function tearDown() {
79
		parent::tearDown();
80
		unset($this->Shell);
81
		CakePlugin::unload();
82
	}
83
 
84
/**
85
 * test that main finds core shells.
86
 *
87
 * @return void
88
 */
89
	public function testMain() {
90
		$this->Shell->main();
91
		$output = $this->Shell->stdout->output;
92
 
93
		$expected = "/\[.*TestPlugin.*\] example/";
94
		$this->assertRegExp($expected, $output);
95
 
96
		$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
97
		$this->assertRegExp($expected, $output);
98
 
99
		$expected = "/\[.*CORE.*\] acl, api, bake, command_list, console, i18n, schema, server, test, testsuite, upgrade/";
100
		$this->assertRegExp($expected, $output);
101
 
102
		$expected = "/\[.*app.*\] sample/";
103
		$this->assertRegExp($expected, $output);
104
	}
105
 
106
/**
107
 * test xml output.
108
 *
109
 * @return void
110
 */
111
	public function testMainXml() {
112
		$this->Shell->params['xml'] = true;
113
		$this->Shell->main();
114
 
115
		$output = $this->Shell->stdout->output;
116
 
117
		$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
118
		$this->assertContains($find, $output);
119
 
120
		$find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
121
		$this->assertContains($find, $output);
122
 
123
		$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
124
		$this->assertContains($find, $output);
125
	}
126
}