Code Duplication    Length = 31-32 lines in 9 locations

eZ/Publish/Core/Persistence/Legacy/Tests/Content/UrlAlias/UrlAliasHandlerTest.php 9 locations

@@ 349-379 (lines=31) @@
346
     * @depends testLookup
347
     * @group location
348
     */
349
    public function testLookupLocationUrlAlias(
350
        $url,
351
        array $pathData,
352
        array $languageCodes,
353
        $alwaysAvailable,
354
        $locationId,
355
        $id
356
    ) {
357
        $handler = $this->getHandler();
358
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
359
360
        $urlAlias = $handler->lookup($url);
361
362
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
363
        self::assertEquals(
364
            new UrlAlias(
365
                [
366
                    'id' => $id,
367
                    'type' => UrlAlias::LOCATION,
368
                    'destination' => $locationId,
369
                    'languageCodes' => $languageCodes,
370
                    'pathData' => $pathData,
371
                    'alwaysAvailable' => $alwaysAvailable,
372
                    'isHistory' => false,
373
                    'isCustom' => false,
374
                    'forward' => false,
375
                ]
376
            ),
377
            $urlAlias
378
        );
379
    }
380
381
    /**
382
     * Testing that looking up case incorrect URL results in redirection to case correct path.
@@ 400-430 (lines=31) @@
397
     *
398
     * @todo refactor, only forward pertinent
399
     */
400
    public function testLookupLocationCaseCorrection(
401
        $url,
402
        array $pathData,
403
        array $languageCodes,
404
        $alwaysAvailable,
405
        $locationId,
406
        $id
407
    ) {
408
        $handler = $this->getHandler();
409
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location.php');
410
411
        $urlAlias = $handler->lookup(strtoupper($url));
412
413
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
414
        self::assertEquals(
415
            new UrlAlias(
416
                [
417
                    'id' => $id,
418
                    'type' => UrlAlias::LOCATION,
419
                    'destination' => $locationId,
420
                    'languageCodes' => $languageCodes,
421
                    'pathData' => $pathData,
422
                    'alwaysAvailable' => $alwaysAvailable,
423
                    'isHistory' => false,
424
                    'isCustom' => false,
425
                    'forward' => false,
426
                ]
427
            ),
428
            $urlAlias
429
        );
430
    }
431
432
    public function providerForTestLookupLocationMultipleLanguages()
