1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar\Test\Collector; |
4
|
|
|
|
5
|
|
|
use LeKoala\DebugBar\DebugBar; |
6
|
|
|
use LeKoala\DebugBar\Collector\SilverStripeCollector; |
7
|
|
|
use SilverStripe\Control\Controller; |
8
|
|
|
use SilverStripe\Control\HTTPRequest; |
9
|
|
|
use SilverStripe\Control\Session; |
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
use SilverStripe\Security\Member; |
12
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
13
|
|
|
use SilverStripe\View\Requirements; |
14
|
|
|
|
15
|
|
|
class SilverStripeCollectorTest extends SapphireTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var DebugBarSilverStripeCollector |
19
|
|
|
*/ |
20
|
|
|
protected $collector; |
21
|
|
|
|
22
|
|
|
protected $usesDatabase = true; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
parent::setUp(); |
27
|
|
|
DebugBar::initDebugBar(); |
28
|
|
|
$this->collector = DebugBar::getDebugBar()->getCollector('silverstripe'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testCollectorExists() |
32
|
|
|
{ |
33
|
|
|
$this->assertInstanceOf(SilverStripeCollector::class, $this->collector); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCollect() |
37
|
|
|
{ |
38
|
|
|
$data = $this->collector->collect(); |
39
|
|
|
|
40
|
|
|
$this->assertArrayHasKey('debug', $data); |
41
|
|
|
$this->assertArrayHasKey('locale', $data); |
42
|
|
|
$this->assertArrayHasKey('parameters', $data); |
43
|
|
|
$this->assertArrayHasKey('templates', $data); |
44
|
|
|
$this->assertContains('Framework', $data['version']); |
45
|
|
|
$this->assertSame('User, ADMIN', $data['user']); |
46
|
|
|
$this->assertCount(0, $data['requirements']); |
47
|
|
|
|
48
|
|
|
Member::currentUser()->logOut(); |
|
|
|
|
49
|
|
|
$data = $this->collector->collect(); |
50
|
|
|
$this->assertSame('Not logged in', $data['user']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testShowRequirements() |
54
|
|
|
{ |
55
|
|
|
Requirements::css('debugbar/assets/debugbar.css'); |
56
|
|
|
$data = $this->collector->collect(); |
57
|
|
|
$this->assertArrayHasKey('requirements', $data); |
58
|
|
|
$this->assertNotEmpty($data['requirements']); |
59
|
|
|
$this->assertContains('assets/debugbar.css', $data['requirements'][0]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testShowRequestParameters() |
63
|
|
|
{ |
64
|
|
|
$controller = new Controller; |
65
|
|
|
$controller->doInit(); |
66
|
|
|
$controller->setRequest( |
67
|
|
|
new HTTPRequest( |
68
|
|
|
'GET', |
69
|
|
|
'/', |
70
|
|
|
array('getvar' => 'value', 'foo' => 'bar'), |
71
|
|
|
array('postvar' => 'value', 'bar' => 'baz') |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
$controller->getRequest()->setRouteParams(array('something' => 'here')); |
75
|
|
|
|
76
|
|
|
$this->collector->setController($controller); |
77
|
|
|
$this->assertSame($controller, $this->collector->getController()); |
78
|
|
|
|
79
|
|
|
$result = SilverStripeCollector::getRequestParameters(); |
80
|
|
|
$this->assertSame('value', $result['GET - getvar']); |
81
|
|
|
$this->assertSame('baz', $result['POST - bar']); |
82
|
|
|
$this->assertSame('here', $result['ROUTE - something']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetSessionData() |
86
|
|
|
{ |
87
|
|
|
Controller::curr()->getRequest()->getSession()->set('DebugBarTesting', 'test value'); |
88
|
|
|
$result = SilverStripeCollector::getSessionData(); |
89
|
|
|
$this->assertSame('test value', $result['DebugBarTesting']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetWidgets() |
93
|
|
|
{ |
94
|
|
|
$this->collector->collect(); |
95
|
|
|
$result = $this->collector->getWidgets(); |
96
|
|
|
// Stub out the dynamic data |
97
|
|
|
$result['version']['tooltip'] = 'Stub'; |
98
|
|
|
$result['locale']['tooltip'] = 'Stub'; |
99
|
|
|
$result['user']['tooltip'] = 'Current member'; |
100
|
|
|
|
101
|
|
|
$expected = array( |
102
|
|
|
'user' => array( |
103
|
|
|
'icon' => 'user', |
104
|
|
|
'tooltip' => 'Current member', |
105
|
|
|
'default' => '', |
106
|
|
|
), |
107
|
|
|
'version' => array( |
108
|
|
|
'icon' => 'desktop', |
109
|
|
|
'tooltip' => 'Stub', |
110
|
|
|
'default' => '', |
111
|
|
|
), |
112
|
|
|
'locale' => array( |
113
|
|
|
'icon' => 'globe', |
114
|
|
|
'tooltip' => 'Stub', |
115
|
|
|
'default' => '', |
116
|
|
|
), |
117
|
|
|
'session' => array( |
118
|
|
|
'icon' => 'archive', |
119
|
|
|
'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
120
|
|
|
'map' => 'silverstripe.session', |
121
|
|
|
'default' => '{}', |
122
|
|
|
), |
123
|
|
|
'cookies' => array( |
124
|
|
|
'icon' => 'asterisk', |
125
|
|
|
'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
126
|
|
|
'map' => 'silverstripe.cookies', |
127
|
|
|
'default' => '{}', |
128
|
|
|
), |
129
|
|
|
'parameters' => array( |
130
|
|
|
'icon' => 'arrow-right', |
131
|
|
|
'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
132
|
|
|
'map' => 'silverstripe.parameters', |
133
|
|
|
'default' => '{}', |
134
|
|
|
), |
135
|
|
|
'requirements' => array( |
136
|
|
|
'icon' => 'file-o ', |
137
|
|
|
'widget' => 'PhpDebugBar.Widgets.ListWidget', |
138
|
|
|
'map' => 'silverstripe.requirements', |
139
|
|
|
'default' => '{}', |
140
|
|
|
), |
141
|
|
|
'templates' => array( |
142
|
|
|
'icon' => 'edit', |
143
|
|
|
'widget' => 'PhpDebugBar.Widgets.ListWidget', |
144
|
|
|
'map' => "silverstripe.templates.templates", |
145
|
|
|
'default' => '{}' |
146
|
|
|
), |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$this->assertSame($expected, $result); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
View Code Duplication |
public function testGetAssets() |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
$expected = array( |
155
|
|
|
'base_path' => '/debugbar/javascript', |
156
|
|
|
'base_url' => 'debugbar/javascript', |
157
|
|
|
'css' => array(), |
158
|
|
|
'js' => 'widgets.js', |
159
|
|
|
); |
160
|
|
|
$this->assertSame($expected, $this->collector->getAssets()); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Test that a message is returned when templates are cached. For retrieval of template info, see |
165
|
|
|
* {@link DebugBarTemplateParserProxyTest} for examples. |
166
|
|
|
* |
167
|
|
|
* Note that the template proxy will register as cached by default until it gets used the first time. |
168
|
|
|
*/ |
169
|
|
|
public function testGetTemplateData() |
170
|
|
|
{ |
171
|
|
|
$result = SilverStripeCollector::getTemplateData(); |
172
|
|
|
$this->assertContains( |
173
|
|
|
'NOTE: Rendered templates will not display when cached', |
174
|
|
|
array_pop($result['templates']) |
175
|
|
|
); |
176
|
|
|
$this->assertSame('', $result['count']); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.