/tests/ConfigurableTestCase.php

https://github.com/xdade/doctrine1 · PHP · 222 lines · 183 code · 37 blank · 2 comment · 0 complexity · 82c2ddf2f2fc9db3a184d071180573b6 MD5 · raw file

  1. <?php
  2. class Doctrine_Configurable_TestCase extends Doctrine_UnitTestCase
  3. {
  4. public function prepareTables()
  5. {
  6. }
  7. public function prepareData()
  8. {
  9. }
  10. public function testGetIndexNameFormatAttribute()
  11. {
  12. // default index name format is %_idx
  13. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT), '%s_idx');
  14. }
  15. public function testGetSequenceNameFormatAttribute()
  16. {
  17. // default sequence name format is %_seq
  18. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT), '%s_seq');
  19. }
  20. public function testSetIndexNameFormatAttribute()
  21. {
  22. $original = $this->manager->getAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT);
  23. $this->manager->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, '%_index');
  24. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT), '%_index');
  25. $this->manager->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, $original);
  26. }
  27. public function testSetSequenceNameFormatAttribute()
  28. {
  29. $original = $this->manager->getAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT);
  30. $this->manager->setAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT, '%_sequence');
  31. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT), '%_sequence');
  32. $this->manager->setAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT, $original);
  33. }
  34. public function testExceptionIsThrownWhenSettingIndexNameFormatAttributeAtTableLevel()
  35. {
  36. try {
  37. $this->connection->getTable('Entity')->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, '%s_idx');
  38. $this->fail();
  39. } catch(Doctrine_Exception $e) {
  40. $this->pass();
  41. }
  42. }
  43. public function testExceptionIsThrownWhenSettingSequenceNameFormatAttributeAtTableLevel()
  44. {
  45. try {
  46. $this->connection->getTable('Entity')->setAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT, '%s_seq');
  47. $this->fail();
  48. } catch(Doctrine_Exception $e) {
  49. $this->pass();
  50. }
  51. }
  52. public function testSettingFieldCaseIsSuccesfulWithZero()
  53. {
  54. $original = $this->connection->getAttribute(Doctrine_Core::ATTR_FIELD_CASE);
  55. try {
  56. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, 0);
  57. $this->pass();
  58. } catch(Doctrine_Exception $e) {
  59. $this->fail();
  60. }
  61. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, $original);
  62. }
  63. public function testSettingFieldCaseIsSuccesfulWithCaseConstants()
  64. {
  65. $original = $this->connection->getAttribute(Doctrine_Core::ATTR_FIELD_CASE);
  66. try {
  67. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, CASE_LOWER);
  68. $this->pass();
  69. } catch(Doctrine_Exception $e) {
  70. $this->fail();
  71. }
  72. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, $original);
  73. }
  74. public function testSettingFieldCaseIsSuccesfulWithCaseConstants2()
  75. {
  76. $original = $this->connection->getAttribute(Doctrine_Core::ATTR_FIELD_CASE);
  77. try {
  78. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, CASE_UPPER);
  79. $this->pass();
  80. } catch(Doctrine_Exception $e) {
  81. $this->fail();
  82. }
  83. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, $original);
  84. }
  85. public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo()
  86. {
  87. try {
  88. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, -1);
  89. $this->fail();
  90. } catch(Doctrine_Exception $e) {
  91. $this->pass();
  92. }
  93. }
  94. public function testExceptionIsThrownWhenSettingFieldCaseToNotZeroOneOrTwo2()
  95. {
  96. try {
  97. $this->connection->setAttribute(Doctrine_Core::ATTR_FIELD_CASE, 5);
  98. $this->fail();
  99. } catch(Doctrine_Exception $e) {
  100. $this->pass();
  101. }
  102. }
  103. public function testDefaultQuoteIdentifierAttributeValueIsFalse()
  104. {
  105. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER), false);
  106. }
  107. public function testQuoteIdentifierAttributeAcceptsBooleans()
  108. {
  109. $this->manager->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
  110. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER), true);
  111. $this->manager->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, false);
  112. }
  113. public function testDefaultSequenceColumnNameAttributeValueIsId()
  114. {
  115. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_SEQCOL_NAME), 'id');
  116. }
  117. public function testSequenceColumnNameAttributeAcceptsStrings()
  118. {
  119. $original = $this->manager->getAttribute(Doctrine_Core::ATTR_SEQCOL_NAME);
  120. $this->manager->setAttribute(Doctrine_Core::ATTR_SEQCOL_NAME, 'sequence');
  121. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_SEQCOL_NAME), 'sequence');
  122. $this->manager->setAttribute(Doctrine_Core::ATTR_SEQCOL_NAME, $original);
  123. }
  124. public function testValidatorAttributeAcceptsBooleans()
  125. {
  126. $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, true);
  127. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_VALIDATE), true);
  128. $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, false);
  129. }
  130. public function testDefaultPortabilityAttributeValueIsAll()
  131. {
  132. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_PORTABILITY), Doctrine_Core::PORTABILITY_NONE);
  133. }
  134. public function testPortabilityAttributeAcceptsPortabilityConstants()
  135. {
  136. $this->manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_RTRIM | Doctrine_Core::PORTABILITY_FIX_CASE);
  137. $this->assertEqual($this->manager->getAttribute(Doctrine_Core::ATTR_PORTABILITY),
  138. Doctrine_Core::PORTABILITY_RTRIM | Doctrine_Core::PORTABILITY_FIX_CASE);
  139. $this->manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_ALL);
  140. }
  141. public function testDefaultListenerIsDoctrineEventListener()
  142. {
  143. $this->assertTrue($this->manager->getAttribute(Doctrine_Core::ATTR_LISTENER) instanceof Doctrine_EventListener);
  144. }
  145. public function testListenerAttributeAcceptsEventListenerObjects()
  146. {
  147. $original = $this->manager->getAttribute(Doctrine_Core::ATTR_LISTENER);
  148. $this->manager->setAttribute(Doctrine_Core::ATTR_LISTENER, new Doctrine_EventListener());
  149. $this->assertTrue($this->manager->getAttribute(Doctrine_Core::ATTR_LISTENER) instanceof Doctrine_EventListener);
  150. $this->manager->setAttribute(Doctrine_Core::ATTR_LISTENER, $original);
  151. }
  152. public function testCollectionKeyAttributeAcceptsValidColumnName()
  153. {
  154. $original = $this->connection->getTable('User')->getAttribute(Doctrine_Core::ATTR_COLL_KEY);
  155. try {
  156. $this->connection->getTable('User')->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'name');
  157. $this->pass();
  158. } catch(Exception $e) {
  159. $this->fail();
  160. }
  161. $this->connection->getTable('User')->setAttribute(Doctrine_Core::ATTR_COLL_KEY, $original);
  162. }
  163. public function testSettingInvalidColumnNameToCollectionKeyAttributeThrowsException()
  164. {
  165. try {
  166. $this->connection->getTable('User')->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'unknown');
  167. $this->fail();
  168. } catch(Exception $e) {
  169. $this->pass();
  170. }
  171. }
  172. public function testSettingCollectionKeyAttributeOnOtherThanTableLevelThrowsException()
  173. {
  174. try {
  175. $this->connection->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'name');
  176. $this->fail();
  177. } catch(Exception $e) {
  178. $this->pass();
  179. }
  180. }
  181. public function testGetAttributes()
  182. {
  183. $this->assertTrue(is_array($this->manager->getAttributes()));
  184. }
  185. }