Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?php
2
/**
3
 * Toolbar Abstract Helper Test Case
4
 *
5
 * PHP 5
6
 *
7
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9
 *
10
 * Licensed under The MIT License
11
 * Redistributions of files must retain the above copyright notice.
12
 *
13
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
14
 * @link          http://cakephp.org CakePHP(tm) Project
15
 * @since         DebugKit 0.1
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 **/
18
 
19
$path = CakePlugin::path('DebugKit');
20
 
21
App::uses('View', 'View');
22
App::uses('Controller', 'Controller');
23
App::uses('CakeResponse', 'Network');
24
App::uses('Router', 'Routing');
25
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
26
App::uses('FirePhpToolbarHelper', 'DebugKit.View/Helper');
27
 
28
require_once $path . 'Test' . DS . 'Case' . DS . 'TestFireCake.php';
29
 
30
/**
31
 * Class FirePhpToolbarHelperTestCase
32
 *
33
 * @since         DebugKit 0.1
34
 */
35
class FirePhpToolbarHelperTestCase extends CakeTestCase {
36
 
37
/**
38
 * setUp
39
 *
40
 * @return void
41
 **/
42
	public function setUp() {
43
		parent::setUp();
44
 
45
		Router::connect('/:controller/:action');
46
		Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
47
		Router::parse('/');
48
 
49
		$this->Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
50
		$this->View = new View($this->Controller);
51
		$this->Toolbar = new ToolbarHelper($this->View, array('output' => 'DebugKit.FirePhpToolbar'));
52
		$this->Toolbar->FirePhpToolbar = new FirePhpToolbarHelper($this->View);
53
 
54
		$this->firecake = FireCake::getInstance('TestFireCake');
55
		TestFireCake::reset();
56
	}
57
 
58
/**
59
 * Start test - switch view paths
60
 *
61
 * @return void
62
 **/
63
	public static function setupBeforeClass() {
64
		App::build(array(
65
			'View' => array(
66
				CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS,
67
				APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS,
68
				CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
69
		)), true);
70
	}
71
 
72
/**
73
 * End Test
74
 *
75
 * @return void
76
 */
77
	public static function tearDownAfterClass() {
78
		App::build();
79
	}
80
 
81
/**
82
 * TearDown
83
 *
84
 * @return void
85
 */
86
	public function tearDown() {
87
		parent::tearDown();
88
		unset($this->Toolbar, $this->Controller);
89
		TestFireCake::reset();
90
	}
91
 
92
/**
93
 * Test neat array (dump)creation
94
 *
95
 * @return void
96
 */
97
	public function testMakeNeatArray() {
98
		$this->Toolbar->makeNeatArray(array(1,2,3));
99
		$result = $this->firecake->sentHeaders;
100
		$this->assertTrue(isset($result['X-Wf-1-1-1-1']));
101
		$this->assertRegexp('/\[1,2,3\]/', $result['X-Wf-1-1-1-1']);
102
	}
103
 
104
/**
105
 * Test afterlayout element rendering
106
 *
107
 * @return void
108
 */
109
	public function testAfterLayout() {
110
		$this->Controller->viewPath = 'Posts';
111
		$request = new CakeRequest('/posts/index');
112
		$request->addParams(Router::parse($request->url));
113
		$request->addPaths(array(
114
			'webroot' => '/',
115
			'base' => '/',
116
			'here' => '/posts/index',
117
		));
118
		$this->Controller->setRequest($request);
119
		$this->Controller->layout = 'default';
120
		$this->Controller->uses = null;
121
		$this->Controller->components = array('DebugKit.Toolbar');
122
		$this->Controller->constructClasses();
123
		$this->Controller->Components->trigger('startup', array($this->Controller));
124
		$this->Controller->Components->trigger('beforeRender', array($this->Controller));
125
		$result = $this->Controller->render();
126
		$this->assertNotRegExp('/debug-toolbar/', (string)$result);
127
		$result = $this->firecake->sentHeaders;
128
		$this->assertTrue(is_array($result));
129
	}
130
 
131
/**
132
 * test starting a panel
133
 *
134
 * @return void
135
 **/
136
	public function testPanelStart() {
137
		$this->Toolbar->panelStart('My Panel', 'my_panel');
138
		$result = $this->firecake->sentHeaders;
139
		$this->assertPattern('/GROUP_START.+My Panel/', $result['X-Wf-1-1-1-1']);
140
	}
141
 
142
/**
143
 * test ending a panel
144
 *
145
 * @return void
146
 **/
147
	public function testPanelEnd() {
148
		$this->Toolbar->panelEnd();
149
		$result = $this->firecake->sentHeaders;
150
		$this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-1']);
151
	}
152
}