1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Bundle\EzPublishDebugBundle\Tests\Collector; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishDebugBundle\Collector\EzPublishCoreCollector; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use Exception; |
16
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; |
17
|
|
|
|
18
|
|
|
class EzPublishCoreCollectorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var EzPublishCoreCollector |
22
|
|
|
*/ |
23
|
|
|
private $mainCollector; |
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
$this->mainCollector = new EzPublishCoreCollector(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testAddGetCollector() |
32
|
|
|
{ |
33
|
|
|
$collector = $this->getDataCollectorMock(); |
34
|
|
|
$name = 'foobar'; |
35
|
|
|
$collector |
36
|
|
|
->expects($this->once()) |
37
|
|
|
->method('getName') |
38
|
|
|
->will($this->returnValue($name)); |
39
|
|
|
|
40
|
|
|
$this->mainCollector->addCollector($collector); |
41
|
|
|
$this->assertSame($collector, $this->mainCollector->getCollector($name)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @expectedException \InvalidArgumentException |
46
|
|
|
*/ |
47
|
|
|
public function testGetInvalidCollector() |
48
|
|
|
{ |
49
|
|
|
$collector = $this->getDataCollectorMock(); |
50
|
|
|
$this->mainCollector->addCollector($collector); |
51
|
|
|
$this->assertSame($collector, $this->mainCollector->getCollector('foo')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetAllCollectors() |
55
|
|
|
{ |
56
|
|
|
$collector1 = $this->getDataCollectorMock(); |
57
|
|
|
$nameCollector1 = 'collector1'; |
58
|
|
|
$collector1 |
59
|
|
|
->expects($this->once()) |
60
|
|
|
->method('getName') |
61
|
|
|
->will($this->returnValue($nameCollector1)); |
62
|
|
|
$collector2 = $this->getDataCollectorMock(); |
63
|
|
|
$nameCollector2 = 'collector2'; |
64
|
|
|
$collector2 |
65
|
|
|
->expects($this->once()) |
66
|
|
|
->method('getName') |
67
|
|
|
->will($this->returnValue($nameCollector2)); |
68
|
|
|
|
69
|
|
|
$allCollectors = [ |
70
|
|
|
$nameCollector1 => $collector1, |
71
|
|
|
$nameCollector2 => $collector2, |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
foreach ($allCollectors as $name => $collector) { |
75
|
|
|
$this->mainCollector->addCollector($collector); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->assertSame($allCollectors, $this->mainCollector->getAllCollectors()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testGetToolbarTemplateNothing() |
82
|
|
|
{ |
83
|
|
|
$collector = $this->getDataCollectorMock(); |
84
|
|
|
$name = 'foobar'; |
85
|
|
|
$collector |
86
|
|
|
->expects($this->once()) |
87
|
|
|
->method('getName') |
88
|
|
|
->will($this->returnValue($name)); |
89
|
|
|
$this->mainCollector->addCollector($collector); |
90
|
|
|
$this->assertNull($this->mainCollector->getToolbarTemplate($name)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public function testGetToolbarTemplate() |
94
|
|
|
{ |
95
|
|
|
$collector = $this->getDataCollectorMock(); |
96
|
|
|
$name = 'foobar'; |
97
|
|
|
$collector |
98
|
|
|
->expects($this->once()) |
99
|
|
|
->method('getName') |
100
|
|
|
->will($this->returnValue($name)); |
101
|
|
|
$toolbarTemplate = 'toolbar.html.twig'; |
102
|
|
|
|
103
|
|
|
$this->mainCollector->addCollector($collector, 'foo', $toolbarTemplate); |
104
|
|
|
$this->assertSame($toolbarTemplate, $this->mainCollector->getToolbarTemplate($name)); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
View Code Duplication |
public function testGetPanelTemplateNothing() |
108
|
|
|
{ |
109
|
|
|
$collector = $this->getDataCollectorMock(); |
110
|
|
|
$name = 'foobar'; |
111
|
|
|
$collector |
112
|
|
|
->expects($this->once()) |
113
|
|
|
->method('getName') |
114
|
|
|
->will($this->returnValue($name)); |
115
|
|
|
$this->mainCollector->addCollector($collector); |
116
|
|
|
$this->assertNull($this->mainCollector->getPanelTemplate($name)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function testGetPanelTemplate() |
120
|
|
|
{ |
121
|
|
|
$collector = $this->getDataCollectorMock(); |
122
|
|
|
$name = 'foobar'; |
123
|
|
|
$collector |
124
|
|
|
->expects($this->once()) |
125
|
|
|
->method('getName') |
126
|
|
|
->will($this->returnValue($name)); |
127
|
|
|
$panelTemplate = 'toolbar.html.twig'; |
128
|
|
|
|
129
|
|
|
$this->mainCollector->addCollector($collector, $panelTemplate, 'foo'); |
130
|
|
|
$this->assertSame($panelTemplate, $this->mainCollector->getPanelTemplate($name)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testCollect() |
134
|
|
|
{ |
135
|
|
|
$collector1 = $this->getDataCollectorMock(); |
136
|
|
|
$nameCollector1 = 'collector1'; |
137
|
|
|
$collector1 |
138
|
|
|
->expects($this->once()) |
139
|
|
|
->method('getName') |
140
|
|
|
->will($this->returnValue($nameCollector1)); |
141
|
|
|
$collector2 = $this->getDataCollectorMock(); |
142
|
|
|
$nameCollector2 = 'collector2'; |
143
|
|
|
$collector2 |
144
|
|
|
->expects($this->once()) |
145
|
|
|
->method('getName') |
146
|
|
|
->will($this->returnValue($nameCollector2)); |
147
|
|
|
|
148
|
|
|
$allCollectors = [ |
149
|
|
|
$nameCollector1 => $collector1, |
150
|
|
|
$nameCollector2 => $collector2, |
151
|
|
|
]; |
152
|
|
|
|
153
|
|
|
$request = new Request(); |
154
|
|
|
$response = new Response(); |
155
|
|
|
$exception = new Exception(); |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
159
|
|
|
*/ |
160
|
|
|
foreach ($allCollectors as $name => $collector) { |
161
|
|
|
$this->mainCollector->addCollector($collector); |
162
|
|
|
$collector |
163
|
|
|
->expects($this->once()) |
164
|
|
|
->method('collect') |
165
|
|
|
->with($request, $response, $exception); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$this->mainCollector->collect($request, $response, $exception); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
protected function getDataCollectorMock() |
172
|
|
|
{ |
173
|
|
|
return $this->createMock(DataCollectorInterface::class); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|