Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like RoleServiceTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RoleServiceTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | class RoleServiceTest extends BaseTest |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * Test for the newRoleCreateStruct() method. |
||
| 44 | * |
||
| 45 | * @see \eZ\Publish\API\Repository\RoleService::newRoleCreateStruct() |
||
| 46 | */ |
||
| 47 | public function testNewRoleCreateStruct() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Test for the newRoleCreateStruct() method. |
||
| 59 | * |
||
| 60 | * @see \eZ\Publish\API\Repository\RoleService::newRoleCreateStruct() |
||
| 61 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 62 | */ |
||
| 63 | public function testNewRoleCreateStructSetsNamePropertyOnStruct() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Test for the createRole() method. |
||
| 79 | * |
||
| 80 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 81 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 82 | */ |
||
| 83 | public function testCreateRole() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Test for the createRole() method. |
||
| 112 | * |
||
| 113 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 114 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 115 | */ |
||
| 116 | public function testRoleCreateStructValues(array $data) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Test for the createRole() method. |
||
| 138 | * |
||
| 139 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 140 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 141 | */ |
||
| 142 | public function testCreateRoleWithPolicy() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Test for the createRole() method. |
||
| 185 | * |
||
| 186 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 187 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithPolicy |
||
| 188 | */ |
||
| 189 | public function testRoleCreateStructValuesWithPolicy(array $data) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Test creating a role with multiple policies. |
||
| 215 | * |
||
| 216 | * @covers \eZ\Publish\API\Repository\RoleService::createRole |
||
| 217 | */ |
||
| 218 | public function testCreateRoleWithMultiplePolicies() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Test for the createRoleDraft() method. |
||
| 306 | * |
||
| 307 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 308 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 309 | */ |
||
| 310 | View Code Duplication | public function testCreateRoleDraft() |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Test for the createRole() method. |
||
| 337 | * |
||
| 338 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 339 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 340 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 341 | */ |
||
| 342 | public function testCreateRoleThrowsInvalidArgumentException() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Test for the createRoleDraft() method. |
||
| 362 | * |
||
| 363 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 364 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 365 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 366 | */ |
||
| 367 | public function testCreateRoleDraftThrowsInvalidArgumentException() |
||
| 368 | { |
||
| 369 | $repository = $this->getRepository(); |
||
| 370 | |||
| 371 | /* BEGIN: Use Case */ |
||
| 372 | |||
| 373 | $roleService = $repository->getRoleService(); |
||
| 374 | $roleCreate = $roleService->newRoleCreateStruct('Editor'); |
||
| 375 | |||
| 376 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 377 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 378 | |||
| 379 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 380 | $roleService->publishRoleDraft($roleDraft); |
||
| 381 | $role = $roleService->loadRole($roleDraft->id); |
||
| 382 | $roleService->createRoleDraft($role); // First role draft |
||
| 383 | |||
| 384 | // This call will fail with an InvalidArgumentException, because there is already a draft |
||
| 385 | $roleService->createRoleDraft($role); |
||
| 386 | |||
| 387 | /* END: Use Case */ |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Test for the createRole() method. |
||
| 392 | * |
||
| 393 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 394 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 395 | */ |
||
| 396 | View Code Duplication | public function testCreateRoleThrowsLimitationValidationException() |
|
| 428 | |||
| 429 | /** |
||
| 430 | * Test for the createRole() method. |
||
| 431 | * |
||
| 432 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 433 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 434 | */ |
||
| 435 | public function testCreateRoleInTransactionWithRollback() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Test for the createRoleDraft() method. |
||
| 467 | * |
||
| 468 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 469 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 470 | */ |
||
| 471 | public function testCreateRoleDraftInTransactionWithRollback() |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Test for the loadRole() method. |
||
| 503 | * |
||
| 504 | * @see \eZ\Publish\API\Repository\RoleService::loadRole() |
||
| 505 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 506 | */ |
||
| 507 | public function testLoadRole() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Test for the loadRoleDraft() method. |
||
| 532 | * |
||
| 533 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleDraft() |
||
| 534 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 535 | */ |
||
| 536 | View Code Duplication | public function testLoadRoleDraft() |
|
| 537 | { |
||
| 538 | $repository = $this->getRepository(); |
||
| 539 | |||
| 540 | /* BEGIN: Use Case */ |
||
| 541 | |||
| 542 | $roleService = $repository->getRoleService(); |
||
| 543 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 544 | |||
| 545 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 546 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 547 | |||
| 548 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 549 | |||
| 550 | // Load the newly created role by its ID |
||
| 551 | $role = $roleService->loadRoleDraft($roleDraft->id); |
||
| 552 | |||
| 553 | /* END: Use Case */ |
||
| 554 | |||
| 555 | $this->assertEquals('roleName', $role->identifier); |
||
| 556 | } |
||
| 557 | |||
| 558 | public function testLoadRoleDraftByRoleId() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Test for the loadRole() method. |
||
| 586 | * |
||
| 587 | * @see \eZ\Publish\API\Repository\RoleService::loadRole() |
||
| 588 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 589 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRole |
||
| 590 | */ |
||
| 591 | View Code Duplication | public function testLoadRoleThrowsNotFoundException() |
|
| 605 | |||
| 606 | /** |
||
| 607 | * Test for the loadRoleDraft() method. |
||
| 608 | * |
||
| 609 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleDraft() |
||
| 610 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 611 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 612 | */ |
||
| 613 | View Code Duplication | public function testLoadRoleDraftThrowsNotFoundException() |
|
| 627 | |||
| 628 | /** |
||
| 629 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 630 | */ |
||
| 631 | View Code Duplication | public function testLoadRoleDraftByRoleIdThrowsNotFoundException() |
|
| 645 | |||
| 646 | /** |
||
| 647 | * Test for the loadRoleByIdentifier() method. |
||
| 648 | * |
||
| 649 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier() |
||
| 650 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 651 | */ |
||
| 652 | View Code Duplication | public function testLoadRoleByIdentifier() |
|
| 674 | |||
| 675 | /** |
||
| 676 | * Test for the loadRoleByIdentifier() method. |
||
| 677 | * |
||
| 678 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier() |
||
| 679 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 680 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 681 | */ |
||
| 682 | public function testLoadRoleByIdentifierThrowsNotFoundException() |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Test for the loadRoles() method. |
||
| 698 | * |
||
| 699 | * @see \eZ\Publish\API\Repository\RoleService::loadRoles() |
||
| 700 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 701 | */ |
||
| 702 | public function testLoadRoles() |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Test for the loadRoles() method. |
||
| 734 | * |
||
| 735 | * @see \eZ\Publish\API\Repository\RoleService::loadRoles() |
||
| 736 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoles |
||
| 737 | */ |
||
| 738 | public function testLoadRolesReturnsExpectedSetOfDefaultRoles() |
||
| 739 | { |
||
| 740 | $repository = $this->getRepository(); |
||
| 741 | |||
| 742 | /* BEGIN: Use Case */ |
||
| 743 | $roleService = $repository->getRoleService(); |
||
| 744 | |||
| 745 | $roles = $roleService->loadRoles(); |
||
| 746 | |||
| 747 | $roleNames = []; |
||
| 748 | foreach ($roles as $role) { |
||
| 749 | $roleNames[] = $role->identifier; |
||
| 750 | } |
||
| 751 | /* END: Use Case */ |
||
| 752 | |||
| 753 | $this->assertEqualsCanonicalizing( |
||
| 754 | [ |
||
| 755 | 'Administrator', |
||
| 756 | 'Anonymous', |
||
| 757 | 'Editor', |
||
| 758 | 'Member', |
||
| 759 | 'Partner', |
||
| 760 | ], |
||
| 761 | $roleNames |
||
| 762 | ); |
||
| 763 | } |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Test for the newRoleUpdateStruct() method. |
||
| 767 | * |
||
| 768 | * @see \eZ\Publish\API\Repository\RoleService::newRoleUpdateStruct() |
||
| 769 | */ |
||
| 770 | public function testNewRoleUpdateStruct() |
||
| 771 | { |
||
| 772 | $repository = $this->getRepository(); |
||
| 773 | |||
| 774 | /* BEGIN: Use Case */ |
||
| 775 | $roleService = $repository->getRoleService(); |
||
| 776 | $roleUpdate = $roleService->newRoleUpdateStruct('newRole'); |
||
| 777 | /* END: Use Case */ |
||
| 778 | |||
| 779 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleUpdateStruct', $roleUpdate); |
||
| 780 | } |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Test for the updateRole() method. |
||
| 784 | * |
||
| 785 | * @see \eZ\Publish\API\Repository\RoleService::updateRole() |
||
| 786 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct |
||
| 787 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 788 | */ |
||
| 789 | public function testUpdateRole() |
||
| 790 | { |
||
| 791 | $repository = $this->getRepository(); |
||
| 792 | |||
| 793 | /* BEGIN: Use Case */ |
||
| 794 | $roleService = $repository->getRoleService(); |
||
| 795 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 796 | |||
| 797 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 798 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 799 | |||
| 800 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 801 | $roleService->publishRoleDraft($roleDraft); |
||
| 802 | $role = $roleService->loadRole($roleDraft->id); |
||
| 803 | |||
| 804 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 805 | $roleUpdate->identifier = 'updatedRole'; |
||
| 806 | |||
| 807 | $updatedRole = $roleService->updateRole($role, $roleUpdate); |
||
| 808 | /* END: Use Case */ |
||
| 809 | |||
| 810 | // Now verify that our change was saved |
||
| 811 | $role = $roleService->loadRoleByIdentifier('updatedRole'); |
||
| 812 | |||
| 813 | $this->assertEquals($role->id, $updatedRole->id); |
||
| 814 | } |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Test for the updateRoleDraft() method. |
||
| 818 | * |
||
| 819 | * @see \eZ\Publish\API\Repository\RoleService::updateRoleDraft() |
||
| 820 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct |
||
| 821 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 822 | */ |
||
| 823 | public function testUpdateRoleDraft() |
||
| 824 | { |
||
| 825 | $repository = $this->getRepository(); |
||
| 826 | |||
| 827 | /* BEGIN: Use Case */ |
||
| 828 | $roleService = $repository->getRoleService(); |
||
| 829 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 830 | |||
| 831 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 832 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 833 | |||
| 834 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 835 | |||
| 836 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 837 | $roleUpdate->identifier = 'updatedRole'; |
||
| 838 | |||
| 839 | $updatedRole = $roleService->updateRoleDraft($roleDraft, $roleUpdate); |
||
| 840 | /* END: Use Case */ |
||
| 841 | |||
| 842 | // Now verify that our change was saved |
||
| 843 | $role = $roleService->loadRoleDraft($updatedRole->id); |
||
| 844 | |||
| 845 | $this->assertEquals($role->identifier, 'updatedRole'); |
||
| 846 | } |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Test for the updateRole() method. |
||
| 850 | * |
||
| 851 | * @see \eZ\Publish\API\Repository\RoleService::updateRole() |
||
| 852 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 853 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRole |
||
| 854 | */ |
||
| 855 | View Code Duplication | public function testUpdateRoleThrowsInvalidArgumentException() |
|
| 856 | { |
||
| 857 | $repository = $this->getRepository(); |
||
| 858 | |||
| 859 | /* BEGIN: Use Case */ |
||
| 860 | $roleService = $repository->getRoleService(); |
||
| 861 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 862 | |||
| 863 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 864 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 865 | |||
| 866 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 867 | $roleService->publishRoleDraft($roleDraft); |
||
| 868 | $role = $roleService->loadRole($roleDraft->id); |
||
| 869 | |||
| 870 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 871 | $roleUpdate->identifier = 'Editor'; |
||
| 872 | |||
| 873 | // This call will fail with an InvalidArgumentException, because Editor is a predefined role |
||
| 874 | $roleService->updateRole($role, $roleUpdate); |
||
| 875 | /* END: Use Case */ |
||
| 876 | } |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Test for the updateRoleDraft() method. |
||
| 880 | * |
||
| 881 | * @see \eZ\Publish\API\Repository\RoleService::updateRoleDraft() |
||
| 882 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 883 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRoleDraft |
||
| 884 | */ |
||
| 885 | public function testUpdateRoleDraftThrowsInvalidArgumentException() |
||
| 886 | { |
||
| 887 | $repository = $this->getRepository(); |
||
| 888 | |||
| 889 | /* BEGIN: Use Case */ |
||
| 890 | $roleService = $repository->getRoleService(); |
||
| 891 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 892 | |||
| 893 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 894 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 895 | |||
| 896 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 897 | |||
| 898 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 899 | $roleUpdate->identifier = 'Editor'; |
||
| 900 | |||
| 901 | // This call will fail with an InvalidArgumentException, because Editor is a predefined role |
||
| 902 | $roleService->updateRoleDraft($roleDraft, $roleUpdate); |
||
| 903 | /* END: Use Case */ |
||
| 904 | } |
||
| 905 | |||
| 906 | /** |
||
| 907 | * Test for the deleteRole() method. |
||
| 908 | * |
||
| 909 | * @see \eZ\Publish\API\Repository\RoleService::deleteRole() |
||
| 910 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 911 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoles |
||
| 912 | */ |
||
| 913 | View Code Duplication | public function testDeleteRole() |
|
| 914 | { |
||
| 915 | $repository = $this->getRepository(); |
||
| 916 | |||
| 917 | /* BEGIN: Use Case */ |
||
| 918 | $roleService = $repository->getRoleService(); |
||
| 919 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 920 | |||
| 921 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 922 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 923 | |||
| 924 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 925 | $roleService->publishRoleDraft($roleDraft); |
||
| 926 | $role = $roleService->loadRole($roleDraft->id); |
||
| 927 | |||
| 928 | $roleService->deleteRole($role); |
||
| 929 | /* END: Use Case */ |
||
| 930 | |||
| 931 | $this->assertEquals(5, count($roleService->loadRoles())); |
||
| 932 | } |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Test for the deleteRoleDraft() method. |
||
| 936 | * |
||
| 937 | * @see \eZ\Publish\API\Repository\RoleService::deleteRoleDraft() |
||
| 938 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 939 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 940 | */ |
||
| 941 | View Code Duplication | public function testDeleteRoleDraft() |
|
| 942 | { |
||
| 943 | $repository = $this->getRepository(); |
||
| 944 | |||
| 945 | /* BEGIN: Use Case */ |
||
| 946 | $roleService = $repository->getRoleService(); |
||
| 947 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 948 | |||
| 949 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 950 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 951 | |||
| 952 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 953 | $roleID = $roleDraft->id; |
||
| 954 | $roleService->deleteRoleDraft($roleDraft); |
||
| 955 | |||
| 956 | // This call will fail with a NotFoundException, because the draft no longer exists |
||
| 957 | $roleService->loadRoleDraft($roleID); |
||
| 958 | /* END: Use Case */ |
||
| 959 | } |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Test for the newPolicyCreateStruct() method. |
||
| 963 | * |
||
| 964 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyCreateStruct() |
||
| 965 | */ |
||
| 966 | public function testNewPolicyCreateStruct() |
||
| 967 | { |
||
| 968 | $repository = $this->getRepository(); |
||
| 969 | |||
| 970 | /* BEGIN: Use Case */ |
||
| 971 | $roleService = $repository->getRoleService(); |
||
| 972 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 973 | /* END: Use Case */ |
||
| 974 | |||
| 975 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyCreateStruct', $policyCreate); |
||
| 976 | } |
||
| 977 | |||
| 978 | /** |
||
| 979 | * Test for the newPolicyCreateStruct() method. |
||
| 980 | * |
||
| 981 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyCreateStruct() |
||
| 982 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 983 | */ |
||
| 984 | public function testNewPolicyCreateStructSetsStructProperties() |
||
| 985 | { |
||
| 986 | $repository = $this->getRepository(); |
||
| 987 | |||
| 988 | /* BEGIN: Use Case */ |
||
| 989 | $roleService = $repository->getRoleService(); |
||
| 990 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 991 | /* END: Use Case */ |
||
| 992 | |||
| 993 | $this->assertEquals( |
||
| 994 | ['content', 'create'], |
||
| 995 | [$policyCreate->module, $policyCreate->function] |
||
| 996 | ); |
||
| 997 | } |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Test for the addPolicy() method. |
||
| 1001 | * |
||
| 1002 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1003 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 1004 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1005 | */ |
||
| 1006 | View Code Duplication | public function testAddPolicy() |
|
| 1007 | { |
||
| 1008 | $repository = $this->getRepository(); |
||
| 1009 | |||
| 1010 | /* BEGIN: Use Case */ |
||
| 1011 | $roleService = $repository->getRoleService(); |
||
| 1012 | |||
| 1013 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1014 | |||
| 1015 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1016 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1017 | |||
| 1018 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1019 | $roleService->publishRoleDraft($roleDraft); |
||
| 1020 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1021 | |||
| 1022 | $role = $roleService->addPolicy( |
||
| 1023 | $role, |
||
| 1024 | $roleService->newPolicyCreateStruct('content', 'delete') |
||
| 1025 | ); |
||
| 1026 | $role = $roleService->addPolicy( |
||
| 1027 | $role, |
||
| 1028 | $roleService->newPolicyCreateStruct('content', 'create') |
||
| 1029 | ); |
||
| 1030 | /* END: Use Case */ |
||
| 1031 | |||
| 1032 | $actual = []; |
||
| 1033 | foreach ($role->getPolicies() as $policy) { |
||
| 1034 | $actual[] = [ |
||
| 1035 | 'module' => $policy->module, |
||
| 1036 | 'function' => $policy->function, |
||
| 1037 | ]; |
||
| 1038 | } |
||
| 1039 | usort( |
||
| 1040 | $actual, |
||
| 1041 | function ($p1, $p2) { |
||
| 1042 | return strcasecmp($p1['function'], $p2['function']); |
||
| 1043 | } |
||
| 1044 | ); |
||
| 1045 | |||
| 1046 | $this->assertEquals( |
||
| 1047 | [ |
||
| 1048 | [ |
||
| 1049 | 'module' => 'content', |
||
| 1050 | 'function' => 'create', |
||
| 1051 | ], |
||
| 1052 | [ |
||
| 1053 | 'module' => 'content', |
||
| 1054 | 'function' => 'delete', |
||
| 1055 | ], |
||
| 1056 | ], |
||
| 1057 | $actual |
||
| 1058 | ); |
||
| 1059 | } |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Test for the addPolicyByRoleDraft() method. |
||
| 1063 | * |
||
| 1064 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1065 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 1066 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1067 | */ |
||
| 1068 | public function testAddPolicyByRoleDraft() |
||
| 1069 | { |
||
| 1070 | $repository = $this->getRepository(); |
||
| 1071 | |||
| 1072 | /* BEGIN: Use Case */ |
||
| 1073 | $roleService = $repository->getRoleService(); |
||
| 1074 | |||
| 1075 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1076 | |||
| 1077 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1078 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1079 | |||
| 1080 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1081 | |||
| 1082 | $roleDraft = $roleService->addPolicyByRoleDraft( |
||
| 1083 | $roleDraft, |
||
| 1084 | $roleService->newPolicyCreateStruct('content', 'delete') |
||
| 1085 | ); |
||
| 1086 | $roleDraft = $roleService->addPolicyByRoleDraft( |
||
| 1087 | $roleDraft, |
||
| 1088 | $roleService->newPolicyCreateStruct('content', 'create') |
||
| 1089 | ); |
||
| 1090 | /* END: Use Case */ |
||
| 1091 | |||
| 1092 | $actual = []; |
||
| 1093 | View Code Duplication | foreach ($roleDraft->getPolicies() as $policy) { |
|
| 1094 | $actual[] = [ |
||
| 1095 | 'module' => $policy->module, |
||
| 1096 | 'function' => $policy->function, |
||
| 1097 | ]; |
||
| 1098 | } |
||
| 1099 | usort( |
||
| 1100 | $actual, |
||
| 1101 | function ($p1, $p2) { |
||
| 1102 | return strcasecmp($p1['function'], $p2['function']); |
||
| 1103 | } |
||
| 1104 | ); |
||
| 1105 | |||
| 1106 | $this->assertEquals( |
||
| 1107 | [ |
||
| 1108 | [ |
||
| 1109 | 'module' => 'content', |
||
| 1110 | 'function' => 'create', |
||
| 1111 | ], |
||
| 1112 | [ |
||
| 1113 | 'module' => 'content', |
||
| 1114 | 'function' => 'delete', |
||
| 1115 | ], |
||
| 1116 | ], |
||
| 1117 | $actual |
||
| 1118 | ); |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Test for the addPolicy() method. |
||
| 1123 | * |
||
| 1124 | * @return array [\eZ\Publish\API\Repository\Values\User\Role, \eZ\Publish\API\Repository\Values\User\Policy] |
||
| 1125 | * |
||
| 1126 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1127 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1128 | */ |
||
| 1129 | public function testAddPolicyUpdatesRole() |
||
| 1130 | { |
||
| 1131 | $repository = $this->getRepository(); |
||
| 1132 | |||
| 1133 | /* BEGIN: Use Case */ |
||
| 1134 | $roleService = $repository->getRoleService(); |
||
| 1135 | |||
| 1136 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1137 | |||
| 1138 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1139 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1140 | |||
| 1141 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1142 | $roleService->publishRoleDraft($roleDraft); |
||
| 1143 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1144 | |||
| 1145 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 1146 | $role = $roleService->addPolicy($role, $policyCreate); |
||
| 1147 | |||
| 1148 | $policy = null; |
||
| 1149 | foreach ($role->getPolicies() as $policy) { |
||
| 1150 | if ($policy->module === 'content' && $policy->function === 'create') { |
||
| 1151 | break; |
||
| 1152 | } |
||
| 1153 | } |
||
| 1154 | /* END: Use Case */ |
||
| 1155 | |||
| 1156 | $this->assertInstanceOf( |
||
| 1157 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', |
||
| 1158 | $policy |
||
| 1159 | ); |
||
| 1160 | |||
| 1161 | return [$role, $policy]; |
||
| 1162 | } |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Test for the addPolicyByRoleDraft() method. |
||
| 1166 | * |
||
| 1167 | * @return array [\eZ\Publish\API\Repository\Values\User\RoleDraft, \eZ\Publish\API\Repository\Values\User\Policy] |
||
| 1168 | * |
||
| 1169 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1170 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 1171 | */ |
||
| 1172 | public function testAddPolicyByRoleDraftUpdatesRole() |
||
| 1173 | { |
||
| 1174 | $repository = $this->getRepository(); |
||
| 1175 | |||
| 1176 | /* BEGIN: Use Case */ |
||
| 1177 | $roleService = $repository->getRoleService(); |
||
| 1178 | |||
| 1179 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1180 | |||
| 1181 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1182 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1183 | |||
| 1184 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1185 | |||
| 1186 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 1187 | $roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreate); |
||
| 1188 | |||
| 1189 | $policy = null; |
||
| 1190 | foreach ($roleDraft->getPolicies() as $policy) { |
||
| 1191 | if ($policy->module === 'content' && $policy->function === 'create') { |
||
| 1192 | break; |
||
| 1193 | } |
||
| 1194 | } |
||
| 1195 | /* END: Use Case */ |
||
| 1196 | |||
| 1197 | $this->assertInstanceOf( |
||
| 1198 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', |
||
| 1199 | $policy |
||
| 1200 | ); |
||
| 1201 | |||
| 1202 | return [$roleDraft, $policy]; |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Test for the addPolicy() method. |
||
| 1207 | * |
||
| 1208 | * @param array $roleAndPolicy |
||
| 1209 | * |
||
| 1210 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1211 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyUpdatesRole |
||
| 1212 | */ |
||
| 1213 | View Code Duplication | public function testAddPolicySetsPolicyProperties($roleAndPolicy) |
|
| 1214 | { |
||
| 1215 | list($role, $policy) = $roleAndPolicy; |
||
| 1216 | |||
| 1217 | $this->assertEquals( |
||
| 1218 | [$role->id, 'content', 'create'], |
||
| 1219 | [$policy->roleId, $policy->module, $policy->function] |
||
| 1220 | ); |
||
| 1221 | } |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Test for the addPolicyByRoleDraft() method. |
||
| 1225 | * |
||
| 1226 | * @param array $roleAndPolicy |
||
| 1227 | * |
||
| 1228 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1229 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraftUpdatesRole |
||
| 1230 | */ |
||
| 1231 | View Code Duplication | public function testAddPolicyByRoleDraftSetsPolicyProperties($roleAndPolicy) |
|
| 1232 | { |
||
| 1233 | list($role, $policy) = $roleAndPolicy; |
||
| 1234 | |||
| 1235 | $this->assertEquals( |
||
| 1236 | [$role->id, 'content', 'create'], |
||
| 1237 | [$policy->roleId, $policy->module, $policy->function] |
||
| 1238 | ); |
||
| 1239 | } |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Test for the addPolicy() method. |
||
| 1243 | * |
||
| 1244 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1245 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1246 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1247 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 1248 | */ |
||
| 1249 | public function testAddPolicyThrowsLimitationValidationException() |
||
| 1250 | { |
||
| 1251 | $repository = $this->getRepository(); |
||
| 1252 | |||
| 1253 | /* BEGIN: Use Case */ |
||
| 1254 | $roleService = $repository->getRoleService(); |
||
| 1255 | |||
| 1256 | $roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
||
| 1257 | |||
| 1258 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1259 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1260 | |||
| 1261 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1262 | $roleService->publishRoleDraft($roleDraft); |
||
| 1263 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1264 | |||
| 1265 | // Create new subtree limitation |
||
| 1266 | $limitation = new SubtreeLimitation( |
||
| 1267 | [ |
||
| 1268 | 'limitationValues' => ['/mountain/forest/tree/42/'], |
||
| 1269 | ] |
||
| 1270 | ); |
||
| 1271 | |||
| 1272 | // Create policy create struct and add limitation to it |
||
| 1273 | $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove'); |
||
| 1274 | $policyCreateStruct->addLimitation($limitation); |
||
| 1275 | |||
| 1276 | // This call will fail with an LimitationValidationException, because subtree |
||
| 1277 | // "/mountain/forest/tree/42/" does not exist |
||
| 1278 | $roleService->addPolicy($role, $policyCreateStruct); |
||
| 1279 | /* END: Use Case */ |
||
| 1280 | } |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * Test for the addPolicyByRoleDraft() method. |
||
| 1284 | * |
||
| 1285 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1286 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1287 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1288 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 1289 | */ |
||
| 1290 | View Code Duplication | public function testAddPolicyByRoleDraftThrowsLimitationValidationException() |
|
| 1291 | { |
||
| 1292 | $repository = $this->getRepository(); |
||
| 1293 | |||
| 1294 | /* BEGIN: Use Case */ |
||
| 1295 | $roleService = $repository->getRoleService(); |
||
| 1296 | |||
| 1297 | $roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
||
| 1298 | |||
| 1299 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1300 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1301 | |||
| 1302 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1303 | |||
| 1304 | // Create new subtree limitation |
||
| 1305 | $limitation = new SubtreeLimitation( |
||
| 1306 | [ |
||
| 1307 | 'limitationValues' => ['/mountain/forest/tree/42/'], |
||
| 1308 | ] |
||
| 1309 | ); |
||
| 1310 | |||
| 1311 | // Create policy create struct and add limitation to it |
||
| 1312 | $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove'); |
||
| 1313 | $policyCreateStruct->addLimitation($limitation); |
||
| 1314 | |||
| 1315 | // This call will fail with an LimitationValidationException, because subtree |
||
| 1316 | // "/mountain/forest/tree/42/" does not exist |
||
| 1317 | $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
||
| 1318 | /* END: Use Case */ |
||
| 1319 | } |
||
| 1320 | |||
| 1321 | /** |
||
| 1322 | * Test for the createRole() method. |
||
| 1323 | * |
||
| 1324 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 1325 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyUpdatesRole |
||
| 1326 | */ |
||
| 1327 | public function testCreateRoleWithAddPolicy() |
||
| 1328 | { |
||
| 1329 | $repository = $this->getRepository(); |
||
| 1330 | |||
| 1331 | /* BEGIN: Use Case */ |
||
| 1332 | $roleService = $repository->getRoleService(); |
||
| 1333 | |||
| 1334 | // Instantiate a new create struct |
||
| 1335 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1336 | |||
| 1337 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1338 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1339 | |||
| 1340 | // Add some role policies |
||
| 1341 | $roleCreate->addPolicy( |
||
| 1342 | $roleService->newPolicyCreateStruct( |
||
| 1343 | 'content', |
||
| 1344 | 'read' |
||
| 1345 | ) |
||
| 1346 | ); |
||
| 1347 | $roleCreate->addPolicy( |
||
| 1348 | $roleService->newPolicyCreateStruct( |
||
| 1349 | 'content', |
||
| 1350 | 'translate' |
||
| 1351 | ) |
||
| 1352 | ); |
||
| 1353 | |||
| 1354 | // Create new role instance |
||
| 1355 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1356 | $roleService->publishRoleDraft($roleDraft); |
||
| 1357 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1358 | |||
| 1359 | $policies = []; |
||
| 1360 | View Code Duplication | foreach ($role->getPolicies() as $policy) { |
|
| 1361 | $policies[] = ['module' => $policy->module, 'function' => $policy->function]; |
||
| 1362 | } |
||
| 1363 | /* END: Use Case */ |
||
| 1364 | array_multisort($policies); |
||
| 1365 | |||
| 1366 | $this->assertEquals( |
||
| 1367 | [ |
||
| 1368 | [ |
||
| 1369 | 'module' => 'content', |
||
| 1370 | 'function' => 'read', |
||
| 1371 | ], |
||
| 1372 | [ |
||
| 1373 | 'module' => 'content', |
||
| 1374 | 'function' => 'translate', |
||
| 1375 | ], |
||
| 1376 | ], |
||
| 1377 | $policies |
||
| 1378 | ); |
||
| 1379 | } |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Test for the createRoleDraft() method. |
||
| 1383 | * |
||
| 1384 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 1385 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraftUpdatesRole |
||
| 1386 | */ |
||
| 1387 | public function testCreateRoleDraftWithAddPolicy() |
||
| 1388 | { |
||
| 1389 | $repository = $this->getRepository(); |
||
| 1390 | |||
| 1391 | /* BEGIN: Use Case */ |
||
| 1392 | $roleService = $repository->getRoleService(); |
||
| 1393 | |||
| 1394 | // Instantiate a new create struct |
||
| 1395 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1396 | |||
| 1397 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1398 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1399 | |||
| 1400 | // Add some role policies |
||
| 1401 | $roleCreate->addPolicy( |
||
| 1402 | $roleService->newPolicyCreateStruct( |
||
| 1403 | 'content', |
||
| 1404 | 'read' |
||
| 1405 | ) |
||
| 1406 | ); |
||
| 1407 | $roleCreate->addPolicy( |
||
| 1408 | $roleService->newPolicyCreateStruct( |
||
| 1409 | 'content', |
||
| 1410 | 'translate' |
||
| 1411 | ) |
||
| 1412 | ); |
||
| 1413 | |||
| 1414 | // Create new role instance |
||
| 1415 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1416 | |||
| 1417 | $policies = []; |
||
| 1418 | View Code Duplication | foreach ($roleDraft->getPolicies() as $policy) { |
|
| 1419 | $policies[] = ['module' => $policy->module, 'function' => $policy->function]; |
||
| 1420 | } |
||
| 1421 | /* END: Use Case */ |
||
| 1422 | |||
| 1423 | $this->assertEquals( |
||
| 1424 | [ |
||
| 1425 | [ |
||
| 1426 | 'module' => 'content', |
||
| 1427 | 'function' => 'read', |
||
| 1428 | ], |
||
| 1429 | [ |
||
| 1430 | 'module' => 'content', |
||
| 1431 | 'function' => 'translate', |
||
| 1432 | ], |
||
| 1433 | ], |
||
| 1434 | $policies |
||
| 1435 | ); |
||
| 1436 | } |
||
| 1437 | |||
| 1438 | /** |
||
| 1439 | * Test for the newPolicyUpdateStruct() method. |
||
| 1440 | * |
||
| 1441 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyUpdateStruct() |
||
| 1442 | */ |
||
| 1443 | public function testNewPolicyUpdateStruct() |
||
| 1444 | { |
||
| 1445 | $repository = $this->getRepository(); |
||
| 1446 | |||
| 1447 | /* BEGIN: Use Case */ |
||
| 1448 | $roleService = $repository->getRoleService(); |
||
| 1449 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
||
| 1450 | /* END: Use Case */ |
||
| 1451 | |||
| 1452 | $this->assertInstanceOf( |
||
| 1453 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\PolicyUpdateStruct', |
||
| 1454 | $policyUpdate |
||
| 1455 | ); |
||
| 1456 | } |
||
| 1457 | |||
| 1458 | public function testUpdatePolicyNoLimitation() |
||
| 1459 | { |
||
| 1460 | $repository = $this->getRepository(); |
||
| 1461 | |||
| 1462 | /* BEGIN: Use Case */ |
||
| 1463 | $roleService = $repository->getRoleService(); |
||
| 1464 | |||
| 1465 | // Instantiate new policy create |
||
| 1466 | $policyCreate = $roleService->newPolicyCreateStruct('foo', 'bar'); |
||
| 1467 | |||
| 1468 | // Instantiate a role create and add the policy create |
||
| 1469 | $roleCreate = $roleService->newRoleCreateStruct('myRole'); |
||
| 1470 | |||
| 1471 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1472 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1473 | |||
| 1474 | $roleCreate->addPolicy($policyCreate); |
||
| 1475 | |||
| 1476 | // Create a new role instance. |
||
| 1477 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1478 | $roleService->publishRoleDraft($roleDraft); |
||
| 1479 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1480 | |||
| 1481 | // Search for the new policy instance |
||
| 1482 | $policy = null; |
||
| 1483 | foreach ($role->getPolicies() as $policy) { |
||
| 1484 | if ($policy->module === 'foo' && $policy->function === 'bar') { |
||
| 1485 | break; |
||
| 1486 | } |
||
| 1487 | } |
||
| 1488 | |||
| 1489 | // Create an update struct |
||
| 1490 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
||
| 1491 | |||
| 1492 | // Update the the policy |
||
| 1493 | $policy = $roleService->updatePolicy($policy, $policyUpdate); |
||
| 1494 | /* END: Use Case */ |
||
| 1495 | |||
| 1496 | $this->assertInstanceOf( |
||
| 1497 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', |
||
| 1498 | $policy |
||
| 1499 | ); |
||
| 1500 | |||
| 1501 | self::assertEquals([], $policy->getLimitations()); |
||
| 1502 | } |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Test for the updatePolicy() method. |
||
| 1506 | * |
||
| 1507 | * @return array |
||
| 1508 | * |
||
| 1509 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1510 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1511 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyUpdateStruct |
||
| 1512 | */ |
||
| 1513 | public function testUpdatePolicy() |
||
| 1514 | { |
||
| 1515 | $repository = $this->getRepository(); |
||
| 1516 | |||
| 1517 | /* BEGIN: Use Case */ |
||
| 1518 | $roleService = $repository->getRoleService(); |
||
| 1519 | |||
| 1520 | // Instantiate new policy create |
||
| 1521 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'translate'); |
||
| 1522 | |||
| 1523 | // Add some limitations for the new policy |
||
| 1524 | $policyCreate->addLimitation( |
||
| 1525 | new LanguageLimitation( |
||
| 1526 | [ |
||
| 1527 | 'limitationValues' => ['eng-US', 'eng-GB'], |
||
| 1528 | ] |
||
| 1529 | ) |
||
| 1530 | ); |
||
| 1531 | |||
| 1532 | // Instantiate a role create and add the policy create |
||
| 1533 | $roleCreate = $roleService->newRoleCreateStruct('myRole'); |
||
| 1534 | |||
| 1535 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1536 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1537 | |||
| 1538 | $roleCreate->addPolicy($policyCreate); |
||
| 1539 | |||
| 1540 | // Create a new role instance. |
||
| 1541 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1542 | $roleService->publishRoleDraft($roleDraft); |
||
| 1543 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1544 | |||
| 1545 | // Search for the new policy instance |
||
| 1546 | $policy = null; |
||
| 1547 | foreach ($role->getPolicies() as $policy) { |
||
| 1548 | if ($policy->module === 'content' && $policy->function === 'translate') { |
||
| 1549 | break; |
||
| 1550 | } |
||
| 1551 | } |
||
| 1552 | |||
| 1553 | // Create an update struct and set a modified limitation |
||
| 1554 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
||
| 1555 | $policyUpdate->addLimitation( |
||
| 1556 | new ContentTypeLimitation( |
||
| 1557 | [ |
||
| 1558 | 'limitationValues' => [29, 30], |
||
| 1559 | ] |
||
| 1560 | ) |
||
| 1561 | ); |
||
| 1562 | |||
| 1563 | // Update the the policy |
||
| 1564 | $policy = $roleService->updatePolicy($policy, $policyUpdate); |
||
| 1565 | /* END: Use Case */ |
||
| 1566 | |||
| 1567 | $this->assertInstanceOf( |
||
| 1568 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\Policy', |
||
| 1569 | $policy |
||
| 1570 | ); |
||
| 1571 | |||
| 1572 | return [$roleService->loadRole($role->id), $policy]; |
||
| 1573 | } |
||
| 1574 | |||
| 1575 | /** |
||
| 1576 | * Test for the updatePolicy() method. |
||
| 1577 | * |
||
| 1578 | * @param array $roleAndPolicy |
||
| 1579 | * |
||
| 1580 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1581 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicy |
||
| 1582 | */ |
||
| 1583 | public function testUpdatePolicyUpdatesLimitations($roleAndPolicy) |
||
| 1584 | { |
||
| 1585 | list($role, $policy) = $roleAndPolicy; |
||
| 1586 | |||
| 1587 | $this->assertEquals( |
||
| 1588 | [ |
||
| 1589 | new ContentTypeLimitation( |
||
| 1590 | [ |
||
| 1591 | 'limitationValues' => [29, 30], |
||
| 1592 | ] |
||
| 1593 | ), |
||
| 1594 | ], |
||
| 1595 | $policy->getLimitations() |
||
| 1596 | ); |
||
| 1597 | |||
| 1598 | return $role; |
||
| 1599 | } |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Test for the updatePolicy() method. |
||
| 1603 | * |
||
| 1604 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 1605 | * |
||
| 1606 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1607 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicyUpdatesLimitations |
||
| 1608 | */ |
||
| 1609 | public function testUpdatePolicyUpdatesRole($role) |
||
| 1610 | { |
||
| 1611 | $limitations = []; |
||
| 1612 | foreach ($role->getPolicies() as $policy) { |
||
| 1613 | foreach ($policy->getLimitations() as $limitation) { |
||
| 1614 | $limitations[] = $limitation; |
||
| 1615 | } |
||
| 1616 | } |
||
| 1617 | |||
| 1618 | $this->assertCount(1, $limitations); |
||
| 1619 | $this->assertInstanceOf( |
||
| 1620 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\Limitation', |
||
| 1621 | $limitations[0] |
||
| 1622 | ); |
||
| 1623 | |||
| 1624 | $expectedData = [ |
||
| 1625 | 'limitationValues' => [29, 30], |
||
| 1626 | ]; |
||
| 1627 | $this->assertPropertiesCorrectUnsorted( |
||
| 1628 | $expectedData, |
||
| 1629 | $limitations[0] |
||
| 1630 | ); |
||
| 1631 | } |
||
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Test for the updatePolicy() method. |
||
| 1635 | * |
||
| 1636 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1637 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1638 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1639 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1640 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyUpdateStruct |
||
| 1641 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 1642 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 1643 | */ |
||
| 1644 | public function testUpdatePolicyThrowsLimitationValidationException() |
||
| 1645 | { |
||
| 1646 | $repository = $this->getRepository(); |
||
| 1647 | |||
| 1648 | /* BEGIN: Use Case */ |
||
| 1649 | $roleService = $repository->getRoleService(); |
||
| 1650 | |||
| 1651 | // Instantiate new policy create |
||
| 1652 | $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove'); |
||
| 1653 | |||
| 1654 | // Add some limitations for the new policy |
||
| 1655 | $policyCreate->addLimitation( |
||
| 1656 | new SubtreeLimitation( |
||
| 1657 | [ |
||
| 1658 | 'limitationValues' => ['/1/2/'], |
||
| 1659 | ] |
||
| 1660 | ) |
||
| 1661 | ); |
||
| 1662 | |||
| 1663 | // Instantiate a role create and add the policy create |
||
| 1664 | $roleCreate = $roleService->newRoleCreateStruct('myRole'); |
||
| 1665 | |||
| 1666 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1667 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1668 | |||
| 1669 | $roleCreate->addPolicy($policyCreate); |
||
| 1670 | |||
| 1671 | // Create a new role instance. |
||
| 1672 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1673 | $roleService->publishRoleDraft($roleDraft); |
||
| 1674 | $role = $roleService->loadRole($roleDraft->id); |
||
| 1675 | |||
| 1676 | // Search for the new policy instance |
||
| 1677 | $policy = null; |
||
| 1678 | foreach ($role->getPolicies() as $policy) { |
||
| 1679 | if ($policy->module === 'content' && $policy->function === 'remove') { |
||
| 1680 | break; |
||
| 1681 | } |
||
| 1682 | } |
||
| 1683 | |||
| 1684 | // Create an update struct and set a modified limitation |
||
| 1685 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
||
| 1686 | $policyUpdate->addLimitation( |
||
| 1687 | new SubtreeLimitation( |
||
| 1688 | [ |
||
| 1689 | 'limitationValues' => ['/mountain/forest/tree/42/'], |
||
| 1690 | ] |
||
| 1691 | ) |
||
| 1692 | ); |
||
| 1693 | |||
| 1694 | // This call will fail with an LimitationValidationException, because subtree |
||
| 1695 | // "/mountain/forest/tree/42/" does not exist |
||
| 1696 | $policy = $roleService->updatePolicy($policy, $policyUpdate); |
||
| 1697 | /* END: Use Case */ |
||
| 1698 | } |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * Test for the removePolicyByRoleDraft() method. |
||
| 1702 | * |
||
| 1703 | * @see \eZ\Publish\API\Repository\RoleService::removePolicyByRoleDraft() |
||
| 1704 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 1705 | */ |
||
| 1706 | View Code Duplication | public function testRemovePolicyByRoleDraft() |
|
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Test for the deletePolicy() method. |
||
| 1741 | * |
||
| 1742 | * @see \eZ\Publish\API\Repository\RoleService::deletePolicy() |
||
| 1743 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRole |
||
| 1744 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1745 | */ |
||
| 1746 | public function testDeletePolicy() |
||
| 1747 | { |
||
| 1748 | $repository = $this->getRepository(); |
||
| 1749 | |||
| 1750 | /* BEGIN: Use Case */ |
||
| 1751 | $roleService = $repository->getRoleService(); |
||
| 1752 | |||
| 1753 | // Instantiate a new role create |
||
| 1754 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 1755 | |||
| 1756 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 1757 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 1758 | |||
| 1759 | // Create a new role with two policies |
||
| 1760 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 1761 | $roleService->addPolicyByRoleDraft( |
||
| 1762 | $roleDraft, |
||
| 1763 | $roleService->newPolicyCreateStruct('content', 'create') |
||
| 1764 | ); |
||
| 1765 | $roleService->addPolicyByRoleDraft( |
||
| 1766 | $roleDraft, |
||
| 1781 | |||
| 1782 | /** |
||
| 1783 | * Test for the addPolicyByRoleDraft() method. |
||
| 1784 | * |
||
| 1785 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1786 | */ |
||
| 1787 | public function testAddPolicyWithRoleAssignment() |
||
| 1826 | |||
| 1827 | /** |
||
| 1828 | * Test loading user/group role assignments. |
||
| 1829 | * |
||
| 1830 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment |
||
| 1831 | * |
||
| 1832 | * @covers \eZ\Publish\API\Repository\RoleService::loadRoleAssignment |
||
| 1833 | */ |
||
| 1834 | public function testLoadRoleAssignment() |
||
| 1879 | |||
| 1880 | /** |
||
| 1881 | * Test for the getRoleAssignments() method. |
||
| 1882 | * |
||
| 1883 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
| 1884 | * |
||
| 1885 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignments() |
||
| 1886 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 1887 | */ |
||
| 1888 | public function testGetRoleAssignments() |
||
| 1915 | |||
| 1916 | /** |
||
| 1917 | * Test for the getRoleAssignments() method. |
||
| 1918 | * |
||
| 1919 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment[] $roleAssignments |
||
| 1920 | * |
||
| 1921 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignments() |
||
| 1922 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 1923 | */ |
||
| 1924 | public function testGetRoleAssignmentsContainExpectedLimitation(array $roleAssignments) |
||
| 1931 | |||
| 1932 | /** |
||
| 1933 | * Test for the assignRoleToUser() method. |
||
| 1934 | * |
||
| 1935 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser() |
||
| 1936 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 1937 | */ |
||
| 1938 | public function testAssignRoleToUser() |
||
| 1959 | |||
| 1960 | /** |
||
| 1961 | * Test for the assignRoleToUser() method. |
||
| 1962 | * |
||
| 1963 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 1964 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 1965 | */ |
||
| 1966 | View Code Duplication | public function testAssignRoleToUserWithRoleLimitation() |
|
| 2064 | |||
| 2065 | /** |
||
| 2066 | * Test for the assignRoleToUser() method. |
||
| 2067 | * |
||
| 2068 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 2069 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 2070 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2071 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2072 | */ |
||
| 2073 | public function testAssignRoleToUserWithRoleLimitationThrowsLimitationValidationException() |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Test for the assignRoleToUser() method. |
||
| 2103 | * |
||
| 2104 | * Makes sure assigning role several times throws. |
||
| 2105 | * |
||
| 2106 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 2107 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2108 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2109 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2110 | */ |
||
| 2111 | public function testAssignRoleToUserThrowsInvalidArgumentException() |
||
| 2142 | |||
| 2143 | /** |
||
| 2144 | * Test for the assignRoleToUser() method. |
||
| 2145 | * |
||
| 2146 | * Makes sure assigning role several times with same limitations throws. |
||
| 2147 | * |
||
| 2148 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 2149 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2150 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2151 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2152 | */ |
||
| 2153 | public function testAssignRoleToUserWithRoleLimitationThrowsInvalidArgumentException() |
||
| 2194 | |||
| 2195 | /** |
||
| 2196 | * Test for the unassignRoleFromUser() method. |
||
| 2197 | * |
||
| 2198 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser() |
||
| 2199 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2200 | */ |
||
| 2201 | View Code Duplication | public function testUnassignRoleFromUser() |
|
| 2225 | |||
| 2226 | /** |
||
| 2227 | * Test for the unassignRoleFromUser() method. |
||
| 2228 | * |
||
| 2229 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser() |
||
| 2230 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2231 | */ |
||
| 2232 | View Code Duplication | public function testUnassignRoleFromUserThrowsInvalidArgumentException() |
|
| 2248 | |||
| 2249 | /** |
||
| 2250 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2251 | * |
||
| 2252 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2253 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2254 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2255 | */ |
||
| 2256 | public function testGetRoleAssignmentsForUserDirect() |
||
| 2303 | |||
| 2304 | /** |
||
| 2305 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2306 | * |
||
| 2307 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2308 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2309 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2310 | */ |
||
| 2311 | public function testGetRoleAssignmentsForUserEmpty() |
||
| 2325 | |||
| 2326 | /** |
||
| 2327 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2328 | * |
||
| 2329 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2330 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2331 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2332 | */ |
||
| 2333 | public function testGetRoleAssignmentsForUserInherited() |
||
| 2351 | |||
| 2352 | /** |
||
| 2353 | * Test for the assignRoleToUserGroup() method. |
||
| 2354 | * |
||
| 2355 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
||
| 2356 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 2357 | */ |
||
| 2358 | View Code Duplication | public function testAssignRoleToUserGroup() |
|
| 2379 | |||
| 2380 | /** |
||
| 2381 | * Test for the assignRoleToUserGroup() method. |
||
| 2382 | * |
||
| 2383 | * Related issue: EZP-29113 |
||
| 2384 | * |
||
| 2385 | * @covers \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
||
| 2386 | */ |
||
| 2387 | public function testAssignRoleToUserGroupAffectsRoleAssignmentsForUser() |
||
| 2409 | |||
| 2410 | /** |
||
| 2411 | * Test for the assignRoleToUserGroup() method. |
||
| 2412 | * |
||
| 2413 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2414 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2415 | */ |
||
| 2416 | View Code Duplication | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2510 | |||
| 2511 | /** |
||
| 2512 | * Test for the assignRoleToUserGroup() method. |
||
| 2513 | * |
||
| 2514 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2515 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 2516 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2517 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2518 | */ |
||
| 2519 | public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException() |
||
| 2549 | |||
| 2550 | /** |
||
| 2551 | * Test for the assignRoleToUserGroup() method. |
||
| 2552 | * |
||
| 2553 | * Makes sure assigning role several times throws. |
||
| 2554 | * |
||
| 2555 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2556 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2557 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2558 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2559 | */ |
||
| 2560 | public function testAssignRoleToUserGroupThrowsInvalidArgumentException() |
||
| 2594 | |||
| 2595 | /** |
||
| 2596 | * Test for the assignRoleToUserGroup() method. |
||
| 2597 | * |
||
| 2598 | * Makes sure assigning role several times with same limitations throws. |
||
| 2599 | * |
||
| 2600 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2601 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2602 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2603 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2604 | */ |
||
| 2605 | public function testAssignRoleToUserGroupWithRoleLimitationThrowsInvalidArgumentException() |
||
| 2649 | |||
| 2650 | /** |
||
| 2651 | * Test for the unassignRoleFromUserGroup() method. |
||
| 2652 | * |
||
| 2653 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup() |
||
| 2654 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2655 | */ |
||
| 2656 | View Code Duplication | public function testUnassignRoleFromUserGroup() |
|
| 2680 | |||
| 2681 | /** |
||
| 2682 | * Test for the unassignRoleFromUserGroup() method. |
||
| 2683 | * |
||
| 2684 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup() |
||
| 2685 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2686 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUnassignRoleFromUserGroup |
||
| 2687 | */ |
||
| 2688 | View Code Duplication | public function testUnassignRoleFromUserGroupThrowsInvalidArgumentException() |
|
| 2704 | |||
| 2705 | /** |
||
| 2706 | * Test unassigning role by assignment. |
||
| 2707 | * |
||
| 2708 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2709 | */ |
||
| 2710 | public function testUnassignRoleByAssignment() |
||
| 2729 | |||
| 2730 | /** |
||
| 2731 | * Test unassigning role by assignment. |
||
| 2732 | * |
||
| 2733 | * But on current admin user so he lacks access to read roles. |
||
| 2734 | * |
||
| 2735 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2736 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2737 | */ |
||
| 2738 | View Code Duplication | public function testUnassignRoleByAssignmentThrowsUnauthorizedException() |
|
| 2755 | |||
| 2756 | /** |
||
| 2757 | * Test unassigning role by non-existing assignment. |
||
| 2758 | * |
||
| 2759 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2760 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2761 | */ |
||
| 2762 | View Code Duplication | public function testUnassignRoleByAssignmentThrowsNotFoundException() |
|
| 2779 | |||
| 2780 | /** |
||
| 2781 | * Test for the getRoleAssignmentsForUserGroup() method. |
||
| 2782 | * |
||
| 2783 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUserGroup() |
||
| 2784 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2785 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2786 | */ |
||
| 2787 | public function testGetRoleAssignmentsForUserGroup() |
||
| 2829 | |||
| 2830 | /** |
||
| 2831 | * Test for the loadPoliciesByUserId() method. |
||
| 2832 | * |
||
| 2833 | * @see \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId() |
||
| 2834 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2835 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2836 | */ |
||
| 2837 | public function testLoadPoliciesByUserId() |
||
| 2900 | |||
| 2901 | /** |
||
| 2902 | * Test for the loadPoliciesByUserId() method. |
||
| 2903 | * |
||
| 2904 | * @see \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId() |
||
| 2905 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2906 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadPoliciesByUserId |
||
| 2907 | */ |
||
| 2908 | public function testLoadPoliciesByUserIdThrowsNotFoundException() |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * Test for the publishRoleDraft() method. |
||
| 2924 | * |
||
| 2925 | * @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft() |
||
| 2926 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 2927 | */ |
||
| 2928 | View Code Duplication | public function testPublishRoleDraft() |
|
| 2958 | |||
| 2959 | /** |
||
| 2960 | * Test for the publishRoleDraft() method. |
||
| 2961 | * |
||
| 2962 | * @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft() |
||
| 2963 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 2964 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 2965 | */ |
||
| 2966 | View Code Duplication | public function testPublishRoleDraftAddPolicies() |
|
| 3020 | |||
| 3021 | /** |
||
| 3022 | * Create a user group fixture in a variable named <b>$userGroup</b>,. |
||
| 3023 | * |
||
| 3024 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
| 3025 | */ |
||
| 3026 | private function createUserGroupVersion1() |
||
| 3053 | } |
||
| 3054 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.