/** * 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(); }
/** * 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'); }
/** * Testing the search method for expected results. * * @since 1.2.3 */ public function testSearch() { $this->article->save(); $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags'); $results = $provider->search('unitTestArticle'); $this->assertTrue(count($results) == 1, 'Testing the search method for expected results'); $this->assertEquals($this->article->getOID(), $results[0]->getOID(), 'Testing the search method for expected results'); $results = $provider->search('unitTestArticle', 'PersonObject'); $this->assertTrue(count($results) == 0, 'Testing the search method honours returnType filtering'); }
/** * 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'); }
/** * 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; }