forked from ezsystems/ezpublish-api
/
URLAliasServiceTest.php
1696 lines (1449 loc) · 58.7 KB
/
URLAliasServiceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* File containing the URLAliasServiceTest class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\API\Repository\Tests;
use Doctrine\DBAL\Connection;
use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Tests\Common\SlugConverter as TestSlugConverter;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\URLAlias;
use Exception;
use PDO;
use RuntimeException;
/**
* Test case for operations in the URLAliasService using in memory storage.
*
* @see \eZ\Publish\API\Repository\URLAliasService
* @group url-alias
*/
class URLAliasServiceTest extends BaseTest
{
/**
* Tests that the required <b>LocationService::loadLocation()</b>
* at least returns an object, because this method is utilized in several
* tests.
*/
protected function setUp()
{
parent::setUp();
try {
// Load the LocationService
$locationService = $this->getRepository()->getLocationService();
$membersUserGroupLocationId = 12;
// Load a location instance
$location = $locationService->loadLocation(
$membersUserGroupLocationId
);
if (false === is_object($location)) {
$this->markTestSkipped(
'This test cannot be executed, because the utilized ' .
'LocationService::loadLocation() does not ' .
'return an object.'
);
}
} catch (Exception $e) {
$this->markTestSkipped(
'This test cannot be executed, because the utilized ' .
'LocationService::loadLocation() failed with ' .
PHP_EOL . PHP_EOL .
$e->getTraceAsString()
);
}
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createUrlAlias()
*/
public function testCreateUrlAlias()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();
$location = $locationService->loadLocation($locationId);
$createdUrlAlias = $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US');
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return array($createdUrlAlias, $location->id);
}
/**
* @param array $testData
*
* @depends testCreateUrlAlias
*/
public function testCreateUrlAliasPropertyValues(array $testData)
{
list($createdUrlAlias, $locationId) = $testData;
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::LOCATION,
'destination' => $locationId,
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => false,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
),
$createdUrlAlias
);
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createUrlAlias($location, $path, $languageCode, $forwarding)
* @depends testCreateUrlAliasPropertyValues
*/
public function testCreateUrlAliasWithForwarding()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();
$location = $locationService->loadLocation($locationId);
$createdUrlAlias = $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US', true);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return array($createdUrlAlias, $location->id);
}
/**
* @param array $testData
*
* @depends testCreateUrlAliasWithForwarding
*/
public function testCreateUrlAliasPropertyValuesWithForwarding(array $testData)
{
list($createdUrlAlias, $locationId) = $testData;
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::LOCATION,
'destination' => $locationId,
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => false,
'isHistory' => false,
'isCustom' => true,
'forward' => true,
),
$createdUrlAlias
);
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createUrlAlias($location, $path, $languageCode, $forwarding, $alwaysAvailable)
*/
public function testCreateUrlAliasWithAlwaysAvailable()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();
$location = $locationService->loadLocation($locationId);
$createdUrlAlias = $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US', false, true);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return array($createdUrlAlias, $location->id);
}
/**
* @param array $testData
*
* @depends testCreateUrlAliasWithAlwaysAvailable
*/
public function testCreateUrlAliasPropertyValuesWithAlwaysAvailable(array $testData)
{
list($createdUrlAlias, $locationId) = $testData;
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::LOCATION,
'destination' => $locationId,
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => true,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
),
$createdUrlAlias
);
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createUrlAlias()
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testCreateUrlAliasThrowsInvalidArgumentException()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();
$location = $locationService->loadLocation($locationId);
// Throws InvalidArgumentException, since this path already exists for the
// language
$createdUrlAlias = $urlAliasService->createUrlAlias($location, '/Design/Plain-site', 'eng-US');
/* END: Use Case */
}
/**
* Test for the createGlobalUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias()
*/
public function testCreateGlobalUrlAlias()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/Home/My-New-Site',
'eng-US'
);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return $createdUrlAlias;
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias
*
* @depends testCreateGlobalUrlAlias
*/
public function testCreateGlobalUrlAliasPropertyValues(URLAlias $createdUrlAlias)
{
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::RESOURCE,
'destination' => 'content/search?SearchText=eZ',
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => false,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
),
$createdUrlAlias
);
}
/**
* Test for the createGlobalUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias($resource, $path, $languageCode, $forward)
*/
public function testCreateGlobalUrlAliasWithForward()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/Home/My-New-Site',
'eng-US',
true
);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return $createdUrlAlias;
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias
*
* @depends testCreateGlobalUrlAliasWithForward
*/
public function testCreateGlobalUrlAliasWithForwardPropertyValues(URLAlias $createdUrlAlias)
{
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::RESOURCE,
'destination' => 'content/search?SearchText=eZ',
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => false,
'isHistory' => false,
'isCustom' => true,
'forward' => true,
),
$createdUrlAlias
);
}
/**
* Test for the createGlobalUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias($resource, $path, $languageCode, $forwarding, $alwaysAvailable)
*/
public function testCreateGlobalUrlAliasWithAlwaysAvailable()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/Home/My-New-Site',
'eng-US',
false,
true
);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return $createdUrlAlias;
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias
*
* @depends testCreateGlobalUrlAliasWithAlwaysAvailable
*/
public function testCreateGlobalUrlAliasWithAlwaysAvailablePropertyValues(URLAlias $createdUrlAlias)
{
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::RESOURCE,
'destination' => 'content/search?SearchText=eZ',
'path' => '/Home/My-New-Site',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => true,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
),
$createdUrlAlias
);
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias($resource, $path, $languageCode, $forwarding, $alwaysAvailable)
*/
public function testCreateGlobalUrlAliasForLocation()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
$locationService = $repository->getLocationService();
$location = $locationService->loadLocation($locationId);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$urlAliasService = $repository->getURLAliasService();
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'module:content/view/full/' . $locationId,
'/Home/My-New-Site-global',
'eng-US',
false,
true
);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return array($createdUrlAlias, $location->id);
}
/**
* Test for the createUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias($resource, $path, $languageCode, $forwarding, $alwaysAvailable)
*/
public function testCreateGlobalUrlAliasForLocationVariation()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 5);
$locationService = $repository->getLocationService();
$location = $locationService->loadLocation($locationId);
/* BEGIN: Use Case */
// $locationId is the ID of an existing location
$urlAliasService = $repository->getURLAliasService();
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'eznode:' . $locationId,
'/Home/My-New-Site-global',
'eng-US',
false,
true
);
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$createdUrlAlias
);
return array($createdUrlAlias, $location->id);
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias
*
* @depends testCreateGlobalUrlAliasForLocation
*/
public function testCreateGlobalUrlAliasForLocationPropertyValues($testData)
{
list($createdUrlAlias, $locationId) = $testData;
$this->assertNotNull($createdUrlAlias->id);
$this->assertPropertiesCorrect(
array(
'type' => URLAlias::LOCATION,
'destination' => $locationId,
'path' => '/Home/My-New-Site-global',
'languageCodes' => array('eng-US'),
'alwaysAvailable' => true,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
),
$createdUrlAlias
);
}
/**
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias
*
* @depends testCreateGlobalUrlAliasForLocationVariation
*/
public function testCreateGlobalUrlAliasForLocationVariationPropertyValues($testData)
{
$this->testCreateGlobalUrlAliasForLocationPropertyValues($testData);
}
/**
* Test for the createGlobalUrlAlias() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::createGlobalUrlAlias()
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testCreateGlobalUrlAliasThrowsInvalidArgumentException()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Throws InvalidArgumentException, since this path already exists for the
// language
$createdUrlAlias = $urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/Design/Plain-site',
'eng-US'
);
/* END: Use Case */
}
/**
* Test for the listLocationAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases()
*/
public function testListLocationAliases()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 12);
/* BEGIN: Use Case */
// $locationId contains the ID of an existing Location
$urlAliasService = $repository->getURLAliasService();
$locationService = $repository->getLocationService();
$location = $locationService->loadLocation($locationId);
// Create a custom URL alias for $location
$urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'eng-US');
// $loadedAliases will contain an array of custom URLAlias objects
$loadedAliases = $urlAliasService->listLocationAliases($location);
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
// Only 1 non-history alias
$this->assertEquals(1, count($loadedAliases));
return array($loadedAliases, $location);
}
/**
* @param array $testData
*
* @depends testListLocationAliases
*/
public function testListLocationAliasesLoadsCorrectly(array $testData)
{
list($loadedAliases, $location) = $testData;
foreach ($loadedAliases as $loadedAlias) {
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$loadedAlias
);
$this->assertEquals(
$location->id,
$loadedAlias->destination
);
}
}
/**
* Test for the listLocationAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom, $languageCode)
*/
public function testListLocationAliasesWithCustomFilter()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 12);
/* BEGIN: Use Case */
// $locationId contains the ID of an existing Location
$urlAliasService = $repository->getURLAliasService();
$locationService = $repository->getLocationService();
$location = $locationService->loadLocation($locationId);
// Create a second URL alias for $location, this is a "custom" one
$urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'ger-DE');
// $loadedAliases will contain 1 aliases in eng-US only
$loadedAliases = $urlAliasService->listLocationAliases($location, false, 'eng-US');
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
}
/**
* Test for the listLocationAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom)
*/
public function testListLocationAliasesWithLanguageCodeFilter()
{
$repository = $this->getRepository();
$locationId = $this->generateId('location', 12);
/* BEGIN: Use Case */
// $locationId contains the ID of an existing Location
$urlAliasService = $repository->getURLAliasService();
$locationService = $repository->getLocationService();
$location = $locationService->loadLocation($locationId);
// Create a custom URL alias for $location
$urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'eng-US');
// $loadedAliases will contain only 1 of 3 aliases (custom in eng-US)
$loadedAliases = $urlAliasService->listLocationAliases($location, true, 'eng-US');
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
}
/**
* Test for the listGlobalAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listGlobalAliases()
*/
public function testListGlobalAliases()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Create some global aliases
$this->createGlobalAliases();
// $loadedAliases will contain all 3 global aliases
$loadedAliases = $urlAliasService->listGlobalAliases();
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(3, count($loadedAliases));
}
/**
* Creates 3 global aliases.
*/
private function createGlobalAliases()
{
$repository = $this->getRepository();
$urlAliasService = $repository->getURLAliasService();
/* BEGIN: Inline */
$urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/My/Special-Support',
'eng-US'
);
$urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=eZ',
'/My/London-Office',
'eng-GB'
);
$urlAliasService->createGlobalUrlAlias(
'module:content/search?SearchText=Sindelfingen',
'/My/Fancy-Site',
'eng-US'
);
/* END: Inline */
}
/**
* Test for the listGlobalAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listGlobalAliases($languageCode)
*/
public function testListGlobalAliasesWithLanguageFilter()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Create some global aliases
$this->createGlobalAliases();
// $loadedAliases will contain only 2 of 3 global aliases
$loadedAliases = $urlAliasService->listGlobalAliases('eng-US');
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(2, count($loadedAliases));
}
/**
* Test for the listGlobalAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listGlobalAliases($languageCode, $offset)
*/
public function testListGlobalAliasesWithOffset()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Create some global aliases
$this->createGlobalAliases();
// $loadedAliases will contain only 2 of 3 global aliases
$loadedAliases = $urlAliasService->listGlobalAliases(null, 1);
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(2, count($loadedAliases));
}
/**
* Test for the listGlobalAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::listGlobalAliases($languageCode, $offset, $limit)
*/
public function testListGlobalAliasesWithLimit()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Create some global aliases
$this->createGlobalAliases();
// $loadedAliases will contain only 1 of 3 global aliases
$loadedAliases = $urlAliasService->listGlobalAliases(null, 0, 1);
/* END: Use Case */
$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
}
/**
* Test for the removeAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::removeAliases()
*/
public function testRemoveAliases()
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();
$someLocation = $locationService->loadLocation(
$this->generateId('location', 12)
);
/* BEGIN: Use Case */
// $someLocation contains a location with automatically generated
// aliases assigned
$urlAliasService = $repository->getURLAliasService();
$initialAliases = $urlAliasService->listLocationAliases($someLocation);
// Creates a custom alias for $someLocation
$urlAliasService->createUrlAlias(
$someLocation,
'/my/fancy/url/alias/sindelfingen',
'eng-US'
);
$customAliases = $urlAliasService->listLocationAliases($someLocation);
// The custom alias just created will be removed
// the automatic aliases stay in tact
$urlAliasService->removeAliases($customAliases);
/* END: Use Case */
$this->assertEquals(
$initialAliases,
$urlAliasService->listLocationAliases($someLocation)
);
}
/**
* Test for the removeAliases() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::removeAliases()
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testRemoveAliasesThrowsInvalidArgumentExceptionIfAutogeneratedAliasesAreToBeRemoved()
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();
$someLocation = $locationService->loadLocation(
$this->generateId('location', 12)
);
/* BEGIN: Use Case */
// $someLocation contains a location with automatically generated
// aliases assigned
$urlAliasService = $repository->getURLAliasService();
$autogeneratedAliases = $urlAliasService->listLocationAliases($someLocation, false);
// Throws an InvalidArgumentException, since autogeneratedAliases
// cannot be removed with this method
$urlAliasService->removeAliases($autogeneratedAliases);
/* END: Use Case */
}
/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp()
*/
public function testLookUp()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
$loadedAlias = $urlAliasService->lookUp('/Setup2');
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$loadedAlias
);
return $loadedAlias;
}
/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp($url, $languageCode)
*/
public function testLookUpWithLanguageFilter()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Create aliases in multiple languages
$this->createGlobalAliases();
$loadedAlias = $urlAliasService->lookUp('/My/Special-Support', 'eng-US');
/* END: Use Case */
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
$loadedAlias
);
$this->assertEquals(
'content/search?SearchText=eZ',
$loadedAlias->destination
);
}
/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp()
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function testLookUpThrowsNotFoundException()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Throws NotFoundException
$loadedAlias = $urlAliasService->lookUp('/non-existent-url');
/* END: Use Case */
}
/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp($url, $languageCode)
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function testLookUpThrowsNotFoundExceptionWithLanguageFilter()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Throws NotFoundException
$loadedAlias = $urlAliasService->lookUp('/Contact-Us', 'ger-DE');
/* END: Use Case */
}
/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp($url, $languageCode)
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testLookUpThrowsInvalidArgumentException()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();
// Throws InvalidArgumentException
$loadedAlias = $urlAliasService->lookUp(str_repeat('/1', 99), 'ger-DE');
/* END: Use Case */
}
/**
* Test for the lookUp() method after renaming parent which is a part of the lookup path.
*
* @see https://jira.ez.no/browse/EZP-28046
* @covers \eZ\Publish\API\Repository\URLAliasService::lookUp
* @covers \eZ\Publish\API\Repository\URLAliasService::listLocationAliases
*/
public function testLookupOnRenamedParent()
{
$urlAliasService = $this->getRepository()->getURLAliasService();
$locationService = $this->getRepository()->getLocationService();
$contentTypeService = $this->getRepository()->getContentTypeService();
$contentService = $this->getRepository()->getContentService();
// 1. Create new container object (e.g. Folder "My Folder").
$folderContentType = $contentTypeService->loadContentTypeByIdentifier('folder');
$folderCreateStruct = $contentService->newContentCreateStruct($folderContentType, 'eng-GB');
$folderCreateStruct->setField('name', 'My-Folder');
$folderDraft = $contentService->createContent($folderCreateStruct, [
$locationService->newLocationCreateStruct(2),
]);
$folder = $contentService->publishVersion($folderDraft->versionInfo);
// 2. Create new object inside this container (e.g. article "My Article").
$folderLocation = $locationService->loadLocation($folder->contentInfo->mainLocationId);
$articleContentType = $contentTypeService->loadContentTypeByIdentifier('article');