diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/URLHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/URLHandlerTest.php index c29e5444b04..05f55d9abef 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/URLHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/URLHandlerTest.php @@ -31,7 +31,6 @@ public function providerForUnCachedMethods(): array ['find', [new URLQuery()]], ['findUsages', [1]], ['loadByUrl', ['http://google.com']], - ['updateUrl', [1, new URLUpdateStruct()], ['url-1']], ]; } @@ -44,4 +43,72 @@ public function providerForCachedLoadMethods(): array ['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); + } } diff --git a/eZ/Publish/Core/Persistence/Cache/URLHandler.php b/eZ/Publish/Core/Persistence/Cache/URLHandler.php index 2fa2f90c6de..682961dc284 100644 --- a/eZ/Publish/Core/Persistence/Cache/URLHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/URLHandler.php @@ -31,6 +31,12 @@ public function updateUrl($id, URLUpdateStruct $struct) $this->cache->invalidateTags(['url-' . $id]); + if ($struct->url !== null) { + $this->cache->invalidateTags(array_map(function ($id) { + return 'content-' . $id; + }, $this->persistenceHandler->urlHandler()->findUsages($id))); + } + return $url; }