Skip to content

Commit

Permalink
Merge branch '7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Mar 5, 2018
2 parents 4fd099d + ac3a5ed commit 97d1c8d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
69 changes: 68 additions & 1 deletion eZ/Publish/Core/Persistence/Cache/Tests/URLHandlerTest.php
Expand Up @@ -31,7 +31,6 @@ public function providerForUnCachedMethods(): array
['find', [new URLQuery()]],
['findUsages', [1]],
['loadByUrl', ['http://google.com']],
['updateUrl', [1, new URLUpdateStruct()], ['url-1']],
];
}

Expand All @@ -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);
}
}
6 changes: 6 additions & 0 deletions eZ/Publish/Core/Persistence/Cache/URLHandler.php
Expand Up @@ -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;
}

Expand Down

0 comments on commit 97d1c8d

Please sign in to comment.