/** * 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(); }
/** * 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(); }
/** * Testing the DEnumItem::loadItems method directly. * * @since 1.2.1 */ public function testDEnumItemLoadItems() { $DEnumID = $this->denum1->getOID(); $item = new DEnumItem(); $items = $item->loadItems($DEnumID); $this->assertGreaterThan(0, count($items), 'testing the DEnumItem::loadItems method directly'); }
/** * {@inheritdoc} * * @since 1.0 */ protected function tearDown() { unset($this->view); $denum = new DEnum(); $denum->dropTable(); $item = new DEnumItem(); $item->dropTable(); }
/** * Set up tests. * * @since 2.0 */ protected function setUp() { parent::setUp(); $tag = new Tag(); $tag->rebuildTable(); $denum = new DEnum(); $denum->rebuildTable(); $item = new DEnumItem(); $item->rebuildTable(); $article = new Article(); $article->rebuildTable(); $denum = new DEnum('Alpha\\Model\\Article::section'); $item->set('DEnumID', $denum->getOID()); $item->set('value', 'Test'); $item->save(); $this->DEnumID = $denum->getOID(); $this->article = $this->createArticle('unitTestArticle'); }
/** * 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(); $denum = new DEnum('Alpha\\Model\\Article::section'); $item->set('DEnumID', $denum->getOID()); $item->set('value', 'Test'); $item->save(); $this->DEnumID = $denum->getOID(); $this->article = $this->createArticle('unitTestArticle'); }
/** * Testing the doPOST method. */ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $front = new FrontController(); $controller = new DEnumController(); $securityParams = $controller->generateSecurityFields(); $item = new DEnumItem(); $denumItems = $item->loadItems($this->denum->getOID()); $item = $denumItems[0]; $params = array('saveBut' => true, 'var1' => $securityParams[0], 'var2' => $securityParams[1], 'value_' . $item->getOID() => 'updated'); $params = array_merge($params, $item->toArray()); $request = new Request(array('method' => 'POST', 'URI' => '/denum/' . $this->denum->getOID(), 'params' => $params)); $response = $front->process($request); $this->assertEquals(200, $response->getStatus(), 'Testing the doPOST method'); $this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doPOST method'); }
/** * Gets an array of the OIDs of the most recent articles added to the system (by date), from the newest * article to the amount specified by the $limit. * * @param int $limit * @param string $excludeID * * @return array * * @since 1.0 * * @throws Alpha\Exception\AlphaException */ public function loadRecentWithLimit($limit, $excludeID = '') { if ($excludeID != '') { $denum = new DEnum('Alpha\\Model\\Article::section'); $excludeID = $denum->getOptionID($excludeID); } $sqlQuery = 'SELECT OID FROM ' . $this->getTableName() . " WHERE published='1' AND section!='{$excludeID}' ORDER BY created_ts DESC LIMIT 0, {$limit};"; $result = $this->query($sqlQuery); $OIDs = array(); foreach ($result as $row) { array_push($OIDs, $row['OID']); } return $OIDs; }
/** * Tear down tests. * * @since 1.0 */ protected function tearDown() { $article = new Article(); $article->dropTable(); $tag = new Tag(); $tag->dropTable(); $denum = new DEnum(); $denum->dropTable(); $item = new DEnumItem(); $item->dropTable(); unset($this->article); }
/** * 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')); }
/** * Method to create the DEnum tables if they don't exist. * * @since 1.0 * * @return string */ private function createDEnumTables() { $tmpDEnum = new DEnum(); $body = '<p>Attempting to build table ' . DEnum::TABLE_NAME . ' for class DEnum : </p>'; try { $tmpDEnum->makeTable(); $body .= View::displayUpdateMessage('Successfully re-created the database table ' . DEnum::TABLE_NAME); self::$logger->action('Re-created the table ' . DEnum::TABLE_NAME); } catch (AlphaException $e) { $body .= View::displayErrorMessage('Failed re-created the database table ' . DEnum::TABLE_NAME . ', check the log'); self::$logger->error($e->getMessage()); } $tmpDEnumItem = new DEnumItem(); $body .= '<p>Attempting to build table ' . DEnumItem::TABLE_NAME . ' for class DEnumItem : </p>'; try { $tmpDEnumItem->makeTable(); $body .= View::displayUpdateMessage('Successfully re-created the database table ' . DEnumItem::TABLE_NAME); self::$logger->action('Re-created the table ' . DEnumItem::TABLE_NAME); } catch (AlphaException $e) { $body .= View::displayErrorMessage('Failed re-created the database table ' . DEnumItem::TABLE_NAME . ', check the log'); self::$logger->error($e->getMessage()); } return $body; }
/** * (non-PHPdoc). * * @see Alpha\Model\ActiveRecordProviderInterface::addProperty() */ public function addProperty($propName) { self::$logger->debug('>>addProperty(propName=[' . $propName . '])'); $sqlQuery = 'ALTER TABLE ' . $this->BO->getTableName() . ' ADD '; if ($this->isTableOverloaded() && $propName == 'classname') { $sqlQuery .= 'classname VARCHAR(100)'; } else { if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) { $reflection = new ReflectionClass($this->BO->getPropObject($propName)); $propClass = $reflection->getShortName(); switch (mb_strtoupper($propClass)) { case 'INTEGER': $sqlQuery .= "{$propName} INT(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'DOUBLE': $sqlQuery .= "{$propName} DOUBLE(" . $this->BO->getPropObject($propName)->getSize(true) . ')'; break; case 'STRING': $sqlQuery .= "{$propName} VARCHAR(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'SEQUENCE': $sqlQuery .= "{$propName} VARCHAR(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'TEXT': $sqlQuery .= "{$propName} TEXT"; break; case 'BOOLEAN': $sqlQuery .= "{$propName} CHAR(1) DEFAULT '0'"; break; case 'DATE': $sqlQuery .= "{$propName} DATE"; break; case 'TIMESTAMP': $sqlQuery .= "{$propName} DATETIME"; break; case 'ENUM': $sqlQuery .= "{$propName} ENUM("; $enumVals = $this->BO->getPropObject($propName)->getOptions(); foreach ($enumVals as $val) { $sqlQuery .= "'" . $val . "',"; } $sqlQuery = rtrim($sqlQuery, ','); $sqlQuery .= ')'; break; case 'DENUM': $tmp = new DEnum(get_class($this->BO) . '::' . $propName); $tmp->save(); $sqlQuery .= "{$propName} INT(11) ZEROFILL"; break; case 'RELATION': $sqlQuery .= "{$propName} INT(11) ZEROFILL UNSIGNED"; break; default: $sqlQuery .= ''; break; } } } $this->BO->setLastQuery($sqlQuery); if (!($result = self::getConnection()->query($sqlQuery))) { throw new AlphaException('Failed to add the new attribute [' . $propName . '] to the table [' . $this->BO->getTableName() . '], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<addProperty'); } else { self::$logger->info('Successfully added the [' . $propName . '] column onto the [' . $this->BO->getTableName() . '] table for the class [' . get_class($this->BO) . ']'); } if ($this->BO->getMaintainHistory()) { $sqlQuery = str_replace($this->BO->getTableName(), $this->BO->getTableName() . '_history', $sqlQuery); if (!($result = self::getConnection()->query($sqlQuery))) { throw new AlphaException('Failed to add the new attribute [' . $propName . '] to the table [' . $this->BO->getTableName() . '_history], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<addProperty'); } else { self::$logger->info('Successfully added the [' . $propName . '] column onto the [' . $this->BO->getTableName() . '_history] table for the class [' . get_class($this->BO) . ']'); } } self::$logger->debug('<<addProperty'); }
/** * (non-PHPdoc). * * @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::tearDown() * @since 1.0 */ protected function tearDown() { $config = ConfigProvider::getInstance(); $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray'); $this->controller->abort(); $this->article->dropTable(); unset($this->article); unset($this->controller); $this->person->dropTable(); unset($this->person); $this->group->dropTable(); $this->group->dropTable('Person2Rights'); unset($this->group); $article = new Article(); $article->dropTable(); $tag = new Tag(); $tag->dropTable(); $denum = new DEnum(); $denum->dropTable(); $item = new DEnumItem(); $item->dropTable(); }