Completed
Push — 7.0 ( f55084...ac3a5e )
by André
53:02 queued 31:19
created

URLHandlerTest::providerForUnCachedMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Tests\Core\Persistence\Cache;
8
9
use eZ\Publish\API\Repository\Values\URL\URLQuery;
10
use eZ\Publish\Core\Persistence\Cache\Tests\AbstractCacheHandlerTest;
11
use eZ\Publish\SPI\Persistence\URL\Handler as SpiURLHandler;
12
use eZ\Publish\SPI\Persistence\URL\URL;
13
use eZ\Publish\SPI\Persistence\URL\URLUpdateStruct;
14
15
class URLHandlerTest extends AbstractCacheHandlerTest
16
{
17
    public function getHandlerMethodName(): string
18
    {
19
        return 'urlHandler';
20
    }
21
22
    public function getHandlerClassName(): string
23
    {
24
        return SpiURLHandler::class;
25
    }
26
27
    public function providerForUnCachedMethods(): array
28
    {
29
        // string $method, array $arguments, array? $tags, string? $key
30
        return [
31
            ['find', [new URLQuery()]],
32
            ['findUsages', [1]],
33
            ['loadByUrl', ['http://google.com']],
34
        ];
35
    }
36
37
    public function providerForCachedLoadMethods(): array
38
    {
39
        $url = new URL(['id' => 1]);
40
41
        // string $method, array $arguments, string $key, mixed? $data
42
        return [
43
            ['loadById', [1], 'ez-url-1', [$url]],
44
        ];
45
    }
46
47
    public function testUpdateUrlWhenAddressIsUpdated()
48
    {
49
        $urlId = 1;
50
        $updateStruct = new URLUpdateStruct();
51
        $updateStruct->url = 'http://ez.no';
52
53
        $this->loggerMock->expects($this->once())->method('logCall');
54
55
        $innerHandlerMock = $this->createMock(SpiURLHandler::class);
56
        $this->persistenceHandlerMock
57
            ->expects($this->any())
58
            ->method('urlHandler')
59
            ->will($this->returnValue($innerHandlerMock));
60
61
        $innerHandlerMock
62
            ->expects($this->exactly(1))
63
            ->method('findUsages')
64
            ->with($urlId)
65
            ->willReturn([2, 3, 5]);
66
67
        $innerHandlerMock
68
            ->expects($this->exactly(1))
69
            ->method('updateUrl')
70
            ->with($urlId, $updateStruct)
71
            ->willReturn(true);
72
73
        $this->cacheMock
74
            ->expects($this->at(0))
75
            ->method('invalidateTags')
76
            ->with(['url-1']);
77
78
        $this->cacheMock
79
            ->expects($this->at(1))
80
            ->method('invalidateTags')
81
            ->with(['content-2', 'content-3', 'content-5']);
82
83
        $handler = $this->persistenceCacheHandler->urlHandler();
84
        $handler->updateUrl($urlId, $updateStruct);
85
    }
86
87
    public function testUpdateUrlStatusIsUpdated()
88
    {
89
        $urlId = 1;
90
        $updateStruct = new URLUpdateStruct();
91
92
        $this->loggerMock->expects($this->once())->method('logCall');
93
94
        $innerHandlerMock = $this->createMock(SpiURLHandler::class);
95
        $this->persistenceHandlerMock
96
            ->expects($this->any())
97
            ->method('urlHandler')
98
            ->will($this->returnValue($innerHandlerMock));
99
100
        $innerHandlerMock
101
            ->expects($this->exactly(1))
102
            ->method('updateUrl')
103
            ->with($urlId, $updateStruct)
104
            ->willReturn(true);
105
106
        $this->cacheMock
107
            ->expects($this->at(0))
108
            ->method('invalidateTags')
109
            ->with(['url-1']);
110
111
        $handler = $this->persistenceCacheHandler->urlHandler();
112
        $handler->updateUrl($urlId, $updateStruct);
113
    }
114
}
115