PageRenderTime 34ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/propel/test/testsuite/runtime/map/RelationMapTest.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 89 lines | 66 code | 9 blank | 14 comment | 0 complexity | 3e3b2891c69d8e45b3a59e84d8b32353 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once dirname(__FILE__) . '/../../../../runtime/lib/map/DatabaseMap.php';
  10. require_once dirname(__FILE__) . '/../../../../runtime/lib/map/RelationMap.php';
  11. require_once dirname(__FILE__) . '/../../../../runtime/lib/map/ColumnMap.php';
  12. require_once dirname(__FILE__) . '/../../../../runtime/lib/map/TableMap.php';
  13. /**
  14. * Test class for RelationMap.
  15. *
  16. * @author François Zaninotto
  17. * @version $Id$
  18. * @package runtime.map
  19. */
  20. class RelationMapTest extends PHPUnit_Framework_TestCase
  21. {
  22. protected $databaseMap, $relationName, $rmap;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $this->databaseMap = new DatabaseMap('foodb');
  27. $this->relationName = 'foo';
  28. $this->rmap = new RelationMap($this->relationName);
  29. }
  30. public function testConstructor()
  31. {
  32. $this->assertEquals($this->relationName, $this->rmap->getName(), 'constructor sets the relation name');
  33. }
  34. public function testLocalTable()
  35. {
  36. $this->assertNull($this->rmap->getLocalTable(), 'A new relation has no local table');
  37. $tmap1 = new TableMap('foo', $this->databaseMap);
  38. $this->rmap->setLocalTable($tmap1);
  39. $this->assertEquals($tmap1, $this->rmap->getLocalTable(), 'The local table is set by setLocalTable()');
  40. }
  41. public function testForeignTable()
  42. {
  43. $this->assertNull($this->rmap->getForeignTable(), 'A new relation has no foreign table');
  44. $tmap2 = new TableMap('bar', $this->databaseMap);
  45. $this->rmap->setForeignTable($tmap2);
  46. $this->assertEquals($tmap2, $this->rmap->getForeignTable(), 'The foreign table is set by setForeignTable()');
  47. }
  48. public function testProperties()
  49. {
  50. $properties = array('type', 'onUpdate', 'onDelete');
  51. foreach ($properties as $property) {
  52. $getter = 'get' . ucfirst($property);
  53. $setter = 'set' . ucfirst($property);
  54. $this->assertNull($this->rmap->$getter(), "A new relation has no $property");
  55. $this->rmap->$setter('foo_value');
  56. $this->assertEquals('foo_value', $this->rmap->$getter(), "The $property is set by setType()");
  57. }
  58. }
  59. public function testColumns()
  60. {
  61. $this->assertEquals(array(), $this->rmap->getLocalColumns(), 'A new relation has no local columns');
  62. $this->assertEquals(array(), $this->rmap->getForeignColumns(), 'A new relation has no foreign columns');
  63. $tmap1 = new TableMap('foo', $this->databaseMap);
  64. $col1 = $tmap1->addColumn('FOO1', 'Foo1PhpName', 'INTEGER');
  65. $tmap2 = new TableMap('bar', $this->databaseMap);
  66. $col2 = $tmap2->addColumn('BAR1', 'Bar1PhpName', 'INTEGER');
  67. $this->rmap->addColumnMapping($col1, $col2);
  68. $this->assertEquals(array($col1), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
  69. $this->assertEquals(array($col2), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
  70. $expected = array('foo.FOO1' => 'bar.BAR1');
  71. $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
  72. $col3 = $tmap1->addColumn('FOOFOO', 'FooFooPhpName', 'INTEGER');
  73. $col4 = $tmap2->addColumn('BARBAR', 'BarBarPhpName', 'INTEGER');
  74. $this->rmap->addColumnMapping($col3, $col4);
  75. $this->assertEquals(array($col1, $col3), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
  76. $this->assertEquals(array($col2, $col4), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
  77. $expected = array('foo.FOO1' => 'bar.BAR1', 'foo.FOOFOO' => 'bar.BARBAR');
  78. $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
  79. }
  80. }