Skip to content

Commit a15afa0

Browse files
committed
fixup! IBX-6773: Bookmarks for non-accessible contents cause exception : Fixed existing tests
1 parent 2668b73 commit a15afa0

File tree

2 files changed

+20
-42
lines changed

2 files changed

+20
-42
lines changed

eZ/Publish/API/Repository/Tests/LocationServiceTest.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -1965,13 +1965,15 @@ public function testBookmarksAreSwappedAfterSwapLocation()
19651965

19661966
$mediaLocationId = $this->generateId('location', 43);
19671967
$demoDesignLocationId = $this->generateId('location', 56);
1968+
$contactUsLocationId = $this->generateId('location', 60);
19681969

19691970
/* BEGIN: Use Case */
19701971
$locationService = $repository->getLocationService();
19711972
$bookmarkService = $repository->getBookmarkService();
19721973

19731974
$mediaLocation = $locationService->loadLocation($mediaLocationId);
19741975
$demoDesignLocation = $locationService->loadLocation($demoDesignLocationId);
1976+
$contactUsLocation = $locationService->loadLocation($contactUsLocationId);
19751977

19761978
// Bookmark locations
19771979
$bookmarkService->createBookmark($mediaLocation);
@@ -1980,13 +1982,23 @@ public function testBookmarksAreSwappedAfterSwapLocation()
19801982
$beforeSwap = $bookmarkService->loadBookmarks();
19811983

19821984
// Swaps the content referred to by the locations
1983-
$locationService->swapLocation($mediaLocation, $demoDesignLocation);
1985+
$locationService->swapLocation($demoDesignLocation, $contactUsLocation);
19841986

19851987
$afterSwap = $bookmarkService->loadBookmarks();
19861988
/* END: Use Case */
19871989

1988-
$this->assertEquals($beforeSwap->items[0]->id, $afterSwap->items[1]->id);
1989-
$this->assertEquals($beforeSwap->items[1]->id, $afterSwap->items[0]->id);
1990+
$expectedIdsAfter = array_map(function (Location $item) use ($demoDesignLocationId, $contactUsLocationId){
1991+
if ($item->id === $demoDesignLocationId ) {
1992+
return $contactUsLocationId;
1993+
}
1994+
return $item->id;
1995+
}, $beforeSwap->items);
1996+
1997+
$actualIdsAfter = array_map(function (Location $item) use ($demoDesignLocationId, $contactUsLocationId){
1998+
return $item->id;
1999+
}, $afterSwap->items);
2000+
2001+
$this->assertEquals($expectedIdsAfter, $actualIdsAfter);
19902002
}
19912003

19922004
/**

eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php

+5-39
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use eZ\Publish\API\Repository\LocationService;
1313
use eZ\Publish\API\Repository\PermissionResolver;
1414
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
15+
use eZ\Publish\API\Repository\Values\Content\LocationList;
1516
use eZ\Publish\Core\Repository\BookmarkService;
1617
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
1718
use eZ\Publish\Core\Repository\Values\Content\Location;
@@ -219,28 +220,14 @@ public function testLoadBookmarks()
219220
$expectedItems = array_map(function ($locationId) {
220221
return $this->createLocation($locationId);
221222
}, range(1, $expectedTotalCount));
223+
$locationList = New LocationList(['totalCount' => $expectedTotalCount, 'locations' => $expectedItems]);
222224

223-
$this->bookmarkHandler
224-
->expects($this->once())
225-
->method('countUserBookmarks')
226-
->with(self::CURRENT_USER_ID)
227-
->willReturn($expectedTotalCount);
228-
229-
$this->bookmarkHandler
230-
->expects($this->once())
231-
->method('loadUserBookmarks')
232-
->with(self::CURRENT_USER_ID, $offset, $limit)
233-
->willReturn(array_map(static function ($locationId) {
234-
return new Bookmark(['locationId' => $locationId]);
235-
}, range(1, $expectedTotalCount)));
236225

237226
$locationServiceMock = $this->createMock(LocationService::class);
238227
$locationServiceMock
239-
->expects($this->exactly($expectedTotalCount))
240-
->method('loadLocation')
241-
->willReturnCallback(function ($locationId) {
242-
return $this->createLocation($locationId);
243-
});
228+
->expects($this->once())
229+
->method('find')
230+
->willReturn($locationList);
244231

245232
$repository = $this->getRepositoryMock();
246233
$repository
@@ -254,27 +241,6 @@ public function testLoadBookmarks()
254241
$this->assertEquals($expectedItems, $bookmarks->items);
255242
}
256243

257-
/**
258-
* @covers \eZ\Publish\Core\Repository\BookmarkService::loadBookmarks
259-
*/
260-
public function testLoadBookmarksEmptyList()
261-
{
262-
$this->bookmarkHandler
263-
->expects($this->once())
264-
->method('countUserBookmarks')
265-
->with(self::CURRENT_USER_ID)
266-
->willReturn(0);
267-
268-
$this->bookmarkHandler
269-
->expects($this->never())
270-
->method('loadUserBookmarks');
271-
272-
$bookmarks = $this->createBookmarkService()->loadBookmarks(0, 10);
273-
274-
$this->assertEquals(0, $bookmarks->totalCount);
275-
$this->assertEmpty($bookmarks->items);
276-
}
277-
278244
/**
279245
* @covers \eZ\Publish\Core\Repository\BookmarkService::isBookmarked
280246
*/

0 commit comments

Comments
 (0)