Exemple #1
0
 function it_should_register_roles_and_permissions(RoleManager $role_manager, Role $role)
 {
     $role_manager->roleFetchByName('members')->will(function () use($role) {
         $this->roleFetchByName('members')->willReturn($role);
         return false;
     });
     $role_manager->permissionDelete(Argument::any())->willReturn(true);
     $role_manager->permissionSave(Argument::any())->will(function ($args) {
         //add a permission id to the permission object
         $args[0]->permission_id = 1;
         return true;
     });
     $this->register_role('members', 'This is the role description')->shouldBeAnInstanceOf('RBAC\\Role\\Role');
     $roles = $this->register_roles(array('members' => 'role description'));
     $roles->shouldBeArray();
     $roles = $this->register_roles(array('members', 'members'));
     $roles->shouldBeArray();
     $roles = $this->register_roles_permissions(array('members' => array('desc' => 'This is an awesome role', 'perms' => array('Permission Name' => 'This is a dummy permission'))));
     $roles->shouldBeArray();
     $roles[0]->shouldBeAnInstanceOf('RBAC\\Role\\Role');
 }
 protected function seed()
 {
     $default_users = array(array('id' => '1', 'ipAddress' => inet_pton('127.0.0.1'), 'username' => 'administrator', 'password' => '$2y$10$EiqipvSt3lnD//nchj4u9OgOTL9R3J4AbZ5bUVVrh.Tq/gmc5xIvS', 'passwordChange' => '0', 'email' => '*****@*****.**', 'createdOn' => date('Y-m-d H:i:s'), 'lastLogin' => date('Y-m-d H:i:s'), 'active' => '1', 'sharedKey' => '9tThG2rFhZv+LslrrPy0I6QcCn9E3kNcyv5rqb3qKLywvFCfwHiSZ2fH2qQAgQXAkfBIrd0zHP+1v/FJ4W/kMA=='));
     //default user to roles
     $default_users_to_roles = array(array('admin', 'member'));
     //roles to descriptions
     $default_roles = array('admin' => 'Site Administrators', 'member' => 'General Members');
     //roles to permissions to permission descriptions
     $default_role_permissions = array('admin' => array('admin_create' => 'Creating administration resources.', 'admin_read' => 'Viewing administration resources.', 'admin_update' => 'Editing administration resources.', 'admin_delete' => 'Deleting administration resources.'), 'member' => array('public_read' => 'Viewing public resources.'));
     //seeding user accounts
     foreach ($default_users as $user) {
         $this->db->insert('user_accounts', $user);
     }
     //seeding roles and permissions
     $role_manager = new RoleManager(new MySQLAdapter($this->db->conn_id, new Options()));
     foreach ($default_role_permissions as $role => $permissions_array) {
         //create the role
         $created_role = Role::create($role, $default_roles[$role]);
         foreach ($permissions_array as $permission => $reason) {
             //create the permission
             $created_permission = Permission::create($permission, $reason);
             //save the permission to the database
             $role_manager->permissionSave($created_permission);
             //add the permission to the role
             $created_role->addPermission($created_permission);
         }
         $role_manager->roleSave($created_role);
     }
     //assign the role to the users
     foreach ($default_users_to_roles as $key => $roles) {
         $user_id = $default_users[$key]['id'];
         foreach ($roles as $role) {
             $assignable_role = $role_manager->roleFetchByName($role);
             $role_manager->roleAddSubjectId($assignable_role, $user_id);
         }
     }
 }
 public function testRoleFetchByName()
 {
     $name = "admin";
     $admin = $this->rm->roleFetchByName($name);
     $this->assertEquals($name, $admin->name);
 }