/** * Ensure that an exception is not thrown, if the user does not exist */ public function testLoadByUsername() { $this->_model->loadByUsername('non_existing_user'); $this->assertNull($this->_model->getId(), 'The admin user has an unexpected ID'); $this->_model->loadByUsername(Magento_Test_Bootstrap::ADMIN_NAME); $this->assertNotEmpty($this->_model->getId(), 'The admin user should have been loaded'); }
public function testSetUserFilter() { $user = new Mage_User_Model_User(); $user->loadByUsername(Magento_Test_Bootstrap::ADMIN_NAME); $this->_collection->setUserFilter($user->getId()); $selectQueryStr = $this->_collection->getSelect()->__toString(); $this->assertContains('user_id', $selectQueryStr); $this->assertContains('role_type', $selectQueryStr); }
/** * Check is user logged in and permissions * * @param Mage_User_Model_User|null $user * @return bool */ protected function _checkUserAccess($user = null) { if ($user && !$user->getId()) { $this->addMessage('error', 'Invalid user name or password'); $this->controller()->setAction('login'); } elseif ($this->getUserId() || $user && $user->getId()) { if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::all')) { return true; } else { $this->logout(); $this->addMessage('error', 'Access Denied', true); $this->controller()->setAction('login'); } } return false; }
/** * Creates predefined admin user to be used by tests, where admin session is required */ protected function _createAdminUser() { $user = new Mage_User_Model_User(); $user->setData(array('firstname' => 'firstname', 'lastname' => 'lastname', 'email' => '*****@*****.**', 'username' => self::ADMIN_NAME, 'password' => self::ADMIN_PASSWORD, 'is_active' => 1)); $user->save(); $roleAdmin = new Mage_User_Model_Role(); $roleAdmin->load(self::ADMIN_ROLE_NAME, 'role_name'); $roleUser = new Mage_User_Model_Role(); $roleUser->setData(array('parent_id' => $roleAdmin->getId(), 'tree_level' => $roleAdmin->getTreeLevel() + 1, 'role_type' => Mage_User_Model_Acl_Role_User::ROLE_TYPE, 'user_id' => $user->getId(), 'role_name' => $user->getFirstname())); $roleUser->save(); }
/** * Create role for provided user of provided type * * @param $parentId * @param Mage_User_Model_User $user */ protected function _createUserRole($parentId, Mage_User_Model_User $user) { if ($parentId > 0) { $parentRole = Mage::getModel('Mage_User_Model_Role')->load($parentId); } else { $role = new Varien_Object(); $role->setTreeLevel(0); } if ($parentRole->getId()) { $data = new Varien_Object(array('parent_id' => $parentRole->getId(), 'tree_level' => $parentRole->getTreeLevel() + 1, 'sort_order' => 0, 'role_type' => 'U', 'user_id' => $user->getId(), 'role_name' => $user->getFirstname())); $insertData = $this->_prepareDataForTable($data, $this->getTable('admin_role')); $this->_getWriteAdapter()->insert($this->getTable('admin_role'), $insertData); } }