Exemple #1
0
 /**
  * Test acl by date
  */
 public function testAclByDate()
 {
     $role = AclModelBase::DEFAULT_ROLE_MEMBER;
     $testResources = ['test_application_settings_administration', 'test_application_modules_administration'];
     $this->addAclResources($testResources, true, $role);
     $currentTime = time();
     // add acl resources connections settings
     foreach ($this->aclResourcesConnections as $connectId) {
         $query = $this->aclModelBase->insert()->into('acl_resource_connection_setting')->values(['connection_id' => $connectId, 'user_id' => $this->userId, 'date_start' => $currentTime, 'date_end' => $currentTime + 1]);
         $statement = $this->aclModelBase->prepareStatementForSqlObject($query);
         $statement->execute();
     }
     $this->initAcl($role);
     // all created acl resources must be active
     foreach ($testResources as $resource) {
         $this->assertTrue(AclService::checkPermission($resource));
     }
     // wait two seconds and check acl resources again
     sleep(2);
     $this->initAcl($role);
     // now all created acl resources must be expired
     foreach ($testResources as $resource) {
         $this->assertFalse(AclService::checkPermission($resource));
     }
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         if ($this->model) {
             // fill the form with default values
             $this->formElements['modules']['values'] = $this->model->getActiveModulesList();
         }
         // hide the status filter
         if ($this->hideStatusFilter) {
             unset($this->formElements['status']);
         }
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
Exemple #3
0
 /**
  * Test role synchronisation
  */
 public function testRoleSynchronisation()
 {
     // create a first test ACL role
     $query = $this->model->insert()->into('acl_role')->values(['name' => 'test role 1']);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     $this->aclRolesIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
     // create a test user
     $query = $this->model->insert()->into('user_list')->values(['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'role' => $this->aclRolesIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     $this->usersIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
     // delete the created ACL role
     $query = $this->model->delete()->from('acl_role')->where(['id' => $this->aclRolesIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     // fire the delete ACL role event
     AclEvent::fireDeleteAclRoleEvent($this->aclRolesIds[0]);
     // check the created test user's role
     $select = $this->model->select();
     $select->from('user_list')->columns(['role'])->where(['user_id' => $this->usersIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $result = $resultSet->initialize($statement->execute());
     // user must be a default member
     $this->assertEquals($result->current()['role'], AclBaseModel::DEFAULT_ROLE_MEMBER);
 }