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