Completed
Push — feature-EZP-25696 ( c75b51...ce24f7 )
by André
24:57 queued 26s
created

SectionHandlerTest::testCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 35

Duplication

Lines 47
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 35
c 1
b 0
f 0
nc 1
nop 0
dl 47
loc 47
rs 9.0303
1
<?php
2
3
/**
4
 * File contains Test 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\Cache\Tests;
12
13
use eZ\Publish\SPI\Persistence\Content\Section as SPISection;
14
15
/**
16
 * Test case for Persistence\Cache\SectionHandler.
17
 */
18
class SectionHandlerTest extends HandlerTest
19
{
20
    /**
21
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::assign
22
     */
23 View Code Duplication
    public function testAssign()
24
    {
25
        $this->loggerMock->expects($this->once())->method('logCall');
26
27
        $this->cacheMock
28
            ->expects($this->at(0))
29
            ->method('clear')
30
            ->with('content', 44)
31
            ->will($this->returnValue(null));
32
33
        $this->cacheMock
34
            ->expects($this->at(1))
35
            ->method('clear')
36
            ->with('content', 'info', 44)
37
            ->will($this->returnValue(null));
38
39
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
40
        $this->persistenceHandlerMock
41
            ->expects($this->once())
42
            ->method('sectionHandler')
43
            ->will($this->returnValue($innerHandler));
44
45
        $innerHandler
46
            ->expects($this->once())
47
            ->method('assign')
48
            ->with(33, 44)
49
            ->will($this->returnValue(null));
50
51
        $handler = $this->persistenceCacheHandler->sectionHandler();
52
        $handler->assign(33, 44);
53
    }
54
55
    /**
56
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::assignmentsCount
57
     */
58
    public function testAssignmentsCount()
59
    {
60
        $this->loggerMock->expects($this->once())->method('logCall');
61
        $this->cacheMock
62
            ->expects($this->never())
63
            ->method($this->anything());
64
65
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
66
        $this->persistenceHandlerMock
67
            ->expects($this->once())
68
            ->method('sectionHandler')
69
            ->will($this->returnValue($innerHandler));
70
71
        $innerHandler
72
            ->expects($this->once())
73
            ->method('assignmentsCount')
74
            ->with(33)
75
            ->will($this->returnValue(null));
76
77
        $handler = $this->persistenceCacheHandler->sectionHandler();
78
        $handler->assignmentsCount(33);
79
    }
80
81
    /**
82
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::policiesCount
83
     */
84
    public function testPoliciesCount()
85
    {
86
        $this->loggerMock->expects($this->once())->method('logCall');
87
        $this->cacheMock
88
            ->expects($this->never())
89
            ->method($this->anything());
90
91
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
92
        $this->persistenceHandlerMock
93
            ->expects($this->once())
94
            ->method('sectionHandler')
95
            ->will($this->returnValue($innerHandler));
96
97
        $innerHandler
98
            ->expects($this->once())
99
            ->method('policiesCount')
100
            ->with(1)
101
            ->will($this->returnValue(7));
102
103
        $handler = $this->persistenceCacheHandler->sectionHandler();
104
        $handler->policiesCount(1);
105
    }
106
107
    /**
108
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::countRoleAssignmentsUsingSection
109
     */
110
    public function testCountRoleAssignmentsUsingSection()
111
    {
112
        $this->loggerMock->expects($this->once())->method('logCall');
113
        $this->cacheMock
114
            ->expects($this->never())
115
            ->method($this->anything());
116
117
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
118
        $this->persistenceHandlerMock
119
            ->expects($this->once())
120
            ->method('sectionHandler')
121
            ->will($this->returnValue($innerHandler));
122
123
        $innerHandler
124
            ->expects($this->once())
125
            ->method('countRoleAssignmentsUsingSection')
126
            ->with(1)
127
            ->will($this->returnValue(0));
128
129
        $handler = $this->persistenceCacheHandler->sectionHandler();
130
        $handler->countRoleAssignmentsUsingSection(1);
131
    }
132
133
    /**
134
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::create
135
     */
136 View Code Duplication
    public function testCreate()
137
    {
138
        $this->loggerMock->expects($this->once())->method('logCall');
139
140
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
141
        $this->persistenceHandlerMock
142
            ->expects($this->once())
143
            ->method('sectionHandler')
144
            ->will($this->returnValue($innerHandlerMock));
145
146
        $innerHandlerMock
147
            ->expects($this->once())
148
            ->method('create')
149
            ->with('Intranet', 'intranet')
150
            ->will(
151
                $this->returnValue(
152
                    new SPISection(
153
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
154
                    )
155
                )
156
            );
157
158
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
159
        $this->cacheMock
160
            ->expects($this->once())
161
            ->method('getItem')
162
            ->with('section', 33)
163
            ->will($this->returnValue($cacheItemMock));
164
165
        $cacheItemMock
166
            ->expects($this->once())
167
            ->method('set')
168
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section'))
169
            ->will($this->returnValue($cacheItemMock));
170
171
        $cacheItemMock
172
            ->expects($this->once())
173
            ->method('save')
174
            ->with();
175
176
        $cacheItemMock
177
            ->expects($this->never())
178
            ->method('get');
179
180
        $handler = $this->persistenceCacheHandler->sectionHandler();
181
        $handler->create('Intranet', 'intranet');
182
    }
183
184
    /**
185
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::delete
186
     */
187
    public function testDelete()
188
    {
189
        $this->loggerMock->expects($this->once())->method('logCall');
190
191
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
192
        $this->persistenceHandlerMock
193
            ->expects($this->once())
194
            ->method('sectionHandler')
195
            ->will($this->returnValue($innerHandlerMock));
196
197
        $innerHandlerMock
198
            ->expects($this->once())
199
            ->method('delete')
200
            ->with(33)
201
            ->will(
202
                $this->returnValue(true)
203
            );
204
205
        $this->cacheMock
206
            ->expects($this->once())
207
            ->method('clear')
208
            ->with('section', 33)
209
            ->will($this->returnValue(true));
210
211
        $handler = $this->persistenceCacheHandler->sectionHandler();
212
        $handler->delete(33);
213
    }
214
215
    /**
216
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load
217
     */
218 View Code Duplication
    public function testLoadCacheIsMiss()
219
    {
220
        $this->loggerMock->expects($this->once())->method('logCall');
221
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
222
        $this->cacheMock
223
            ->expects($this->once())
224
            ->method('getItem')
225
            ->with('section', 33)
226
            ->will($this->returnValue($cacheItemMock));
227
228
        $cacheItemMock
229
            ->expects($this->once())
230
            ->method('isMiss')
231
            ->will($this->returnValue(true));
232
233
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
234
        $this->persistenceHandlerMock
235
            ->expects($this->once())
236
            ->method('sectionHandler')
237
            ->will($this->returnValue($innerHandlerMock));
238
239
        $innerHandlerMock
240
            ->expects($this->once())
241
            ->method('load')
242
            ->with(33)
243
            ->will(
244
                $this->returnValue(
245
                    new SPISection(
246
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
247
                    )
248
                )
249
            );
250
251
        $cacheItemMock
252
            ->expects($this->once())
253
            ->method('set')
254
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section'))
255
            ->will($this->returnValue($cacheItemMock));
256
257
        $cacheItemMock
258
            ->expects($this->once())
259
            ->method('save')
260
            ->with();
261
262
        $cacheItemMock
263
            ->expects($this->once())
264
            ->method('get')
265
            ->will($this->returnValue(null));
266
267
        $handler = $this->persistenceCacheHandler->sectionHandler();
268
        $handler->load(33);
269
    }
270
271
    /**
272
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load
273
     */
274 View Code Duplication
    public function testLoadHasCache()
275
    {
276
        $this->loggerMock->expects($this->never())->method($this->anything());
277
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
278
        $this->cacheMock
279
            ->expects($this->once())
280
            ->method('getItem')
281
            ->with('section', 33)
282
            ->will($this->returnValue($cacheItemMock));
283
284
        $cacheItemMock
285
            ->expects($this->once())
286
            ->method('isMiss')
287
            ->will($this->returnValue(false));
288
289
        $this->persistenceHandlerMock
290
            ->expects($this->never())
291
            ->method('sectionHandler');
292
293
        $cacheItemMock
294
            ->expects($this->once())
295
            ->method('get')
296
            ->will(
297
                $this->returnValue(
298
                    new SPISection(
299
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
300
                    )
301
                )
302
            );
303
304
        $cacheItemMock
305
            ->expects($this->never())
306
            ->method('set');
307
308
        $handler = $this->persistenceCacheHandler->sectionHandler();
309
        $handler->load(33);
310
    }
311
312
    /**
313
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadAll
314
     */
315
    public function testLoadAll()
316
    {
317
        $this->loggerMock->expects($this->once())->method('logCall');
318
        $this->cacheMock
319
            ->expects($this->never())
320
            ->method($this->anything());
321
322
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
323
        $this->persistenceHandlerMock
324
            ->expects($this->once())
325
            ->method('sectionHandler')
326
            ->will($this->returnValue($innerHandler));
327
328
        $innerHandler
329
            ->expects($this->once())
330
            ->method('loadAll')
331
            ->will($this->returnValue(array()));
332
333
        $handler = $this->persistenceCacheHandler->sectionHandler();
334
        $handler->loadAll();
335
    }
336
337
    /**
338
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadByIdentifier
339
     */
340
    public function testLoadByIdentifier()
341
    {
342
        $this->loggerMock->expects($this->once())->method('logCall');
343
        $this->cacheMock
344
            ->expects($this->never())
345
            ->method($this->anything());
346
347
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
348
        $this->persistenceHandlerMock
349
            ->expects($this->once())
350
            ->method('sectionHandler')
351
            ->will($this->returnValue($innerHandler));
352
353
        $innerHandler
354
            ->expects($this->once())
355
            ->method('loadByIdentifier')
356
            ->with('intranet')
357
            ->will(
358
                $this->returnValue(
359
                    new SPISection(
360
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
361
                    )
362
                )
363
            );
364
365
        $handler = $this->persistenceCacheHandler->sectionHandler();
366
        $handler->loadByIdentifier('intranet');
367
    }
368
369
    /**
370
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::update
371
     */
372 View Code Duplication
    public function testUpdate()
373
    {
374
        $this->loggerMock->expects($this->once())->method('logCall');
375
376
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
377
        $this->persistenceHandlerMock
378
            ->expects($this->once())
379
            ->method('sectionHandler')
380
            ->will($this->returnValue($innerHandler));
381
382
        $innerHandler
383
            ->expects($this->once())
384
            ->method('update')
385
            ->with(33, 'Old Intranet', 'old_intranet')
386
            ->will(
387
                $this->returnValue(
388
                    new SPISection(
389
                        array('id' => 33, 'name' => 'Old Intranet', 'identifier' => 'old_intranet')
390
                    )
391
                )
392
            );
393
394
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
395
        $this->cacheMock
396
            ->expects($this->once())
397
            ->method('getItem')
398
            ->with('section', 33)
399
            ->will($this->returnValue($cacheItemMock));
400
401
        $cacheItemMock
402
            ->expects($this->once())
403
            ->method('set')
404
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section'))
405
            ->will($this->returnValue($cacheItemMock));
406
407
        $cacheItemMock
408
            ->expects($this->once())
409
            ->method('save')
410
            ->with();
411
412
        $cacheItemMock
413
            ->expects($this->never())
414
            ->method('get');
415
416
        $handler = $this->persistenceCacheHandler->sectionHandler();
417
        $handler->update(33, 'Old Intranet', 'old_intranet');
418
    }
419
}
420