PageRenderTime 144ms CodeModel.GetById 54ms RepoModel.GetById 2ms app.codeStats 0ms

/test/testsuite/generator/builder/om/GeneratedObjectArrayColumnTypeTest.php

https://github.com/mattleff/propel
PHP | 131 lines | 106 code | 11 blank | 14 comment | 1 complexity | f92926c015e2dbe93e1e72a311ad7b21 MD5 | raw file
  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 'PHPUnit/Framework.php';
  10. require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
  11. require_once dirname(__FILE__) . '/../../../../../runtime/lib/Propel.php';
  12. /**
  13. * Tests the generated objects for array column types accessor & mutator
  14. *
  15. * @author Francois Zaninotto
  16. * @package generator.builder.om
  17. */
  18. class GeneratedObjectArrayColumnTypeTest extends PHPUnit_Framework_TestCase
  19. {
  20. public function setUp()
  21. {
  22. if (!class_exists('ComplexColumnTypeEntity2')) {
  23. $schema = <<<EOF
  24. <database name="generated_object_complex_type_test_2">
  25. <table name="complex_column_type_entity_2">
  26. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  27. <column name="tags" type="ARRAY" />
  28. <column name="value_set" type="ARRAY" />
  29. </table>
  30. </database>
  31. EOF;
  32. PropelQuickBuilder::buildSchema($schema);
  33. }
  34. }
  35. public function testActiveRecordMethods()
  36. {
  37. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'getTags'));
  38. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'hasTag'));
  39. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'setTags'));
  40. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'addTag'));
  41. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'removeTag'));
  42. // only plural column names get a tester, an adder, and a remover method
  43. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'getValueSet'));
  44. $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'hasValueSet'));
  45. $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'setValueSet'));
  46. $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'addValueSet'));
  47. $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'removeValueSet'));
  48. }
  49. public function testGetterDefaultValue()
  50. {
  51. $e = new ComplexColumnTypeEntity2();
  52. $this->assertEquals(array(), $e->getTags(), 'array columns return an empty array by default');
  53. }
  54. public function testSetterArrayValue()
  55. {
  56. $e = new ComplexColumnTypeEntity2();
  57. $value = array('foo', 1234);
  58. $e->setTags($value);
  59. $this->assertEquals($value, $e->getTags(), 'array columns can store arrays');
  60. }
  61. public function testSetterResetValue()
  62. {
  63. $e = new ComplexColumnTypeEntity2();
  64. $value = array('foo', 1234);
  65. $e->setTags($value);
  66. $e->setTags(array());
  67. $this->assertEquals(array(), $e->getTags(), 'object columns can be reset');
  68. }
  69. public function testTester()
  70. {
  71. $e = new ComplexColumnTypeEntity2();
  72. $this->assertFalse($e->hasTag('foo'));
  73. $this->assertFalse($e->hasTag(1234));
  74. $value = array('foo', 1234);
  75. $e->setTags($value);
  76. $this->assertTrue($e->hasTag('foo'));
  77. $this->assertTrue($e->hasTag(1234));
  78. $this->assertFalse($e->hasTag('bar'));
  79. $this->assertFalse($e->hasTag(12));
  80. }
  81. public function testAdder()
  82. {
  83. $e = new ComplexColumnTypeEntity2();
  84. $e->addTag('foo');
  85. $this->assertEquals(array('foo'), $e->getTags());
  86. $e->addTag(1234);
  87. $this->assertEquals(array('foo', 1234), $e->getTags());
  88. $e->addTag('foo');
  89. $this->assertEquals(array('foo', 1234, 'foo'), $e->getTags());
  90. $e->setTags(array(12, 34));
  91. $e->addTag('foo');
  92. $this->assertEquals(array(12, 34, 'foo'), $e->getTags());
  93. }
  94. public function testRemover()
  95. {
  96. $e = new ComplexColumnTypeEntity2();
  97. $e->removeTag('foo');
  98. $this->assertEquals(array(), $e->getTags());
  99. $e->setTags(array('foo', 1234));
  100. $e->removeTag('foo');
  101. $this->assertEquals(array(1234), $e->getTags());
  102. $e->removeTag(1234);
  103. $this->assertEquals(array(), $e->getTags());
  104. $e->setTags(array(12, 34, 1234));
  105. $e->removeTag('foo');
  106. $this->assertEquals(array(12, 34, 1234), $e->getTags());
  107. $e->removeTag('1234');
  108. $this->assertEquals(array(12, 34), $e->getTags());
  109. }
  110. public function testValueIsPersisted()
  111. {
  112. $e = new ComplexColumnTypeEntity2();
  113. $value = array('foo', 1234);
  114. $e->setTags($value);
  115. $e->save();
  116. ComplexColumnTypeEntity2Peer::clearInstancePool();
  117. $e = ComplexColumnTypeEntity2Query::create()->findOne();
  118. $this->assertEquals($value, $e->getTags(), 'array columns are persisted');
  119. }
  120. }