public function testHasPermission() { $admin_read = new Permission(); $admin_read->permission_id = 1; $admin_read->name = "admin_read"; $role_set = new RoleSet([Role::create("role_a")]); $role_b = Role::create("role_b"); $role_b->addPermission($admin_read); $role_set->addRole($role_b); $this->assertTrue($role_set->has_permission("admin_read")); $this->assertFalse($role_set->has_permission("bs_perm")); }
function setup_role_manager_mocks(Permission $permission, Role $role, RoleSet $role_set, RoleManager $role_manager) { $permission->permission_id = 1; $permission->name = 'Permission Name'; $permission->description = 'A dummy permission'; $role->role_id = 1; $role->name = 'members'; $role->description = 'A dummy role'; $role->hasPermission(Argument::type('RBAC\\Permission'))->willReturn(true); $role->getPermissions()->willReturn(array($permission)); $role->addPermission(Argument::any())->willReturn(true); $role_set->addRole(Argument::type('RBAC\\Role\\Role'))->willReturn(true); $role_set->has_permission('Permission Name')->willReturn(true); $role_manager->roleFetchByName('members')->willReturn($role); $role_manager->roleFetch()->willReturn(array($role)); $role_manager->roleSave(Argument::any())->willReturn(true); $role_manager->permissionFetch()->willReturn(array($permission)); //assigns a role set object to the UserAccount object $role_manager->loadSubjectRoles(Argument::type('PolyAuth\\UserAccount'))->will(function ($args) use($role_set) { $user = $args[0]; $user->loadRoleSet($role_set); return $user; }); //adds a role to the role set of the role object $role_manager->roleAddSubject(Argument::cetera())->will(function ($args) { $role = $args[0]; $user = $args[1]; $role_set = $user->getRoleSet(); $role_set->addRole($role); $user->loadRoleSet($role_set); return $user; }); return ['role_manager' => $role_manager]; }
function let(RoleSet $role_set, Role $role, Permission $permission) { //fixtures $subject_id = 1; $permission->permission_id = 1; $permission->name = 'admin_view'; $permission->description = 'Admin View Permission'; //collaborator stubbing/mocking $permission->__toString()->willReturn($permission->name); $role_set->getRoles()->willReturn(array($role)); $role_set->getPermissions()->willReturn(array($permission)); $role_set->has_permission($permission)->willReturn(true); $this->beConstructedWith($subject_id, $role_set); }