/**
  * {@inheritdoc}
  *
  * @since 2.0
  */
 protected function tearDown()
 {
     parent::tearDown();
     $article = new Article();
     $article->dropTable();
     $articleComment = new ArticleComment();
     $articleComment->dropTable();
 }
Example #2
0
 /**
  * Called before the test functions will be executed
  * this function is defined in PHPUnit_TestCase and overwritten
  * here.
  *
  * @since 1.0
  */
 protected function setUp()
 {
     $denum = new DEnum();
     $denum->rebuildTable();
     $item = new DEnumItem();
     $item->rebuildTable();
     $this->BO = new Article();
     $this->BO->set('title', 'Test Article Title');
     $this->BO->set('description', 'Test Article Description');
     $this->BO->set('created_ts', '2011-01-01 00:00:00');
 }
 /**
  * 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();
 }
Example #4
0
 /**
  * Testing the loadTags() method for accessing the tags on a given object type directly.
  *
  * @since 1.0
  */
 public function testLoadTags()
 {
     $this->article->save();
     $tagsA = $this->article->getPropObject('tags')->getRelatedObjects();
     $tag = new Tag();
     $tagsB = $tag->loadTags('Alpha\\Model\\Article', $this->article->getOID());
     $this->assertEquals(count($tagsA), count($tagsB), 'testing the loadTags() method for accessing the tags on a given object type directly');
 }
Example #5
0
 /**
  * Creates an article object for testing.
  *
  * @return Alpha\Model\Article
  *
  * @since 1.2.3
  */
 private function createArticle($name)
 {
     $article = new Article();
     $article->set('title', $name);
     $article->set('description', 'A test article called unitTestArticle');
     $article->set('author', 'blah');
     $article->set('content', 'blah');
     return $article;
 }
 /**
  * Testing the method for getting related objects.
  *
  * @since 1.2.3
  */
 public function testGetRelated()
 {
     $this->article->save();
     $article2 = $this->createArticle('unitTestArticle 2');
     $article2->save();
     $article3 = $this->createArticle('unitTestArticle 3');
     $article3->save();
     $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags');
     $results = $provider->getRelated($this->article);
     $this->assertTrue(count($results) == 2, 'Testing the method for getting related objects');
     $results = $provider->getRelated($this->article, 'all', 0, 1);
     $this->assertTrue(count($results) == 1, 'Testing the method for getting related objects honours limit param');
     $results = $provider->getRelated($this->article, 'PersonObject');
     $this->assertTrue(count($results) == 0, 'Testing the get related objects method honours returnType filtering');
 }
