12
12
use Ibexa \Contracts \Core \Repository \Values \Content \Location ;
13
13
use Ibexa \Contracts \Core \Repository \Values \Content \LocationQuery ;
14
14
use Ibexa \Contracts \Core \Repository \Values \Content \Query ;
15
+ use Ibexa \Contracts \Core \Repository \Values \Content \Search \SearchHit ;
16
+ use Ibexa \Contracts \Core \Repository \Values \Content \Search \SearchResult ;
15
17
use Ibexa \Tests \Integration \Core \RepositorySearchTestCase ;
16
18
17
19
final class SearchServiceBookmarkTest extends RepositorySearchTestCase
18
20
{
19
21
private const FOLDER_CONTENT_TYPE_IDENTIFIER = 'folder ' ;
20
22
private const MEDIA_CONTENT_TYPE_ID = 43 ;
21
23
private const ALL_BOOKMARKED_LOCATIONS = 6 ;
24
+ private const ALL_BOOKMARKED_CONTENT_REMOTE_IDS = [
25
+ '1bb4fe25487f05527efa8bfd394cecc7 ' ,
26
+ '3c160cca19fb135f83bd02d911f04db2 ' ,
27
+ '5f7f0bdb3381d6a461d8c29ff53d908f ' ,
28
+ '9b47a45624b023b1a76c73b74d704acf ' ,
29
+ 'a6e35cbcb7cd6ae4b691f3eee30cd262 ' ,
30
+ 'f5c88a2209584891056f987fd965b0ba ' ,
31
+ ];
32
+ private const ALL_NO_BOOKMARKED_CONTENT_REMOTE_IDS = [
33
+ '08799e609893f7aba22f10cb466d9cc8 ' ,
34
+ '09082deb98662a104f325aaa8c4933d3 ' ,
35
+ '14e4411b264a6194a33847843919451a ' ,
36
+ '15b256dbea2ae72418ff5facc999e8f9 ' ,
37
+ '241d538ce310074e602f29f49e44e938 ' ,
38
+ '27437f3547db19cf81a33c92578b2c89 ' ,
39
+ '732a5acd01b51a6fe6eab448ad4138a9 ' ,
40
+ '8a9c9c761004866fb458d89910f52bee ' ,
41
+ '8b8b22fe3c6061ed500fbd2b377b885f ' ,
42
+ 'e7ff633c6b8e0fd3531e74c6e712bead ' ,
43
+ 'f8cc7a4cf8a964a1a0ea6666f5da7d0d ' ,
44
+ 'faaeb9be3bd98ed09f606fc16d144eca ' ,
45
+ ];
46
+ private const MEDIA_CONTENT_REMOTE_ID = 'a6e35cbcb7cd6ae4b691f3eee30cd262 ' ;
22
47
23
48
protected function setUp (): void
24
49
{
@@ -33,14 +58,16 @@ protected function setUp(): void
33
58
* @dataProvider provideDataForTestCriterion
34
59
*
35
60
* @param array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion> $criteria
61
+ * @param array<string> $remoteIds
36
62
*/
37
63
public function testCriterion (
38
64
int $ expectedCount ,
39
- array $ criteria
65
+ array $ criteria ,
66
+ array $ remoteIds
40
67
): void {
41
68
$ query = $ this ->createQuery ($ criteria );
42
69
43
- $ this ->assertExpectedSearchHits ($ expectedCount , $ query );
70
+ $ this ->assertExpectedSearchHits ($ expectedCount , $ remoteIds , $ query );
44
71
}
45
72
46
73
/**
@@ -56,6 +83,7 @@ public function provideDataForTestCriterion(): iterable
56
83
[
57
84
new Query \Criterion \Location \IsBookmarked (),
58
85
],
86
+ self ::ALL_BOOKMARKED_CONTENT_REMOTE_IDS ,
59
87
];
60
88
61
89
yield 'All bookmarked locations limited to folder content type ' => [
@@ -64,6 +92,7 @@ public function provideDataForTestCriterion(): iterable
64
92
new Query \Criterion \ContentTypeIdentifier (self ::FOLDER_CONTENT_TYPE_IDENTIFIER ),
65
93
new Query \Criterion \Location \IsBookmarked (),
66
94
],
95
+ [self ::MEDIA_CONTENT_REMOTE_ID ],
67
96
];
68
97
69
98
yield 'All bookmarked locations limited to user group content type ' => [
@@ -72,6 +101,12 @@ public function provideDataForTestCriterion(): iterable
72
101
new Query \Criterion \ContentTypeIdentifier ('user_group ' ),
73
102
new Query \Criterion \Location \IsBookmarked (),
74
103
],
104
+ [
105
+ '3c160cca19fb135f83bd02d911f04db2 ' ,
106
+ '5f7f0bdb3381d6a461d8c29ff53d908f ' ,
107
+ '9b47a45624b023b1a76c73b74d704acf ' ,
108
+ 'f5c88a2209584891056f987fd965b0ba ' ,
109
+ ],
75
110
];
76
111
77
112
yield 'All bookmarked locations limited to user content type ' => [
@@ -80,13 +115,15 @@ public function provideDataForTestCriterion(): iterable
80
115
new Query \Criterion \ContentTypeIdentifier ('user ' ),
81
116
new Query \Criterion \Location \IsBookmarked (),
82
117
],
118
+ ['1bb4fe25487f05527efa8bfd394cecc7 ' ],
83
119
];
84
120
85
121
yield 'All no bookmarked locations ' => [
86
122
12 ,
87
123
[
88
124
new Query \Criterion \Location \IsBookmarked (false ),
89
125
],
126
+ self ::ALL_NO_BOOKMARKED_CONTENT_REMOTE_IDS ,
90
127
];
91
128
}
92
129
@@ -98,7 +135,11 @@ public function testCriterionDeleteBookmark(): void
98
135
]
99
136
);
100
137
101
- $ this ->assertExpectedSearchHits (self ::ALL_BOOKMARKED_LOCATIONS , $ query );
138
+ $ this ->assertExpectedSearchHits (
139
+ self ::ALL_BOOKMARKED_LOCATIONS ,
140
+ self ::ALL_BOOKMARKED_CONTENT_REMOTE_IDS ,
141
+ $ query
142
+ );
102
143
103
144
$ mediaLocation = $ this ->loadMediaFolderLocation ();
104
145
@@ -109,19 +150,54 @@ public function testCriterionDeleteBookmark(): void
109
150
110
151
$ this ->refreshSearch ();
111
152
112
- $ this ->assertExpectedSearchHits (5 , $ query );
153
+ $ this ->assertExpectedSearchHits (
154
+ 5 ,
155
+ [
156
+ '1bb4fe25487f05527efa8bfd394cecc7 ' ,
157
+ '3c160cca19fb135f83bd02d911f04db2 ' ,
158
+ '5f7f0bdb3381d6a461d8c29ff53d908f ' ,
159
+ '9b47a45624b023b1a76c73b74d704acf ' ,
160
+ 'f5c88a2209584891056f987fd965b0ba ' ,
161
+ ],
162
+ $ query
163
+ );
113
164
}
114
165
166
+ /**
167
+ * @param array<string> $expectedRemoteIds
168
+ */
115
169
private function assertExpectedSearchHits (
116
170
int $ expectedCount ,
171
+ array $ expectedRemoteIds ,
117
172
LocationQuery $ query
118
173
): void {
119
174
$ searchHits = self ::getSearchService ()->findLocations ($ query );
120
175
121
- self ::assertSame (
122
- $ expectedCount ,
123
- $ searchHits ->totalCount
176
+ self ::assertSame ($ expectedCount , $ searchHits ->totalCount );
177
+
178
+ $ remoteIds = $ this ->extractRemoteIds ($ searchHits );
179
+
180
+ self ::assertSame ($ expectedRemoteIds , $ remoteIds );
181
+ }
182
+
183
+ /**
184
+ * @return array<string>
185
+ */
186
+ private function extractRemoteIds (SearchResult $ result ): array
187
+ {
188
+ $ remoteIds = array_map (
189
+ static function (SearchHit $ searchHit ): string {
190
+ /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
191
+ $ location = $ searchHit ->valueObject ;
192
+
193
+ return $ location ->getContentInfo ()->remoteId ;
194
+ },
195
+ $ result ->searchHits
124
196
);
197
+
198
+ sort ($ remoteIds );
199
+
200
+ return $ remoteIds ;
125
201
}
126
202
127
203
/**
0 commit comments