/** * Tests if getFrom returns correct value. * */ public function testGetFromReturnsCorrectPermission() { $grantedResource = $this->getMockBuilder('\\Core\\Entity\\PermissionsResourceInterface')->getMockForAbstractClass(); $grantedResource->expects($this->atLeastOnce())->method('getPermissionsUserIds')->will($this->onConsecutiveCalls(array('all' => array('user1', 'user2'), 'view' => array('popel', 'dopel')), array('all' => array('user3')))); $grantedResource->method('getPermissionsResourceId')->willReturn('grantResource'); $ungrantedResource = $this->getMockBuilder('\\Core\\Entity\\PermissionsResourceInterface')->getMockForAbstractClass(); $ungrantedResource->method('getPermissionsResourceId')->willReturn('ungrant'); $target = new Permissions(); $target->grant($grantedResource, PermissionsInterface::PERMISSION_ALL); $this->assertEquals(PermissionsInterface::PERMISSION_NONE, $target->getFrom($ungrantedResource)); $this->assertEquals(null, $target->getFrom($grantedResource)); $target->grant($grantedResource, PermissionsInterface::PERMISSION_CHANGE); $this->assertEquals(PermissionsInterface::PERMISSION_ALL, $target->getFrom($grantedResource)); }
/** * {@inheritDoc} * @see \Core\Entity\PermissionsAwareInterface::getPermissions() */ public function getPermissions() { if (!$this->permissions) { $permissions = new Permissions('Application'); if ($this->user) { $permissions->grant($this->user, Permissions::PERMISSION_ALL); } $this->setPermissions($permissions); } return $this->permissions; }
public function getPermissions() { if (!$this->permissions) { $perms = new Permissions(); if ($this->user instanceof UserInterface) { $perms->grant($this->user, PermissionsInterface::PERMISSION_ALL); } $this->setPermissions($perms); } return $this->permissions; }