| @@ 53-89 (lines=37) @@ | ||
| 50 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 51 | } |
|
| 52 | ||
| 53 | public function testReturnCreateGlobalUrlAliasResultInBeforeEvents() |
|
| 54 | { |
|
| 55 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 56 | URLAliasEvents::BEFORE_CREATE_GLOBAL_URL_ALIAS, |
|
| 57 | URLAliasEvents::CREATE_GLOBAL_URL_ALIAS |
|
| 58 | ); |
|
| 59 | ||
| 60 | $parameters = [ |
|
| 61 | 'random_value_5cff79c3183999.45723962', |
|
| 62 | 'random_value_5cff79c31839a0.16919746', |
|
| 63 | 'random_value_5cff79c31839b6.04657069', |
|
| 64 | 'random_value_5cff79c31839c8.99027893', |
|
| 65 | 'random_value_5cff79c31839d9.22502123', |
|
| 66 | ]; |
|
| 67 | ||
| 68 | $urlAlias = $this->createMock(URLAlias::class); |
|
| 69 | $eventUrlAlias = $this->createMock(URLAlias::class); |
|
| 70 | $innerServiceMock = $this->createMock(URLAliasServiceInterface::class); |
|
| 71 | $innerServiceMock->method('createGlobalUrlAlias')->willReturn($urlAlias); |
|
| 72 | ||
| 73 | $traceableEventDispatcher->addListener(URLAliasEvents::BEFORE_CREATE_GLOBAL_URL_ALIAS, function (BeforeCreateGlobalUrlAliasEvent $event) use ($eventUrlAlias) { |
|
| 74 | $event->setUrlAlias($eventUrlAlias); |
|
| 75 | }, 10); |
|
| 76 | ||
| 77 | $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher); |
|
| 78 | $result = $service->createGlobalUrlAlias(...$parameters); |
|
| 79 | ||
| 80 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 81 | ||
| 82 | $this->assertSame($eventUrlAlias, $result); |
|
| 83 | $this->assertSame($calledListeners, [ |
|
| 84 | [URLAliasEvents::BEFORE_CREATE_GLOBAL_URL_ALIAS, 10], |
|
| 85 | [URLAliasEvents::BEFORE_CREATE_GLOBAL_URL_ALIAS, 0], |
|
| 86 | [URLAliasEvents::CREATE_GLOBAL_URL_ALIAS, 0], |
|
| 87 | ]); |
|
| 88 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 89 | } |
|
| 90 | ||
| 91 | public function testCreateGlobalUrlAliasStopPropagationInBeforeEvents() |
|
| 92 | { |
|
| @@ 221-257 (lines=37) @@ | ||
| 218 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 219 | } |
|
| 220 | ||
| 221 | public function testReturnCreateUrlAliasResultInBeforeEvents() |
|
| 222 | { |
|
| 223 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 224 | URLAliasEvents::BEFORE_CREATE_URL_ALIAS, |
|
| 225 | URLAliasEvents::CREATE_URL_ALIAS |
|
| 226 | ); |
|
| 227 | ||
| 228 | $parameters = [ |
|
| 229 | $this->createMock(Location::class), |
|
| 230 | 'random_value_5cff79c3184fd7.07408772', |
|
| 231 | 'random_value_5cff79c3184fe2.98616568', |
|
| 232 | 'random_value_5cff79c3184ff0.62652505', |
|
| 233 | 'random_value_5cff79c3185003.87499400', |
|
| 234 | ]; |
|
| 235 | ||
| 236 | $urlAlias = $this->createMock(URLAlias::class); |
|
| 237 | $eventUrlAlias = $this->createMock(URLAlias::class); |
|
| 238 | $innerServiceMock = $this->createMock(URLAliasServiceInterface::class); |
|
| 239 | $innerServiceMock->method('createUrlAlias')->willReturn($urlAlias); |
|
| 240 | ||
| 241 | $traceableEventDispatcher->addListener(URLAliasEvents::BEFORE_CREATE_URL_ALIAS, function (BeforeCreateUrlAliasEvent $event) use ($eventUrlAlias) { |
|
| 242 | $event->setUrlAlias($eventUrlAlias); |
|
| 243 | }, 10); |
|
| 244 | ||
| 245 | $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher); |
|
| 246 | $result = $service->createUrlAlias(...$parameters); |
|
| 247 | ||
| 248 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 249 | ||
| 250 | $this->assertSame($eventUrlAlias, $result); |
|
| 251 | $this->assertSame($calledListeners, [ |
|
| 252 | [URLAliasEvents::BEFORE_CREATE_URL_ALIAS, 10], |
|
| 253 | [URLAliasEvents::BEFORE_CREATE_URL_ALIAS, 0], |
|
| 254 | [URLAliasEvents::CREATE_URL_ALIAS, 0], |
|
| 255 | ]); |
|
| 256 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 257 | } |
|
| 258 | ||
| 259 | public function testCreateUrlAliasStopPropagationInBeforeEvents() |
|
| 260 | { |
|
| @@ 107-141 (lines=35) @@ | ||
| 104 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 105 | } |
|
| 106 | ||
| 107 | public function testReturnCreateResultInBeforeEvents() |
|
| 108 | { |
|
| 109 | $traceableEventDispatcher = $this->getEventDispatcher( |
|
| 110 | URLWildcardEvents::BEFORE_CREATE, |
|
| 111 | URLWildcardEvents::CREATE |
|
| 112 | ); |
|
| 113 | ||
| 114 | $parameters = [ |
|
| 115 | 'random_value_5cff79c316c2d5.26653678', |
|
| 116 | 'random_value_5cff79c316c2e7.55400833', |
|
| 117 | 'random_value_5cff79c316c2f8.59874187', |
|
| 118 | ]; |
|
| 119 | ||
| 120 | $urlWildcard = $this->createMock(URLWildcard::class); |
|
| 121 | $eventUrlWildcard = $this->createMock(URLWildcard::class); |
|
| 122 | $innerServiceMock = $this->createMock(URLWildcardServiceInterface::class); |
|
| 123 | $innerServiceMock->method('create')->willReturn($urlWildcard); |
|
| 124 | ||
| 125 | $traceableEventDispatcher->addListener(URLWildcardEvents::BEFORE_CREATE, function (BeforeCreateEvent $event) use ($eventUrlWildcard) { |
|
| 126 | $event->setUrlWildcard($eventUrlWildcard); |
|
| 127 | }, 10); |
|
| 128 | ||
| 129 | $service = new URLWildcardService($innerServiceMock, $traceableEventDispatcher); |
|
| 130 | $result = $service->create(...$parameters); |
|
| 131 | ||
| 132 | $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners()); |
|
| 133 | ||
| 134 | $this->assertSame($eventUrlWildcard, $result); |
|
| 135 | $this->assertSame($calledListeners, [ |
|
| 136 | [URLWildcardEvents::BEFORE_CREATE, 10], |
|
| 137 | [URLWildcardEvents::BEFORE_CREATE, 0], |
|
| 138 | [URLWildcardEvents::CREATE, 0], |
|
| 139 | ]); |
|
| 140 | $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners()); |
|
| 141 | } |
|
| 142 | ||
| 143 | public function testCreateStopPropagationInBeforeEvents() |
|
| 144 | { |
|