public function testRelation() { /** * @var $schema \Cti\Storage\Schema */ $schema = getApplication()->getStorage()->getSchema(); $person = $schema->getModel('person'); $personInReferences = $person->getInReferences(); $this->assertCount(3, $personInReferences); $map = array(); foreach ($personInReferences as $reference) { $map[] = $reference->getSource() . ':' . $reference->getDestination(); } $this->assertContains("module:person", $map); $this->assertContains("person_favorite_module_link:person", $map); $this->assertContains("module_developer_link:person", $map); $personOutReferences = $person->getOutReferences(); $this->assertCount(1, $personOutReferences); $outReference = array_shift($personOutReferences); $outReference->process($schema); $this->assertEquals("person", $outReference->getSource()); $this->assertEquals("module", $outReference->getDestination()); $this->assertEquals("default_module", $outReference->getDestinationAlias()); $this->assertEquals('merge', $outReference->getStrategy()); $outReferenceProperties = $outReference->getProperties(); $this->assertCount(1, $outReferenceProperties); $personModuleLink = $outReferenceProperties['id_module_default_module']; $this->assertEquals('id_module', $personModuleLink->getForeignName()); $pfml = $schema->getModel("person_favorite_module_link"); foreach ($pfml->getOutReferences() as $reference) { // @todo Expand reference test } }
public function testProperties() { $application = getApplication(); /** * @var $schema Schema */ $schema = $application->getStorage()->getSchema(); $model = $schema->getModel('person'); // comment, required and string type check $login = $model->getProperty('login'); $this->assertNotEmpty($login); $this->assertEquals('Имя пользователя', $login->getComment()); $this->assertEquals('string', $login->getType()); $this->assertTrue($login->getRequired()); // type check $model = $schema->getModel('person_favorite_module_link'); $rating = $model->getProperty('rating'); $this->assertEquals('integer', $rating->getType()); $this->assertEquals(100, $rating->getMax()); $this->assertEquals(0, $rating->getMin()); $this->assertFalse($rating->getPrimary()); $model->addProperty("test", array("comment" => 'test', "type" => 'integer')); // test property creation and removing $property = $model->getProperty("test"); $this->assertNotEmpty($property); $this->assertEquals("test", $property->getComment()); $this->assertEquals("integer", $property->getType()); $this->assertEquals($model, $property->getModel()); $model->removeProperty("test"); $this->setExpectedException("Exception"); $model->getProperty("test"); }
/** * Create fake records (Admin in persons, Backend in modules) */ public static function generateFakeRecords() { $dbal = getApplication()->getStorage()->getAdapter(); $master = getApplication()->getStorage()->getMaster(); $admin = $master->getPersons()->create(array('hash' => '123', 'login' => 'admin', 'salt' => '123'))->save(); $backend = $master->getModules()->create(array('id_person_owner' => $admin->getIdPerson(), 'name' => 'Backend'))->save(); $user = $master->getPersons()->create(array('hash' => '123', 'login' => 'user', 'salt' => '321', 'id_module_default_module' => $backend->getIdModule()))->save(); $user->setSalt('123456'); $user->save(); /** * Move old models start time to the past */ $now = $dbal->fetchNow(); $time = strtotime($now); $veryPastTime = date("Y-m-d H:i:s", $time - 10000); $pastTime = date("Y-m-d H:i:s", $time - 5001); $startTime = date("Y-m-d H:i:s", $time - 5000); $dbal->executeQuery("update person set v_start = :very_past, v_end = :past where v_end < '9999-12-31 23:59:59'", array('very_past' => $veryPastTime, 'past' => $pastTime)); $dbal->executeQuery("update person set v_start = :start where v_end > :now", array('start' => $startTime, 'now' => $now)); /** * Clear repositories maps */ foreach (array($master->getModules(), $master->getPersons()) as $repo) { $mapProperty = Reflection::getReflectionProperty(get_class($repo), 'map'); $mapProperty->setAccessible(true); $mapProperty->setValue($repo, array()); $mapProperty->setAccessible(false); } }
public function testDifference() { $from = Container::getSchema(); $to = Container::getModifiedSchema(); $diffTool = getApplication()->getManager()->create("\\Migration\\Diff", array('from' => $from, 'to' => $to)); $difference = $diffTool->getDiff(); $this->assertEquals(Container::getCorrectDifference(), $difference); }
public function setUp() { \DatabaseManager::syncDatabase(); $master = getApplication()->getStorage()->getMaster(); $this->personRepository = $master->getPersons(); $this->moduleRepository = $master->getModules(); $this->dbal = getApplication()->getStorage()->getAdapter(); }
function testModuleRepository() { $application = getApplication(); $class = $application->getStorage()->getSchema()->getModel('module')->getRepositoryClass(); $this->assertSame($class, 'Repository\\Module'); $master = file_get_contents($application->getProject()->getPath('build php Storage Master.php')); $this->assertContains("->get('Repository\\Module')", $master); }
function testModuleModel() { $application = getApplication(); $class = $application->getStorage()->getSchema()->getModel('module')->getModelClass(); $this->assertSame($class, 'Model\\Module'); $repository = file_get_contents($application->getProject()->getPath('build php Storage Repository ModuleRepository.php')); $this->assertContains('use Model\\Module as Module', $repository); }
function testMaster() { $application = getApplication(); /** * @var $generator \Cti\Storage\Command\GenerateFiles */ $generator = $application->getConsole()->find('generate:storage'); $input = new ArrayInput(array('command' => 'generate:storage')); $output = new NullOutput(); $generator->run($input, $output); }
/** * migration based test */ function testLinking() { /** * @var Schema $schema */ $schema = getApplication()->getStorage()->getSchema(); $link = $schema->getModel('person_favorite_module_link'); $this->assertTrue($link->hasBehaviour('link')); $this->assertSame($link->getPk(), array('id_module_favorite_module', 'id_person', 'v_end')); $foreignModel = $link->getBehaviour('link')->getForeignModel($schema->getModel('person')); $this->assertSame($foreignModel, $schema->getModel('module')); }
function testLog() { $manager = getApplication()->getManager(); /** * @var \Cti\Storage\Component\Model $model */ $model = $manager->create('Cti\\Storage\\Component\\Model', array('name' => 'page')); $model->addBehaviour('log'); $this->assertTrue($model->hasProperty('v_start')); $this->assertTrue($model->hasProperty('v_end')); $this->assertCount(2, $model->getPk()); $this->assertSame($model->getPk(), array('id_page', 'v_end')); }
public function testSequences() { $application = getApplication(); /** * @var $schema Schema */ $schema = $application->getStorage()->getSchema(); $sequences = $schema->getSequences(); $this->assertCount(2, $sequences); $this->assertArrayHasKey('sq_person', $sequences); $person_model = $schema->getModel('person'); $person_sequence = $sequences['sq_person']; $this->assertEquals($person_sequence, $person_model->getSequence()); }
public function testSchema() { $application = getApplication(); /** * @var $schema \Cti\Storage\Schema */ $schema = $application->getStorage()->getSchema(); $this->assertNotEmpty($schema->getModel('person')); $schema->createModel('test', "Тестовая модель", array('text' => 'Текст')); $this->assertNotEmpty($schema->getModel('test')); $schema->removeModel('test'); $this->setExpectedException('Exception', 'Model test not found in schema'); $schema->removeModel('test'); }
public function testSchemaConverter() { $application = getApplication(); $manager = $application->getManager(); $this->adapter = $manager->get('Cti\\Storage\\Adapter\\DBAL'); $generator = $application->getConsole()->find('generate:database'); $this->clearDatabase(); $input = new StringInput("generate:database --test"); $output = new NullOutput(); ob_start(); $generator->run($input, $output); $sql = ob_get_contents(); ob_end_clean(); $this->assertEquals($this->getExpectedMigrateSql(), $sql); $this->adapter->rollBack(); $this->adapter->beginTransaction(); }
function testId() { $manager = getApplication()->getManager(); /** * @var \Cti\Storage\Component\Model $test */ $test = $manager->create('Cti\\Storage\\Component\\Model', array('name' => 'test', 'comment' => 'test')); $test->addProperty('name', array('type' => 'string')); // behaviour id added by default // $test->addBehaviour('id'); $this->assertSame($test->getPk(), array('id_test')); $this->assertCount(2, $test->getProperties()); $id = $test->getProperty('id_test'); $this->assertSame($id->getType(), 'integer'); $this->assertSame($id->getComment(), 'Identifier'); $this->assertSame($id->getRequired(), true, "Need to be notNull field"); }
public function testIndex() { $application = getApplication(); /** * @var $schema \Cti\Storage\Schema */ $schema = $application->getStorage()->getSchema(); foreach ($schema->getModels() as $model) { $indexes = $model->getIndexes(); // only person must have indexes if ($model->getName() == 'person') { $this->assertCount(1, $indexes); $this->assertEquals(array('login'), $indexes[0]->getFields()); } else { $this->assertCount(0, $indexes); } } }
function testGenerator() { $application = getApplication(); $migration = $application->getConsole()->find('generate:migration'); $input = new ArrayInput(array('command' => 'generate:migration', 'name' => array('hello', 'world'))); $output = new NullOutput(); $migration->run($input, $output); $finder = new Finder(); $finder->files()->name("*.php")->in($application->getProject()->getPath('resources php migrations')); $found = false; foreach ($finder as $file) { if (strpos($file->getBasename(), 'hello_world')) { $filesystem = new Filesystem(); $filesystem->remove($file->getRealPath()); $found = true; break; } } $this->assertTrue($found); }
public function testDBALAdapter() { $application = getApplication(); /** * @var $manager \Cti\Di\Manager */ $manager = $application->getManager(); /** * constructor and connect check * @var $dbal \Cti\Storage\Adapter\DBAL */ $dbal = $manager->get('Cti\\Storage\\Adapter\\DBAL'); if ($dbal->getDriver()->getName() == 'pdo_sqlite') { $query = "select current_timestamp"; } elseif ($dbal->getDriver()->getName() == 'oci8') { $query = "select sysdate from dual"; } elseif ($dbal->getDriver()->getName() == 'pdo_pgsql') { $query = "select clock_timestamp()"; } else { throw new \Exception("Undefined driver {$dbal->getDriver()->getName()}"); } $dbnow = $dbal->fetchColumn($query); $this->assertNotEmpty($dbnow); }
include "../include/common.php"; include "../config.php"; include "../include/db_connect.php"; include "../include/session.php"; include "../include/apply_submit.php"; include "../include/apply_gen.php"; if (isset($_SESSION['user_id'])) { if (isset($_REQUEST['club_id']) && isset($_REQUEST['action'])) { if (!isset($_REQUEST['cat_id'])) { $clubGet = "club_id=" . $_REQUEST['club_id']; } else { $clubGet = "club_id=" . $_REQUEST['club_id'] . "&cat_id=" . $_REQUEST['cat_id']; } if ($_REQUEST['action'] == "view") { $applicationId = getApplication($_SESSION['user_id'], $_REQUEST['club_id']); } else { if ($_REQUEST['action'] == "submit" && isset($_REQUEST['app_id'])) { $data = processSubmission($_REQUEST); $data += processFileSubmission($_FILES); $result = saveApplication($_SESSION['user_id'], $_REQUEST['app_id'], $data); $applicationId = $_REQUEST['app_id']; if ($result === TRUE) { $inform["success"] = "Your application to has been saved!"; } else { $inform["error"] = "Sorry! There seems to have been some error while saving your application."; $inform["detail"] = $result; } } else { echo $_REQUEST['action'] . "<br />"; }
public function setUp() { $this->master = getApplication()->getStorage()->getMaster(); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; $paths = (require __DIR__ . '/../paths.php'); return getApplication(getApplicationConfig('phprest', '0.1', true, $paths), $paths); /** * @param \Phprest\Config $config * @param array $paths * * @return \Phprest\Application */ function getApplication(\Phprest\Config $config, array $paths) { $app = new \Phprest\Application($config); require_once $paths['services']; require_once $paths['config.logger']; require_once $paths['routes']; return $app; } /** * @param string $vendor * @param string|integer$apiVersion * @param boolean $debug * @param array $paths * * @return \Phprest\Config */ function getApplicationConfig($vendor, $apiVersion, $debug, array $paths) { $config = new \Phprest\Config($vendor, $apiVersion, $debug); return $config;
public static function getCorrectDifference() { $path = getApplication()->getProject()->getPath('resources correctDifference.php'); return include $path; }
public function testConverting() { $schema = getApplication()->getStorage()->getSchema(); $array = $schema->asArray(); $this->assertEquals($this->getResultArray(), $array); }
public function testDBAL() { $application = getApplication(); /** * @var $schema \Cti\Storage\Schema */ $schema = $application->getStorage()->getSchema(); /** * @var $converter \Cti\Storage\Converter\DBAL */ $converter = $application->getManager()->get('\\Cti\\Storage\\Converter\\DBAL'); $dbalSchema = $converter->convert($schema); foreach ($schema->getModels() as $model) { $table = $dbalSchema->getTable($model->getName()); // check table existence $this->assertNotEmpty($table); $properties = $model->getProperties(); $this->assertEquals(count($properties), count($table->getColumns())); foreach ($properties as $property) { $column = $table->getColumn($property->getName()); $this->assertNotEmpty($column); // check column existance if ($property->getType() == 'char') { $this->assertEquals('string', $column->getType()->getName()); $this->assertEquals(1, $column->getLength()); } else { $this->assertEquals($property->getType(), $column->getType()->getName()); } $this->assertEquals($property->getRequired(), $column->getNotnull()); } $this->assertCount(count($model->getProperties()), $table->getColumns()); // primary key equals if (count($model->getPk())) { $this->assertNotEmpty($table->getPrimaryKey(), "Table \"{$table->getName()}\" don't have any primary key"); $this->assertEquals($table->getPrimaryKey()->getColumns(), $model->getPk(), "Table \"{$table->getName()}\" have invalid primary key"); } else { $this->assertEmpty($table->getPrimaryKey()); } //indexes isset $tableIndexes = array(); foreach ($table->getIndexes() as $index) { $tableIndexes[] = implode(':', $index->getColumns()); } foreach ($model->getIndexes() as $index) { $this->assertContains(implode(':', $index->getFields()), $tableIndexes, "Table don't have index with fields \"" . implode(':', $index->getFields()) . "\""); } // check foreign keys $tableFKs = array(); foreach ($table->getForeignKeys() as $key) { $tableFKs[] = $key->getForeignTableName() . "-" . implode(':', $key->getColumns()) . "-" . implode(':', $key->getForeignColumns()); } foreach ($model->getOutReferences() as $reference) { $remoteModel = $schema->getModel($reference->getDestination()); $localProperties = array_keys($reference->getProperties()); $remoteProperties = array(); foreach ($reference->getProperties() as $property) { $remoteProperties[] = $property->getForeignName(); } $key = $reference->getDestination() . '-' . implode(':', $localProperties) . '-' . implode(':', $remoteProperties); if ($remoteModel->getBehaviour('log')) { $this->assertNotContains($key, $tableFKs); } else { $this->assertContains($key, $tableFKs); } } $sequence = $model->getSequence(); if ($sequence) { $this->assertNotNull($dbalSchema->getSequence($sequence->getName())); } } }
protected function getCorrectMigration() { $correctMigrationPath = getApplication()->getProject()->getPath('resources correctMigration.php'); return file_get_contents($correctMigrationPath); }
public function __construct() { $this->application = getApplication(); $this->schema = $this->application->getStorage()->getSchema(); parent::__construct(); }