Esempio n. 1
0
 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 testloadSubjectRoles()
 {
     $admin = new Subject(1);
     $this->assertEquals(0, sizeof($admin->getRoleSet()->getRoles()));
     $this->rm->loadSubjectRoles($admin);
     $this->assertEquals(1, sizeof($admin->getRoleSet()->getRoles()));
 }