Example #7
0
 /**
  * Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller's keywords.
  *
  * @since 1.0
  */
 public function testTagsMapToMetaKeywords()
 {
     ActiveRecord::begin();
     $this->article->save();
     ActiveRecord::commit();
     $tags = $this->article->getPropObject('tags')->getRelatedObjects();
     $found = false;
     foreach ($tags as $tag) {
         if ($tag->get('content') == 'unittestarticle') {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Testing the Tag::tokenize method returns a tag called "unittestarticle"');
     $this->controller->setRecord($this->article);
     $this->assertEquals('unittestarticle,unittestarticletagone,unittestarticletagtwo', $this->controller->getKeywords(), 'Testing that a BO attached to a controller that contains tags will have those tags mapped to the controller\'s keywords');
 }
Example #8
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');
 }
Example #9
0
 /**
  * Testing the renderAllFields() method.
  *
  * @since 2.0
  */
 public function testRenderAllFields()
 {
     $article = new Article();
     $article->set('title', 'Test Article');
     $this->view = View::getInstance($article);
     $this->assertNotEmpty($this->view->renderAllFields('view'), 'Testing the renderAllFields() method');
     $this->assertTrue(strpos($this->view->renderAllFields('view'), 'Test Article') !== false, 'Testing the renderAllFields() method');
 }
Example #10
0
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\ResourceNotFoundException
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     try {
         if (isset($params['articleOID']) && isset($params['filename'])) {
             if (!Validator::isInteger($params['articleOID'])) {
                 throw new IllegalArguementException('The articleOID [' . $params['articleOID'] . '] provided is invalid');
             }
             $article = new Article();
             $article->setOID($params['articleOID']);
             $filePath = $article->getAttachmentsLocation() . '/' . $params['filename'];
             if (file_exists($filePath)) {
                 self::$logger->info('Downloading the file [' . $params['filename'] . '] from the folder [' . $article->getAttachmentsLocation() . ']');
                 $pathParts = pathinfo($filePath);
                 $mimeType = FileUtils::getMIMETypeByExtension($pathParts['extension']);
                 $response = new Response(200, file_get_contents($filePath));
                 $response->setHeader('Content-Type', $mimeType);
                 $response->setHeader('Content-Disposition', 'attachment; filename="' . $pathParts['basename'] . '"');
                 $response->setHeader('Content-Length', filesize($filePath));
                 self::$logger->debug('<<doGET');
                 return $response;
             } else {
                 self::$logger->error('Could not access article attachment file [' . $filePath . '] as it does not exist!');
                 throw new IllegalArguementException('File not found');
             }
         } else {
             self::$logger->error('Could not access article attachment as articleOID and/or filename were not provided!');
             throw new IllegalArguementException('File not found');
         }
     } catch (IllegalArguementException $e) {
         self::$logger->error($e->getMessage());
         throw new ResourceNotFoundException($e->getMessage());
     }
     self::$logger->debug('<<doGET');
 }
Example #11
0
 /**
  * Method to handle PUT requests.
  *
  * @param Alpha\Util\Http\Request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doPUT($request)
 {
     self::$logger->debug('>>doPUT($request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
             self::$logger->debug('<<doPUT');
         }
         if (isset($params['markdownTextBoxRows']) && $params['markdownTextBoxRows'] != '') {
             $viewState = ViewState::getInstance();
             $viewState->set('markdownTextBoxRows', $params['markdownTextBoxRows']);
         }
         if (isset($params['title']) || isset($params['ActiveRecordOID'])) {
             if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) {
                 $record = new $params['ActiveRecordType']();
             } else {
                 $record = new Article();
             }
             if (isset($params['title'])) {
                 $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']);
                 $record->loadByAttribute('title', $title, false, array('OID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent'));
             } else {
                 $record->load($params['ActiveRecordOID']);
             }
             // uploading an article attachment
             if (isset($params['uploadBut'])) {
                 $source = $request->getFile('userfile')['tmp_name'];
                 $dest = $record->getAttachmentsLocation() . '/' . $request->getFile('userfile')['name'];
                 // upload the file to the attachments directory
                 FileUtils::copy($source, $dest);
                 if (!file_exists($dest)) {
                     throw new AlphaException('Could not move the uploaded file [' . $request->getFile('userfile')['name'] . ']');
                 }
                 // set read/write permissions on the file
                 $success = chmod($dest, 0666);
                 if (!$success) {
                     throw new AlphaException('Unable to set read/write permissions on the uploaded file [' . $dest . '].');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $source . ' uploaded to ' . $dest);
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $source . ' uploaded to ' . $dest));
                 }
             } elseif (isset($params['deletefile']) && $params['deletefile'] != '') {
                 $success = unlink($record->getAttachmentsLocation() . '/' . $params['deletefile']);
                 if (!$success) {
                     throw new AlphaException('Could not delete the file [' . $params['deletefile'] . ']');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted');
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted'));
                 }
             } else {
                 self::$logger->debug('<<doPUT');
                 return parent::doPUT($request);
             }
         } else {
             throw new IllegalArguementException('No valid article ID provided!');
         }
     } catch (SecurityException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->warn($e->getMessage());
     } catch (IllegalArguementException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     } catch (RecordNotFoundException $e) {
         self::$logger->warn($e->getMessage());
         $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested article from the database!'));
     } catch (AlphaException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     }
     $response = new Response(301);
     if ($this->getNextJob() != '') {
         $response->redirect($this->getNextJob());
     } else {
         if ($this->request->isSecureURI()) {
             $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\Article&ActiveRecordOID=' . $record->getOID() . '&view=edit'));
         } else {
             $title = str_replace(' ', $config->get('cms.url.title.separator'), $record->get('title'));
             $response->redirect($config->get('app.url') . '/a/' . $title . '/edit');
         }
     }
     self::$logger->debug('<<doPUT');
     return $response;
 }
Example #12
0
 /**
  * Creates an article object for testing.
  *
  * @return Alpha\Model\Article
  *
  * @since 1.2.3
  */
 private function createArticle($name)
 {
     $article = new Article();
     $article->set('title', $name);
     $article->set('description', 'A test article called unitTestArticle with some stop words and the unitTestArticle title twice');
     $article->set('author', 'blah');
     $article->set('content', 'blah');
     $article->set('section', $this->DEnumID);
     return $article;
 }
