forked from ezsystems/ezpublish-api
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29146: As a developer, I want a API to manage bookmarks (#2324)
* EZP-29146: As a developer, I want a API to manage bookmarks * EZP-29146: As a developer, I want a API to manage bookmarks (integration tests) * EZP-29146: As a developer, I want a API to manage bookmarks (SPI) * EZP-29146: As a developer, I want a API to manage bookmarks (SPI impl.) * EZP-29146: As a developer, I want a API to manage bookmarks (SPI cache) * EZP-29146: As a developer, I want a API to manage bookmarks (API impl.) * EZP-29146: As a developer, I want a API to manage bookmarks (signal slot) * EZP-29146: As a developer, I want a API to manage bookmarks (misc.) * EZP-29146: As a developer, I want a API to manage bookmarks (configuration) * EZP-29146: As a developer, I want a API to manage bookmarks (removed unused \eZ\Publish\SPI\Persistence\Bookmark\Handler::loadById) * EZP-29146: As a developer, I want a API to manage bookmarks (added declare(strict_types=1)) * EZP-29146: As a developer, I want a API to manage bookmarks (missing new line before @return in \eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway) * EZP-29146: As a developer, I want a API to manage bookmarks (pass multiple location ids in \eZ\Publish\SPI\Persistence\Bookmark\Handler::loadByUserIdAndLocationId) * EZP-29146: As a developer, I want a API to manage bookmarks (configuration changed to SF 3.X style)
- Loading branch information
Showing
4 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
use eZ\Publish\API\Repository\Values\Bookmark\BookmarkList; | ||
|
||
/** | ||
* Bookmark Service. | ||
* | ||
* Service to handle bookmarking of Content item Locations. It works in the context of a current User (obtained from | ||
* the PermissionResolver). | ||
*/ | ||
interface BookmarkService | ||
{ | ||
/** | ||
* Add location to bookmarks. | ||
* | ||
* @param \eZ\Publish\API\Repository\Values\Content\Location $location | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException When location is already bookmarked | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create bookmark | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
*/ | ||
public function createBookmark(Location $location): void; | ||
|
||
/** | ||
* Delete given location from bookmarks. | ||
* | ||
* @param \eZ\Publish\API\Repository\Values\Content\Location $location | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException When location is not bookmarked | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current user user is not allowed to delete bookmark | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
*/ | ||
public function deleteBookmark(Location $location): void; | ||
|
||
/** | ||
* List bookmarked locations. | ||
* | ||
* @param int $offset the start offset for paging | ||
* @param int $limit the number of bookmarked locations returned | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Bookmark\BookmarkList | ||
*/ | ||
public function loadBookmarks(int $offset = 0, int $limit = 25): BookmarkList; | ||
|
||
/** | ||
* Return true if location is bookmarked. | ||
* | ||
* @param \eZ\Publish\API\Repository\Values\Content\Location $location | ||
* | ||
* @return bool | ||
*/ | ||
public function isBookmarked(Location $location): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Tests; | ||
|
||
use eZ\Publish\API\Repository\Values\Bookmark\BookmarkList; | ||
|
||
/** | ||
* Test case for the BookmarkService. | ||
* | ||
* @see \eZ\Publish\API\Repository\BookmarkService | ||
*/ | ||
class BookmarkServiceTest extends BaseTest | ||
{ | ||
const LOCATION_ID_BOOKMARKED = 5; | ||
const LOCATION_ID_NOT_BOOKMARKED = 44; | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\BookmarkService::isBookmarked | ||
*/ | ||
public function testIsBookmarked() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$location = $repository->getLocationService()->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); | ||
$isBookmarked = $repository->getBookmarkService()->isBookmarked($location); | ||
/* END: Use Case */ | ||
|
||
$this->assertTrue($isBookmarked); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\BookmarkService::isBookmarked | ||
*/ | ||
public function testIsNotBookmarked() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$location = $repository->getLocationService()->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); | ||
$isBookmarked = $repository->getBookmarkService()->isBookmarked($location); | ||
/* END: Use Case */ | ||
|
||
$this->assertFalse($isBookmarked); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Repository\BookmarkService::createBookmark | ||
*/ | ||
public function testCreateBookmark() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$bookmarkService = $repository->getBookmarkService(); | ||
$locationService = $repository->getLocationService(); | ||
|
||
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); | ||
$beforeCreateBookmark = $bookmarkService->isBookmarked($location); | ||
$bookmarkService->createBookmark($location); | ||
$afterCreateBookmark = $bookmarkService->isBookmarked($location); | ||
/* END: Use Case */ | ||
|
||
$this->assertFalse($beforeCreateBookmark); | ||
$this->assertTrue($afterCreateBookmark); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Repository\BookmarkService::createBookmark | ||
* @depends testCreateBookmark | ||
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
*/ | ||
public function testCreateBookmarkThrowsInvalidArgumentException() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$bookmarkService = $repository->getBookmarkService(); | ||
$locationService = $repository->getLocationService(); | ||
|
||
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); | ||
$bookmarkService->createBookmark($location); | ||
/* END: Use Case */ | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Repository\BookmarkService::deleteBookmark | ||
*/ | ||
public function testDeleteBookmark() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$bookmarkService = $repository->getBookmarkService(); | ||
$locationService = $repository->getLocationService(); | ||
|
||
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); | ||
|
||
$beforeDeleteBookmark = $bookmarkService->isBookmarked($location); | ||
$bookmarkService->deleteBookmark($location); | ||
$afterDeleteBookmark = $bookmarkService->isBookmarked($location); | ||
/* END: Use Case */ | ||
|
||
$this->assertTrue($beforeDeleteBookmark); | ||
$this->assertFalse($afterDeleteBookmark); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Repository\BookmarkService::deleteBookmark | ||
* @depends testDeleteBookmark | ||
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
*/ | ||
public function testDeleteBookmarkThrowsInvalidArgumentException() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$bookmarkService = $repository->getBookmarkService(); | ||
$locationService = $repository->getLocationService(); | ||
|
||
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); | ||
$bookmarkService->deleteBookmark($location); | ||
/* END: Use Case */ | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Repository\BookmarkService::loadBookmarks | ||
*/ | ||
public function testLoadBookmarks() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$bookmarks = $repository->getBookmarkService()->loadBookmarks(1, 3); | ||
/* END: Use Case */ | ||
|
||
$this->assertInstanceOf(BookmarkList::class, $bookmarks); | ||
$this->assertEquals($bookmarks->totalCount, 5); | ||
// Assert bookmarks order: recently added should be first | ||
$this->assertEquals([15, 13, 12], array_map(function ($location) { | ||
return $location->id; | ||
}, $bookmarks->items)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Values\Bookmark; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
|
||
/** | ||
* List of bookmarked locations. | ||
*/ | ||
class BookmarkList extends ValueObject implements IteratorAggregate | ||
{ | ||
/** | ||
* The total number of bookmarks. | ||
* | ||
* @var int | ||
*/ | ||
public $totalCount = 0; | ||
|
||
/** | ||
* List of bookmarked locations. | ||
* | ||
* @var \eZ\Publish\API\Repository\Values\Content\Location[] | ||
*/ | ||
public $items = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new ArrayIterator($this->items); | ||
} | ||
} |