Completed
Push — master ( ec2de6...d160d9 )
by
unknown
28:59 queued 08:31
created

TrashHandlerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 134
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlerMethodName() 0 4 1
A getHandlerClassName() 0 4 1
A providerForUnCachedMethods() 0 9 1
A providerForCachedLoadMethods() 0 6 1
A testRecover() 0 52 1
A testTrashSubtree() 0 51 1
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
namespace eZ\Publish\Core\Persistence\Cache\Tests;
10
11
use eZ\Publish\Core\Persistence\Cache\ContentHandler;
12
use eZ\Publish\Core\Persistence\Cache\LocationHandler;
13
use eZ\Publish\SPI\Persistence\Content\Location;
14
use eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler as TrashHandler;
15
16
/**
17
 * Test case for Persistence\Cache\SectionHandler.
18
 */
19
class TrashHandlerTest extends AbstractCacheHandlerTest
20
{
21
    public function getHandlerMethodName(): string
22
    {
23
        return 'trashHandler';
24
    }
25
26
    public function getHandlerClassName(): string
27
    {
28
        return TrashHandler::class;
29
    }
30
31
    public function providerForUnCachedMethods(): array
32
    {
33
        // string $method, array $arguments, array? $tags, string? $key
34
        return [
35
            ['loadTrashItem', [6]],
36
            ['emptyTrash', []],
37
            ['deleteTrashItem', [6]],
38
        ];
39
    }
40
41
    public function providerForCachedLoadMethods(): array
42
    {
43
        // string $method, array $arguments, string $key, mixed? $data
44
        return [
45
        ];
46
    }
47
48
    public function testRecover()
49
    {
50
        $originalLocationId = 6;
51
        $targetLocationId = 2;
52
        $contentId = 42;
53
54
        $tags = [
55
            'content-' . $contentId,
56
            'content-fields-' . $contentId,
57
            'location-' . $originalLocationId,
58
            'location-path-' . $originalLocationId,
59
        ];
60
61
        $handlerMethodName = $this->getHandlerMethodName();
62
63
        $this->loggerMock->expects($this->once())->method('logCall');
64
65
        $innerHandler = $this->createMock($this->getHandlerClassName());
66
        $contentHandlerMock = $this->createMock(ContentHandler::class);
67
        $locationHandlerMock = $this->createMock(LocationHandler::class);
68
69
        $locationHandlerMock
70
            ->method('load')
71
            ->will($this->returnValue(new Location(['id' => $originalLocationId, 'contentId' => $contentId])));
72
73
        $this->persistenceHandlerMock
74
            ->method('contentHandler')
75
            ->will($this->returnValue($contentHandlerMock));
76
77
        $this->persistenceHandlerMock
78
            ->method('locationHandler')
79
            ->will($this->returnValue($locationHandlerMock));
80
81
        $this->persistenceHandlerMock
82
            ->expects($this->once())
83
            ->method($handlerMethodName)
84
            ->will($this->returnValue($innerHandler));
85
86
        $innerHandler
87
            ->expects($this->once())
88
            ->method('recover')
89
            ->with($originalLocationId, $targetLocationId)
90
            ->will($this->returnValue(null));
91
92
        $this->cacheMock
93
            ->expects($this->once())
94
            ->method('invalidateTags')
95
            ->with($tags);
96
97
        $handler = $this->persistenceCacheHandler->$handlerMethodName();
98
        $handler->recover($originalLocationId, $targetLocationId);
99
    }
100
101
    public function testTrashSubtree()
102
    {
103
        $locationId = 6;
104
        $contentId = 42;
105
106
        $tags = [
107
            'content-' . $contentId,
108
            'content-fields-' . $contentId,
109
            'location-' . $locationId,
110
            'location-path-' . $locationId,
111
        ];
112
113
        $handlerMethodName = $this->getHandlerMethodName();
114
115
        $this->loggerMock->expects($this->once())->method('logCall');
116
117
        $innerHandler = $this->createMock($this->getHandlerClassName());
118
        $contentHandlerMock = $this->createMock(ContentHandler::class);
119
        $locationHandlerMock = $this->createMock(LocationHandler::class);
120
121
        $locationHandlerMock
122
            ->method('load')
123
            ->will($this->returnValue(new Location(['id' => $locationId, 'contentId' => $contentId])));
124
125
        $this->persistenceHandlerMock
126
            ->method('contentHandler')
127
            ->will($this->returnValue($contentHandlerMock));
128
129
        $this->persistenceHandlerMock
130
            ->method('locationHandler')
131
            ->will($this->returnValue($locationHandlerMock));
132
133
        $this->persistenceHandlerMock
134
            ->expects($this->once())
135
            ->method($handlerMethodName)
136
            ->will($this->returnValue($innerHandler));
137
138
        $innerHandler
139
            ->expects($this->once())
140
            ->method('trashSubtree')
141
            ->with($locationId)
142
            ->will($this->returnValue(null));
143
144
        $this->cacheMock
145
            ->expects($this->once())
146
            ->method('invalidateTags')
147
            ->with($tags);
148
149
        $handler = $this->persistenceCacheHandler->$handlerMethodName();
150
        $handler->trashSubtree($locationId);
151
    }
152
}
153