/** * 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'); $person = new Person(); $person->rebuildTable(); $rights = new Rights(); $rights->rebuildTable(); $rights->set('name', 'Standard'); $rights->save(); }
/** * Drop the user tables and session between tests. * * @since 2.0 */ protected function tearDown() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $session->set('currentUser', null); $person = new Person(); $person->dropTable(); $rights = new Rights(); $rights->dropTable(); $rights->dropTable('Person2Rights'); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $action = new ActionLog(); $action->rebuildTable(); $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(); }
/** * 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'); }
/** * Called after the test functions are executed * this function is defined in PHPUnit_TestCase and overwritten * here. * * @since 1.0 */ protected function tearDown() { parent::tearDown(); unset($this->enum1); $this->person->dropTable(); $rights = new Rights(); $rights->dropTable(); $rights->dropTable('Person2Rights'); unset($this->person); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); // if there is nobody logged in, we will send them off to the Login controller to do so before coming back here if ($session->get('currentUser') === false) { self::$logger->info('Nobody logged in, invoking Login controller...'); $controller = new LoginController(); $controller->setName('LoginController'); $controller->setRequest($request); $controller->setUnitOfWork(array('Alpha\\Controller\\LoginController', 'Alpha\\Controller\\InstallController')); self::$logger->debug('<<__construct'); return $controller->doGET($request); } $params = $request->getParams(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $body = View::displayPageHead($this); $body .= '<h1>Installing the ' . $config->get('app.title') . ' application</h1>'; try { $body .= $this->createApplicationDirs(); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); return new Response(500, $body, array('Content-Type' => 'text/html')); } // start a new database transaction ActiveRecord::begin(); /* * Create DEnum tables */ $DEnum = new DEnum(); $DEnumItem = new DEnumItem(); try { $body .= '<p>Attempting to create the DEnum tables...'; if (!$DEnum->checkTableExists()) { $DEnum->makeTable(); } self::$logger->info('Created the [' . $DEnum->getTableName() . '] table successfully'); if (!$DEnumItem->checkTableExists()) { $DEnumItem->makeTable(); } self::$logger->info('Created the [' . $DEnumItem->getTableName() . '] table successfully'); // create a default article DEnum category $DEnum = new DEnum('Alpha\\Model\\Article::section'); $DEnumItem = new DEnumItem(); $DEnumItem->set('value', 'Main'); $DEnumItem->set('DEnumID', $DEnum->getID()); $DEnumItem->save(); $body .= View::displayUpdateMessage('DEnums set up successfully.'); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } /* * Loop over each business object in the system, and create a table for it */ $classNames = ActiveRecord::getBOClassNames(); $loadedClasses = array(); foreach ($classNames as $classname) { array_push($loadedClasses, $classname); } foreach ($loadedClasses as $classname) { try { $body .= '<p>Attempting to create the table for the class [' . $classname . ']...'; try { $BO = new $classname(); if (!$BO->checkTableExists()) { $BO->makeTable(); } else { if ($BO->checkTableNeedsUpdate()) { $missingFields = $BO->findMissingFields(); $count = count($missingFields); for ($i = 0; $i < $count; ++$i) { $BO->addProperty($missingFields[$i]); } } } } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } self::$logger->info('Created the [' . $BO->getTableName() . '] table successfully'); $body .= View::displayUpdateMessage('Created the [' . $BO->getTableName() . '] table successfully'); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } } $body .= View::displayUpdateMessage('All business object tables created successfully!'); /* * Create the Admin and Standard groups */ $adminGroup = new Rights(); $adminGroup->set('name', 'Admin'); $standardGroup = new Rights(); $standardGroup->set('name', 'Standard'); try { try { $body .= '<p>Attempting to create the Admin and Standard groups...'; $adminGroup->save(); $standardGroup->save(); self::$logger->info('Created the Admin and Standard rights groups successfully'); $body .= View::displayUpdateMessage('Created the Admin and Standard rights groups successfully'); } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } /* * Save the admin user to the database in the right group */ try { try { $body .= '<p>Attempting to save the Admin account...'; $admin = new Person(); $admin->set('displayName', 'Admin'); $admin->set('email', $session->get('currentUser')->get('email')); $admin->set('password', $session->get('currentUser')->get('password')); $admin->save(); self::$logger->info('Created the admin user account [' . $session->get('currentUser')->get('email') . '] successfully'); $adminGroup->loadByAttribute('name', 'Admin'); $lookup = $adminGroup->getMembers()->getLookup(); $lookup->setValue(array($admin->getID(), $adminGroup->getID())); $lookup->save(); self::$logger->info('Added the admin account to the Admin group successfully'); $body .= View::displayUpdateMessage('Added the admin account to the Admin group successfully'); } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } $body .= '<br><p align="center"><a href="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ListActiveRecordsController') . '">Administration Home Page</a></p><br>'; $body .= View::displayPageFoot($this); // commit ActiveRecord::commit(); self::$logger->info('Finished installation!'); self::$logger->action('Installed the application'); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Called before the test functions will be executed * this function is defined in PHPUnit_TestCase and overwritten * here. * * @since 1.0 */ protected function setUp() { parent::setUp(); $config = ConfigProvider::getInstance(); foreach ($this->getActiveRecordProviders() as $provider) { $config->set('db.provider.name', $provider[0]); $rights = new Rights(); $rights->rebuildTable(); $standardGroup = new Rights(); $standardGroup->set('name', 'Standard'); $standardGroup->save(); $request = new BadRequest(); $request->rebuildTable(); $this->person = $this->createPersonObject('unitTestUser'); $this->person->rebuildTable(); $lookup = new RelationLookup('Alpha\\Model\\Person', 'Alpha\\Model\\Rights'); // just making sure no previous test user is in the DB $this->person->deleteAllByAttribute('URL', 'http://unitTestUser/'); $this->person->deleteAllByAttribute('displayName', 'unitTestUser'); $article = new Article(); $article->rebuildTable(); $comment = new ArticleComment(); $comment->rebuildTable(); $tag = new Tag(); $tag->rebuildTable(); } }
/** * Adds this person to the rights group specified. * * @param string $groupName * * @throws Alpha\Exception\RecordNotFoundException * * @since 2.0 */ public function addToGroup($groupName) { if (self::$logger == null) { self::$logger = new Logger('Person'); } self::$logger->debug('>>addToGroup(groupName=[' . $groupName . '])'); $group = new Rights(); $group->loadByAttribute('name', $groupName); $lookup = $this->getPropObject('rights')->getLookup(); $lookup->setValue(array($this->getOID(), $group->getOID())); $lookup->save(); self::$logger->debug('<<addToGroup'); }
/** * Testing the loadAllbyAttribute() method. * * @since 1.2.1 */ public function testLoadAllbyAttribute() { $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(); $lookup = new RelationLookup('Alpha\\Model\\Person', 'Alpha\\Model\\Rights'); $this->assertEquals(2, count($lookup->loadAllbyAttribute('rightID', $group->getOID())), 'testing the loadAllbyAttribute() method'); }
/** * test cases to see if access rights on controllers are working as expected. * * @since 1.0 */ public function testRightsAccess() { $config = ConfigProvider::getInstance(); $this->group = new Rights(); $this->group->set('name', 'testgroup'); $this->group->save(); $this->person->save(); $lookup = $this->person->getPropObject('rights')->getLookup(); $lookup->setValue(array($this->person->getOID(), $this->group->getOID())); $lookup->save(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $session->set('currentUser', $this->person); try { $controller = new ImageController('testgroup'); } catch (PHPException $e) { $this->fail('failed to access a controller that I have access to by rights group membership'); } }
/** * 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(); }