public function setup() { $this->target = new Organization(); $owner = new User(); $employee1 = new Employee(new User(), EmployeePermissionsInterface::APPLICATIONS_CHANGE); $employee2 = new Employee(new User(), EmployeePermissionsInterface::APPLICATIONS_CHANGE); $employees = new \Doctrine\Common\Collections\ArrayCollection([$employee1, $employee2]); $this->target->setEmployees($employees); }
public function testUserIsEmployeeWithJobsChangePermissions() { $userId = 1234; $user = new User(); $user->setId($userId); $organization = new Organization(); $permissionsMock = $this->getMockBuilder('Core\\Entity\\Permissions')->setMethods(['isGranted', 'isAllowed'])->getMock(); $permissionsMock->expects($this->once())->method('isGranted')->willReturn(false); $permissionsMock->expects($this->once())->method('isAllowed')->with(EmployeePermissionsInterface::JOBS_CHANGE)->willReturn(true); $employeeMock = $this->getMockBuilder('Organizations\\Entity\\Employee')->setMethods(['getPermissions', 'getUser'])->getMock(); $employeeMock->expects($this->once())->method('getPermissions')->willReturn($permissionsMock); $employeeMock->expects($this->once())->method('getUser')->willReturn($user); $employees = new ArrayCollection(); $employees->add($employeeMock); $organization->setEmployees($employees); $jobMock = $this->getMockBuilder('Jobs\\Entity\\Job')->setMethods(['getPermissions', 'getOrganization'])->getMock(); $jobMock->expects($this->once())->method('getPermissions')->willReturn($permissionsMock); $jobMock->expects($this->once())->method('getOrganization')->willReturn($organization); $this->assertTrue($this->target->assert(new Acl(), $user, $jobMock, 'edit')); }