private function checkDeletedFk() { $this->readDatabase(); $diff = DatabaseComparator::computeDiff($this->database, $this->updatedBuilder->getDatabase()); $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff); $expected = 'issue617_user'; $this->assertNotContains($expected, $sql); }
private function checkDeletedFk() { $this->readDatabase(); $diff = PropelDatabaseComparator::computeDiff($this->database, $this->updatedBuilder->getDatabase()); $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff); $expected = ' # This is a fix for InnoDB in MySQL >= 4.1.x # It "suspends judgement" for fkey relationships until are tables are set. SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS `book`; # This restores the fkey checks, after having unset them earlier SET FOREIGN_KEY_CHECKS = 1; '; $this->assertEquals($expected, $sql); }
public function testValidateReturnsTrueForValidSchema() { $schema = <<<EOF <database name="bookstore"> \t<table name="book"> \t\t<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> \t\t<column name="title" type="VARCHAR" size="100" primaryString="true" /> \t</table> </database> EOF; $builder = new PropelQuickBuilder(); $builder->setSchema($schema); $database = $builder->getDatabase(); $appData = new AppData(); $appData->addDatabase($database); $validator = new PropelSchemaValidator($appData); $this->assertTrue($validator->validate()); }
public function testTableWithPrefix() { $schema = <<<EOF <database name="default" tablePrefix="plop_"> <table name="group"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> <column name="title" type="varchar" primaryString="true" size="255" /> <behavior name="i18n"> <parameter name="i18n_columns" value="title" /> <parameter name="locale_column" value="locale" /> </behavior> </table> </database> EOF; $builder = new PropelQuickBuilder(); $builder->setSchema($schema); $this->assertTrue($builder->getDatabase()->hasTable('plop_group')); $this->assertFalse($builder->getDatabase()->hasTable('plop_plop_group_i18n')); $this->assertTrue($builder->getDatabase()->hasTable('plop_group_i18n')); }
public function testModiFyTableDoesNotMoveValidatorsOnNonI18nColumns() { $schema = <<<EOF <database name="i18n_behavior_test_0"> \t<table name="i18n_behavior_test_0"> \t\t<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" /> \t\t<validator column="id"> \t\t\t<rule name="minLength" value="4" message="title must be at least 4 characters !" /> \t\t</validator> \t\t<column name="title" type="VARCHAR" /> \t\t<behavior name="i18n"> \t\t\t<parameter name="i18n_columns" value="title" /> \t\t</behavior> \t</table> </database> EOF; $builder = new PropelQuickBuilder(); $builder->setSchema($schema); $table = $builder->getDatabase()->getTable('i18n_behavior_test_0'); $this->assertEquals(1, count($table->getValidators())); $i18nTable = $builder->getDatabase()->getTable('i18n_behavior_test_0_i18n'); $this->assertEquals(array(), $i18nTable->getValidators()); }
public function testValidateReturnsFalseWhenCrossRefTableHasTwoFksToTheSameTable() { $schema = <<<EOF <database name="bookstore"> <table name="book"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="title" type="VARCHAR" size="100" primaryString="true" /> </table> <table name="book_book" isCrossRef="true"> <column name="parent_id" type="INTEGER" primaryKey="true" required="true"/> <column name="child_id" type="INTEGER" primaryKey="true" required="true"/> <foreign-key foreignTable="book"> <reference local="child_id" foreign="id"/> </foreign-key> <foreign-key foreignTable="book"> <reference local="parent_id" foreign="id"/> </foreign-key> </table> </database> EOF; $builder = new PropelQuickBuilder(); $builder->setSchema($schema); $database = $builder->getDatabase(); $appData = new AppData(); $appData->addDatabase($database); $validator = new PropelSchemaValidator($appData); $this->assertFalse($validator->validate()); $this->assertContains('Table "book_book" implements an equal nest relationship for table "book". This feature is not supported', $validator->getErrors()); }
protected function loadAndBuild() { $this->loadPropelQuickBuilder(); if (!class_exists('Glorpen\\Propel\\PropelBundle\\Tests\\Fixtures\\Model\\Book', false)) { $builder = new \PropelQuickBuilder(); $builder->getConfig()->setBuildProperty('behaviorEventClass', 'Behaviors.EventBehavior'); $builder->getConfig()->setBuildProperty('behaviorExtendClass', 'Behaviors.ExtendBehavior'); $builder->setSchema(static::$schema); $builder->setClassTargets(array('tablemap', 'peer', 'object', 'query', 'peerstub', 'querystub')); file_put_contents("/tmp/a.php", $builder->getClasses()); $builder->build(); $con = new EventPropelPDO('sqlite::memory:'); $con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); $name = $builder->getDatabase()->getName(); \Propel::setConnection($name, $con, \Propel::CONNECTION_READ); \Propel::setConnection($name, $con, \Propel::CONNECTION_WRITE); $builder->buildSQL($con); } }