From a15afa0605348810b14955e3c8d70cb871f812bc Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Thu, 30 May 2024 14:01:16 +0200 Subject: [PATCH] fixup! IBX-6773: Bookmarks for non-accessible contents cause exception : Fixed existing tests --- .../Repository/Tests/LocationServiceTest.php | 18 ++++++-- .../Tests/Service/Mock/BookmarkTest.php | 44 +++---------------- 2 files changed, 20 insertions(+), 42 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/LocationServiceTest.php b/eZ/Publish/API/Repository/Tests/LocationServiceTest.php index 153f768ba7..aa8a8d1473 100644 --- a/eZ/Publish/API/Repository/Tests/LocationServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/LocationServiceTest.php @@ -1965,6 +1965,7 @@ public function testBookmarksAreSwappedAfterSwapLocation() $mediaLocationId = $this->generateId('location', 43); $demoDesignLocationId = $this->generateId('location', 56); + $contactUsLocationId = $this->generateId('location', 60); /* BEGIN: Use Case */ $locationService = $repository->getLocationService(); @@ -1972,6 +1973,7 @@ public function testBookmarksAreSwappedAfterSwapLocation() $mediaLocation = $locationService->loadLocation($mediaLocationId); $demoDesignLocation = $locationService->loadLocation($demoDesignLocationId); + $contactUsLocation = $locationService->loadLocation($contactUsLocationId); // Bookmark locations $bookmarkService->createBookmark($mediaLocation); @@ -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); } /** diff --git a/eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php b/eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php index 5c23d98b3e..d214f2c738 100644 --- a/eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php +++ b/eZ/Publish/Core/Repository/Tests/Service/Mock/BookmarkTest.php @@ -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; @@ -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 @@ -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 */