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