コード例 #1
0
ファイル: ActiveRecordTest.php プロジェクト: alphadevx/alpha
 /**
  * Testing the clear method for unsetting the attributes of an object.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testClear($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $state = $this->person->get('state');
     $this->assertTrue(!empty($state), 'Testing the clear method for unsetting the attributes of an object');
     $reflection = new \ReflectionClass(get_class($this->person));
     $properties = $reflection->getProperties();
     foreach ($properties as $propObj) {
         $propName = $propObj->name;
         if (!in_array($propName, $this->person->getDefaultAttributes()) && !in_array($propName, $this->person->getTransientAttributes())) {
             $this->assertNotNull($this->person->get($propName), 'Testing the clear method for unsetting the attributes of an object');
         }
     }
     // delete will invoke clear(), which is private
     $this->person->delete();
     try {
         $state = $this->person->get('state');
         $this->fail('Testing the clear method for unsetting the attributes of an object');
     } catch (AlphaException $e) {
         $reflection = new \ReflectionClass(get_class($this->person));
         $properties = $reflection->getProperties();
         foreach ($properties as $propObj) {
             $propName = $propObj->name;
             try {
                 $this->person->get($propName);
             } catch (PHPException $e) {
                 $this->assertEquals(preg_match('/Undefined property/', $e->getMessage()), 1, 'Testing the clear method for unsetting the attributes of an object');
             } catch (AlphaException $e) {
                 $this->assertEquals('Could not access the property [' . $propName . '] on the object of class [Alpha\\Model\\Person]', $e->getMessage(), 'Testing the clear method for unsetting the attributes of an object');
             }
         }
     }
 }
コード例 #2
0
ファイル: LoginController.php プロジェクト: alphadevx/alpha
 /**
  * Login the user and re-direct to the defined destination.
  *
  * @param string $password The password supplied by the user logging in
  *
  * @throws Alpha\Exception\ValidationException
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 protected function doLoginAndRedirect($password)
 {
     self::$logger->debug('>>doLoginAndRedirect(password=[' . $password . '])');
     $config = ConfigProvider::getInstance();
     if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Active') {
         if (password_verify($password, $this->personObject->get('password'))) {
             $sessionProvider = $config->get('session.provider.name');
             $session = SessionProviderFactory::getInstance($sessionProvider);
             $session->set('currentUser', $this->personObject);
             self::$logger->debug('Logging in [' . $this->personObject->get('email') . '] at [' . date('Y-m-d H:i:s') . ']');
             self::$logger->action('Login');
             $response = new Response(301);
             if ($this->getNextJob() != '') {
                 $response->redirect(FrontController::generateSecureURL('act=' . $this->getNextJob()));
                 $this->clearUnitOfWorkAttributes();
             } else {
                 $response->redirect($config->get('app.url'));
             }
             return $response;
         } else {
             throw new ValidationException('Failed to login user ' . $this->personObject->get('email') . ', the password is incorrect!');
             self::$logger->debug('<<doLoginAndRedirect');
         }
     }
 }
コード例 #3
0
 /**
  * Method to generate the markdown HTML render of the ArticleComment content.
  *
  * @param array $fields hash array of HTML fields to pass to the template
  *
  * @since 1.0
  *
  * @return string
  */
 public function markdownView($fields = array())
 {
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $markdown = new MarkdownFacade($this->BO);
     $author = new Person();
     $id = $this->BO->getCreatorID();
     $author->load($id->getValue());
     $html = '<blockquote class="usercomment">';
     $createTS = $this->BO->getCreateTS();
     $updateTS = $this->BO->getUpdateTS();
     $html .= '<p>Posted by ' . ($author->get('URL') == '' ? $author->get('displayname') : '<a href="' . $author->get('URL') . '" target="new window">' . $author->get('displayname') . '</a>') . ' at ' . $createTS->getValue() . '.';
     $html .= '&nbsp;' . $author->get('displayname') . ' has posted [' . $author->getCommentCount() . '] comments on articles since joining.';
     $html .= '</p>';
     if ($config->get('cms.comments.allowed') && $session->get('currentUser') != null && $session->get('currentUser')->getID() == $author->getID()) {
         $html .= $this->editView($fields);
     } else {
         $html .= $markdown->getContent();
     }
     if ($createTS->getValue() != $updateTS->getValue()) {
         $updator = new Person();
         $id = $this->BO->getCreatorID();
         $updator->load($id->getValue());
         $html .= '<p>Updated by ' . ($updator->get('URL') == '' ? $updator->get('displayname') : '<a href="' . $updator->get('URL') . '" target="new window">' . $updator->get('displayname') . '</a>') . ' at ' . $updateTS->getValue() . '.</p>';
     }
     $html .= '</blockquote>';
     return $html;
 }
コード例 #4
0
ファイル: ActiveRecordTest.php プロジェクト: alphadevx/alpha
 /**
  * Testing that a saved record is subsequently retrievable from the cache.
  *
  * @since 1.2.1
  * @dataProvider getActiveRecordProviders
  */
 public function testLoadFromCache($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $config = ConfigProvider::getInstance();
     $oldSetting = $config->get('cache.provider.name');
     $config->set('cache.provider.name', 'Alpha\\Util\\Cache\\CacheProviderArray');
     $this->person->save();
     $fromCache = new Person();
     $fromCache->setOID($this->person->getOID());
     $this->assertTrue($fromCache->loadFromCache(), 'testing that the item loads from the cache');
     $this->assertEquals('unitTestUser', $fromCache->get('displayName', true), 'testing that a saved record is subsequently retrievable from the cache');
     $config->set('cache.provider.name', $oldSetting);
 }