Completed
Push — signal_search_issues ( 5556b2...f328ba )
by André
63:06 queued 07:22
created

SectionHandlerTest::testDelete()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
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
170
        $cacheItemMock
171
            ->expects($this->never())
172
            ->method('get');
173
174
        $handler = $this->persistenceCacheHandler->sectionHandler();
175
        $handler->create('Intranet', 'intranet');
176
    }
177
178
    /**
179
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::delete
180
     */
181
    public function testDelete()
182
    {
183
        $this->loggerMock->expects($this->once())->method('logCall');
184
185
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
186
        $this->persistenceHandlerMock
187
            ->expects($this->once())
188
            ->method('sectionHandler')
189
            ->will($this->returnValue($innerHandlerMock));
190
191
        $innerHandlerMock
192
            ->expects($this->once())
193
            ->method('delete')
194
            ->with(33)
195
            ->will(
196
                $this->returnValue(true)
197
            );
198
199
        $this->cacheMock
200
            ->expects($this->once())
201
            ->method('clear')
202
            ->with('section', 33)
203
            ->will($this->returnValue(true));
204
205
        $handler = $this->persistenceCacheHandler->sectionHandler();
206
        $handler->delete(33);
207
    }
208
209
    /**
210
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load
211
     */
212 View Code Duplication
    public function testLoadCacheIsMiss()
213
    {
214
        $this->loggerMock->expects($this->once())->method('logCall');
215
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
216
        $this->cacheMock
217
            ->expects($this->once())
218
            ->method('getItem')
219
            ->with('section', 33)
220
            ->will($this->returnValue($cacheItemMock));
221
222
        $cacheItemMock
223
            ->expects($this->once())
224
            ->method('isMiss')
225
            ->will($this->returnValue(true));
226
227
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
228
        $this->persistenceHandlerMock
229
            ->expects($this->once())
230
            ->method('sectionHandler')
231
            ->will($this->returnValue($innerHandlerMock));
232
233
        $innerHandlerMock
234
            ->expects($this->once())
235
            ->method('load')
236
            ->with(33)
237
            ->will(
238
                $this->returnValue(
239
                    new SPISection(
240
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
241
                    )
242
                )
243
            );
244
245
        $cacheItemMock
246
            ->expects($this->once())
247
            ->method('set')
248
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section'));
249
250
        $cacheItemMock
251
            ->expects($this->once())
252
            ->method('get')
253
            ->will($this->returnValue(null));
254
255
        $handler = $this->persistenceCacheHandler->sectionHandler();
256
        $handler->load(33);
257
    }
258
259
    /**
260
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load
261
     */
262 View Code Duplication
    public function testLoadHasCache()
263
    {
264
        $this->loggerMock->expects($this->never())->method($this->anything());
265
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
266
        $this->cacheMock
267
            ->expects($this->once())
268
            ->method('getItem')
269
            ->with('section', 33)
270
            ->will($this->returnValue($cacheItemMock));
271
272
        $cacheItemMock
273
            ->expects($this->once())
274
            ->method('isMiss')
275
            ->will($this->returnValue(false));
276
277
        $this->persistenceHandlerMock
278
            ->expects($this->never())
279
            ->method('sectionHandler');
280
281
        $cacheItemMock
282
            ->expects($this->once())
283
            ->method('get')
284
            ->will(
285
                $this->returnValue(
286
                    new SPISection(
287
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
288
                    )
289
                )
290
            );
291
292
        $cacheItemMock
293
            ->expects($this->never())
294
            ->method('set');
295
296
        $handler = $this->persistenceCacheHandler->sectionHandler();
297
        $handler->load(33);
298
    }
299
300
    /**
301
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadAll
302
     */
303
    public function testLoadAll()
304
    {
305
        $this->loggerMock->expects($this->once())->method('logCall');
306
        $this->cacheMock
307
            ->expects($this->never())
308
            ->method($this->anything());
309
310
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
311
        $this->persistenceHandlerMock
312
            ->expects($this->once())
313
            ->method('sectionHandler')
314
            ->will($this->returnValue($innerHandler));
315
316
        $innerHandler
317
            ->expects($this->once())
318
            ->method('loadAll')
319
            ->will($this->returnValue(array()));
320
321
        $handler = $this->persistenceCacheHandler->sectionHandler();
322
        $handler->loadAll();
323
    }
324
325
    /**
326
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadByIdentifier
327
     */
328
    public function testLoadByIdentifier()
329
    {
330
        $this->loggerMock->expects($this->once())->method('logCall');
331
        $this->cacheMock
332
            ->expects($this->never())
333
            ->method($this->anything());
334
335
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
336
        $this->persistenceHandlerMock
337
            ->expects($this->once())
338
            ->method('sectionHandler')
339
            ->will($this->returnValue($innerHandler));
340
341
        $innerHandler
342
            ->expects($this->once())
343
            ->method('loadByIdentifier')
344
            ->with('intranet')
345
            ->will(
346
                $this->returnValue(
347
                    new SPISection(
348
                        array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet')
349
                    )
350
                )
351
            );
352
353
        $handler = $this->persistenceCacheHandler->sectionHandler();
354
        $handler->loadByIdentifier('intranet');
355
    }
356
357
    /**
358
     * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::update
359
     */
360 View Code Duplication
    public function testUpdate()
361
    {
362
        $this->loggerMock->expects($this->once())->method('logCall');
363
364
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler');
365
        $this->persistenceHandlerMock
366
            ->expects($this->once())
367
            ->method('sectionHandler')
368
            ->will($this->returnValue($innerHandler));
369
370
        $innerHandler
371
            ->expects($this->once())
372
            ->method('update')
373
            ->with(33, 'Old Intranet', 'old_intranet')
374
            ->will(
375
                $this->returnValue(
376
                    new SPISection(
377
                        array('id' => 33, 'name' => 'Old Intranet', 'identifier' => 'old_intranet')
378
                    )
379
                )
380
            );
381
382
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
383
        $this->cacheMock
384
            ->expects($this->once())
385
            ->method('getItem')
386
            ->with('section', 33)
387
            ->will($this->returnValue($cacheItemMock));
388
389
        $cacheItemMock
390
            ->expects($this->once())
391
            ->method('set')
392
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section'));
393
394
        $cacheItemMock
395
            ->expects($this->never())
396
            ->method('get');
397
398
        $handler = $this->persistenceCacheHandler->sectionHandler();
399
        $handler->update(33, 'Old Intranet', 'old_intranet');
400
    }
401
}
402