예제 #1
0
 /**
  * Tests if the user group can save and return a id.
  */
 public function testId()
 {
     $group = new Group();
     $group->setId(3);
     $this->assertEquals(3, $group->getId(), 'The group id did not save correctly.');
     $this->assertTrue(is_int($group->getId()), 'The group id was not returned as an Integer.');
 }
예제 #2
0
 /**
  * Returns a user group created using an array with user group data.
  *
  * @param  mixed[]    $groupRow
  * @return GroupModel
  */
 public function loadFromArray($groupRow = array())
 {
     $group = new GroupModel();
     if (isset($groupRow['id'])) {
         $group->setId($groupRow['id']);
     }
     if (isset($groupRow['name'])) {
         $group->setName($groupRow['name']);
     }
     return $group;
 }
예제 #3
0
파일: Index.php 프로젝트: sCar-w4y/Ilch-2.0
 /**
  * Shows a form to create or edit a new user.
  */
 public function treatAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuUser'), array('action' => 'index'))->add($this->getTranslator()->trans('editUser'), array('action' => 'treat'));
     $userMapper = new UserMapper();
     if ($this->getRequest()->isPost()) {
         $userData = $this->getRequest()->getPost('user');
         if (!empty($userData['password'])) {
             $userData['password'] = (new PasswordService())->hash($userData['password']);
         }
         $user = $userMapper->loadFromArray($userData);
         if (!empty($userData['groups'])) {
             foreach ($userData['groups'] as $groupId) {
                 $group = new GroupModel();
                 $group->setId($groupId);
                 $user->addGroup($group);
             }
         }
         $date = new \Ilch\Date();
         $user->setDateCreated($date);
         $userId = $userMapper->save($user);
         if (!empty($userId) && empty($userData['id'])) {
             $this->addMessage('newUserMsg');
         }
     }
     if (empty($userId)) {
         $userId = $this->getRequest()->getParam('id');
     }
     if ($userMapper->userWithIdExists($userId)) {
         $user = $userMapper->getUserById($userId);
     } else {
         $user = new UserModel();
     }
     $groupMapper = new GroupMapper();
     $this->getView()->set('user', $user);
     $this->getView()->set('groupList', $groupMapper->getGroupList());
 }
예제 #4
0
 /**
  * Tests if the access for a user can be returned.
  */
 public function testHasAccess()
 {
     $group = new Group();
     $group->setId(3);
     $group->setName('Testgroup');
     $user = new User();
     $user->setId(123);
     $user->addGroup($group);
     $dbMock = $this->getMock('Ilch_Database', array('queryCell'));
     $dbMock->expects($this->once())->method('queryCell')->with($this->logicalAnd($this->stringContains('FROM [prefix]_groups_access'), $this->stringContains('INNER JOIN `[prefix]_modules`'), $this->stringContains('user')))->will($this->returnValue('0'));
     Registry::remove('db');
     Registry::set('db', $dbMock);
     $this->assertEquals(0, $user->hasAccess('module_user'));
 }