433
    {
@@ 527-557 (lines=31) @@
524
     * @group multiple-languages
525
     * @group location
526
     */
527
    public function testLookupLocationMultipleLanguages(
528
        $url,
529
        array $pathData,
530
        array $languageCodes,
531
        $alwaysAvailable,
532
        $locationId,
533
        $id
534
    ) {
535
        $handler = $this->getHandler();
536
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
537
538
        $urlAlias = $handler->lookup($url);
539
540
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
541
        self::assertEquals(
542
            new UrlAlias(
543
                [
544
                    'id' => $id,
545
                    'type' => UrlAlias::LOCATION,
546
                    'destination' => $locationId,
547
                    'languageCodes' => $languageCodes,
548
                    'pathData' => $pathData,
549
                    'alwaysAvailable' => $alwaysAvailable,
550
                    'isHistory' => false,
551
                    'isCustom' => false,
552
                    'forward' => false,
553
                ]
554
            ),
555
            $urlAlias
556
        );
557
    }
558
559
    /**
560
     * Test for the lookup() method.
@@ 709-739 (lines=31) @@
706
     * @group location
707
     * @group custom
708
     */
709
    public function testLookupCustomLocationUrlAlias(
710
        $url,
711
        array $pathData,
712
        array $languageCodes,
713
        $forward,
714
        $alwaysAvailable,
715
        $destination,
716
        $id
717
    ) {
718
        $handler = $this->getHandler();
719
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
720
721
        $urlAlias = $handler->lookup($url);
722
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
723
        self::assertEquals(
724
            new UrlAlias(
725
                [
726
                    'id' => $id,
727
                    'type' => UrlAlias::LOCATION,
728
                    'destination' => $destination,
729
                    'languageCodes' => $languageCodes,
730
                    'pathData' => $pathData,
731
                    'alwaysAvailable' => $alwaysAvailable,
732
                    'isHistory' => false,
733
                    'isCustom' => true,
734
                    'forward' => $forward,
735
                ]
736
            ),
737
            $urlAlias
738
        );
739
    }
740
741
    /**
742
     * Test for the lookup() method.
@@ 752-783 (lines=32) @@
749
     * @group location
750
     * @group custom
751
     */
752
    public function testLookupCustomLocationUrlAliasCaseCorrection(
753
        $url,
754
        array $pathData,
755
        array $languageCodes,
756
        $forward,
757
        $alwaysAvailable,
758
        $destination,
759
        $id
760
    ) {
761
        $handler = $this->getHandler();
762
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_custom.php');
763
764
        $urlAlias = $handler->lookup(strtoupper($url));
765
766
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
767
        self::assertEquals(
768
            new UrlAlias(
769
                [
770
                    'id' => $id,
771
                    'type' => UrlAlias::LOCATION,
772
                    'destination' => $destination,
773
                    'languageCodes' => $languageCodes,
774
                    'pathData' => $pathData,
775
                    'alwaysAvailable' => $alwaysAvailable,
776
                    'isHistory' => false,
777
                    'isCustom' => true,
778
                    'forward' => $forward,
779
                ]
780
            ),
781
            $urlAlias
782
        );
783
    }
784
785
    public function providerForTestLookupVirtualUrlAlias()
786
    {
@@ 879-910 (lines=32) @@
876
     * @depends testLookup
877
     * @group resource
878
     */
879
    public function testLookupResourceUrlAlias(
880
        $url,
881
        $pathData,
882
        array $languageCodes,
883
        $forward,
884
        $alwaysAvailable,
885
        $destination,
886
        $id
887
    ) {
888
        $handler = $this->getHandler();
889
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
890
891
        $urlAlias = $handler->lookup($url);
892
893
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
894
        self::assertEquals(
895
            new UrlAlias(
896
                [
897
                    'id' => $id,
898
                    'type' => UrlAlias::RESOURCE,
899
                    'destination' => $destination,
900
                    'languageCodes' => $languageCodes,
901
                    'pathData' => $pathData,
902
                    'alwaysAvailable' => $alwaysAvailable,
903
                    'isHistory' => false,
904
                    'isCustom' => true,
905
                    'forward' => $forward,
906
                ]
907
            ),
908
            $urlAlias
909
        );
910
    }
911
912
    /**
913
     * Test for the lookup() method.
@@ 922-953 (lines=32) @@
919
     * @depends testLookup
920
     * @group resource
921
     */
922
    public function testLookupResourceUrlAliasCaseInsensitive(
923
        $url,
924
        $pathData,
925
        array $languageCodes,
926
        $forward,
927
        $alwaysAvailable,
928
        $destination,
929
        $id
930
    ) {
931
        $handler = $this->getHandler();
932
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
933
934
        $urlAlias = $handler->lookup(strtoupper($url));
935
936
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
937
        self::assertEquals(
938
            new UrlAlias(
939
                [
940
                    'id' => $id,
941
                    'type' => UrlAlias::RESOURCE,
942
                    'destination' => $destination,
943
                    'languageCodes' => $languageCodes,
944
                    'pathData' => $pathData,
945
                    'alwaysAvailable' => $alwaysAvailable,
946
                    'isHistory' => false,
947
                    'isCustom' => true,
948
                    'forward' => $forward,
949
                ]
950
            ),
951
            $urlAlias
952
        );
953
    }
954
955
    /**
956
     * Test for the lookup() method with uppercase utf8 characters.
@@ 2992-3022 (lines=31) @@
2989
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
2990
     * @dataProvider providerForTestLookupLocationMultipleLanguages
2991
     */
2992
    public function testLoadAutogeneratedUrlAlias(
2993
        $url,
2994
        array $pathData,
2995
        array $languageCodes,
2996
        $alwaysAvailable,
2997
        $locationId,
2998
        $id
2999
    ) {
3000
        $handler = $this->getHandler();
3001
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_location_multilang.php');
3002
3003
        $urlAlias = $handler->loadUrlAlias($id);
3004
3005
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
3006
        self::assertEquals(
3007
            new UrlAlias(
3008
                [
3009
                    'id' => $id,
3010
                    'type' => UrlAlias::LOCATION,
3011
                    'destination' => $locationId,
3012
                    'languageCodes' => $languageCodes,
3013
                    'pathData' => $pathData,
3014
                    'alwaysAvailable' => $alwaysAvailable,
3015
                    'isHistory' => false,
3016
                    'isCustom' => false,
3017
                    'forward' => false,
3018
                ]
3019
            ),
3020
            $urlAlias
3021
        );
3022
    }
3023
3024
    /**
3025
     * Test for the loadUrlAlias() method.
@@ 3030-3061 (lines=32) @@
3027
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::loadUrlAlias
3028
     * @dataProvider providerForTestLookupResourceUrlAlias
3029
     */
3030
    public function testLoadResourceUrlAlias(
3031
        $url,
3032
        $pathData,
3033
        array $languageCodes,
3034
        $forward,
3035
        $alwaysAvailable,
3036
        $destination,
3037
        $id
3038
    ) {
3039
        $handler = $this->getHandler();
3040
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/urlaliases_resource.php');
3041
3042
        $urlAlias = $handler->loadUrlAlias($id);
3043
3044
        self::assertInstanceOf(UrlAlias::class, $urlAlias);
3045
        self::assertEquals(
3046
            new UrlAlias(
3047
                [
3048
                    'id' => $id,
3049
                    'type' => UrlAlias::RESOURCE,
3050
                    'destination' => $destination,
3051
                    'languageCodes' => $languageCodes,
3052
                    'pathData' => $pathData,
3053
                    'alwaysAvailable' => $alwaysAvailable,
3054
                    'isHistory' => false,
3055
                    'isCustom' => true,
3056
                    'forward' => $forward,
3057
                ]
3058
            ),
3059
            $urlAlias
3060
        );
3061
    }
3062
3063
    /**
3064
     * Test for the loadUrlAlias() method.