|
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\UserPreference\BeforeSetUserPreferenceEvent as BeforeSetUserPreferenceEventInterface; |
|
10
|
|
|
use eZ\Publish\API\Repository\Events\UserPreference\SetUserPreferenceEvent as SetUserPreferenceEventInterface; |
|
11
|
|
|
use eZ\Publish\API\Repository\UserPreferenceService as UserPreferenceServiceInterface; |
|
12
|
|
|
use eZ\Publish\Core\Event\UserPreferenceService; |
|
13
|
|
|
|
|
14
|
|
|
class UserPreferenceServiceTest extends AbstractServiceTest |
|
15
|
|
|
{ |
|
16
|
|
|
public function testSetUserPreferenceEvents() |
|
17
|
|
|
{ |
|
18
|
|
|
$traceableEventDispatcher = $this->getEventDispatcher( |
|
19
|
|
|
BeforeSetUserPreferenceEventInterface::class, |
|
20
|
|
|
SetUserPreferenceEventInterface::class |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
$parameters = [ |
|
24
|
|
|
[], |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
$innerServiceMock = $this->createMock(UserPreferenceServiceInterface::class); |
|
28
|
|
|
|
|
29
|
|
|
$service = new UserPreferenceService($innerServiceMock, $traceableEventDispatcher); |
|
30
|
|
|
$service->setUserPreference(...$parameters); |
|
31
|
|
|
|
|
32
|
|
|
$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertSame($calledListeners, [ |
|
35
|
|
|
[BeforeSetUserPreferenceEventInterface::class, 0], |
|
36
|
|
|
[SetUserPreferenceEventInterface::class, 0], |
|
37
|
|
|
]); |
|
38
|
|
|
$this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testSetUserPreferenceStopPropagationInBeforeEvents() |
|
42
|
|
|
{ |
|
43
|
|
|
$traceableEventDispatcher = $this->getEventDispatcher( |
|
44
|
|
|
BeforeSetUserPreferenceEventInterface::class, |
|
45
|
|
|
SetUserPreferenceEventInterface::class |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$parameters = [ |
|
49
|
|
|
[], |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
$innerServiceMock = $this->createMock(UserPreferenceServiceInterface::class); |
|
53
|
|
|
|
|
54
|
|
|
$traceableEventDispatcher->addListener(BeforeSetUserPreferenceEventInterface::class, function (BeforeSetUserPreferenceEventInterface $event) { |
|
55
|
|
|
$event->stopPropagation(); |
|
56
|
|
|
}, 10); |
|
57
|
|
|
|
|
58
|
|
|
$service = new UserPreferenceService($innerServiceMock, $traceableEventDispatcher); |
|
59
|
|
|
$service->setUserPreference(...$parameters); |
|
60
|
|
|
|
|
61
|
|
|
$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
62
|
|
|
$notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners()); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertSame($calledListeners, [ |
|
65
|
|
|
[BeforeSetUserPreferenceEventInterface::class, 10], |
|
66
|
|
|
]); |
|
67
|
|
|
$this->assertSame($notCalledListeners, [ |
|
68
|
|
|
[BeforeSetUserPreferenceEventInterface::class, 0], |
|
69
|
|
|
[SetUserPreferenceEventInterface::class, 0], |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|