|
@@ 754-814 (lines=61) @@
|
| 751 |
|
* @covers \eZ\Publish\Core\Repository\RoleService::assignRoleToUserGroup |
| 752 |
|
* @covers \eZ\Publish\Core\Repository\Helper\LimitationService::validateLimitation |
| 753 |
|
*/ |
| 754 |
|
public function testAssignRoleToUserGroupWithNullLimitation() |
| 755 |
|
{ |
| 756 |
|
$repository = $this->getRepositoryMock(); |
| 757 |
|
$roleServiceMock = $this->getPartlyMockedRoleService(['checkAssignmentAndFilterLimitationValues']); |
| 758 |
|
$roleMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\Role'); |
| 759 |
|
$userGroupMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup'); |
| 760 |
|
$userServiceMock = $this->getMock('eZ\\Publish\\API\\Repository\\UserService'); |
| 761 |
|
$userHandlerMock = $this->getPersistenceMockHandler('User\\Handler'); |
| 762 |
|
|
| 763 |
|
$repository->expects($this->once()) |
| 764 |
|
->method('getUserService') |
| 765 |
|
->will($this->returnValue($userServiceMock)); |
| 766 |
|
$userGroupMock->expects($this->any()) |
| 767 |
|
->method('__get') |
| 768 |
|
->with('id') |
| 769 |
|
->will($this->returnValue(24)); |
| 770 |
|
|
| 771 |
|
$repository->expects($this->once()) |
| 772 |
|
->method('canUser') |
| 773 |
|
->with( |
| 774 |
|
$this->equalTo('role'), |
| 775 |
|
$this->equalTo('assign'), |
| 776 |
|
$this->equalTo($userGroupMock), |
| 777 |
|
$this->equalTo($roleMock) |
| 778 |
|
)->will($this->returnValue(true)); |
| 779 |
|
|
| 780 |
|
$roleMock->expects($this->any()) |
| 781 |
|
->method('__get') |
| 782 |
|
->with('id') |
| 783 |
|
->will($this->returnValue(42)); |
| 784 |
|
|
| 785 |
|
$userHandlerMock->expects($this->once()) |
| 786 |
|
->method('loadRole') |
| 787 |
|
->with($this->equalTo(42)) |
| 788 |
|
->will($this->returnValue(new SPIRole(['id' => 42]))); |
| 789 |
|
|
| 790 |
|
$userServiceMock->expects($this->once()) |
| 791 |
|
->method('loadUserGroup') |
| 792 |
|
->with($this->equalTo(24)) |
| 793 |
|
->will($this->returnValue($userGroupMock)); |
| 794 |
|
|
| 795 |
|
$roleServiceMock->expects($this->once()) |
| 796 |
|
->method('checkAssignmentAndFilterLimitationValues') |
| 797 |
|
->with(24, $this->isInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\Role'), null) |
| 798 |
|
->will($this->returnValue(null)); |
| 799 |
|
|
| 800 |
|
$repository->expects($this->once())->method('beginTransaction'); |
| 801 |
|
$userHandlerMock = $this->getPersistenceMockHandler('User\\Handler'); |
| 802 |
|
$userHandlerMock->expects($this->once()) |
| 803 |
|
->method('assignRole') |
| 804 |
|
->with( |
| 805 |
|
$this->equalTo(24), |
| 806 |
|
$this->equalTo(42), |
| 807 |
|
$this->equalTo(null) |
| 808 |
|
); |
| 809 |
|
$repository->expects($this->once())->method('commit'); |
| 810 |
|
|
| 811 |
|
/* @var \eZ\Publish\API\Repository\Values\User\Role $roleMock */ |
| 812 |
|
/* @var \eZ\Publish\API\Repository\Values\User\UserGroup $userGroupMock */ |
| 813 |
|
$roleServiceMock->assignRoleToUserGroup($roleMock, $userGroupMock, null); |
| 814 |
|
} |
| 815 |
|
|
| 816 |
|
/** |
| 817 |
|
* Test for the assignRoleToUserGroup() method. |
|
@@ 823-883 (lines=61) @@
|
| 820 |
|
* @covers \eZ\Publish\Core\Repository\Helper\LimitationService::validateLimitation |
| 821 |
|
* @expectedException \Exception |
| 822 |
|
*/ |
| 823 |
|
public function testAssignRoleToUserGroupWithRollback() |
| 824 |
|
{ |
| 825 |
|
$repository = $this->getRepositoryMock(); |
| 826 |
|
$roleServiceMock = $this->getPartlyMockedRoleService(['checkAssignmentAndFilterLimitationValues']); |
| 827 |
|
$roleMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\Role'); |
| 828 |
|
$userGroupMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup'); |
| 829 |
|
$userServiceMock = $this->getMock('eZ\\Publish\\API\\Repository\\UserService'); |
| 830 |
|
$userHandlerMock = $this->getPersistenceMockHandler('User\\Handler'); |
| 831 |
|
|
| 832 |
|
$repository->expects($this->once()) |
| 833 |
|
->method('getUserService') |
| 834 |
|
->will($this->returnValue($userServiceMock)); |
| 835 |
|
$userGroupMock->expects($this->any()) |
| 836 |
|
->method('__get') |
| 837 |
|
->with('id') |
| 838 |
|
->will($this->returnValue(24)); |
| 839 |
|
|
| 840 |
|
$repository->expects($this->once()) |
| 841 |
|
->method('canUser') |
| 842 |
|
->with( |
| 843 |
|
$this->equalTo('role'), |
| 844 |
|
$this->equalTo('assign'), |
| 845 |
|
$this->equalTo($userGroupMock), |
| 846 |
|
$this->equalTo($roleMock) |
| 847 |
|
)->will($this->returnValue(true)); |
| 848 |
|
|
| 849 |
|
$roleMock->expects($this->any()) |
| 850 |
|
->method('__get') |
| 851 |
|
->with('id') |
| 852 |
|
->will($this->returnValue(42)); |
| 853 |
|
|
| 854 |
|
$userHandlerMock->expects($this->once()) |
| 855 |
|
->method('loadRole') |
| 856 |
|
->with($this->equalTo(42)) |
| 857 |
|
->will($this->returnValue(new SPIRole(['id' => 42]))); |
| 858 |
|
|
| 859 |
|
$userServiceMock->expects($this->once()) |
| 860 |
|
->method('loadUserGroup') |
| 861 |
|
->with($this->equalTo(24)) |
| 862 |
|
->will($this->returnValue($userGroupMock)); |
| 863 |
|
|
| 864 |
|
$roleServiceMock->expects($this->once()) |
| 865 |
|
->method('checkAssignmentAndFilterLimitationValues') |
| 866 |
|
->with(24, $this->isInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\Role'), null) |
| 867 |
|
->will($this->returnValue(null)); |
| 868 |
|
|
| 869 |
|
$repository->expects($this->once())->method('beginTransaction'); |
| 870 |
|
$userHandlerMock = $this->getPersistenceMockHandler('User\\Handler'); |
| 871 |
|
$userHandlerMock->expects($this->once()) |
| 872 |
|
->method('assignRole') |
| 873 |
|
->with( |
| 874 |
|
$this->equalTo(24), |
| 875 |
|
$this->equalTo(42), |
| 876 |
|
$this->equalTo(null) |
| 877 |
|
)->will($this->throwException(new \Exception())); |
| 878 |
|
$repository->expects($this->once())->method('rollback'); |
| 879 |
|
|
| 880 |
|
/* @var \eZ\Publish\API\Repository\Values\User\Role $roleMock */ |
| 881 |
|
/* @var \eZ\Publish\API\Repository\Values\User\UserGroup $userGroupMock */ |
| 882 |
|
$roleServiceMock->assignRoleToUserGroup($roleMock, $userGroupMock, null); |
| 883 |
|
} |
| 884 |
|
|
| 885 |
|
/** |
| 886 |
|
* Test for the deletePolicy() method. |