/** * @dataProvider phpNameData */ public function testGetTableByPhpNameNamespaced($name, $phpName, $classname) { try { $this->databaseMap->getTableByPhpName($classname); $this->fail('getTableByPhpName() throws an exception when called on an inexistent table'); } catch (PropelException $e) { $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table'); } $tmap2 = new TableMap($name); $tmap2->setPhpName($phpName); $tmap2->setClassname($classname); $this->databaseMap->addTableObject($tmap2); $this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName($classname), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()'); }
public function testAddRelation() { $foreigntmap1 = new TableMap('bar'); $foreigntmap1->setClassname('Bar'); $this->databaseMap->addTableObject($foreigntmap1); $foreigntmap2 = new TableMap('baz'); $foreigntmap2->setClassname('Baz'); $this->databaseMap->addTableObject($foreigntmap2); $this->rmap1 = $this->tmap->addRelation('Bar', 'Bar', RelationMap::MANY_TO_ONE); $this->rmap2 = $this->tmap->addRelation('Bazz', 'Baz', RelationMap::ONE_TO_MANY); $this->tmap->getRelations(); // now on to the test $this->assertEquals($this->rmap1->getLocalTable(), $this->tmap, 'adding a relation with HAS_ONE sets the local table to the current table'); $this->assertEquals($this->rmap1->getForeignTable(), $foreigntmap1, 'adding a relation with HAS_ONE sets the foreign table according to the name given'); $this->assertEquals(RelationMap::MANY_TO_ONE, $this->rmap1->getType(), 'adding a relation with HAS_ONE sets the foreign table type accordingly'); $this->assertEquals($this->rmap2->getForeignTable(), $this->tmap, 'adding a relation with HAS_MANY sets the foreign table to the current table'); $this->assertEquals($this->rmap2->getLocalTable(), $foreigntmap2, 'adding a relation with HAS_MANY sets the local table according to the name given'); $this->assertEquals(RelationMap::ONE_TO_MANY, $this->rmap2->getType(), 'adding a relation with HAS_MANY sets the foreign table type accordingly'); $expectedRelations = array('Bar' => $this->rmap1, 'Bazz' => $this->rmap2); $this->assertEquals($expectedRelations, $this->tmap->getRelations(), 'getRelations() returns an associative array of all the relations'); }
public function translatableFieldNamesProvider() { $dbMap = new \DatabaseMap('default'); $authorTableMap = new \TableMap(); $authorTableMap->setName('author'); $authorTableMap->setPhpName('Author'); $authorTableMap->setClassname('Acme\\DemoBundle\\Model\\Author'); $authorTableMap->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $dbMap->addTableObject($authorTableMap); $bookTableMap = new \TableMap(); $bookTableMap->setName('book'); $bookTableMap->setPhpName('Book'); $bookTableMap->setClassname('Acme\\DemoBundle\\Model\\Book'); $bookTableMap->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $bookTableMap->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); $bookTableMap->addColumn('SLUG', 'Slug', 'VARCHAR', false, 255, null); $bookTableMap->addForeignKey('AUTHOR_ID', 'AuthorId', 'INTEGER', 'author', 'id', true, null, null); $dbMap->addTableObject($bookTableMap); $bookTableMap->addRelation('Author', 'Acme\\DemoBundle\\Model\\Author', \RelationMap::MANY_TO_ONE, array('AUTHOR_ID' => 'ID'), 'CASCADE', null); $manager = new TestableModelManager(); $manager->addTable('Acme\\DemoBundle\\Model\\Author', $authorTableMap); $manager->addTable('Acme\\DemoBundle\\Model\\Book', $bookTableMap); return array(array($manager, 'Acme\\DemoBundle\\Model\\Author', 'ID', 'Id'), array($manager, 'Acme\\DemoBundle\\Model\\Author', 'Id', 'Id'), array($manager, 'Acme\\DemoBundle\\Model\\Author', 'id', 'Id'), array($manager, 'Acme\\DemoBundle\\Model\\Book', 'name', 'Name'), array($manager, 'Acme\\DemoBundle\\Model\\Book', 'author', 'AuthorId'), array($manager, 'Acme\\DemoBundle\\Model\\Book', 'Author', 'AuthorId')); }