| @@ 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 | ||
| @@ 606-628 (lines=23) @@ | ||
| 603 | * |
|
| 604 | * @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom, $languageCode) |
|
| 605 | */ |
|
| 606 | public function testListLocationAliasesWithCustomFilter() |
|
| 607 | { |
|
| 608 | $repository = $this->getRepository(); |
|
| 609 | ||
| 610 | $locationId = $this->generateId('location', 12); |
|
| 611 | ||
| 612 | /* BEGIN: Use Case */ |
|
| 613 | // $locationId contains the ID of an existing Location |
|
| 614 | $urlAliasService = $repository->getURLAliasService(); |
|
| 615 | $locationService = $repository->getLocationService(); |
|
| 616 | ||
| 617 | $location = $locationService->loadLocation($locationId); |
|
| 618 | ||
| 619 | // Create a second URL alias for $location, this is a "custom" one |
|
| 620 | $urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'ger-DE'); |
|
| 621 | ||
| 622 | // $loadedAliases will contain 1 aliases in eng-US only |
|
| 623 | $loadedAliases = $urlAliasService->listLocationAliases($location, false, 'eng-US'); |
|
| 624 | /* END: Use Case */ |
|
| 625 | ||
| 626 | $this->assertIsArray($loadedAliases); |
|
| 627 | $this->assertCount(1, $loadedAliases); |
|
| 628 | } |
|
| 629 | ||
| 630 | /** |
|
| 631 | * Test for the listLocationAliases() method. |
|
| @@ 635-656 (lines=22) @@ | ||
| 632 | * |
|
| 633 | * @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases($location, $custom) |
|
| 634 | */ |
|
| 635 | public function testListLocationAliasesWithLanguageCodeFilter() |
|
| 636 | { |
|
| 637 | $repository = $this->getRepository(); |
|
| 638 | ||
| 639 | $locationId = $this->generateId('location', 12); |
|
| 640 | ||
| 641 | /* BEGIN: Use Case */ |
|
| 642 | // $locationId contains the ID of an existing Location |
|
| 643 | $urlAliasService = $repository->getURLAliasService(); |
|
| 644 | $locationService = $repository->getLocationService(); |
|
| 645 | ||
| 646 | $location = $locationService->loadLocation($locationId); |
|
| 647 | // Create a custom URL alias for $location |
|
| 648 | $urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'eng-US'); |
|
| 649 | ||
| 650 | // $loadedAliases will contain only 1 of 3 aliases (custom in eng-US) |
|
| 651 | $loadedAliases = $urlAliasService->listLocationAliases($location, true, 'eng-US'); |
|
| 652 | /* END: Use Case */ |
|
| 653 | ||
| 654 | $this->assertIsArray($loadedAliases); |
|
| 655 | $this->assertCount(1, $loadedAliases); |
|
| 656 | } |
|
| 657 | ||
| 658 | /** |
|
| 659 | * Test for the listGlobalAliases() method. |
|
| @@ 552-578 (lines=27) @@ | ||
| 549 | * |
|
| 550 | * @see \eZ\Publish\API\Repository\URLAliasService::listLocationAliases() |
|
| 551 | */ |
|
| 552 | public function testListLocationAliases() |
|
| 553 | { |
|
| 554 | $repository = $this->getRepository(); |
|
| 555 | ||
| 556 | $locationId = $this->generateId('location', 12); |
|
| 557 | ||
| 558 | /* BEGIN: Use Case */ |
|
| 559 | // $locationId contains the ID of an existing Location |
|
| 560 | $urlAliasService = $repository->getURLAliasService(); |
|
| 561 | $locationService = $repository->getLocationService(); |
|
| 562 | ||
| 563 | $location = $locationService->loadLocation($locationId); |
|
| 564 | ||
| 565 | // Create a custom URL alias for $location |
|
| 566 | $urlAliasService->createUrlAlias($location, '/My/Great-new-Site', 'eng-US'); |
|
| 567 | ||
| 568 | // $loadedAliases will contain an array of custom URLAlias objects |
|
| 569 | $loadedAliases = $urlAliasService->listLocationAliases($location); |
|
| 570 | /* END: Use Case */ |
|
| 571 | ||
| 572 | $this->assertIsArray($loadedAliases); |
|
| 573 | ||
| 574 | // Only 1 non-history alias |
|
| 575 | $this->assertCount(1, $loadedAliases); |
|
| 576 | ||
| 577 | return [$loadedAliases, $location]; |
|
| 578 | } |
|
| 579 | ||
| 580 | /** |
|
| 581 | * @param array $testData |
|