public function testSetRoleAccess() { $role = new Role(); $role->setName("admin"); $role->setACL(new ACL()); $acl = new ACL(); $acl->setRoleReadAccess($role, true); $out = $acl->encode(); $this->assertEquals(true, $out["role:admin"]["read"]); $this->assertEquals(true, $acl->getRoleReadAccess($role)); $acl->setRoleWriteAccess($role, false); $out = $acl->encode(); $this->assertEquals(false, $out["role:admin"]["write"]); $this->assertEquals(false, $acl->getRoleWriteAccess($role)); }
public function testSaveRole() { $role = new Role(); $role->setName("admin"); $acl = new ACL(); $acl->setPublicWriteAccess(true); // so it can be destroyed $role->setACL($acl); $role->save(); $this->assertNotEmpty($role->getObjectId()); $this->assertTrue($role->getUsers() instanceof Relation); $this->assertTrue($role->getRoles() instanceof Relation); $role->destroy(); }
/** * Initialize application key and settings * * @param string $appId Application ID * @param string $appKey Application key * @param string $appMasterKey Application master key */ public static function initialize($appId, $appKey, $appMasterKey) { self::$appId = $appId; self::$appKey = $appKey; self::$appMasterKey = $appMasterKey; self::$defaultHeaders = array('X-LC-Id' => self::$appId, 'Content-Type' => 'application/json;charset=utf-8', 'User-Agent' => self::getVersionString()); // Use session storage by default if (!self::$storage) { self::$storage = new SessionStorage(); } User::registerClass(); Role::registerClass(); }
public function testGetRoles() { $user = new User(); $user->setUsername("alice3"); $user->setPassword("blabla"); $user->signUp(); $role = new Role(); $role->setName("test_role"); $acl = new ACL(); $acl->setPublicWriteAccess(true); $acl->setPublicReadAccess(true); $role->setACL($acl); $rel = $role->getUsers(); $rel->add($user); $role->save(); $this->assertNotEmpty($role->getObjectId()); $roles = $user->getRoles(); $this->assertEquals("test_role", $roles[0]->getName()); $user->destroy(); $role->destroy(); }