|
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\Event\Tests; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent as BeforeUpdateUrlEventInterface; |
|
10
|
|
|
use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent as UpdateUrlEventInterface; |
|
11
|
|
|
use eZ\Publish\API\Repository\URLService as URLServiceInterface; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\URL\URL; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\URL\URLUpdateStruct; |
|
14
|
|
|
use eZ\Publish\Core\Event\URLService; |
|
15
|
|
|
|
|
16
|
|
|
class URLServiceTest extends AbstractServiceTest |
|
17
|
|
|
{ |
|
18
|
|
View Code Duplication |
public function testUpdateUrlEvents() |
|
19
|
|
|
{ |
|
20
|
|
|
$traceableEventDispatcher = $this->getEventDispatcher( |
|
21
|
|
|
BeforeUpdateUrlEventInterface::class, |
|
22
|
|
|
UpdateUrlEventInterface::class |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
$parameters = [ |
|
26
|
|
|
$this->createMock(URL::class), |
|
27
|
|
|
$this->createMock(URLUpdateStruct::class), |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
$updatedUrl = $this->createMock(URL::class); |
|
31
|
|
|
$innerServiceMock = $this->createMock(URLServiceInterface::class); |
|
32
|
|
|
$innerServiceMock->method('updateUrl')->willReturn($updatedUrl); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$service = new URLService($innerServiceMock, $traceableEventDispatcher); |
|
35
|
|
|
$result = $service->updateUrl(...$parameters); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertSame($updatedUrl, $result); |
|
40
|
|
|
$this->assertSame($calledListeners, [ |
|
41
|
|
|
[BeforeUpdateUrlEventInterface::class, 0], |
|
42
|
|
|
[UpdateUrlEventInterface::class, 0], |
|
43
|
|
|
]); |
|
44
|
|
|
$this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function testReturnUpdateUrlResultInBeforeEvents() |
|
48
|
|
|
{ |
|
49
|
|
|
$traceableEventDispatcher = $this->getEventDispatcher( |
|
50
|
|
|
BeforeUpdateUrlEventInterface::class, |
|
51
|
|
|
UpdateUrlEventInterface::class |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$parameters = [ |
|
55
|
|
|
$this->createMock(URL::class), |
|
56
|
|
|
$this->createMock(URLUpdateStruct::class), |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
$updatedUrl = $this->createMock(URL::class); |
|
60
|
|
|
$eventUpdatedUrl = $this->createMock(URL::class); |
|
61
|
|
|
$innerServiceMock = $this->createMock(URLServiceInterface::class); |
|
62
|
|
|
$innerServiceMock->method('updateUrl')->willReturn($updatedUrl); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$traceableEventDispatcher->addListener(BeforeUpdateUrlEventInterface::class, function (BeforeUpdateUrlEventInterface $event) use ($eventUpdatedUrl) { |
|
65
|
|
|
$event->setUpdatedUrl($eventUpdatedUrl); |
|
66
|
|
|
}, 10); |
|
67
|
|
|
|
|
68
|
|
|
$service = new URLService($innerServiceMock, $traceableEventDispatcher); |
|
69
|
|
|
$result = $service->updateUrl(...$parameters); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertSame($eventUpdatedUrl, $result); |
|
74
|
|
|
$this->assertSame($calledListeners, [ |
|
75
|
|
|
[BeforeUpdateUrlEventInterface::class, 10], |
|
76
|
|
|
[BeforeUpdateUrlEventInterface::class, 0], |
|
77
|
|
|
[UpdateUrlEventInterface::class, 0], |
|
78
|
|
|
]); |
|
79
|
|
|
$this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
View Code Duplication |
public function testUpdateUrlStopPropagationInBeforeEvents() |
|
83
|
|
|
{ |
|
84
|
|
|
$traceableEventDispatcher = $this->getEventDispatcher( |
|
85
|
|
|
BeforeUpdateUrlEventInterface::class, |
|
86
|
|
|
UpdateUrlEventInterface::class |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$parameters = [ |
|
90
|
|
|
$this->createMock(URL::class), |
|
91
|
|
|
$this->createMock(URLUpdateStruct::class), |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
$updatedUrl = $this->createMock(URL::class); |
|
95
|
|
|
$eventUpdatedUrl = $this->createMock(URL::class); |
|
96
|
|
|
$innerServiceMock = $this->createMock(URLServiceInterface::class); |
|
97
|
|
|
$innerServiceMock->method('updateUrl')->willReturn($updatedUrl); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$traceableEventDispatcher->addListener(BeforeUpdateUrlEventInterface::class, function (BeforeUpdateUrlEventInterface $event) use ($eventUpdatedUrl) { |
|
100
|
|
|
$event->setUpdatedUrl($eventUpdatedUrl); |
|
101
|
|
|
$event->stopPropagation(); |
|
102
|
|
|
}, 10); |
|
103
|
|
|
|
|
104
|
|
|
$service = new URLService($innerServiceMock, $traceableEventDispatcher); |
|
105
|
|
|
$result = $service->updateUrl(...$parameters); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
108
|
|
|
$notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners()); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertSame($eventUpdatedUrl, $result); |
|
111
|
|
|
$this->assertSame($calledListeners, [ |
|
112
|
|
|
[BeforeUpdateUrlEventInterface::class, 10], |
|
113
|
|
|
]); |
|
114
|
|
|
$this->assertSame($notCalledListeners, [ |
|
115
|
|
|
[BeforeUpdateUrlEventInterface::class, 0], |
|
116
|
|
|
[UpdateUrlEventInterface::class, 0], |
|
117
|
|
|
]); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.