Example #13
0
 /**
  * Creates an article object for Testing.
  *
  * @return Alpha\Model\Article
  *
  * @since 2.0
  */
 private function createArticleObject($name)
 {
     $article = new Article();
     $article->set('title', $name);
     $article->set('description', 'unitTestArticleTagOneAA unitTestArticleTagTwo');
     $article->set('author', 'unitTestArticleTagOneBB');
     $article->set('content', 'unitTestArticleTagOneCC');
     $article->set('published', true);
     $article->set('section', 1);
     return $article;
 }
Example #14
0
 /**
  * Creates an article object for Testing.
  *
  * @return Alpha\Model\Article
  *
  * @since 1.0
  */
 private function createArticleObject($name)
 {
     $article = new Article();
     $article->set('title', $name);
     $article->set('description', 'unitTestArticleTagOne unitTestArticleTagTwo');
     $article->set('author', 'unitTestArticleTagOne');
     $article->set('content', 'unitTestArticleTagOne');
     return $article;
 }
Example #15
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 updating a table via doPOST method
  */
 public function testDoPOSTUpdateTable()
 {
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $front = new FrontController();
     $controller = new ListActiveRecordsController();
     $article = new Article();
     $securityParams = $controller->generateSecurityFields();
     $params = array('var1' => $securityParams[0], 'var2' => $securityParams[1], 'admin_AlphaModelArticle_button_pressed' => 'updateTableBut', 'updateTableClass' => 'Alpha\\Model\\Article');
     $request = new Request(array('method' => 'POST', 'URI' => '/listactiverecords', 'params' => $params));
     $response = $front->process($request);
     $this->assertEquals(0, count($article->findMissingFields()), 'Testing updating a table via doPOST method');
 }
Example #17
0
 /**
  * Testing the RelationLookup constructor.
  *
  * @since 1.2.1
  */
 public function testConstruct()
 {
     try {
         $lookup = new RelationLookup('', '');
         $this->fail('testing the RelationLookup constructor');
     } catch (IllegalArguementException $e) {
         $this->assertEquals('Cannot create RelationLookup object without providing the left and right class names!', $e->getMessage(), 'testing the RelationLookup constructor');
     }
     $article = new Article();
     try {
         $article->dropTable();
         $lookup = new RelationLookup('Alpha\\Model\\Person', 'Alpha\\Model\\Article');
         $this->fail('testing the RelationLookup constructor');
     } catch (FailedLookupCreateException $e) {
         $this->assertEquals('Error trying to create a lookup table [Person2Article], as tables for BOs [Alpha\\Model\\Person] or [Alpha\\Model\\Article] don\'t exist!', $e->getMessage(), 'testing the RelationLookup constructor');
     }
     $article->rebuildTable();
     $lookup = new RelationLookup('Alpha\\Model\\Person', 'Alpha\\Model\\Article');
     $this->assertTrue($lookup->checkTableExists(), 'testing the RelationLookup constructor');
 }