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]; }
public function testPermissions() { $p1 = Permission::create("test_1", "", 1); $p2 = Permission::create("test_2", "", 2); $p3 = Permission::create("test_3", "", 3); $p4 = Permission::create("test_4", "", 4); $r1 = Role::create("role_1", "", [$p1, $p2]); $r2 = Role::create("role_2", "", [$p1, $p2, $p4]); $role_set = new RoleSet([$r1, $r2]); $permissions = $role_set->getPermissions(); $this->assertEquals(3, sizeof($permissions)); }
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); }