/**
  * Set up tests.
  *
  * @since 2.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $standardGroup = new Rights();
     $standardGroup->rebuildTable();
     $standardGroup->set('name', 'Standard');
     $standardGroup->save();
     $person = new Person();
     $person->set('displayName', 'unittestuser');
     $person->set('email', '*****@*****.**');
     $person->set('password', 'password');
     $person->rebuildTable();
     $person->save();
     $article = new Article();
     $article->set('title', 'unit test');
     $article->set('description', 'unit test');
     $article->set('content', 'unit test');
     $article->set('author', 'unit test');
     $article->rebuildTable();
     $article->save();
     $comment = new ArticleComment();
     $comment->set('content', 'unit test');
     $comment->getPropObject('articleOID')->setValue($article->getOID());
     $comment->rebuildTable();
     $comment->save();
 }
 /**
  * Set up tests.
  *
  * @since 2.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $tag = new Tag();
     $tag->rebuildTable();
     $denum = new DEnum();
     $denum->rebuildTable();
     $item = new DEnumItem();
     $item->rebuildTable();
     $article = new Article();
     $article->rebuildTable();
     $articleVote = new ArticleVote();
     $articleVote->rebuildTable();
     $articleComment = new ArticleComment();
     $articleComment->rebuildTable();
     $person = new Person();
     $person->rebuildTable();
     $rights = new Rights();
     $rights->rebuildTable();
     $rights->set('name', 'Standard');
     $rights->save();
     $rights = new Rights();
     $rights->set('name', 'Admin');
     $rights->save();
 }
Beispiel #3
0
 /**
  * Set up tests.
  *
  * @since 2.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $tag = new Tag();
     $tag->rebuildTable();
     $denum = new DEnum();
     $denum->rebuildTable();
     $item = new DEnumItem();
     $item->rebuildTable();
     // create a default article DEnum category
     $denum = new DEnum('Alpha\\Model\\Article::section');
     $item->set('value', 'Main');
     $item->set('DEnumID', $denum->getID());
     $item->save();
     $article = new Article();
     $article->rebuildTable();
     $articleVote = new ArticleVote();
     $articleVote->rebuildTable();
     $articleComment = new ArticleComment();
     $articleComment->rebuildTable();
     $person = new Person();
     $person->rebuildTable();
     $rights = new Rights();
     $rights->rebuildTable();
     $rights->set('name', 'Standard');
     $rights->save();
     $rights = new Rights();
     $rights->set('name', 'Admin');
     $rights->save();
 }
Beispiel #4
0
 /**
  * Testing the getRelatedObjects method with a ONE-TO-MANY and MANY-TO-MANY relation.
  *
  * @since 1.2.1
  */
 public function testGetRelatedObjects()
 {
     $group = new Rights();
     $group->set('name', 'unittestgroup');
     $group->save();
     $person1 = new Person();
     $person1->set('displayName', 'user1');
     $person1->set('email', '*****@*****.**');
     $person1->set('password', 'password');
     $person1->save();
     $lookup = $person1->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person1->getOID(), $group->getOID()));
     $lookup->save();
     $person2 = new Person();
     $person2->set('displayName', 'user2');
     $person2->set('email', '*****@*****.**');
     $person2->set('password', 'password');
     $person2->save();
     $lookup = $person2->getPropObject('rights')->getLookup();
     $lookup->setValue(array($person2->getOID(), $group->getOID()));
     $lookup->save();
     $person2->getPropObject('rights')->setValue($group->getOID());
     $this->assertEquals(2, count($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')), 'testing the getRelatedObjects method with a MANY-TO-MANY relation');
     $this->assertTrue($group->getPropObject('members')->getRelatedObjects('Alpha\\Model\\Rights')[0] instanceof Person, 'testing the getRelatedObjects method with a MANY-TO-MANY relation');
     $article = new Article();
     $article->set('title', 'unit test');
     $article->set('description', 'unit test');
     $article->set('content', 'unit test');
     $article->set('author', 'unit test');
     $article->save();
     $comment1 = new ArticleComment();
     $comment1->set('content', 'unit test');
     $comment1->getPropObject('articleOID')->setValue($article->getOID());
     $comment1->save();
     $comment2 = new ArticleComment();
     $comment2->set('content', 'unit test');
     $comment2->getPropObject('articleOID')->setValue($article->getOID());
     $comment2->save();
     $this->assertEquals(2, count($article->getPropObject('comments')->getRelatedObjects()), 'testing the getRelatedObjects method with a ONE-TO-MANY relation');
     $this->assertTrue($article->getPropObject('comments')->getRelatedObjects()[0] instanceof ArticleComment, 'testing the getRelatedObjects method with a ONE-TO-MANY relation');
 }
Beispiel #5
0
 /**
  * Testing the getFriendlyClassName() method.
  *
  * @since 1.2.1
  */
 public function testGetFriendlyClassName()
 {
     $person = new Person();
     $article = new Article();
     $comment = new ArticleComment();
     $this->assertEquals('Person', $person->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
     $this->assertEquals('Article', $article->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
     $this->assertEquals('ArticleComment', $comment->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
 }
 /**
  * Testing the editView() method.
  *
  * @since 2.0
  */
 public function testEditView()
 {
     $articleComment = new ArticleComment();
     $articleComment->set('content', 'test comment');
     $articleComment->save();
     $view = View::getInstance($articleComment);
     $this->assertNotEmpty($view->editView(array('formAction' => '/')), 'Testing the editView() method');
     $this->assertTrue(strpos($view->editView(array('formAction' => '/')), 'Update Your Comment') !== false, 'Testing the editView() method');
 }
Beispiel #7
0
 /**
  * Method for getting a count of the amount of article comments posted by the user.
  *
  * @return int
  *
  * @since 1.0
  */
 public function getCommentCount()
 {
     $temp = new ArticleComment();
     $sqlQuery = 'SELECT COUNT(OID) AS post_count FROM ' . $temp->getTableName() . " WHERE created_by='" . $this->OID . "';";
     $result = $this->query($sqlQuery);
     $row = $result[0];
     if (isset($row['post_count'])) {
         return $row['post_count'];
     } else {
         return 0;
     }
 }
Beispiel #8
0
 /**
  * Method for displaying the user comments for the article.
  *
  * @return string
  *
  * @since 1.0
  */
 private function renderComments()
 {
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $html = '';
     $comments = $this->record->getArticleComments();
     $commentsCount = count($comments);
     $URL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\ArticleComment');
     $fields = array('formAction' => $URL);
     if ($config->get('cms.display.comments') && $commentsCount > 0) {
         $html .= '<h2>There are [' . $commentsCount . '] user comments for this article</h2>';
         for ($i = 0; $i < $commentsCount; ++$i) {
             $view = View::getInstance($comments[$i]);
             $html .= $view->markdownView($fields);
         }
     }
     if ($session->get('currentUser') != null && $config->get('cms.comments.allowed')) {
         $comment = new ArticleComment();
         $comment->set('articleOID', $this->record->getID());
         $view = View::getInstance($comment);
         $html .= $view->createView($fields);
     }
     return $html;
 }