|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\API\Repository\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Bookmark\BookmarkList; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Test case for the BookmarkService. |
|
15
|
|
|
* |
|
16
|
|
|
* @see \eZ\Publish\API\Repository\BookmarkService |
|
17
|
|
|
*/ |
|
18
|
|
|
class BookmarkServiceTest extends BaseTest |
|
19
|
|
|
{ |
|
20
|
|
|
const LOCATION_ID_BOOKMARKED = 5; |
|
21
|
|
|
const LOCATION_ID_NOT_BOOKMARKED = 44; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @covers \eZ\Publish\API\Repository\BookmarkService::isBookmarked |
|
25
|
|
|
*/ |
|
26
|
|
View Code Duplication |
public function testIsBookmarked() |
|
27
|
|
|
{ |
|
28
|
|
|
$repository = $this->getRepository(); |
|
29
|
|
|
|
|
30
|
|
|
/* BEGIN: Use Case */ |
|
31
|
|
|
$location = $repository->getLocationService()->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); |
|
32
|
|
|
$isBookmarked = $repository->getBookmarkService()->isBookmarked($location); |
|
33
|
|
|
/* END: Use Case */ |
|
34
|
|
|
|
|
35
|
|
|
$this->assertTrue($isBookmarked); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @covers \eZ\Publish\API\Repository\BookmarkService::isBookmarked |
|
40
|
|
|
*/ |
|
41
|
|
View Code Duplication |
public function testIsNotBookmarked() |
|
42
|
|
|
{ |
|
43
|
|
|
$repository = $this->getRepository(); |
|
44
|
|
|
|
|
45
|
|
|
/* BEGIN: Use Case */ |
|
46
|
|
|
$location = $repository->getLocationService()->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); |
|
47
|
|
|
$isBookmarked = $repository->getBookmarkService()->isBookmarked($location); |
|
48
|
|
|
/* END: Use Case */ |
|
49
|
|
|
|
|
50
|
|
|
$this->assertFalse($isBookmarked); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @covers \eZ\Publish\Core\Repository\BookmarkService::createBookmark |
|
55
|
|
|
*/ |
|
56
|
|
View Code Duplication |
public function testCreateBookmark() |
|
57
|
|
|
{ |
|
58
|
|
|
$repository = $this->getRepository(); |
|
59
|
|
|
|
|
60
|
|
|
/* BEGIN: Use Case */ |
|
61
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
|
62
|
|
|
$locationService = $repository->getLocationService(); |
|
63
|
|
|
|
|
64
|
|
|
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); |
|
65
|
|
|
$beforeCreateBookmark = $bookmarkService->isBookmarked($location); |
|
66
|
|
|
$bookmarkService->createBookmark($location); |
|
67
|
|
|
$afterCreateBookmark = $bookmarkService->isBookmarked($location); |
|
68
|
|
|
/* END: Use Case */ |
|
69
|
|
|
|
|
70
|
|
|
$this->assertFalse($beforeCreateBookmark); |
|
71
|
|
|
$this->assertTrue($afterCreateBookmark); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers \eZ\Publish\Core\Repository\BookmarkService::createBookmark |
|
76
|
|
|
* @depends testCreateBookmark |
|
77
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function testCreateBookmarkThrowsInvalidArgumentException() |
|
80
|
|
|
{ |
|
81
|
|
|
$repository = $this->getRepository(); |
|
82
|
|
|
|
|
83
|
|
|
/* BEGIN: Use Case */ |
|
84
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
|
85
|
|
|
$locationService = $repository->getLocationService(); |
|
86
|
|
|
|
|
87
|
|
|
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); |
|
88
|
|
|
$bookmarkService->createBookmark($location); |
|
89
|
|
|
/* END: Use Case */ |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @covers \eZ\Publish\Core\Repository\BookmarkService::deleteBookmark |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
public function testDeleteBookmark() |
|
96
|
|
|
{ |
|
97
|
|
|
$repository = $this->getRepository(); |
|
98
|
|
|
|
|
99
|
|
|
/* BEGIN: Use Case */ |
|
100
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
|
101
|
|
|
$locationService = $repository->getLocationService(); |
|
102
|
|
|
|
|
103
|
|
|
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_BOOKMARKED)); |
|
104
|
|
|
|
|
105
|
|
|
$beforeDeleteBookmark = $bookmarkService->isBookmarked($location); |
|
106
|
|
|
$bookmarkService->deleteBookmark($location); |
|
107
|
|
|
$afterDeleteBookmark = $bookmarkService->isBookmarked($location); |
|
108
|
|
|
/* END: Use Case */ |
|
109
|
|
|
|
|
110
|
|
|
$this->assertTrue($beforeDeleteBookmark); |
|
111
|
|
|
$this->assertFalse($afterDeleteBookmark); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @covers \eZ\Publish\Core\Repository\BookmarkService::deleteBookmark |
|
116
|
|
|
* @depends testDeleteBookmark |
|
117
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
118
|
|
|
*/ |
|
119
|
|
View Code Duplication |
public function testDeleteBookmarkThrowsInvalidArgumentException() |
|
120
|
|
|
{ |
|
121
|
|
|
$repository = $this->getRepository(); |
|
122
|
|
|
|
|
123
|
|
|
/* BEGIN: Use Case */ |
|
124
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
|
125
|
|
|
$locationService = $repository->getLocationService(); |
|
126
|
|
|
|
|
127
|
|
|
$location = $locationService->loadLocation($this->generateId('location', self::LOCATION_ID_NOT_BOOKMARKED)); |
|
128
|
|
|
$bookmarkService->deleteBookmark($location); |
|
129
|
|
|
/* END: Use Case */ |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @covers \eZ\Publish\Core\Repository\BookmarkService::loadBookmarks |
|
134
|
|
|
*/ |
|
135
|
|
|
public function testLoadBookmarks() |
|
136
|
|
|
{ |
|
137
|
|
|
$repository = $this->getRepository(); |
|
138
|
|
|
|
|
139
|
|
|
/* BEGIN: Use Case */ |
|
140
|
|
|
$bookmarks = $repository->getBookmarkService()->loadBookmarks(1, 3); |
|
141
|
|
|
/* END: Use Case */ |
|
142
|
|
|
|
|
143
|
|
|
$this->assertInstanceOf(BookmarkList::class, $bookmarks); |
|
144
|
|
|
$this->assertEquals($bookmarks->totalCount, 5); |
|
145
|
|
|
// Assert bookmarks order: recently added should be first |
|
146
|
|
|
$this->assertEquals([15, 13, 12], array_map(function ($location) { |
|
147
|
|
|
return $location->id; |
|
148
|
|
|
}, $bookmarks->items)); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|