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

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