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
|
|
|
namespace eZ\Publish\API\Repository\Tests; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\API\Repository\Values\URL\Query\Criterion; |
10
|
|
|
use eZ\Publish\API\Repository\Values\URL\Query\SortClause; |
11
|
|
|
use eZ\Publish\API\Repository\Values\URL\URL; |
12
|
|
|
use eZ\Publish\API\Repository\Values\URL\URLQuery; |
13
|
|
|
use eZ\Publish\API\Repository\Values\URL\URLUpdateStruct; |
14
|
|
|
use DateTime; |
15
|
|
|
use eZ\Publish\API\Repository\Values\URL\UsageSearchResult; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for operations in the UserService using in memory storage. |
19
|
|
|
* |
20
|
|
|
* @see eZ\Publish\API\Repository\URLService |
21
|
|
|
* @group integration |
22
|
|
|
* @group url |
23
|
|
|
*/ |
24
|
|
|
class URLServiceTest extends BaseURLServiceTest |
25
|
|
|
{ |
26
|
|
|
protected function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$urls = [ |
31
|
|
|
[ |
32
|
|
|
'name' => 'Twitter', |
33
|
|
|
'url' => 'http://twitter.com/', |
34
|
|
|
'published' => true, |
35
|
|
|
'sectionId' => 1, |
36
|
|
|
], |
37
|
|
|
[ |
38
|
|
|
'name' => 'Facebook', |
39
|
|
|
'url' => 'http://www.facebook.com/', |
40
|
|
|
'published' => true, |
41
|
|
|
'sectionId' => 1, |
42
|
|
|
], |
43
|
|
|
[ |
44
|
|
|
'name' => 'Google', |
45
|
|
|
'url' => 'http://www.google.com/', |
46
|
|
|
'published' => true, |
47
|
|
|
'sectionId' => 1, |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
'name' => 'Vimeo', |
51
|
|
|
'url' => 'http://vimeo.com/', |
52
|
|
|
'published' => true, |
53
|
|
|
'sectionId' => 1, |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
'name' => 'Facebook Sharer', |
57
|
|
|
'url' => 'http://www.facebook.com/sharer.php', |
58
|
|
|
'published' => true, |
59
|
|
|
'sectionId' => 1, |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'name' => 'Youtube', |
63
|
|
|
'url' => 'http://www.youtube.com/', |
64
|
|
|
'published' => true, |
65
|
|
|
'sectionId' => 1, |
66
|
|
|
], |
67
|
|
|
[ |
68
|
|
|
'name' => 'Googel support', |
69
|
|
|
'url' => 'http://support.google.com/chrome/answer/95647?hl=es', |
70
|
|
|
'published' => true, |
71
|
|
|
'sectionId' => 1, |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
'name' => 'Instagram', |
75
|
|
|
'url' => 'http://instagram.com/', |
76
|
|
|
'published' => true, |
77
|
|
|
'sectionId' => 1, |
78
|
|
|
], |
79
|
|
|
[ |
80
|
|
|
'name' => 'Discuz', |
81
|
|
|
'url' => 'http://www.discuz.net/forum.php', |
82
|
|
|
'published' => true, |
83
|
|
|
'sectionId' => 1, |
84
|
|
|
], |
85
|
|
|
[ |
86
|
|
|
'name' => 'Google calendar', |
87
|
|
|
'url' => 'http://calendar.google.com/calendar/render', |
88
|
|
|
'published' => true, |
89
|
|
|
'sectionId' => 1, |
90
|
|
|
], |
91
|
|
|
[ |
92
|
|
|
'name' => 'Wikipedia', |
93
|
|
|
'url' => 'http://www.wikipedia.org/', |
94
|
|
|
'published' => true, |
95
|
|
|
'sectionId' => 1, |
96
|
|
|
], |
97
|
|
|
[ |
98
|
|
|
'name' => 'Google Analytics', |
99
|
|
|
'url' => 'http://www.google.com/analytics/', |
100
|
|
|
'published' => true, |
101
|
|
|
'sectionId' => 1, |
102
|
|
|
], |
103
|
|
|
[ |
104
|
|
|
'name' => 'nazwa.pl', |
105
|
|
|
'url' => 'http://www.nazwa.pl/', |
106
|
|
|
'published' => true, |
107
|
|
|
'sectionId' => 1, |
108
|
|
|
], |
109
|
|
|
[ |
110
|
|
|
'name' => 'Apache', |
111
|
|
|
'url' => 'http://www.apache.org/', |
112
|
|
|
'published' => true, |
113
|
|
|
'sectionId' => 2, |
114
|
|
|
], |
115
|
|
|
[ |
116
|
|
|
'name' => 'Nginx', |
117
|
|
|
'url' => 'http://www.nginx.com/', |
118
|
|
|
'published' => true, |
119
|
|
|
'sectionId' => 2, |
120
|
|
|
], |
121
|
|
|
[ |
122
|
|
|
'name' => 'Microsoft.com', |
123
|
|
|
'url' => 'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
124
|
|
|
'published' => true, |
125
|
|
|
'sectionId' => 3, |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
'name' => 'Dropbox', |
129
|
|
|
'url' => 'http://www.dropbox.com/', |
130
|
|
|
'published' => false, |
131
|
|
|
'sectionId' => 3, |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
'name' => 'Google [DE]', |
135
|
|
|
'url' => 'http://www.google.de/', |
136
|
|
|
'published' => true, |
137
|
|
|
'sectionId' => 3, |
138
|
|
|
], |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$repository = $this->getRepository(); |
142
|
|
|
|
143
|
|
|
$parentLocationId = $this->generateId('location', 2); |
144
|
|
|
|
145
|
|
|
$contentService = $repository->getContentService(); |
146
|
|
|
$locationService = $repository->getLocationService(); |
147
|
|
|
|
148
|
|
|
$contentType = $repository->getContentTypeService()->loadContentTypeByIdentifier('url'); |
149
|
|
|
foreach ($urls as $data) { |
150
|
|
|
$struct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
151
|
|
|
$struct->setField('name', $data['name']); |
152
|
|
|
$struct->setField('url', $data['url']); |
153
|
|
|
$struct->sectionId = $data['sectionId']; |
154
|
|
|
|
155
|
|
|
$location = $locationService->newLocationCreateStruct($parentLocationId); |
156
|
|
|
|
157
|
|
|
$draft = $contentService->createContent($struct, [$location]); |
158
|
|
|
if ($data['published']) { |
159
|
|
|
$contentService->publishVersion($draft->versionInfo); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Test for URLService::findUrls() method. |
166
|
|
|
* |
167
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
168
|
|
|
*/ |
169
|
|
View Code Duplication |
public function testFindUrls() |
170
|
|
|
{ |
171
|
|
|
$expectedUrls = [ |
172
|
|
|
'http://www.apache.org/', |
173
|
|
|
'http://calendar.google.com/calendar/render', |
174
|
|
|
'http://www.dropbox.com/', |
175
|
|
|
'/content/view/sitemap/2', |
176
|
|
|
'http://support.google.com/chrome/answer/95647?hl=es', |
177
|
|
|
'http://www.nazwa.pl/', |
178
|
|
|
'http://www.facebook.com/sharer.php', |
179
|
|
|
'http://www.wikipedia.org/', |
180
|
|
|
'http://www.google.de/', |
181
|
|
|
'http://www.google.com/', |
182
|
|
|
'http://www.nginx.com/', |
183
|
|
|
'/content/view/tagcloud/2', |
184
|
|
|
'http://www.youtube.com/', |
185
|
|
|
'http://vimeo.com/', |
186
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
187
|
|
|
'http://twitter.com/', |
188
|
|
|
'http://www.google.com/analytics/', |
189
|
|
|
'http://www.facebook.com/', |
190
|
|
|
'http://www.discuz.net/forum.php', |
191
|
|
|
'http://instagram.com/', |
192
|
|
|
]; |
193
|
|
|
|
194
|
|
|
$query = new URLQuery(); |
195
|
|
|
$query->filter = new Criterion\MatchAll(); |
196
|
|
|
|
197
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Test for URLService::findUrls() method. |
202
|
|
|
* |
203
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
204
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
205
|
|
|
*/ |
206
|
|
|
public function testFindUrlsUsingMatchNone() |
207
|
|
|
{ |
208
|
|
|
$query = new URLQuery(); |
209
|
|
|
$query->filter = new Criterion\MatchNone(); |
210
|
|
|
|
211
|
|
|
$this->doTestFindUrls($query, []); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Test for URLService::findUrls() method. |
216
|
|
|
* |
217
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
218
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
219
|
|
|
*/ |
220
|
|
View Code Duplication |
public function testFindUrlsUsingPatternCriterion() |
221
|
|
|
{ |
222
|
|
|
$expectedUrls = [ |
223
|
|
|
'http://www.google.de/', |
224
|
|
|
'http://www.google.com/', |
225
|
|
|
'http://support.google.com/chrome/answer/95647?hl=es', |
226
|
|
|
'http://calendar.google.com/calendar/render', |
227
|
|
|
'http://www.google.com/analytics/', |
228
|
|
|
]; |
229
|
|
|
|
230
|
|
|
$query = new URLQuery(); |
231
|
|
|
$query->filter = new Criterion\Pattern('google'); |
232
|
|
|
|
233
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Test for URLService::findUrls() method. |
238
|
|
|
* |
239
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
240
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
241
|
|
|
*/ |
242
|
|
View Code Duplication |
public function testFindUrlsUsingValidityCriterionValid() |
243
|
|
|
{ |
244
|
|
|
$expectedUrls = [ |
245
|
|
|
'http://www.google.com/', |
246
|
|
|
'/content/view/sitemap/2', |
247
|
|
|
'http://support.google.com/chrome/answer/95647?hl=es', |
248
|
|
|
'http://www.google.de/', |
249
|
|
|
'http://www.nginx.com/', |
250
|
|
|
'http://www.google.com/analytics/', |
251
|
|
|
'http://www.discuz.net/forum.php', |
252
|
|
|
'http://www.wikipedia.org/', |
253
|
|
|
'http://www.facebook.com/sharer.php', |
254
|
|
|
'http://twitter.com/', |
255
|
|
|
'http://www.nazwa.pl/', |
256
|
|
|
'http://instagram.com/', |
257
|
|
|
'http://www.apache.org/', |
258
|
|
|
'http://www.dropbox.com/', |
259
|
|
|
'http://www.facebook.com/', |
260
|
|
|
'http://www.youtube.com/', |
261
|
|
|
'http://calendar.google.com/calendar/render', |
262
|
|
|
'http://vimeo.com/', |
263
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
264
|
|
|
]; |
265
|
|
|
|
266
|
|
|
$query = new URLQuery(); |
267
|
|
|
$query->filter = new Criterion\Validity(true); |
268
|
|
|
|
269
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Test for URLService::findUrls() method. |
274
|
|
|
* |
275
|
|
|
* @covers \eZ\Publish\Core\Repository\URLService::findUrls |
276
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
277
|
|
|
*/ |
278
|
|
View Code Duplication |
public function testFindUrlsUsingSectionIdCriterion(): void |
279
|
|
|
{ |
280
|
|
|
$expectedUrls = [ |
281
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
282
|
|
|
'http://www.dropbox.com/', |
283
|
|
|
'http://www.google.de/', |
284
|
|
|
]; |
285
|
|
|
|
286
|
|
|
$query = new URLQuery(); |
287
|
|
|
$query->filter = new Criterion\SectionId([3]); |
288
|
|
|
|
289
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Test for URLService::findUrls() method. |
294
|
|
|
* |
295
|
|
|
* @covers \eZ\Publish\Core\Repository\URLService::findUrls() |
296
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
297
|
|
|
*/ |
298
|
|
|
public function testFindUrlsUsingSectionIdAndValidityCriterionValid(): void |
299
|
|
|
{ |
300
|
|
|
$expectedUrls = [ |
301
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
302
|
|
|
'http://www.dropbox.com/', |
303
|
|
|
'http://www.google.de/', |
304
|
|
|
]; |
305
|
|
|
|
306
|
|
|
$query = new URLQuery(); |
307
|
|
|
$query->filter = new Criterion\LogicalAnd([ |
308
|
|
|
new Criterion\SectionId([3]), |
309
|
|
|
new Criterion\Validity(true), |
310
|
|
|
]); |
311
|
|
|
|
312
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Test for URLService::findUrls() method. |
317
|
|
|
* |
318
|
|
|
* @covers \eZ\Publish\Core\Repository\URLService::findUrls |
319
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
320
|
|
|
*/ |
321
|
|
View Code Duplication |
public function testFindUrlsUsingSectionIdentifierCriterion(): void |
322
|
|
|
{ |
323
|
|
|
$expectedUrls = [ |
324
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
325
|
|
|
'http://www.dropbox.com/', |
326
|
|
|
'http://www.google.de/', |
327
|
|
|
]; |
328
|
|
|
|
329
|
|
|
$query = new URLQuery(); |
330
|
|
|
$query->filter = new Criterion\SectionIdentifier(['media']); |
331
|
|
|
|
332
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Test for URLService::findUrls() method. |
337
|
|
|
* |
338
|
|
|
* @covers \eZ\Publish\Core\Repository\URLService::findUrls() |
339
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
340
|
|
|
*/ |
341
|
|
View Code Duplication |
public function testFindUrlsUsingSectionIdentifierAndValidityCriterionValid(): void |
342
|
|
|
{ |
343
|
|
|
$expectedUrls = [ |
344
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
345
|
|
|
'http://www.dropbox.com/', |
346
|
|
|
'http://www.google.de/', |
347
|
|
|
'http://www.apache.org/', |
348
|
|
|
'http://www.nginx.com/', |
349
|
|
|
]; |
350
|
|
|
|
351
|
|
|
$query = new URLQuery(); |
352
|
|
|
$query->filter = new Criterion\LogicalAnd([ |
353
|
|
|
new Criterion\SectionIdentifier(['media', 'users']), |
354
|
|
|
new Criterion\Validity(true), |
355
|
|
|
]); |
356
|
|
|
|
357
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Test for URLService::findUrls() method. |
362
|
|
|
* |
363
|
|
|
* @covers \eZ\Publish\Core\Repository\URLService::findUrls() |
364
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
365
|
|
|
*/ |
366
|
|
View Code Duplication |
public function testFindUrlsUsingSectionIdentifierOrSectionIdCriterion(): void |
367
|
|
|
{ |
368
|
|
|
$expectedUrls = [ |
369
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
370
|
|
|
'http://www.dropbox.com/', |
371
|
|
|
'http://www.google.de/', |
372
|
|
|
'http://www.apache.org/', |
373
|
|
|
'http://www.nginx.com/', |
374
|
|
|
]; |
375
|
|
|
|
376
|
|
|
$query = new URLQuery(); |
377
|
|
|
$query->filter = new Criterion\LogicalOr([ |
378
|
|
|
new Criterion\SectionIdentifier(['media']), |
379
|
|
|
new Criterion\SectionId([2]), |
380
|
|
|
]); |
381
|
|
|
|
382
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Test for URLService::findUrls() method. |
387
|
|
|
* |
388
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
389
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
390
|
|
|
*/ |
391
|
|
|
public function testFindUrlsUsingValidityCriterionInvalid() |
392
|
|
|
{ |
393
|
|
|
$expectedUrls = [ |
394
|
|
|
'/content/view/tagcloud/2', |
395
|
|
|
]; |
396
|
|
|
|
397
|
|
|
$query = new URLQuery(); |
398
|
|
|
$query->filter = new Criterion\Validity(false); |
399
|
|
|
|
400
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Test for URLService::findUrls() method. |
405
|
|
|
* |
406
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
407
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
408
|
|
|
*/ |
409
|
|
View Code Duplication |
public function testFindUrlsUsingVisibleOnlyCriterion() |
410
|
|
|
{ |
411
|
|
|
$expectedUrls = [ |
412
|
|
|
'http://vimeo.com/', |
413
|
|
|
'http://calendar.google.com/calendar/render', |
414
|
|
|
'http://www.facebook.com/', |
415
|
|
|
'http://www.google.com/', |
416
|
|
|
'http://www.google.com/analytics/', |
417
|
|
|
'http://www.facebook.com/sharer.php', |
418
|
|
|
'http://www.apache.org/', |
419
|
|
|
'http://www.nginx.com/', |
420
|
|
|
'http://www.wikipedia.org/', |
421
|
|
|
'http://www.youtube.com/', |
422
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
423
|
|
|
'http://www.google.de/', |
424
|
|
|
'http://instagram.com/', |
425
|
|
|
'http://www.nazwa.pl/', |
426
|
|
|
'/content/view/tagcloud/2', |
427
|
|
|
'http://www.discuz.net/forum.php', |
428
|
|
|
'http://support.google.com/chrome/answer/95647?hl=es', |
429
|
|
|
'http://twitter.com/', |
430
|
|
|
'/content/view/sitemap/2', |
431
|
|
|
]; |
432
|
|
|
|
433
|
|
|
$query = new URLQuery(); |
434
|
|
|
$query->filter = new Criterion\VisibleOnly(); |
435
|
|
|
|
436
|
|
|
$this->doTestFindUrls($query, $expectedUrls); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Test for URLService::findUrls() method. |
441
|
|
|
* |
442
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
443
|
|
|
*/ |
444
|
|
View Code Duplication |
public function testFindUrlsWithInvalidOffsetThrowsInvalidArgumentException() |
445
|
|
|
{ |
446
|
|
|
$this->expectException(\eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue::class); |
447
|
|
|
|
448
|
|
|
$query = new URLQuery(); |
449
|
|
|
$query->filter = new Criterion\MatchAll(); |
450
|
|
|
$query->offset = 'invalid!'; |
|
|
|
|
451
|
|
|
|
452
|
|
|
$repository = $this->getRepository(); |
453
|
|
|
|
454
|
|
|
/* BEGIN: Use Case */ |
455
|
|
|
$urlService = $repository->getURLService(); |
456
|
|
|
// This call will fail with a InvalidArgumentException |
457
|
|
|
$urlService->findUrls($query); |
458
|
|
|
/* END: Use Case */ |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* Test for URLService::findUrls() method. |
463
|
|
|
* |
464
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
465
|
|
|
*/ |
466
|
|
View Code Duplication |
public function testFindUrlsWithInvalidLimitThrowsInvalidArgumentException() |
467
|
|
|
{ |
468
|
|
|
$this->expectException(\eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue::class); |
469
|
|
|
|
470
|
|
|
$query = new URLQuery(); |
471
|
|
|
$query->filter = new Criterion\MatchAll(); |
472
|
|
|
$query->limit = 'invalid!'; |
|
|
|
|
473
|
|
|
|
474
|
|
|
$repository = $this->getRepository(); |
475
|
|
|
|
476
|
|
|
/* BEGIN: Use Case */ |
477
|
|
|
$urlService = $repository->getURLService(); |
478
|
|
|
// This call will fail with a InvalidArgumentException |
479
|
|
|
$urlService->findUrls($query); |
480
|
|
|
/* END: Use Case */ |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Test for URLService::findUrls() method. |
485
|
|
|
* |
486
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
487
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
488
|
|
|
*/ |
489
|
|
|
public function testFindUrlsWithOffset() |
490
|
|
|
{ |
491
|
|
|
$expectedUrls = [ |
492
|
|
|
'http://www.discuz.net/forum.php', |
493
|
|
|
'http://calendar.google.com/calendar/render', |
494
|
|
|
'http://www.wikipedia.org/', |
495
|
|
|
'http://www.google.com/analytics/', |
496
|
|
|
'http://www.nazwa.pl/', |
497
|
|
|
'http://www.apache.org/', |
498
|
|
|
'http://www.nginx.com/', |
499
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
500
|
|
|
'http://www.dropbox.com/', |
501
|
|
|
'http://www.google.de/', |
502
|
|
|
]; |
503
|
|
|
|
504
|
|
|
$query = new URLQuery(); |
505
|
|
|
$query->filter = new Criterion\MatchAll(); |
506
|
|
|
$query->offset = 10; |
507
|
|
|
|
508
|
|
|
$this->doTestFindUrls($query, $expectedUrls, 20); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Test for URLService::findUrls() method. |
513
|
|
|
* |
514
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
515
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
516
|
|
|
*/ |
517
|
|
|
public function testFindUrlsWithOffsetAndLimit() |
518
|
|
|
{ |
519
|
|
|
$expectedUrls = [ |
520
|
|
|
'http://www.discuz.net/forum.php', |
521
|
|
|
'http://calendar.google.com/calendar/render', |
522
|
|
|
'http://www.wikipedia.org/', |
523
|
|
|
]; |
524
|
|
|
|
525
|
|
|
$query = new URLQuery(); |
526
|
|
|
$query->filter = new Criterion\MatchAll(); |
527
|
|
|
$query->offset = 10; |
528
|
|
|
$query->limit = 3; |
529
|
|
|
|
530
|
|
|
$this->doTestFindUrls($query, $expectedUrls, 20); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Test for URLService::findUrls() method. |
535
|
|
|
* |
536
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
537
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
538
|
|
|
*/ |
539
|
|
|
public function testFindUrlsWithLimitZero() |
540
|
|
|
{ |
541
|
|
|
$query = new URLQuery(); |
542
|
|
|
$query->filter = new Criterion\MatchAll(); |
543
|
|
|
$query->limit = 0; |
544
|
|
|
|
545
|
|
|
$this->doTestFindUrls($query, [], 20); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Test for URLService::findUrls() method. |
550
|
|
|
* |
551
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::findUrls() |
552
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUrls |
553
|
|
|
* @dataProvider dataProviderForFindUrlsWithSorting |
554
|
|
|
*/ |
555
|
|
|
public function testFindUrlsWithSorting(SortClause $sortClause, array $expectedUrls) |
556
|
|
|
{ |
557
|
|
|
$query = new URLQuery(); |
558
|
|
|
$query->filter = new Criterion\MatchAll(); |
559
|
|
|
$query->sortClauses = [$sortClause]; |
560
|
|
|
|
561
|
|
|
$this->doTestFindUrls($query, $expectedUrls, null, false); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
public function dataProviderForFindUrlsWithSorting() |
565
|
|
|
{ |
566
|
|
|
$urlsSortedById = [ |
567
|
|
|
'/content/view/sitemap/2', |
568
|
|
|
'/content/view/tagcloud/2', |
569
|
|
|
'http://twitter.com/', |
570
|
|
|
'http://www.facebook.com/', |
571
|
|
|
'http://www.google.com/', |
572
|
|
|
'http://vimeo.com/', |
573
|
|
|
'http://www.facebook.com/sharer.php', |
574
|
|
|
'http://www.youtube.com/', |
575
|
|
|
'http://support.google.com/chrome/answer/95647?hl=es', |
576
|
|
|
'http://instagram.com/', |
577
|
|
|
'http://www.discuz.net/forum.php', |
578
|
|
|
'http://calendar.google.com/calendar/render', |
579
|
|
|
'http://www.wikipedia.org/', |
580
|
|
|
'http://www.google.com/analytics/', |
581
|
|
|
'http://www.nazwa.pl/', |
582
|
|
|
'http://www.apache.org/', |
583
|
|
|
'http://www.nginx.com/', |
584
|
|
|
'http://windows.microsoft.com/en-US/internet-explorer/products/ie/home', |
585
|
|
|
'http://www.dropbox.com/', |
586
|
|
|
'http://www.google.de/', |
587
|
|
|
]; |
588
|
|
|
|
589
|
|
|
$urlsSortedByURL = $urlsSortedById; |
590
|
|
|
sort($urlsSortedByURL); |
591
|
|
|
|
592
|
|
|
return [ |
593
|
|
|
[new SortClause\Id(SortClause::SORT_ASC), $urlsSortedById], |
594
|
|
|
[new SortClause\Id(SortClause::SORT_DESC), array_reverse($urlsSortedById)], |
595
|
|
|
[new SortClause\URL(SortClause::SORT_ASC), $urlsSortedByURL], |
596
|
|
|
[new SortClause\URL(SortClause::SORT_DESC), array_reverse($urlsSortedByURL)], |
597
|
|
|
]; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* Test for URLService::updateUrl() method. |
602
|
|
|
* |
603
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::updateUrl() |
604
|
|
|
*/ |
605
|
|
|
public function testUpdateUrl() |
606
|
|
|
{ |
607
|
|
|
$repository = $this->getRepository(); |
608
|
|
|
|
609
|
|
|
$id = $this->generateId('url', 23); |
610
|
|
|
|
611
|
|
|
/* BEGIN: Use Case */ |
612
|
|
|
$urlService = $repository->getURLService(); |
613
|
|
|
|
614
|
|
|
$urlBeforeUpdate = $urlService->loadById($id); |
615
|
|
|
$updateStruct = $urlService->createUpdateStruct(); |
616
|
|
|
$updateStruct->url = 'https://someurl.com/'; |
617
|
|
|
|
618
|
|
|
$urlAfterUpdate = $urlService->updateUrl($urlBeforeUpdate, $updateStruct); |
619
|
|
|
/* END: Use Case */ |
620
|
|
|
|
621
|
|
|
$this->assertInstanceOf(URL::class, $urlAfterUpdate); |
622
|
|
|
$this->assertPropertiesCorrect([ |
623
|
|
|
'id' => 23, |
624
|
|
|
'url' => 'https://someurl.com/', |
625
|
|
|
// (!) URL status should be reset to valid nad never checked |
626
|
|
|
'isValid' => true, |
627
|
|
|
'lastChecked' => null, |
628
|
|
|
'created' => new DateTime('@1343140541'), |
629
|
|
|
], $urlAfterUpdate); |
630
|
|
|
$this->assertGreaterThanOrEqual($urlBeforeUpdate->modified, $urlAfterUpdate->modified); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Test for URLService::updateUrl() method. |
635
|
|
|
* |
636
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::updateUrl() |
637
|
|
|
*/ |
638
|
|
|
public function testUpdateUrlStatus() |
639
|
|
|
{ |
640
|
|
|
$repository = $this->getRepository(); |
641
|
|
|
|
642
|
|
|
$id = $this->generateId('url', 23); |
643
|
|
|
$checked = new DateTime('@' . time()); |
644
|
|
|
|
645
|
|
|
/* BEGIN: Use Case */ |
646
|
|
|
$urlService = $repository->getURLService(); |
647
|
|
|
|
648
|
|
|
$urlBeforeUpdate = $urlService->loadById($id); |
649
|
|
|
$updateStruct = $urlService->createUpdateStruct(); |
650
|
|
|
$updateStruct->isValid = false; |
651
|
|
|
$updateStruct->lastChecked = $checked; |
652
|
|
|
|
653
|
|
|
$urlAfterUpdate = $urlService->updateUrl($urlBeforeUpdate, $updateStruct); |
654
|
|
|
/* END: Use Case */ |
655
|
|
|
|
656
|
|
|
$this->assertInstanceOf(URL::class, $urlAfterUpdate); |
657
|
|
|
$this->assertPropertiesCorrect([ |
658
|
|
|
'id' => $id, |
659
|
|
|
'url' => '/content/view/sitemap/2', |
660
|
|
|
// (!) URL status should be reset to valid nad never checked |
661
|
|
|
'isValid' => false, |
662
|
|
|
'lastChecked' => $checked, |
663
|
|
|
'created' => new DateTime('@1343140541'), |
664
|
|
|
], $urlAfterUpdate); |
665
|
|
|
$this->assertGreaterThanOrEqual($urlBeforeUpdate->modified, $urlAfterUpdate->modified); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Test for URLService::updateUrl() method. |
670
|
|
|
* |
671
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::updateUrl() |
672
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testUpdateUrl |
673
|
|
|
*/ |
674
|
|
|
public function testUpdateUrlWithNonUniqueUrl() |
675
|
|
|
{ |
676
|
|
|
$this->expectException(\eZ\Publish\Core\Base\Exceptions\InvalidArgumentException::class); |
677
|
|
|
|
678
|
|
|
$repository = $this->getRepository(); |
679
|
|
|
|
680
|
|
|
$id = $this->generateId('url', 23); |
681
|
|
|
|
682
|
|
|
/* BEGIN: Use Case */ |
683
|
|
|
$urlService = $repository->getURLService(); |
684
|
|
|
|
685
|
|
|
$urlBeforeUpdate = $urlService->loadById($id); |
686
|
|
|
$updateStruct = $urlService->createUpdateStruct(); |
687
|
|
|
$updateStruct->url = 'http://www.youtube.com/'; |
688
|
|
|
|
689
|
|
|
// This call will fail with a InvalidArgumentException |
690
|
|
|
$urlService->updateUrl($urlBeforeUpdate, $updateStruct); |
691
|
|
|
/* END: Use Case */ |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
/** |
695
|
|
|
* Test for URLService::loadById() method. |
696
|
|
|
* |
697
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::loadById |
698
|
|
|
*/ |
699
|
|
View Code Duplication |
public function testLoadById() |
700
|
|
|
{ |
701
|
|
|
$repository = $this->getRepository(); |
702
|
|
|
|
703
|
|
|
$id = $this->generateId('url', 23); |
704
|
|
|
|
705
|
|
|
/* BEGIN: Use Case */ |
706
|
|
|
$urlService = $repository->getURLService(); |
707
|
|
|
|
708
|
|
|
$url = $urlService->loadById($id); |
709
|
|
|
/* END: Use Case */ |
710
|
|
|
|
711
|
|
|
$this->assertInstanceOf(URL::class, $url); |
712
|
|
|
$this->assertPropertiesCorrect([ |
713
|
|
|
'id' => 23, |
714
|
|
|
'url' => '/content/view/sitemap/2', |
715
|
|
|
'isValid' => true, |
716
|
|
|
'lastChecked' => null, |
717
|
|
|
'created' => new DateTime('@1343140541'), |
718
|
|
|
'modified' => new DateTime('@1343140541'), |
719
|
|
|
], $url); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* Test for URLService::loadById() method. |
724
|
|
|
* |
725
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::loadById |
726
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testLoadById |
727
|
|
|
*/ |
728
|
|
|
public function testLoadByIdThrowsNotFoundException() |
729
|
|
|
{ |
730
|
|
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class); |
731
|
|
|
|
732
|
|
|
$repository = $this->getRepository(); |
733
|
|
|
|
734
|
|
|
$nonExistentUrlId = $this->generateId('url', self::DB_INT_MAX); |
735
|
|
|
/* BEGIN: Use Case */ |
736
|
|
|
$urlService = $repository->getURLService(); |
737
|
|
|
|
738
|
|
|
// This call will fail with a NotFoundException |
739
|
|
|
$url = $urlService->loadById($nonExistentUrlId); |
|
|
|
|
740
|
|
|
/* END: Use Case */ |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Test for URLService::loadByUrl() method. |
745
|
|
|
* |
746
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::loadByUrl |
747
|
|
|
*/ |
748
|
|
View Code Duplication |
public function testLoadByUrl() |
749
|
|
|
{ |
750
|
|
|
$repository = $this->getRepository(); |
751
|
|
|
|
752
|
|
|
$urlAddr = '/content/view/sitemap/2'; |
753
|
|
|
/* BEGIN: Use Case */ |
754
|
|
|
$urlService = $repository->getURLService(); |
755
|
|
|
|
756
|
|
|
$url = $urlService->loadByUrl($urlAddr); |
757
|
|
|
|
758
|
|
|
/* END: Use Case */ |
759
|
|
|
|
760
|
|
|
$this->assertInstanceOf(URL::class, $url); |
761
|
|
|
$this->assertPropertiesCorrect([ |
762
|
|
|
'id' => 23, |
763
|
|
|
'url' => '/content/view/sitemap/2', |
764
|
|
|
'isValid' => true, |
765
|
|
|
'lastChecked' => null, |
766
|
|
|
'created' => new DateTime('@1343140541'), |
767
|
|
|
'modified' => new DateTime('@1343140541'), |
768
|
|
|
], $url); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* Test for URLService::loadByUrl() method. |
773
|
|
|
* |
774
|
|
|
* @see \eZ\Publish\Core\Repository\URLService::loadByUrl |
775
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testLoadByUrl |
776
|
|
|
*/ |
777
|
|
|
public function testLoadByUrlThrowsNotFoundException() |
778
|
|
|
{ |
779
|
|
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class); |
780
|
|
|
|
781
|
|
|
$repository = $this->getRepository(); |
782
|
|
|
|
783
|
|
|
$nonExistentUrl = 'https://laravel.com/'; |
784
|
|
|
/* BEGIN: Use Case */ |
785
|
|
|
$urlService = $repository->getURLService(); |
786
|
|
|
|
787
|
|
|
// This call will fail with a NotFoundException |
788
|
|
|
$url = $urlService->loadByUrl($nonExistentUrl); |
|
|
|
|
789
|
|
|
/* END: Use Case */ |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* Test for URLService::createUpdateStruct() method. |
794
|
|
|
* |
795
|
|
|
* @see \eZ\Publish\API\Repository\URLService::createUpdateStruct |
796
|
|
|
* |
797
|
|
|
* @return \eZ\Publish\API\Repository\Values\URL\URLUpdateStruct |
798
|
|
|
*/ |
799
|
|
|
public function testCreateUpdateStruct() |
800
|
|
|
{ |
801
|
|
|
$repository = $this->getRepository(); |
802
|
|
|
|
803
|
|
|
/* BEGIN: Use Case */ |
804
|
|
|
$urlService = $repository->getURLService(); |
805
|
|
|
$updateStruct = $urlService->createUpdateStruct(); |
806
|
|
|
/* END: Use Case */ |
807
|
|
|
|
808
|
|
|
$this->assertInstanceOf(URLUpdateStruct::class, $updateStruct); |
809
|
|
|
|
810
|
|
|
return $updateStruct; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
/** |
814
|
|
|
* Test for URLService::createUpdateStruct() method. |
815
|
|
|
* |
816
|
|
|
* @param \eZ\Publish\API\Repository\Values\URL\URLUpdateStruct $updateStruct |
817
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testCreateUpdateStruct |
818
|
|
|
*/ |
819
|
|
|
public function testCreateUpdateStructValues(URLUpdateStruct $updateStruct) |
820
|
|
|
{ |
821
|
|
|
$this->assertPropertiesCorrect([ |
822
|
|
|
'url' => null, |
823
|
|
|
'isValid' => null, |
824
|
|
|
'lastChecked' => null, |
825
|
|
|
], $updateStruct); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* Test for URLService::testFindUsages() method. |
830
|
|
|
* |
831
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testLoadById |
832
|
|
|
* @dataProvider dataProviderForFindUsages |
833
|
|
|
*/ |
834
|
|
|
public function testFindUsages($urlId, $offset, $limit, array $expectedContentInfos, $expectedTotalCount = null) |
835
|
|
|
{ |
836
|
|
|
$repository = $this->getRepository(); |
837
|
|
|
|
838
|
|
|
$id = $this->generateId('url', $urlId); |
839
|
|
|
/* BEGIN: Use Case */ |
840
|
|
|
$urlService = $repository->getURLService(); |
841
|
|
|
|
842
|
|
|
$loadedUrl = $urlService->loadById($id); |
843
|
|
|
|
844
|
|
|
$usagesSearchResults = $urlService->findUsages($loadedUrl, $offset, $limit); |
845
|
|
|
/* END: Use Case */ |
846
|
|
|
|
847
|
|
|
$this->assertInstanceOf(UsageSearchResult::class, $usagesSearchResults); |
848
|
|
|
$this->assertEquals($expectedTotalCount, $usagesSearchResults->totalCount); |
849
|
|
|
$this->assertUsagesSearchResultItems($usagesSearchResults, $expectedContentInfos); |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
public function dataProviderForFindUsages() |
853
|
|
|
{ |
854
|
|
|
return [ |
855
|
|
|
// findUsages($url, 0, -1) |
856
|
|
|
[23, 0, -1, [54], 1], |
857
|
|
|
// findUsages($url, 0, $limit) |
858
|
|
|
[23, 0, 1, [54], 1], |
859
|
|
|
]; |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* Test for URLService::testFindUsages() method. |
864
|
|
|
* |
865
|
|
|
* @depends eZ\Publish\API\Repository\Tests\URLServiceTest::testFindUsages |
866
|
|
|
*/ |
867
|
|
|
public function testFindUsagesReturnsEmptySearchResults() |
868
|
|
|
{ |
869
|
|
|
$repository = $this->getRepository(); |
870
|
|
|
|
871
|
|
|
/* BEGIN: Use Case */ |
872
|
|
|
$urlService = $repository->getURLService(); |
873
|
|
|
|
874
|
|
|
$loadedUrl = $urlService->loadByUrl('http://www.dropbox.com/'); |
875
|
|
|
|
876
|
|
|
$usagesSearchResults = $urlService->findUsages($loadedUrl); |
877
|
|
|
/* END: Use Case */ |
878
|
|
|
|
879
|
|
|
$this->assertInstanceOf(UsageSearchResult::class, $usagesSearchResults); |
880
|
|
|
$this->assertPropertiesCorrect([ |
881
|
|
|
'totalCount' => 0, |
882
|
|
|
'items' => [], |
883
|
|
|
], $usagesSearchResults); |
884
|
|
|
} |
885
|
|
|
} |
886
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.