Code Duplication    Length = 22-34 lines in 4 locations

eZ/Publish/API/Repository/Tests/LocationServiceAuthorizationTest.php 2 locations

@@ 485-518 (lines=34) @@
482
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
483
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
484
     */
485
    public function testCopySubtreeThrowsUnauthorizedException()
486
    {
487
        $repository = $this->getRepository();
488
489
        $mediaLocationId = $this->generateId('location', 43);
490
        $demoDesignLocationId = $this->generateId('location', 56);
491
        /* BEGIN: Use Case */
492
        $user = $this->createMediaUserVersion1();
493
494
        // $mediaLocationId is the ID of the "Media" Location in
495
        // an eZ Publish demo installation
496
497
        // $demoDesignLocationId is the ID of the "Demo Design" Location in an eZ
498
        // Publish demo installation
499
500
        // Load the location service
501
        $locationService = $repository->getLocationService();
502
503
        // Load location to copy
504
        $locationToCopy = $locationService->loadLocation($mediaLocationId);
505
506
        // Load new parent location
507
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
508
509
        // Set media editor as current user
510
        $repository->setCurrentUser($user);
511
512
        // This call will fail with an "UnauthorizedException"
513
        $locationService->copySubtree(
514
            $locationToCopy,
515
            $newParentLocation
516
        );
517
        /* END: Use Case */
518
    }
519
520
    /**
521
     * Test for the moveSubtree() method.
@@ 527-560 (lines=34) @@
524
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
525
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
526
     */
527
    public function testMoveSubtreeThrowsUnauthorizedException()
528
    {
529
        $repository = $this->getRepository();
530
531
        $mediaLocationId = $this->generateId('location', 43);
532
        $demoDesignLocationId = $this->generateId('location', 56);
533
        /* BEGIN: Use Case */
534
        $user = $this->createMediaUserVersion1();
535
536
        // $mediaLocationId is the ID of the "Media" page location in
537
        // an eZ Publish demo installation
538
539
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
540
        // Publish demo installation
541
542
        // Load the location service
543
        $locationService = $repository->getLocationService();
544
545
        // Load location to move
546
        $locationToMove = $locationService->loadLocation($mediaLocationId);
547
548
        // Load new parent location
549
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
550
551
        // Set media editor as current user
552
        $repository->setCurrentUser($user);
553
554
        // This call will fail with an "UnauthorizedException"
555
        $locationService->moveSubtree(
556
            $locationToMove,
557
            $newParentLocation
558
        );
559
        /* END: Use Case */
560
    }
561
}
562

eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php 2 locations

@@ 630-652 (lines=23) @@
627
     *
628
     * @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom, $languageCode)
629
     */
630
    public function testListLocationAliasesWithCustomFilter()
631
    {
632
        $repository = $this->getRepository();
633
634
        $locationId = $this->generateId('location', 12);
635
636
        /* BEGIN: Use Case */
637
        // $locationId contains the ID of an existing Location
638
        $urlAliasService = $repository->getURLAliasService();
639
        $locationService = $repository->getLocationService();
640
641
        $location = $locationService->loadLocation($locationId);
642
643
        // Create a second URL alias for $location, this is a "custom" one
644
        $urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'ger-DE');
645
646
        // $loadedAliases will contain 1 aliases in eng-US only
647
        $loadedAliases = $urlAliasService->listLocationAliases($location, false, 'eng-US');
648
        /* END: Use Case */
649
650
        $this->assertIsArray($loadedAliases);
651
        $this->assertCount(1, $loadedAliases);
652
    }
653
654
    /**
655
     * Test for the listLocationAliases() method.
@@ 659-680 (lines=22) @@
656
     *
657
     * @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom)
658
     */
659
    public function testListLocationAliasesWithLanguageCodeFilter()
660
    {
661
        $repository = $this->getRepository();
662
663
        $locationId = $this->generateId('location', 12);
664
665
        /* BEGIN: Use Case */
666
        // $locationId contains the ID of an existing Location
667
        $urlAliasService = $repository->getURLAliasService();
668
        $locationService = $repository->getLocationService();
669
670
        $location = $locationService->loadLocation($locationId);
671
        // Create a custom URL alias for $location
672
        $urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'eng-US');
673
674
        // $loadedAliases will contain only 1 of 3 aliases (custom in eng-US)
675
        $loadedAliases = $urlAliasService->listLocationAliases($location, true, 'eng-US');
676
        /* END: Use Case */
677
678
        $this->assertIsArray($loadedAliases);
679
        $this->assertCount(1, $loadedAliases);
680
    }
681
682
    /**
683
     * Test for the listGlobalAliases() method.