/** * 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(); }
/** * 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; }
/** * 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'); }
/** * 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'); }
/** * 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; }
/** * 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; }
/** * 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'); }
/** * Testing the delete method also removes Tags related to the deleted record. * * @since 2.0.1 * @dataProvider getActiveRecordProviders */ public function testDeleteRelatedTags($provider) { $article = new Article(); $tag = new Tag(); $this->assertEquals(0, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $article->set('title', 'Unit test'); $article->set('description', 'Unit test'); $article->set('author', 'Unit test'); $article->set('content', 'jupiter neptune venus'); $article->save(); $this->assertEquals(3, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $article->delete(); $this->assertEquals(0, $article->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); $this->assertEquals(0, $tag->getCount(), 'Testing the delete method also removes Tags related to the deleted record.'); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\ResourceNotFoundException * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $body = ''; // handle requests for PDFs if (isset($params['title']) && (isset($params['pdf']) || $request->getHeader('Accept') == 'application/pdf')) { try { $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } $record->loadByAttribute('title', $title); $this->record = $record; ActiveRecord::disconnect(); $pdf = new TCPDFFacade($record); $pdfData = $pdf->getPDFData(); $pdfDownloadName = str_replace(' ', '-', $record->get('title') . '.pdf'); $headers = array('Pragma' => 'public', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/pdf', 'Content-Length' => strlen($pdfData), 'Content-Disposition' => 'attachment; filename="' . $pdfDownloadName . '";'); return new Response(200, $pdfData, $headers); } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } catch (RecordNotFoundException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } } // view edit article requests if (isset($params['view']) && $params['view'] == 'edit' && (isset($params['title']) || isset($params['ActiveRecordOID']))) { if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } try { if (isset($params['title'])) { $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); $record->loadByAttribute('title', $title); } else { $record->load($params['ActiveRecordOID']); } } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); $body .= View::renderErrorPage(404, 'Failed to find the requested article!'); return new Response(404, $body, array('Content-Type' => 'text/html')); } ActiveRecord::disconnect(); $this->record = $record; $view = View::getInstance($record); // set up the title and meta details $this->setTitle($record->get('title') . ' (editing)'); $this->setDescription('Page to edit ' . $record->get('title') . '.'); $this->setKeywords('edit,article'); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= $view->editView(array('URI' => $request->getURI())); $body .= View::renderDeleteForm($request->getURI()); $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests for viewing articles if (isset($params['title']) || isset($params['ActiveRecordOID'])) { $KDP = new KPI('viewarticle'); if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } try { 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']); } if (!$record->get('published')) { throw new RecordNotFoundException('Attempted to load an article which is not published yet'); } $record->set('tags', $record->getOID()); } catch (IllegalArguementException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The file that you have requested cannot be found!'); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The article that you have requested cannot be found!'); } $this->record = $record; $this->setTitle($record->get('title')); $this->setDescription($record->get('description')); $BOView = View::getInstance($record); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= $BOView->markdownView(); $body .= View::displayPageFoot($this); $KDP->log(); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests to view an article stored in a file if (isset($params['file'])) { try { $record = new Article(); // just checking to see if the file path is absolute or not if (mb_substr($params['file'], 0, 1) == '/') { $record->loadContentFromFile($params['file']); } else { $record->loadContentFromFile($config->get('app.root') . 'docs/' . $params['file']); } } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } catch (FileNotFoundException $e) { self::$logger->warn($e->getMessage() . ' File path is [' . $params['file'] . ']'); throw new ResourceNotFoundException('Failed to load the requested article from the file system!'); } $this->record = $record; $this->setTitle($record->get('title')); $BOView = View::getInstance($record); $body .= View::displayPageHead($this, false); $body .= $BOView->markdownView(); $body .= View::displayPageFoot($this); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests to view a list of articles if (isset($params['start'])) { return parent::doGET($request); } // create a new article requests $record = new Article(); $view = View::getInstance($record); // set up the title and meta details $this->setTitle('Creating article'); $this->setDescription('Page to create a new article.'); $this->setKeywords('create,article'); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $fields = array('formAction' => $this->request->getURI()); $body .= $view->createView($fields); $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * 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; }