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 |
||
| 37 | class RoleServiceTest extends BaseTest |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * Test for the newRoleCreateStruct() method. |
||
| 41 | * |
||
| 42 | * @see \eZ\Publish\API\Repository\RoleService::newRoleCreateStruct() |
||
| 43 | */ |
||
| 44 | public function testNewRoleCreateStruct() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Test for the newRoleCreateStruct() method. |
||
| 56 | * |
||
| 57 | * @see \eZ\Publish\API\Repository\RoleService::newRoleCreateStruct() |
||
| 58 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 59 | */ |
||
| 60 | public function testNewRoleCreateStructSetsNamePropertyOnStruct() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Test for the createRole() method. |
||
| 76 | * |
||
| 77 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 78 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 79 | */ |
||
| 80 | public function testCreateRole() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Test for the createRole() method. |
||
| 109 | * |
||
| 110 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 111 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 112 | */ |
||
| 113 | public function testRoleCreateStructValues(array $data) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Test for the createRole() method. |
||
| 135 | * |
||
| 136 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 137 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 138 | */ |
||
| 139 | public function testCreateRoleWithPolicy() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Test for the createRole() method. |
||
| 182 | * |
||
| 183 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 184 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithPolicy |
||
| 185 | */ |
||
| 186 | public function testRoleCreateStructValuesWithPolicy(array $data) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Test for the createRoleDraft() method. |
||
| 212 | * |
||
| 213 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 214 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 215 | */ |
||
| 216 | View Code Duplication | public function testCreateRoleDraft() |
|
| 240 | |||
| 241 | /** |
||
| 242 | * Test for the createRole() method. |
||
| 243 | * |
||
| 244 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 245 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 246 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 247 | */ |
||
| 248 | public function testCreateRoleThrowsInvalidArgumentException() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Test for the createRoleDraft() method. |
||
| 268 | * |
||
| 269 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 270 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 271 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 272 | */ |
||
| 273 | public function testCreateRoleDraftThrowsInvalidArgumentException() |
||
| 274 | { |
||
| 275 | $repository = $this->getRepository(); |
||
| 276 | |||
| 277 | /* BEGIN: Use Case */ |
||
| 278 | |||
| 279 | $roleService = $repository->getRoleService(); |
||
| 280 | $roleCreate = $roleService->newRoleCreateStruct('Editor'); |
||
| 281 | |||
| 282 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 283 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 284 | |||
| 285 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 286 | $roleService->publishRoleDraft($roleDraft); |
||
| 287 | $role = $roleService->loadRole($roleDraft->id); |
||
| 288 | $roleService->createRoleDraft($role); // First role draft |
||
| 289 | |||
| 290 | // This call will fail with an InvalidArgumentException, because there is already a draft |
||
| 291 | $roleService->createRoleDraft($role); |
||
| 292 | |||
| 293 | /* END: Use Case */ |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Test for the createRole() method. |
||
| 298 | * |
||
| 299 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 300 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 301 | */ |
||
| 302 | View Code Duplication | public function testCreateRoleThrowsLimitationValidationException() |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Test for the createRole() method. |
||
| 337 | * |
||
| 338 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 339 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 340 | */ |
||
| 341 | View Code Duplication | public function testCreateRoleInTransactionWithRollback() |
|
| 342 | { |
||
| 343 | $repository = $this->getRepository(); |
||
| 344 | |||
| 345 | /* BEGIN: Use Case */ |
||
| 346 | |||
| 347 | $roleService = $repository->getRoleService(); |
||
| 348 | |||
| 349 | $repository->beginTransaction(); |
||
| 350 | |||
| 351 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 352 | |||
| 353 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 354 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 355 | |||
| 356 | $createdRoleId = $roleService->createRole($roleCreate)->id; |
||
| 357 | |||
| 358 | $repository->rollback(); |
||
| 359 | |||
| 360 | try { |
||
| 361 | // This call will fail with a "NotFoundException" |
||
| 362 | $role = $roleService->loadRole($createdRoleId); |
||
|
|
|||
| 363 | } catch (NotFoundException $e) { |
||
| 364 | return; |
||
| 365 | } |
||
| 366 | /* END: Use Case */ |
||
| 367 | |||
| 368 | $this->fail('Role object still exists after rollback.'); |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Test for the createRoleDraft() method. |
||
| 373 | * |
||
| 374 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 375 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 376 | */ |
||
| 377 | View Code Duplication | public function testCreateRoleDraftInTransactionWithRollback() |
|
| 378 | { |
||
| 379 | $repository = $this->getRepository(); |
||
| 380 | |||
| 381 | /* BEGIN: Use Case */ |
||
| 382 | |||
| 383 | $roleService = $repository->getRoleService(); |
||
| 384 | |||
| 385 | $repository->beginTransaction(); |
||
| 386 | |||
| 387 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 388 | |||
| 389 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 390 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 391 | |||
| 392 | $createdRoleId = $roleService->createRole($roleCreate)->id; |
||
| 393 | |||
| 394 | $repository->rollback(); |
||
| 395 | |||
| 396 | try { |
||
| 397 | // This call will fail with a "NotFoundException" |
||
| 398 | $role = $roleService->loadRoleDraft($createdRoleId); |
||
| 399 | } catch (NotFoundException $e) { |
||
| 400 | return; |
||
| 401 | } |
||
| 402 | /* END: Use Case */ |
||
| 403 | |||
| 404 | $this->fail('Role draft object still exists after rollback.'); |
||
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Test for the loadRole() method. |
||
| 409 | * |
||
| 410 | * @see \eZ\Publish\API\Repository\RoleService::loadRole() |
||
| 411 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 412 | */ |
||
| 413 | View Code Duplication | public function testLoadRole() |
|
| 414 | { |
||
| 415 | $repository = $this->getRepository(); |
||
| 416 | |||
| 417 | /* BEGIN: Use Case */ |
||
| 418 | |||
| 419 | $roleService = $repository->getRoleService(); |
||
| 420 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 421 | |||
| 422 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 423 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 424 | |||
| 425 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 426 | $roleService->publishRoleDraft($roleDraft); |
||
| 427 | |||
| 428 | // Load the newly created role by its ID |
||
| 429 | $role = $roleService->loadRole($roleDraft->id); |
||
| 430 | |||
| 431 | /* END: Use Case */ |
||
| 432 | |||
| 433 | $this->assertEquals('roleName', $role->identifier); |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Test for the loadRoleDraft() method. |
||
| 438 | * |
||
| 439 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleDraft() |
||
| 440 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 441 | */ |
||
| 442 | View Code Duplication | public function testLoadRoleDraft() |
|
| 443 | { |
||
| 444 | $repository = $this->getRepository(); |
||
| 445 | |||
| 446 | /* BEGIN: Use Case */ |
||
| 447 | |||
| 448 | $roleService = $repository->getRoleService(); |
||
| 449 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 450 | |||
| 451 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 452 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 453 | |||
| 454 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 455 | |||
| 456 | // Load the newly created role by its ID |
||
| 457 | $role = $roleService->loadRoleDraft($roleDraft->id); |
||
| 458 | |||
| 459 | /* END: Use Case */ |
||
| 460 | |||
| 461 | $this->assertEquals('roleName', $role->identifier); |
||
| 462 | } |
||
| 463 | |||
| 464 | public function testLoadRoleDraftByRoleId() |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Test for the loadRole() method. |
||
| 492 | * |
||
| 493 | * @see \eZ\Publish\API\Repository\RoleService::loadRole() |
||
| 494 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 495 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRole |
||
| 496 | */ |
||
| 497 | View Code Duplication | public function testLoadRoleThrowsNotFoundException() |
|
| 511 | |||
| 512 | /** |
||
| 513 | * Test for the loadRoleDraft() method. |
||
| 514 | * |
||
| 515 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleDraft() |
||
| 516 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 517 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 518 | */ |
||
| 519 | View Code Duplication | public function testLoadRoleDraftThrowsNotFoundException() |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 536 | */ |
||
| 537 | View Code Duplication | public function testLoadRoleDraftByRoleIdThrowsNotFoundException() |
|
| 551 | |||
| 552 | /** |
||
| 553 | * Test for the loadRoleByIdentifier() method. |
||
| 554 | * |
||
| 555 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier() |
||
| 556 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 557 | */ |
||
| 558 | View Code Duplication | public function testLoadRoleByIdentifier() |
|
| 580 | |||
| 581 | /** |
||
| 582 | * Test for the loadRoleByIdentifier() method. |
||
| 583 | * |
||
| 584 | * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier() |
||
| 585 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 586 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 587 | */ |
||
| 588 | public function testLoadRoleByIdentifierThrowsNotFoundException() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Test for the loadRoles() method. |
||
| 604 | * |
||
| 605 | * @see \eZ\Publish\API\Repository\RoleService::loadRoles() |
||
| 606 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 607 | */ |
||
| 608 | View Code Duplication | public function testLoadRoles() |
|
| 609 | { |
||
| 610 | $repository = $this->getRepository(); |
||
| 611 | |||
| 612 | /* BEGIN: Use Case */ |
||
| 613 | |||
| 614 | // First create a custom role |
||
| 615 | $roleService = $repository->getRoleService(); |
||
| 616 | $roleCreate = $roleService->newRoleCreateStruct('roleName'); |
||
| 617 | |||
| 618 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 619 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 620 | |||
| 621 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 622 | $roleService->publishRoleDraft($roleDraft); |
||
| 623 | |||
| 624 | // Now load all available roles |
||
| 625 | $roles = $roleService->loadRoles(); |
||
| 626 | |||
| 627 | foreach ($roles as $role) { |
||
| 628 | if ($role->identifier === 'roleName') { |
||
| 629 | break; |
||
| 630 | } |
||
| 631 | } |
||
| 632 | |||
| 633 | /* END: Use Case */ |
||
| 634 | |||
| 635 | $this->assertEquals('roleName', $role->identifier); |
||
| 636 | } |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Test for the loadRoles() method. |
||
| 640 | * |
||
| 641 | * @see \eZ\Publish\API\Repository\RoleService::loadRoles() |
||
| 642 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoles |
||
| 643 | */ |
||
| 644 | public function testLoadRolesReturnsExpectedSetOfDefaultRoles() |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Test for the newRoleUpdateStruct() method. |
||
| 675 | * |
||
| 676 | * @see \eZ\Publish\API\Repository\RoleService::newRoleUpdateStruct() |
||
| 677 | */ |
||
| 678 | public function testNewRoleUpdateStruct() |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Test for the updateRole() method. |
||
| 692 | * |
||
| 693 | * @see \eZ\Publish\API\Repository\RoleService::updateRole() |
||
| 694 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct |
||
| 695 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 696 | */ |
||
| 697 | public function testUpdateRole() |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Test for the updateRoleDraft() method. |
||
| 726 | * |
||
| 727 | * @see \eZ\Publish\API\Repository\RoleService::updateRoleDraft() |
||
| 728 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct |
||
| 729 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 730 | */ |
||
| 731 | View Code Duplication | public function testUpdateRoleDraft() |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Test for the updateRole() method. |
||
| 758 | * |
||
| 759 | * @see \eZ\Publish\API\Repository\RoleService::updateRole() |
||
| 760 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 761 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRole |
||
| 762 | */ |
||
| 763 | public function testUpdateRoleThrowsInvalidArgumentException() |
||
| 764 | { |
||
| 765 | $repository = $this->getRepository(); |
||
| 766 | |||
| 767 | /* BEGIN: Use Case */ |
||
| 768 | $roleService = $repository->getRoleService(); |
||
| 769 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 770 | |||
| 771 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 772 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 773 | |||
| 774 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 775 | $roleService->publishRoleDraft($roleDraft); |
||
| 776 | $role = $roleService->loadRole($roleDraft->id); |
||
| 777 | |||
| 778 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 779 | $roleUpdate->identifier = 'Editor'; |
||
| 780 | |||
| 781 | // This call will fail with an InvalidArgumentException, because Editor is a predefined role |
||
| 782 | $roleService->updateRole($role, $roleUpdate); |
||
| 783 | /* END: Use Case */ |
||
| 784 | } |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Test for the updateRoleDraft() method. |
||
| 788 | * |
||
| 789 | * @see \eZ\Publish\API\Repository\RoleService::updateRoleDraft() |
||
| 790 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 791 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRoleDraft |
||
| 792 | */ |
||
| 793 | View Code Duplication | public function testUpdateRoleDraftThrowsInvalidArgumentException() |
|
| 794 | { |
||
| 795 | $repository = $this->getRepository(); |
||
| 796 | |||
| 797 | /* BEGIN: Use Case */ |
||
| 798 | $roleService = $repository->getRoleService(); |
||
| 799 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 800 | |||
| 801 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 802 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 803 | |||
| 804 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 805 | |||
| 806 | $roleUpdate = $roleService->newRoleUpdateStruct(); |
||
| 807 | $roleUpdate->identifier = 'Editor'; |
||
| 808 | |||
| 809 | // This call will fail with an InvalidArgumentException, because Editor is a predefined role |
||
| 810 | $roleService->updateRoleDraft($roleDraft, $roleUpdate); |
||
| 811 | /* END: Use Case */ |
||
| 812 | } |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Test for the deleteRole() method. |
||
| 816 | * |
||
| 817 | * @see \eZ\Publish\API\Repository\RoleService::deleteRole() |
||
| 818 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 819 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoles |
||
| 820 | */ |
||
| 821 | View Code Duplication | public function testDeleteRole() |
|
| 841 | |||
| 842 | /** |
||
| 843 | * Test for the deleteRoleDraft() method. |
||
| 844 | * |
||
| 845 | * @see \eZ\Publish\API\Repository\RoleService::deleteRoleDraft() |
||
| 846 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 847 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft |
||
| 848 | */ |
||
| 849 | View Code Duplication | public function testDeleteRoleDraft() |
|
| 850 | { |
||
| 851 | $repository = $this->getRepository(); |
||
| 852 | |||
| 853 | /* BEGIN: Use Case */ |
||
| 854 | $roleService = $repository->getRoleService(); |
||
| 855 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
||
| 856 | |||
| 857 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
||
| 858 | // $roleCreate->mainLanguageCode = 'eng-US'; |
||
| 859 | |||
| 860 | $roleDraft = $roleService->createRole($roleCreate); |
||
| 861 | $roleID = $roleDraft->id; |
||
| 862 | $roleService->deleteRoleDraft($roleDraft); |
||
| 863 | |||
| 864 | // This call will fail with a NotFoundException, because the draft no longer exists |
||
| 865 | $roleService->loadRoleDraft($roleID); |
||
| 866 | /* END: Use Case */ |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Test for the newPolicyCreateStruct() method. |
||
| 871 | * |
||
| 872 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyCreateStruct() |
||
| 873 | */ |
||
| 874 | public function testNewPolicyCreateStruct() |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Test for the newPolicyCreateStruct() method. |
||
| 888 | * |
||
| 889 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyCreateStruct() |
||
| 890 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 891 | */ |
||
| 892 | public function testNewPolicyCreateStructSetsStructProperties() |
||
| 906 | |||
| 907 | /** |
||
| 908 | * Test for the addPolicy() method. |
||
| 909 | * |
||
| 910 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 911 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 912 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 913 | */ |
||
| 914 | View Code Duplication | public function testAddPolicy() |
|
| 968 | |||
| 969 | /** |
||
| 970 | * Test for the addPolicyByRoleDraft() method. |
||
| 971 | * |
||
| 972 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 973 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 974 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 975 | */ |
||
| 976 | public function testAddPolicyByRoleDraft() |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Test for the addPolicy() method. |
||
| 1031 | * |
||
| 1032 | * @return array [\eZ\Publish\API\Repository\Values\User\Role, \eZ\Publish\API\Repository\Values\User\Policy] |
||
| 1033 | * |
||
| 1034 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1035 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1036 | */ |
||
| 1037 | public function testAddPolicyUpdatesRole() |
||
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Test for the addPolicyByRoleDraft() method. |
||
| 1074 | * |
||
| 1075 | * @return array [\eZ\Publish\API\Repository\Values\User\RoleDraft, \eZ\Publish\API\Repository\Values\User\Policy] |
||
| 1076 | * |
||
| 1077 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1078 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 1079 | */ |
||
| 1080 | public function testAddPolicyByRoleDraftUpdatesRole() |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Test for the addPolicy() method. |
||
| 1115 | * |
||
| 1116 | * @param array $roleAndPolicy |
||
| 1117 | * |
||
| 1118 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1119 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyUpdatesRole |
||
| 1120 | */ |
||
| 1121 | View Code Duplication | public function testAddPolicySetsPolicyProperties($roleAndPolicy) |
|
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Test for the addPolicyByRoleDraft() method. |
||
| 1133 | * |
||
| 1134 | * @param array $roleAndPolicy |
||
| 1135 | * |
||
| 1136 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1137 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraftUpdatesRole |
||
| 1138 | */ |
||
| 1139 | View Code Duplication | public function testAddPolicyByRoleDraftSetsPolicyProperties($roleAndPolicy) |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Test for the addPolicy() method. |
||
| 1151 | * |
||
| 1152 | * @see \eZ\Publish\API\Repository\RoleService::addPolicy() |
||
| 1153 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1154 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1155 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 1156 | */ |
||
| 1157 | public function testAddPolicyThrowsLimitationValidationException() |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * Test for the addPolicyByRoleDraft() method. |
||
| 1192 | * |
||
| 1193 | * @see \eZ\Publish\API\Repository\RoleService::addPolicyByRoleDraft() |
||
| 1194 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1195 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1196 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 1197 | */ |
||
| 1198 | View Code Duplication | public function testAddPolicyByRoleDraftThrowsLimitationValidationException() |
|
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Test for the createRole() method. |
||
| 1231 | * |
||
| 1232 | * @see \eZ\Publish\API\Repository\RoleService::createRole() |
||
| 1233 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyUpdatesRole |
||
| 1234 | */ |
||
| 1235 | public function testCreateRoleWithAddPolicy() |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Test for the createRoleDraft() method. |
||
| 1291 | * |
||
| 1292 | * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
||
| 1293 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraftUpdatesRole |
||
| 1294 | */ |
||
| 1295 | public function testCreateRoleDraftWithAddPolicy() |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * Test for the newPolicyUpdateStruct() method. |
||
| 1348 | * |
||
| 1349 | * @see \eZ\Publish\API\Repository\RoleService::newPolicyUpdateStruct() |
||
| 1350 | */ |
||
| 1351 | public function testNewPolicyUpdateStruct() |
||
| 1365 | |||
| 1366 | public function testUpdatePolicyNoLimitation() |
||
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Test for the updatePolicy() method. |
||
| 1414 | * |
||
| 1415 | * @return array |
||
| 1416 | * |
||
| 1417 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1418 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1419 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyUpdateStruct |
||
| 1420 | */ |
||
| 1421 | public function testUpdatePolicy() |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Test for the updatePolicy() method. |
||
| 1485 | * |
||
| 1486 | * @param array $roleAndPolicy |
||
| 1487 | * |
||
| 1488 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1489 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicy |
||
| 1490 | */ |
||
| 1491 | public function testUpdatePolicyUpdatesLimitations($roleAndPolicy) |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * Test for the updatePolicy() method. |
||
| 1511 | * |
||
| 1512 | * @param \eZ\Publish\API\Repository\Values\User\Role $role |
||
| 1513 | * |
||
| 1514 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1515 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicyUpdatesLimitations |
||
| 1516 | */ |
||
| 1517 | public function testUpdatePolicyUpdatesRole($role) |
||
| 1540 | |||
| 1541 | /** |
||
| 1542 | * Test for the updatePolicy() method. |
||
| 1543 | * |
||
| 1544 | * @see \eZ\Publish\API\Repository\RoleService::updatePolicy() |
||
| 1545 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1546 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1547 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
||
| 1548 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyUpdateStruct |
||
| 1549 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
||
| 1550 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
||
| 1551 | */ |
||
| 1552 | public function testUpdatePolicyThrowsLimitationValidationException() |
||
| 1607 | |||
| 1608 | /** |
||
| 1609 | * Test for the removePolicy() method. |
||
| 1610 | * |
||
| 1611 | * @see \eZ\Publish\API\Repository\RoleService::removePolicy() |
||
| 1612 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1613 | */ |
||
| 1614 | View Code Duplication | public function testRemovePolicy() |
|
| 1648 | |||
| 1649 | /** |
||
| 1650 | * Test for the removePolicyByRoleDraft() method. |
||
| 1651 | * |
||
| 1652 | * @see \eZ\Publish\API\Repository\RoleService::removePolicyByRoleDraft() |
||
| 1653 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 1654 | */ |
||
| 1655 | View Code Duplication | public function testRemovePolicyByRoleDraft() |
|
| 1687 | |||
| 1688 | /** |
||
| 1689 | * Test for the deletePolicy() method. |
||
| 1690 | * |
||
| 1691 | * @see \eZ\Publish\API\Repository\RoleService::deletePolicy() |
||
| 1692 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRole |
||
| 1693 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
||
| 1694 | */ |
||
| 1695 | View Code Duplication | public function testDeletePolicy() |
|
| 1730 | |||
| 1731 | /** |
||
| 1732 | * Test loading user/group role assignments. |
||
| 1733 | * |
||
| 1734 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment |
||
| 1735 | * |
||
| 1736 | * @covers \eZ\Publish\API\Repository\RoleService::loadRoleAssignment |
||
| 1737 | */ |
||
| 1738 | public function testLoadRoleAssignment() |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Test for the getRoleAssignments() method. |
||
| 1783 | * |
||
| 1784 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] |
||
| 1785 | * |
||
| 1786 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignments() |
||
| 1787 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 1788 | */ |
||
| 1789 | public function testGetRoleAssignments() |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * Test for the getRoleAssignments() method. |
||
| 1819 | * |
||
| 1820 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment[] $roleAssignments |
||
| 1821 | * |
||
| 1822 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignments() |
||
| 1823 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 1824 | */ |
||
| 1825 | public function testGetRoleAssignmentsContainExpectedLimitation(array $roleAssignments) |
||
| 1832 | |||
| 1833 | /** |
||
| 1834 | * Test for the assignRoleToUser() method. |
||
| 1835 | * |
||
| 1836 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser() |
||
| 1837 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 1838 | */ |
||
| 1839 | public function testAssignRoleToUser() |
||
| 1840 | { |
||
| 1841 | $repository = $this->getRepository(); |
||
| 1842 | $roleService = $repository->getRoleService(); |
||
| 1843 | |||
| 1844 | /* BEGIN: Use Case */ |
||
| 1845 | $user = $this->createUserVersion1(); |
||
| 1846 | |||
| 1847 | // Load the existing "Administrator" role |
||
| 1848 | $role = $roleService->loadRoleByIdentifier('Administrator'); |
||
| 1849 | |||
| 1850 | // Assign the "Administrator" role to the newly created user |
||
| 1851 | $roleService->assignRoleToUser($role, $user); |
||
| 1852 | |||
| 1853 | // The assignments array will contain the new role<->user assignment |
||
| 1854 | $roleAssignments = $roleService->getRoleAssignments($role); |
||
| 1855 | /* END: Use Case */ |
||
| 1856 | |||
| 1857 | // Administrator + Example User |
||
| 1858 | $this->assertEquals(2, count($roleAssignments)); |
||
| 1859 | } |
||
| 1860 | |||
| 1861 | /** |
||
| 1862 | * Test for the assignRoleToUser() method. |
||
| 1863 | * |
||
| 1864 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 1865 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 1866 | */ |
||
| 1867 | View Code Duplication | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1965 | |||
| 1966 | /** |
||
| 1967 | * Test for the assignRoleToUser() method. |
||
| 1968 | * |
||
| 1969 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 1970 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 1971 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 1972 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 1973 | */ |
||
| 1974 | public function testAssignRoleToUserWithRoleLimitationThrowsLimitationValidationException() |
||
| 2001 | |||
| 2002 | /** |
||
| 2003 | * Test for the assignRoleToUser() method. |
||
| 2004 | * |
||
| 2005 | * Makes sure assigning role several times throws. |
||
| 2006 | * |
||
| 2007 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 2008 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2009 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2010 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2011 | */ |
||
| 2012 | public function testAssignRoleToUserThrowsInvalidArgumentException() |
||
| 2013 | { |
||
| 2014 | $repository = $this->getRepository(); |
||
| 2015 | |||
| 2016 | /* BEGIN: Use Case */ |
||
| 2017 | $roleService = $repository->getRoleService(); |
||
| 2018 | |||
| 2019 | // Load the existing "Anonymous" role |
||
| 2020 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
||
| 2021 | |||
| 2022 | // Get current user |
||
| 2023 | $currentUser = $repository->getCurrentUser(); |
||
| 2024 | |||
| 2025 | // Assign the "Anonymous" role to the current user |
||
| 2026 | try { |
||
| 2027 | $roleService->assignRoleToUser( |
||
| 2028 | $role, |
||
| 2029 | $currentUser |
||
| 2030 | ); |
||
| 2031 | } catch (Exception $e) { |
||
| 2032 | $this->fail('Got exception at first valid attempt to assign role'); |
||
| 2033 | } |
||
| 2034 | |||
| 2035 | // Re-Assign the "Anonymous" role to the current user |
||
| 2036 | // This call will fail with an InvalidArgumentException, because limitation is already assigned |
||
| 2037 | $roleService->assignRoleToUser( |
||
| 2038 | $role, |
||
| 2039 | $currentUser |
||
| 2040 | ); |
||
| 2041 | /* END: Use Case */ |
||
| 2042 | } |
||
| 2043 | |||
| 2044 | /** |
||
| 2045 | * Test for the assignRoleToUser() method. |
||
| 2046 | * |
||
| 2047 | * Makes sure assigning role several times with same limitations throws. |
||
| 2048 | * |
||
| 2049 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
||
| 2050 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2051 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2052 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2053 | */ |
||
| 2054 | public function testAssignRoleToUserWithRoleLimitationThrowsInvalidArgumentException() |
||
| 2095 | |||
| 2096 | /** |
||
| 2097 | * Test for the unassignRoleFromUser() method. |
||
| 2098 | * |
||
| 2099 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser() |
||
| 2100 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2101 | */ |
||
| 2102 | View Code Duplication | public function testUnassignRoleFromUser() |
|
| 2126 | |||
| 2127 | /** |
||
| 2128 | * Test for the unassignRoleFromUser() method. |
||
| 2129 | * |
||
| 2130 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUser() |
||
| 2131 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2132 | */ |
||
| 2133 | View Code Duplication | public function testUnassignRoleFromUserThrowsInvalidArgumentException() |
|
| 2149 | |||
| 2150 | /** |
||
| 2151 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2152 | * |
||
| 2153 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2154 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2155 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2156 | */ |
||
| 2157 | View Code Duplication | public function testGetRoleAssignmentsForUserDirect() |
|
| 2199 | |||
| 2200 | /** |
||
| 2201 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2202 | * |
||
| 2203 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2204 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2205 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2206 | */ |
||
| 2207 | public function testGetRoleAssignmentsForUserEmpty() |
||
| 2221 | |||
| 2222 | /** |
||
| 2223 | * Test for the getRoleAssignmentsForUser() method. |
||
| 2224 | * |
||
| 2225 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser() |
||
| 2226 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2227 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2228 | */ |
||
| 2229 | public function testGetRoleAssignmentsForUserInherited() |
||
| 2247 | |||
| 2248 | /** |
||
| 2249 | * Test for the assignRoleToUserGroup() method. |
||
| 2250 | * |
||
| 2251 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
||
| 2252 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
||
| 2253 | */ |
||
| 2254 | public function testAssignRoleToUserGroup() |
||
| 2255 | { |
||
| 2256 | $repository = $this->getRepository(); |
||
| 2257 | $roleService = $repository->getRoleService(); |
||
| 2258 | |||
| 2259 | /* BEGIN: Use Case */ |
||
| 2260 | $userGroup = $this->createUserGroupVersion1(); |
||
| 2261 | |||
| 2262 | // Load the existing "Administrator" role |
||
| 2263 | $role = $roleService->loadRoleByIdentifier('Administrator'); |
||
| 2264 | |||
| 2265 | // Assign the "Administrator" role to the newly created user group |
||
| 2266 | $roleService->assignRoleToUserGroup($role, $userGroup); |
||
| 2267 | |||
| 2268 | // The assignments array will contain the new role<->group assignment |
||
| 2269 | $roleAssignments = $roleService->getRoleAssignments($role); |
||
| 2270 | /* END: Use Case */ |
||
| 2271 | |||
| 2272 | // Administrator + Example Group |
||
| 2273 | $this->assertEquals(2, count($roleAssignments)); |
||
| 2274 | } |
||
| 2275 | |||
| 2276 | /** |
||
| 2277 | * Test for the assignRoleToUserGroup() method. |
||
| 2278 | * |
||
| 2279 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2280 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2281 | */ |
||
| 2282 | View Code Duplication | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2376 | |||
| 2377 | /** |
||
| 2378 | * Test for the assignRoleToUserGroup() method. |
||
| 2379 | * |
||
| 2380 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2381 | * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException |
||
| 2382 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2383 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2384 | */ |
||
| 2385 | public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException() |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Test for the assignRoleToUserGroup() method. |
||
| 2418 | * |
||
| 2419 | * Makes sure assigning role several times throws. |
||
| 2420 | * |
||
| 2421 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2422 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2423 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2424 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2425 | */ |
||
| 2426 | View Code Duplication | public function testAssignRoleToUserGroupThrowsInvalidArgumentException() |
|
| 2427 | { |
||
| 2428 | $repository = $this->getRepository(); |
||
| 2429 | |||
| 2430 | $mainGroupId = $this->generateId('group', 4); |
||
| 2431 | /* BEGIN: Use Case */ |
||
| 2432 | // $mainGroupId is the ID of the main "Users" group |
||
| 2433 | |||
| 2434 | $userService = $repository->getUserService(); |
||
| 2435 | $roleService = $repository->getRoleService(); |
||
| 2436 | |||
| 2437 | $userGroup = $userService->loadUserGroup($mainGroupId); |
||
| 2438 | |||
| 2439 | // Load the existing "Anonymous" role |
||
| 2440 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
||
| 2441 | |||
| 2442 | // Assign the "Anonymous" role to the newly created user group |
||
| 2443 | try { |
||
| 2444 | $roleService->assignRoleToUserGroup( |
||
| 2445 | $role, |
||
| 2446 | $userGroup |
||
| 2447 | ); |
||
| 2448 | } catch (Exception $e) { |
||
| 2449 | $this->fail('Got exception at first valid attempt to assign role'); |
||
| 2450 | } |
||
| 2451 | |||
| 2452 | // Re-Assign the "Anonymous" role to the newly created user group |
||
| 2453 | // This call will fail with an InvalidArgumentException, because role is already assigned |
||
| 2454 | $roleService->assignRoleToUserGroup( |
||
| 2455 | $role, |
||
| 2456 | $userGroup |
||
| 2457 | ); |
||
| 2458 | /* END: Use Case */ |
||
| 2459 | } |
||
| 2460 | |||
| 2461 | /** |
||
| 2462 | * Test for the assignRoleToUserGroup() method. |
||
| 2463 | * |
||
| 2464 | * Makes sure assigning role several times with same limitations throws. |
||
| 2465 | * |
||
| 2466 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
||
| 2467 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2468 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
||
| 2469 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2470 | */ |
||
| 2471 | public function testAssignRoleToUserGroupWithRoleLimitationThrowsInvalidArgumentException() |
||
| 2515 | |||
| 2516 | /** |
||
| 2517 | * Test for the unassignRoleFromUserGroup() method. |
||
| 2518 | * |
||
| 2519 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup() |
||
| 2520 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2521 | */ |
||
| 2522 | View Code Duplication | public function testUnassignRoleFromUserGroup() |
|
| 2546 | |||
| 2547 | /** |
||
| 2548 | * Test for the unassignRoleFromUserGroup() method. |
||
| 2549 | * |
||
| 2550 | * @see \eZ\Publish\API\Repository\RoleService::unassignRoleFromUserGroup() |
||
| 2551 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2552 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUnassignRoleFromUserGroup |
||
| 2553 | */ |
||
| 2554 | View Code Duplication | public function testUnassignRoleFromUserGroupThrowsInvalidArgumentException() |
|
| 2570 | |||
| 2571 | /** |
||
| 2572 | * Test unassigning role by assignment. |
||
| 2573 | * |
||
| 2574 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2575 | */ |
||
| 2576 | public function testUnassignRoleByAssignment() |
||
| 2595 | |||
| 2596 | /** |
||
| 2597 | * Test unassigning role by assignment. |
||
| 2598 | * |
||
| 2599 | * But on current admin user so he lacks access to read roles. |
||
| 2600 | * |
||
| 2601 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2602 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2603 | */ |
||
| 2604 | View Code Duplication | public function testUnassignRoleByAssignmentThrowsUnauthorizedException() |
|
| 2621 | |||
| 2622 | /** |
||
| 2623 | * Test unassigning role by non-existing assignment. |
||
| 2624 | * |
||
| 2625 | * @covers \eZ\Publish\API\Repository\RoleService::removeRoleAssignment |
||
| 2626 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2627 | */ |
||
| 2628 | View Code Duplication | public function testUnassignRoleByAssignmentThrowsNotFoundException() |
|
| 2645 | |||
| 2646 | /** |
||
| 2647 | * Test for the getRoleAssignmentsForUserGroup() method. |
||
| 2648 | * |
||
| 2649 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUserGroup() |
||
| 2650 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2651 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
||
| 2652 | */ |
||
| 2653 | View Code Duplication | public function testGetRoleAssignmentsForUserGroup() |
|
| 2695 | |||
| 2696 | /** |
||
| 2697 | * Test for the loadPoliciesByUserId() method. |
||
| 2698 | * |
||
| 2699 | * @see \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId() |
||
| 2700 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
||
| 2701 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
||
| 2702 | */ |
||
| 2703 | public function testLoadPoliciesByUserId() |
||
| 2766 | |||
| 2767 | /** |
||
| 2768 | * Test for the loadPoliciesByUserId() method. |
||
| 2769 | * |
||
| 2770 | * @see \eZ\Publish\API\Repository\RoleService::loadPoliciesByUserId() |
||
| 2771 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2772 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadPoliciesByUserId |
||
| 2773 | */ |
||
| 2774 | public function testLoadPoliciesByUserIdThrowsNotFoundException() |
||
| 2787 | |||
| 2788 | /** |
||
| 2789 | * Test for the publishRoleDraft() method. |
||
| 2790 | * |
||
| 2791 | * @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft() |
||
| 2792 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 2793 | */ |
||
| 2794 | View Code Duplication | public function testPublishRoleDraft() |
|
| 2824 | |||
| 2825 | /** |
||
| 2826 | * Test for the publishRoleDraft() method. |
||
| 2827 | * |
||
| 2828 | * @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft() |
||
| 2829 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
||
| 2830 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
||
| 2831 | */ |
||
| 2832 | View Code Duplication | public function testPublishRoleDraftAddPolicies() |
|
| 2886 | |||
| 2887 | /** |
||
| 2888 | * Create a user group fixture in a variable named <b>$userGroup</b>,. |
||
| 2889 | * |
||
| 2890 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
| 2891 | */ |
||
| 2892 | View Code Duplication | private function createUserGroupVersion1() |
|
| 2893 | { |
||
| 2894 | $repository = $this->getRepository(); |
||
| 2895 | |||
| 2896 | $mainGroupId = $this->generateId('group', 4); |
||
| 2897 | /* BEGIN: Inline */ |
||
| 2898 | // $mainGroupId is the ID of the main "Users" group |
||
| 2919 | } |
||
| 2920 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.