Completed
Push — ezp-30616-follow-up ( 2e0607...b74676 )
by
unknown
35:08 queued 20:12
created

testCreateUrlAliasStopPropagationInBeforeEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40

Duplication

Lines 40
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 40
loc 40
rs 9.28
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\Core\Event\Tests;
8
9
use eZ\Publish\API\Repository\Events\URLAlias\BeforeCreateGlobalUrlAliasEvent as BeforeCreateGlobalUrlAliasEventInterface;
10
use eZ\Publish\API\Repository\Events\URLAlias\BeforeCreateUrlAliasEvent as BeforeCreateUrlAliasEventInterface;
11
use eZ\Publish\API\Repository\Events\URLAlias\BeforeRefreshSystemUrlAliasesForLocationEvent as BeforeRefreshSystemUrlAliasesForLocationEventInterface;
12
use eZ\Publish\API\Repository\Events\URLAlias\BeforeRemoveAliasesEvent as BeforeRemoveAliasesEventInterface;
13
use eZ\Publish\API\Repository\Events\URLAlias\CreateGlobalUrlAliasEvent as CreateGlobalUrlAliasEventInterface;
14
use eZ\Publish\API\Repository\Events\URLAlias\CreateUrlAliasEvent as CreateUrlAliasEventInterface;
15
use eZ\Publish\API\Repository\Events\URLAlias\RefreshSystemUrlAliasesForLocationEvent as RefreshSystemUrlAliasesForLocationEventInterface;
16
use eZ\Publish\API\Repository\Events\URLAlias\RemoveAliasesEvent as RemoveAliasesEventInterface;
17
use eZ\Publish\API\Repository\URLAliasService as URLAliasServiceInterface;
18
use eZ\Publish\API\Repository\Values\Content\Location;
19
use eZ\Publish\API\Repository\Values\Content\URLAlias;
20
use eZ\Publish\Core\Event\URLAliasService;
21
22
class URLAliasServiceTest extends AbstractServiceTest
23
{
24 View Code Duplication
    public function testCreateGlobalUrlAliasEvents()
25
    {
26
        $traceableEventDispatcher = $this->getEventDispatcher(
27
            BeforeCreateGlobalUrlAliasEventInterface::class,
28
            CreateGlobalUrlAliasEventInterface::class
29
        );
30
31
        $parameters = [
32
            'random_value_5cff79c3183471.48198669',
33
            'random_value_5cff79c3183491.90712521',
34
            'random_value_5cff79c31834a2.27245619',
35
            'random_value_5cff79c31834b7.17763784',
36
            'random_value_5cff79c31834c3.69513526',
37
        ];
38
39
        $urlAlias = $this->createMock(URLAlias::class);
40
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
41
        $innerServiceMock->method('createGlobalUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
42
43
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
44
        $result = $service->createGlobalUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createGlobalUrlAlias() misses some required arguments starting with $path.
Loading history...
45
46
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
47
48
        $this->assertSame($urlAlias, $result);
49
        $this->assertSame($calledListeners, [
50
            [BeforeCreateGlobalUrlAliasEventInterface::class, 0],
51
            [CreateGlobalUrlAliasEventInterface::class, 0],
52
        ]);
53
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
54
    }
55
56 View Code Duplication
    public function testReturnCreateGlobalUrlAliasResultInBeforeEvents()
57
    {
58
        $traceableEventDispatcher = $this->getEventDispatcher(
59
            BeforeCreateGlobalUrlAliasEventInterface::class,
60
            CreateGlobalUrlAliasEventInterface::class
61
        );
62
63
        $parameters = [
64
            'random_value_5cff79c3183999.45723962',
65
            'random_value_5cff79c31839a0.16919746',
66
            'random_value_5cff79c31839b6.04657069',
67
            'random_value_5cff79c31839c8.99027893',
68
            'random_value_5cff79c31839d9.22502123',
69
        ];
70
71
        $urlAlias = $this->createMock(URLAlias::class);
72
        $eventUrlAlias = $this->createMock(URLAlias::class);
73
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
74
        $innerServiceMock->method('createGlobalUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
75
76
        $traceableEventDispatcher->addListener(BeforeCreateGlobalUrlAliasEventInterface::class, function (BeforeCreateGlobalUrlAliasEventInterface $event) use ($eventUrlAlias) {
77
            $event->setUrlAlias($eventUrlAlias);
78
        }, 10);
79
80
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
81
        $result = $service->createGlobalUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createGlobalUrlAlias() misses some required arguments starting with $path.
Loading history...
82
83
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
84
85
        $this->assertSame($eventUrlAlias, $result);
86
        $this->assertSame($calledListeners, [
87
            [BeforeCreateGlobalUrlAliasEventInterface::class, 10],
88
            [BeforeCreateGlobalUrlAliasEventInterface::class, 0],
89
            [CreateGlobalUrlAliasEventInterface::class, 0],
90
        ]);
91
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
92
    }
93
94 View Code Duplication
    public function testCreateGlobalUrlAliasStopPropagationInBeforeEvents()
95
    {
96
        $traceableEventDispatcher = $this->getEventDispatcher(
97
            BeforeCreateGlobalUrlAliasEventInterface::class,
98
            CreateGlobalUrlAliasEventInterface::class
99
        );
100
101
        $parameters = [
102
            'random_value_5cff79c3183a40.78467503',
103
            'random_value_5cff79c3183a52.60688594',
104
            'random_value_5cff79c3183a62.37338343',
105
            'random_value_5cff79c3183a74.31062414',
106
            'random_value_5cff79c3183a85.16422549',
107
        ];
108
109
        $urlAlias = $this->createMock(URLAlias::class);
110
        $eventUrlAlias = $this->createMock(URLAlias::class);
111
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
112
        $innerServiceMock->method('createGlobalUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
113
114
        $traceableEventDispatcher->addListener(BeforeCreateGlobalUrlAliasEventInterface::class, function (BeforeCreateGlobalUrlAliasEventInterface $event) use ($eventUrlAlias) {
115
            $event->setUrlAlias($eventUrlAlias);
116
            $event->stopPropagation();
117
        }, 10);
118
119
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
120
        $result = $service->createGlobalUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createGlobalUrlAlias() misses some required arguments starting with $path.
Loading history...
121
122
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
123
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
124
125
        $this->assertSame($eventUrlAlias, $result);
126
        $this->assertSame($calledListeners, [
127
            [BeforeCreateGlobalUrlAliasEventInterface::class, 10],
128
        ]);
129
        $this->assertSame($notCalledListeners, [
130
            [BeforeCreateGlobalUrlAliasEventInterface::class, 0],
131
            [CreateGlobalUrlAliasEventInterface::class, 0],
132
        ]);
133
    }
134
135
    public function testRefreshSystemUrlAliasesForLocationEvents()
136
    {
137
        $traceableEventDispatcher = $this->getEventDispatcher(
138
            BeforeRefreshSystemUrlAliasesForLocationEventInterface::class,
139
            RefreshSystemUrlAliasesForLocationEventInterface::class
140
        );
141
142
        $parameters = [
143
            $this->createMock(Location::class),
144
        ];
145
146
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
147
148
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
149
        $service->refreshSystemUrlAliasesForLocation(...$parameters);
150
151
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
152
153
        $this->assertSame($calledListeners, [
154
            [BeforeRefreshSystemUrlAliasesForLocationEventInterface::class, 0],
155
            [RefreshSystemUrlAliasesForLocationEventInterface::class, 0],
156
        ]);
157
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
158
    }
159
160
    public function testRefreshSystemUrlAliasesForLocationStopPropagationInBeforeEvents()
161
    {
162
        $traceableEventDispatcher = $this->getEventDispatcher(
163
            BeforeRefreshSystemUrlAliasesForLocationEventInterface::class,
164
            RefreshSystemUrlAliasesForLocationEventInterface::class
165
        );
166
167
        $parameters = [
168
            $this->createMock(Location::class),
169
        ];
170
171
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
172
173
        $traceableEventDispatcher->addListener(BeforeRefreshSystemUrlAliasesForLocationEventInterface::class, function (BeforeRefreshSystemUrlAliasesForLocationEventInterface $event) {
174
            $event->stopPropagation();
175
        }, 10);
176
177
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
178
        $service->refreshSystemUrlAliasesForLocation(...$parameters);
179
180
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
181
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
182
183
        $this->assertSame($calledListeners, [
184
            [BeforeRefreshSystemUrlAliasesForLocationEventInterface::class, 10],
185
        ]);
186
        $this->assertSame($notCalledListeners, [
187
            [BeforeRefreshSystemUrlAliasesForLocationEventInterface::class, 0],
188
            [RefreshSystemUrlAliasesForLocationEventInterface::class, 0],
189
        ]);
190
    }
191
192 View Code Duplication
    public function testCreateUrlAliasEvents()
193
    {
194
        $traceableEventDispatcher = $this->getEventDispatcher(
195
            BeforeCreateUrlAliasEventInterface::class,
196
            CreateUrlAliasEventInterface::class
197
        );
198
199
        $parameters = [
200
            $this->createMock(Location::class),
201
            'random_value_5cff79c3184f05.03459159',
202
            'random_value_5cff79c3184f14.18292216',
203
            'random_value_5cff79c3184f24.01158164',
204
            'random_value_5cff79c3184f32.03833593',
205
        ];
206
207
        $urlAlias = $this->createMock(URLAlias::class);
208
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
209
        $innerServiceMock->method('createUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
210
211
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
212
        $result = $service->createUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUrlAlias() misses some required arguments starting with $path.
Loading history...
213
214
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
215
216
        $this->assertSame($urlAlias, $result);
217
        $this->assertSame($calledListeners, [
218
            [BeforeCreateUrlAliasEventInterface::class, 0],
219
            [CreateUrlAliasEventInterface::class, 0],
220
        ]);
221
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
222
    }
223
224 View Code Duplication
    public function testReturnCreateUrlAliasResultInBeforeEvents()
225
    {
226
        $traceableEventDispatcher = $this->getEventDispatcher(
227
            BeforeCreateUrlAliasEventInterface::class,
228
            CreateUrlAliasEventInterface::class
229
        );
230
231
        $parameters = [
232
            $this->createMock(Location::class),
233
            'random_value_5cff79c3184fd7.07408772',
234
            'random_value_5cff79c3184fe2.98616568',
235
            'random_value_5cff79c3184ff0.62652505',
236
            'random_value_5cff79c3185003.87499400',
237
        ];
238
239
        $urlAlias = $this->createMock(URLAlias::class);
240
        $eventUrlAlias = $this->createMock(URLAlias::class);
241
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
242
        $innerServiceMock->method('createUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
243
244
        $traceableEventDispatcher->addListener(BeforeCreateUrlAliasEventInterface::class, function (BeforeCreateUrlAliasEventInterface $event) use ($eventUrlAlias) {
245
            $event->setUrlAlias($eventUrlAlias);
246
        }, 10);
247
248
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
249
        $result = $service->createUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUrlAlias() misses some required arguments starting with $path.
Loading history...
250
251
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
252
253
        $this->assertSame($eventUrlAlias, $result);
254
        $this->assertSame($calledListeners, [
255
            [BeforeCreateUrlAliasEventInterface::class, 10],
256
            [BeforeCreateUrlAliasEventInterface::class, 0],
257
            [CreateUrlAliasEventInterface::class, 0],
258
        ]);
259
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
260
    }
261
262 View Code Duplication
    public function testCreateUrlAliasStopPropagationInBeforeEvents()
263
    {
264
        $traceableEventDispatcher = $this->getEventDispatcher(
265
            BeforeCreateUrlAliasEventInterface::class,
266
            CreateUrlAliasEventInterface::class
267
        );
268
269
        $parameters = [
270
            $this->createMock(Location::class),
271
            'random_value_5cff79c3185072.24449261',
272
            'random_value_5cff79c3185080.62311461',
273
            'random_value_5cff79c3185095.31877612',
274
            'random_value_5cff79c31850a4.20254218',
275
        ];
276
277
        $urlAlias = $this->createMock(URLAlias::class);
278
        $eventUrlAlias = $this->createMock(URLAlias::class);
279
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
280
        $innerServiceMock->method('createUrlAlias')->willReturn($urlAlias);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
281
282
        $traceableEventDispatcher->addListener(BeforeCreateUrlAliasEventInterface::class, function (BeforeCreateUrlAliasEventInterface $event) use ($eventUrlAlias) {
283
            $event->setUrlAlias($eventUrlAlias);
284
            $event->stopPropagation();
285
        }, 10);
286
287
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
288
        $result = $service->createUrlAlias(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUrlAlias() misses some required arguments starting with $path.
Loading history...
289
290
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
291
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
292
293
        $this->assertSame($eventUrlAlias, $result);
294
        $this->assertSame($calledListeners, [
295
            [BeforeCreateUrlAliasEventInterface::class, 10],
296
        ]);
297
        $this->assertSame($notCalledListeners, [
298
            [BeforeCreateUrlAliasEventInterface::class, 0],
299
            [CreateUrlAliasEventInterface::class, 0],
300
        ]);
301
    }
302
303
    public function testRemoveAliasesEvents()
304
    {
305
        $traceableEventDispatcher = $this->getEventDispatcher(
306
            BeforeRemoveAliasesEventInterface::class,
307
            RemoveAliasesEventInterface::class
308
        );
309
310
        $parameters = [
311
            [],
312
        ];
313
314
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
315
316
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
317
        $service->removeAliases(...$parameters);
318
319
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
320
321
        $this->assertSame($calledListeners, [
322
            [BeforeRemoveAliasesEventInterface::class, 0],
323
            [RemoveAliasesEventInterface::class, 0],
324
        ]);
325
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
326
    }
327
328
    public function testRemoveAliasesStopPropagationInBeforeEvents()
329
    {
330
        $traceableEventDispatcher = $this->getEventDispatcher(
331
            BeforeRemoveAliasesEventInterface::class,
332
            RemoveAliasesEventInterface::class
333
        );
334
335
        $parameters = [
336
            [],
337
        ];
338
339
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
340
341
        $traceableEventDispatcher->addListener(BeforeRemoveAliasesEventInterface::class, function (BeforeRemoveAliasesEventInterface $event) {
342
            $event->stopPropagation();
343
        }, 10);
344
345
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
346
        $service->removeAliases(...$parameters);
347
348
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
349
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
350
351
        $this->assertSame($calledListeners, [
352
            [BeforeRemoveAliasesEventInterface::class, 10],
353
        ]);
354
        $this->assertSame($notCalledListeners, [
355
            [BeforeRemoveAliasesEventInterface::class, 0],
356
            [RemoveAliasesEventInterface::class, 0],
357
        ]);
358
    }
359
}
360