public function testColumns() { $this->assertEquals(array(), $this->rmap->getLocalColumns(), 'A new relation has no local columns'); $this->assertEquals(array(), $this->rmap->getForeignColumns(), 'A new relation has no foreign columns'); $tmap1 = new TableMap('foo', $this->databaseMap); $col1 = $tmap1->addColumn('FOO1', 'Foo1PhpName', 'INTEGER'); $tmap2 = new TableMap('bar', $this->databaseMap); $col2 = $tmap2->addColumn('BAR1', 'Bar1PhpName', 'INTEGER'); $this->rmap->addColumnMapping($col1, $col2); $this->assertEquals(array($col1), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table'); $this->assertEquals(array($col2), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table'); $expected = array('foo.FOO1' => 'bar.BAR1'); $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings'); $col3 = $tmap1->addColumn('FOOFOO', 'FooFooPhpName', 'INTEGER'); $col4 = $tmap2->addColumn('BARBAR', 'BarBarPhpName', 'INTEGER'); $this->rmap->addColumnMapping($col3, $col4); $this->assertEquals(array($col1, $col3), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table'); $this->assertEquals(array($col2, $col4), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table'); $expected = array('foo.FOO1' => 'bar.BAR1', 'foo.FOOFOO' => 'bar.BARBAR'); $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings'); }
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')); }