Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 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
App::uses('CommandTask', 'Console/Command/Task');
24
 
25
/**
26
 * Class TestStringOutput
27
 *
28
 * @package       Cake.Test.Case.Console.Command
29
 */
30
class TestStringOutput extends ConsoleOutput {
31
 
32
	public $output = '';
33
 
34
	protected function _write($message) {
35
		$this->output .= $message;
36
	}
37
 
38
}
39
 
40
/**
41
 * Class CommandListShellTest
42
 *
43
 * @package       Cake.Test.Case.Console.Command
44
 */
45
class CommandListShellTest extends CakeTestCase {
46
 
47
/**
48
 * setUp method
49
 *
50
 * @return void
51
 */
52
	public function setUp() {
53
		parent::setUp();
54
		App::build(array(
55
			'Plugin' => array(
56
				CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
57
			),
58
			'Console/Command' => array(
59
				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
60
			)
61
		), App::RESET);
62
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
63
 
64
		$out = new TestStringOutput();
65
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
66
 
67
		$this->Shell = $this->getMock(
68
			'CommandListShell',
69
			array('in', '_stop', 'clear'),
70
			array($out, $out, $in)
71
		);
72
 
73
		$this->Shell->Command = $this->getMock(
74
			'CommandTask',
75
			array('in', '_stop', 'clear'),
76
			array($out, $out, $in)
77
		);
78
	}
79
 
80
/**
81
 * tearDown
82
 *
83
 * @return void
84
 */
85
	public function tearDown() {
86
		parent::tearDown();
87
		unset($this->Shell);
88
		CakePlugin::unload();
89
	}
90
 
91
/**
92
 * test that main finds core shells.
93
 *
94
 * @return void
95
 */
96
	public function testMain() {
97
		$this->Shell->main();
98
		$output = $this->Shell->stdout->output;
99
 
100
		$expected = "/\[.*TestPlugin.*\] example/";
101
		$this->assertRegExp($expected, $output);
102
 
103
		$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
104
		$this->assertRegExp($expected, $output);
105
 
106
		$expected = "/\[.*CORE.*\] acl, api, bake, command_list, completion, console, i18n, schema, server, test, testsuite, upgrade/";
107
		$this->assertRegExp($expected, $output);
108
 
109
		$expected = "/\[.*app.*\] sample/";
110
		$this->assertRegExp($expected, $output);
111
	}
112
 
113
/**
114
 * test xml output.
115
 *
116
 * @return void
117
 */
118
	public function testMainXml() {
119
		$this->Shell->params['xml'] = true;
120
		$this->Shell->main();
121
 
122
		$output = $this->Shell->stdout->output;
123
 
124
		$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
125
		$this->assertContains($find, $output);
126
 
127
		$find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
128
		$this->assertContains($find, $output);
129
 
130
		$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
131
		$this->assertContains($find, $output);
132
	}
133
}