1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Section\SectionHandlerTest class. |
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
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content\Section; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\Section; |
15
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for Section Handler. |
19
|
|
|
*/ |
20
|
|
|
class SectionHandlerTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Section handler. |
24
|
|
|
* |
25
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler |
26
|
|
|
*/ |
27
|
|
|
protected $sectionHandler; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Section gateway mock. |
31
|
|
|
* |
32
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway |
33
|
|
|
*/ |
34
|
|
|
protected $gatewayMock; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::create |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function testCreate() |
40
|
|
|
{ |
41
|
|
|
$handler = $this->getSectionHandler(); |
42
|
|
|
|
43
|
|
|
$gatewayMock = $this->getGatewayMock(); |
44
|
|
|
|
45
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
46
|
|
|
->method('insertSection') |
47
|
|
|
->with( |
48
|
|
|
$this->equalTo('New Section'), |
49
|
|
|
$this->equalTo('new_section') |
50
|
|
|
)->will($this->returnValue(23)); |
51
|
|
|
|
52
|
|
|
$sectionRef = new Section(); |
53
|
|
|
$sectionRef->id = 23; |
54
|
|
|
$sectionRef->name = 'New Section'; |
55
|
|
|
$sectionRef->identifier = 'new_section'; |
56
|
|
|
|
57
|
|
|
$result = $handler->create('New Section', 'new_section'); |
58
|
|
|
|
59
|
|
|
$this->assertEquals( |
60
|
|
|
$sectionRef, |
61
|
|
|
$result |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::update |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function testUpdate() |
69
|
|
|
{ |
70
|
|
|
$handler = $this->getSectionHandler(); |
71
|
|
|
|
72
|
|
|
$gatewayMock = $this->getGatewayMock(); |
73
|
|
|
|
74
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
75
|
|
|
->method('updateSection') |
76
|
|
|
->with( |
77
|
|
|
$this->equalTo(23), |
78
|
|
|
$this->equalTo('New Section'), |
79
|
|
|
$this->equalTo('new_section') |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$sectionRef = new Section(); |
83
|
|
|
$sectionRef->id = 23; |
84
|
|
|
$sectionRef->name = 'New Section'; |
85
|
|
|
$sectionRef->identifier = 'new_section'; |
86
|
|
|
|
87
|
|
|
$result = $handler->update(23, 'New Section', 'new_section'); |
88
|
|
|
|
89
|
|
|
$this->assertEquals( |
90
|
|
|
$sectionRef, |
91
|
|
|
$result |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::load |
97
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray |
98
|
|
|
*/ |
99
|
|
View Code Duplication |
public function testLoad() |
100
|
|
|
{ |
101
|
|
|
$handler = $this->getSectionHandler(); |
102
|
|
|
|
103
|
|
|
$gatewayMock = $this->getGatewayMock(); |
104
|
|
|
|
105
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
106
|
|
|
->method('loadSectionData') |
107
|
|
|
->with( |
108
|
|
|
$this->equalTo(23) |
109
|
|
|
)->will( |
110
|
|
|
$this->returnValue( |
111
|
|
|
array( |
112
|
|
|
array( |
113
|
|
|
'id' => '23', |
114
|
|
|
'identifier' => 'new_section', |
115
|
|
|
'name' => 'New Section', |
116
|
|
|
), |
117
|
|
|
) |
118
|
|
|
) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$sectionRef = new Section(); |
122
|
|
|
$sectionRef->id = 23; |
123
|
|
|
$sectionRef->name = 'New Section'; |
124
|
|
|
$sectionRef->identifier = 'new_section'; |
125
|
|
|
|
126
|
|
|
$result = $handler->load(23); |
127
|
|
|
|
128
|
|
|
$this->assertEquals( |
129
|
|
|
$sectionRef, |
130
|
|
|
$result |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::loadAll |
136
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray |
137
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionsFromArray |
138
|
|
|
*/ |
139
|
|
|
public function testLoadAll() |
140
|
|
|
{ |
141
|
|
|
$handler = $this->getSectionHandler(); |
142
|
|
|
|
143
|
|
|
$gatewayMock = $this->getGatewayMock(); |
144
|
|
|
|
145
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
146
|
|
|
->method('loadAllSectionData') |
147
|
|
|
->will( |
148
|
|
|
$this->returnValue( |
149
|
|
|
array( |
150
|
|
|
array( |
151
|
|
|
'id' => '23', |
152
|
|
|
'identifier' => 'new_section', |
153
|
|
|
'name' => 'New Section', |
154
|
|
|
), |
155
|
|
|
array( |
156
|
|
|
'id' => '46', |
157
|
|
|
'identifier' => 'new_section2', |
158
|
|
|
'name' => 'New Section2', |
159
|
|
|
), |
160
|
|
|
) |
161
|
|
|
) |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
$sectionRef = new Section(); |
165
|
|
|
$sectionRef->id = 23; |
166
|
|
|
$sectionRef->name = 'New Section'; |
167
|
|
|
$sectionRef->identifier = 'new_section'; |
168
|
|
|
|
169
|
|
|
$sectionRef2 = new Section(); |
170
|
|
|
$sectionRef2->id = 46; |
171
|
|
|
$sectionRef2->name = 'New Section2'; |
172
|
|
|
$sectionRef2->identifier = 'new_section2'; |
173
|
|
|
|
174
|
|
|
$result = $handler->loadAll(); |
175
|
|
|
|
176
|
|
|
$this->assertEquals( |
177
|
|
|
array($sectionRef, $sectionRef2), |
178
|
|
|
$result |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::loadByIdentifier |
184
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::createSectionFromArray |
185
|
|
|
*/ |
186
|
|
View Code Duplication |
public function testLoadByIdentifier() |
187
|
|
|
{ |
188
|
|
|
$handler = $this->getSectionHandler(); |
189
|
|
|
|
190
|
|
|
$gatewayMock = $this->getGatewayMock(); |
191
|
|
|
|
192
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
193
|
|
|
->method('loadSectionDataByIdentifier') |
194
|
|
|
->with( |
195
|
|
|
$this->equalTo('new_section') |
196
|
|
|
)->will( |
197
|
|
|
$this->returnValue( |
198
|
|
|
array( |
199
|
|
|
array( |
200
|
|
|
'id' => '23', |
201
|
|
|
'identifier' => 'new_section', |
202
|
|
|
'name' => 'New Section', |
203
|
|
|
), |
204
|
|
|
) |
205
|
|
|
) |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$sectionRef = new Section(); |
209
|
|
|
$sectionRef->id = 23; |
210
|
|
|
$sectionRef->name = 'New Section'; |
211
|
|
|
$sectionRef->identifier = 'new_section'; |
212
|
|
|
|
213
|
|
|
$result = $handler->loadByIdentifier('new_section'); |
214
|
|
|
|
215
|
|
|
$this->assertEquals( |
216
|
|
|
$sectionRef, |
217
|
|
|
$result |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::delete |
223
|
|
|
*/ |
224
|
|
View Code Duplication |
public function testDelete() |
225
|
|
|
{ |
226
|
|
|
$handler = $this->getSectionHandler(); |
227
|
|
|
|
228
|
|
|
$gatewayMock = $this->getGatewayMock(); |
229
|
|
|
|
230
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
231
|
|
|
->method('countContentObjectsInSection') |
232
|
|
|
->with($this->equalTo(23)) |
233
|
|
|
->will($this->returnValue(0)); |
234
|
|
|
|
235
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
236
|
|
|
->method('deleteSection') |
237
|
|
|
->with( |
238
|
|
|
$this->equalTo(23) |
239
|
|
|
); |
240
|
|
|
|
241
|
|
|
$result = $handler->delete(23); |
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::delete |
246
|
|
|
* @expectedException RuntimeException |
247
|
|
|
*/ |
248
|
|
View Code Duplication |
public function testDeleteFailure() |
249
|
|
|
{ |
250
|
|
|
$handler = $this->getSectionHandler(); |
251
|
|
|
|
252
|
|
|
$gatewayMock = $this->getGatewayMock(); |
253
|
|
|
|
254
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
255
|
|
|
->method('countContentObjectsInSection') |
256
|
|
|
->with($this->equalTo(23)) |
257
|
|
|
->will($this->returnValue(2)); |
258
|
|
|
|
259
|
|
|
$gatewayMock->expects($this->never()) |
|
|
|
|
260
|
|
|
->method('deleteSection'); |
261
|
|
|
|
262
|
|
|
$result = $handler->delete(23); |
|
|
|
|
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::assign |
267
|
|
|
*/ |
268
|
|
View Code Duplication |
public function testAssign() |
269
|
|
|
{ |
270
|
|
|
$handler = $this->getSectionHandler(); |
271
|
|
|
|
272
|
|
|
$gatewayMock = $this->getGatewayMock(); |
273
|
|
|
|
274
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
275
|
|
|
->method('assignSectionToContent') |
276
|
|
|
->with( |
277
|
|
|
$this->equalTo(23), |
278
|
|
|
$this->equalTo(42) |
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
$result = $handler->assign(23, 42); |
|
|
|
|
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::policiesCount |
286
|
|
|
*/ |
287
|
|
View Code Duplication |
public function testPoliciesCount() |
288
|
|
|
{ |
289
|
|
|
$handler = $this->getSectionHandler(); |
290
|
|
|
|
291
|
|
|
$gatewayMock = $this->getGatewayMock(); |
292
|
|
|
|
293
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
294
|
|
|
->method('countPoliciesUsingSection') |
295
|
|
|
->with( |
296
|
|
|
$this->equalTo(1) |
297
|
|
|
) |
298
|
|
|
->will( |
299
|
|
|
$this->returnValue(7) |
300
|
|
|
); |
301
|
|
|
|
302
|
|
|
$result = $handler->policiesCount(1); |
|
|
|
|
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @covers eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler::countRoleAssignmentsUsingSection |
307
|
|
|
*/ |
308
|
|
View Code Duplication |
public function testCountRoleAssignmentsUsingSection() |
309
|
|
|
{ |
310
|
|
|
$handler = $this->getSectionHandler(); |
311
|
|
|
|
312
|
|
|
$gatewayMock = $this->getGatewayMock(); |
313
|
|
|
|
314
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
315
|
|
|
->method('countRoleAssignmentsUsingSection') |
316
|
|
|
->with( |
317
|
|
|
$this->equalTo(1) |
318
|
|
|
) |
319
|
|
|
->will( |
320
|
|
|
$this->returnValue(0) |
321
|
|
|
); |
322
|
|
|
|
323
|
|
|
$handler->countRoleAssignmentsUsingSection(1); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Returns the section handler to test. |
328
|
|
|
* |
329
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler |
330
|
|
|
*/ |
331
|
|
|
protected function getSectionHandler() |
332
|
|
|
{ |
333
|
|
|
if (!isset($this->sectionHandler)) { |
334
|
|
|
$this->sectionHandler = new Handler( |
335
|
|
|
$this->getGatewayMock() |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
return $this->sectionHandler; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Returns a mock for the section gateway. |
344
|
|
|
* |
345
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway |
346
|
|
|
*/ |
347
|
|
|
protected function getGatewayMock() |
348
|
|
|
{ |
349
|
|
|
if (!isset($this->gatewayMock)) { |
350
|
|
|
$this->gatewayMock = $this->getMockForAbstractClass( |
|
|
|
|
351
|
|
|
'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Section\\Gateway' |
352
|
|
|
); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return $this->gatewayMock; |
|
|
|
|
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.