Ejemplo n.º 1
0
 /**
  * @magentoDataFixture roleDataFixture
  */
 public function testGetRole()
 {
     $this->_model->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
     $role = $this->_model->getRole();
     $this->assertInstanceOf('Magento\\User\\Model\\Role', $role);
     $this->assertEquals(1, $role->getId());
     $this->_model->setRoleId(self::$_newRole->getId())->save();
     $role = $this->_model->getRole();
     $this->assertEquals(self::$_newRole->getId(), $role->getId());
 }
Ejemplo n.º 2
0
 /**
  * Get admin role model
  *
  * @return \Magento\User\Model\Role
  */
 public function getRole()
 {
     if (null === $this->_role) {
         $this->_role = $this->_roleFactory->create();
         $roles = $this->getRoles();
         if ($roles && isset($roles[0]) && $roles[0]) {
             $this->_role->load($roles[0]);
         }
     }
     return $this->_role;
 }
Ejemplo n.º 3
0
 /**
  * Associate resources with the specified role. All resources previously assigned to the role will be unassigned.
  *
  * @param Role $role
  * @param string[] $resources
  * @return void
  * @throws \LogicException
  */
 protected function _associateResourcesWithRole($role, array $resources)
 {
     /** @var \Magento\User\Model\Rules $rules */
     $rules = $this->_rulesFactory->create();
     $rules->setRoleId($role->getId())->setResources($resources)->saveRel();
 }
Ejemplo n.º 4
0
 /**
  * Get role users
  *
  * @param \Magento\User\Model\Role $role
  * @return array
  */
 public function getRoleUsers(\Magento\User\Model\Role $role)
 {
     $read = $this->_getReadAdapter();
     $binds = array('role_id' => $role->getId(), 'role_type' => RoleUser::ROLE_TYPE);
     $select = $read->select()->from($this->getMainTable(), array('user_id'))->where('parent_id = :role_id')->where('role_type = :role_type')->where('user_id > 0');
     return $read->fetchCol($select, $binds);
 }
Ejemplo n.º 5
0
 public function testGetRoleUsers()
 {
     $this->assertEmpty($this->_model->getRoleUsers());
     $this->_model->load(\Magento\TestFramework\Bootstrap::ADMIN_ROLE_NAME, 'role_name');
     $this->assertNotEmpty($this->_model->getRoleUsers());
 }