Skip to content

Commit

Permalink
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
Browse files Browse the repository at this point in the history
…n : Fixed existing tests
  • Loading branch information
vidarl committed May 30, 2024
1 parent 2668b73 commit a15afa0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
18 changes: 15 additions & 3 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1965,13 +1965,15 @@ public function testBookmarksAreSwappedAfterSwapLocation()

$mediaLocationId = $this->generateId('location', 43);
$demoDesignLocationId = $this->generateId('location', 56);
$contactUsLocationId = $this->generateId('location', 60);

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

$mediaLocation = $locationService->loadLocation($mediaLocationId);
$demoDesignLocation = $locationService->loadLocation($demoDesignLocationId);
$contactUsLocation = $locationService->loadLocation($contactUsLocationId);

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

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

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

$this->assertEquals($beforeSwap->items[0]->id, $afterSwap->items[1]->id);
$this->assertEquals($beforeSwap->items[1]->id, $afterSwap->items[0]->id);
$expectedIdsAfter = array_map(function (Location $item) use ($demoDesignLocationId, $contactUsLocationId){
if ($item->id === $demoDesignLocationId ) {
return $contactUsLocationId;
}
return $item->id;
}, $beforeSwap->items);

$actualIdsAfter = array_map(function (Location $item) use ($demoDesignLocationId, $contactUsLocationId){
return $item->id;
}, $afterSwap->items);

$this->assertEquals($expectedIdsAfter, $actualIdsAfter);
}

/**
Expand Down
44 changes: 5 additions & 39 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\LocationList;
use eZ\Publish\Core\Repository\BookmarkService;
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
use eZ\Publish\Core\Repository\Values\Content\Location;
Expand Down Expand Up @@ -219,28 +220,14 @@ public function testLoadBookmarks()
$expectedItems = array_map(function ($locationId) {
return $this->createLocation($locationId);
}, range(1, $expectedTotalCount));
$locationList = New LocationList(['totalCount' => $expectedTotalCount, 'locations' => $expectedItems]);

$this->bookmarkHandler
->expects($this->once())
->method('countUserBookmarks')
->with(self::CURRENT_USER_ID)
->willReturn($expectedTotalCount);

$this->bookmarkHandler
->expects($this->once())
->method('loadUserBookmarks')
->with(self::CURRENT_USER_ID, $offset, $limit)
->willReturn(array_map(static function ($locationId) {
return new Bookmark(['locationId' => $locationId]);
}, range(1, $expectedTotalCount)));

$locationServiceMock = $this->createMock(LocationService::class);
$locationServiceMock
->expects($this->exactly($expectedTotalCount))
->method('loadLocation')
->willReturnCallback(function ($locationId) {
return $this->createLocation($locationId);
});
->expects($this->once())
->method('find')
->willReturn($locationList);

$repository = $this->getRepositoryMock();
$repository
Expand All @@ -254,27 +241,6 @@ public function testLoadBookmarks()
$this->assertEquals($expectedItems, $bookmarks->items);
}

/**
* @covers \eZ\Publish\Core\Repository\BookmarkService::loadBookmarks
*/
public function testLoadBookmarksEmptyList()
{
$this->bookmarkHandler
->expects($this->once())
->method('countUserBookmarks')
->with(self::CURRENT_USER_ID)
->willReturn(0);

$this->bookmarkHandler
->expects($this->never())
->method('loadUserBookmarks');

$bookmarks = $this->createBookmarkService()->loadBookmarks(0, 10);

$this->assertEquals(0, $bookmarks->totalCount);
$this->assertEmpty($bookmarks->items);
}

/**
* @covers \eZ\Publish\Core\Repository\BookmarkService::isBookmarked
*/
Expand Down

0 comments on commit a15afa0

Please sign in to comment.