示例#1
0
 /**
  * Testing the getLastQuery method after various persistance calls.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testGetLastQuery($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $this->person->save();
     if ($config->get('db.provider.name') == 'ActiveRecordProviderMySQL') {
         $this->assertEquals('INSERT INTO Person', mb_substr($this->person->getLastQuery(), 0, 18), 'Testing the getLastQuery method after various persistance calls');
         $this->person->checkTableNeedsUpdate();
         $this->assertEquals('SHOW INDEX FROM Person', mb_substr($this->person->getLastQuery(), 0, 22), 'Testing the getLastQuery method after various persistance calls');
         $this->person->getCount();
         $this->assertEquals('SELECT COUNT(OID)', mb_substr($this->person->getLastQuery(), 0, 17), 'Testing the getLastQuery method after various persistance calls');
         $this->person->getMAX();
         $this->assertEquals('SELECT MAX(OID)', mb_substr($this->person->getLastQuery(), 0, 15), 'Testing the getLastQuery method after various persistance calls');
         $this->person->load($this->person->getID());
         $this->assertEquals('SHOW COLUMNS FROM Person', mb_substr($this->person->getLastQuery(), 0, 24), 'Testing the getLastQuery method after various persistance calls');
     }
     if ($config->get('db.provider.name') == 'ActiveRecordProviderSQLite') {
         $this->assertEquals('PRAGMA table_info(Person)', mb_substr($this->person->getLastQuery(), 0, 25), 'Testing the getLastQuery method after various persistance calls');
         $this->person->checkTableNeedsUpdate();
         $this->assertEquals('SELECT name FROM sqlite_master WHERE type=\'index\'', mb_substr($this->person->getLastQuery(), 0, 49), 'Testing the getLastQuery method after various persistance calls');
         $this->person->getCount();
         $this->assertEquals('SELECT COUNT(OID)', mb_substr($this->person->getLastQuery(), 0, 17), 'Testing the getLastQuery method after various persistance calls');
         $this->person->getMAX();
         $this->assertEquals('SELECT MAX(OID)', mb_substr($this->person->getLastQuery(), 0, 15), 'Testing the getLastQuery method after various persistance calls');
         $this->person->load($this->person->getID());
         $this->assertEquals('SELECT displayName,email,password,state,URL,OID,version_num,created_ts,created_by,updated_ts,updated_by FROM Person WHERE OID = :OID LIMIT 1;', mb_substr($this->person->getLastQuery(), 0, 150), 'Testing the getLastQuery method after various persistance calls');
     }
 }
示例#2
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;
 }
示例#3
0
 /**
  * Testing optimistic locking mechanism#.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testSaveObjectLocking($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     try {
         $this->person->save();
         $personInstance1 = new Person();
         $personInstance1->load($this->person->getID());
         $personInstance2 = new Person();
         $personInstance2->load($this->person->getID());
         $personInstance1->save();
         $personInstance2->save();
         $this->fail('Testing optimistic locking mechanism');
     } catch (LockingException $e) {
         $this->assertEquals('Could not save the object as it has been updated by another user.  Please try saving again.', $e->getMessage(), 'Testing optimistic locking mechanism');
     }
 }