PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/propel_15/vendor/propel/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorPeerBuilderModifierWithScopeTest.php

http://github.com/eventhorizonpl/forked-php-orm-benchmark
PHP | 253 lines | 186 code | 10 blank | 57 comment | 0 complexity | c7f0a78f4868f4bde9a33b40acb983a8 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * $Id: NestedSetBehaviorPeerBuilderModifierWithScopeTest.php 1612 2010-03-16 22:56:21Z francois $
  4. * This file is part of the Propel package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. require_once 'tools/helpers/bookstore/behavior/BookstoreNestedSetTestBase.php';
  11. /**
  12. * Tests for NestedSetBehaviorPeerBuilderModifier class
  13. *
  14. * @author Fran??ois Zaninotto
  15. * @version $Revision: 1612 $
  16. * @package generator.behavior.nestedset
  17. */
  18. class NestedSetBehaviorPeerBuilderModifierWithScopeTest extends BookstoreNestedSetTestBase
  19. {
  20. public function testConstants()
  21. {
  22. $this->assertEquals(Table10Peer::LEFT_COL, 'table10.MY_LEFT_COLUMN', 'nested_set adds a LEFT_COL constant using the custom left_column parameter');
  23. $this->assertEquals(Table10Peer::RIGHT_COL, 'table10.MY_RIGHT_COLUMN', 'nested_set adds a RIGHT_COL constant using the custom right_column parameter');
  24. $this->assertEquals(Table10Peer::LEVEL_COL, 'table10.MY_LEVEL_COLUMN', 'nested_set adds a LEVEL_COL constant using the custom level_column parameter');
  25. $this->assertEquals(Table10Peer::SCOPE_COL, 'table10.MY_SCOPE_COLUMN', 'nested_set adds a SCOPE_COL constant when the use_scope parameter is true');
  26. }
  27. public function testRetrieveRoots()
  28. {
  29. $this->assertTrue(method_exists('Table10Peer', 'retrieveRoots'), 'nested_set adds a retrieveRoots() method for trees that use scope');
  30. $this->assertFalse(method_exists('Table9Peer', 'retrieveRoots'), 'nested_set does not add a retrieveRoots() method for trees that don\'t use scope');
  31. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  32. /* Tree used for tests
  33. Scope 1
  34. t1
  35. | \
  36. t2 t3
  37. | \
  38. t4 t5
  39. | \
  40. t6 t7
  41. Scope 2
  42. t8
  43. | \
  44. t9 t10
  45. */
  46. $this->assertEquals(array($t1, $t8), Table10Peer::retrieveRoots(), 'retrieveRoots() returns the tree roots');
  47. $c = new Criteria();
  48. $c->add(Table10Peer::TITLE, 't1');
  49. $this->assertEquals(array($t1), Table10Peer::retrieveRoots($c), 'retrieveRoots() accepts a Criteria as first parameter');
  50. }
  51. public function testRetrieveRoot()
  52. {
  53. $this->assertTrue(method_exists('Table10Peer', 'retrieveRoot'), 'nested_set adds a retrieveRoot() method');
  54. Table10Peer::doDeleteAll();
  55. $t1 = new Table10();
  56. $t1->setLeftValue(1);
  57. $t1->setRightValue(2);
  58. $t1->setScopeValue(2);
  59. $t1->save();
  60. $this->assertNull(Table10Peer::retrieveRoot(1), 'retrieveRoot() returns null as long as no root node is defined in the required scope');
  61. $t2 = new Table10();
  62. $t2->setLeftValue(1);
  63. $t2->setRightValue(2);
  64. $t2->setScopeValue(1);
  65. $t2->save();
  66. $this->assertEquals(Table10Peer::retrieveRoot(1), $t2, 'retrieveRoot() retrieves the root node in the required scope');
  67. }
  68. public function testRetrieveTree()
  69. {
  70. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  71. /* Tree used for tests
  72. Scope 1
  73. t1
  74. | \
  75. t2 t3
  76. | \
  77. t4 t5
  78. | \
  79. t6 t7
  80. Scope 2
  81. t8
  82. | \
  83. t9 t10
  84. */
  85. $tree = Table10Peer::retrieveTree(1);
  86. $this->assertEquals(array($t1, $t2, $t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() retrieves the scoped tree');
  87. $tree = Table10Peer::retrieveTree(2);
  88. $this->assertEquals(array($t8, $t9, $t10), $tree, 'retrieveTree() retrieves the scoped tree');
  89. $c = new Criteria();
  90. $c->add(Table10Peer::LEFT_COL, 4, Criteria::GREATER_EQUAL);
  91. $tree = Table10Peer::retrieveTree(1, $c);
  92. $this->assertEquals(array($t3, $t4, $t5, $t6, $t7), $tree, 'retrieveTree() accepts a Criteria as first parameter');
  93. }
  94. public function testDeleteTree()
  95. {
  96. $this->initTreeWithScope();
  97. Table10Peer::deleteTree(1);
  98. $expected = array(
  99. 't8' => array(1, 6, 0),
  100. 't9' => array(2, 3, 1),
  101. 't10' => array(4, 5, 1),
  102. );
  103. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'deleteTree() does not delete anything out of the scope');
  104. }
  105. public function testShiftRLValues()
  106. {
  107. $this->assertTrue(method_exists('Table10Peer', 'shiftRLValues'), 'nested_set adds a shiftRLValues() method');
  108. $this->initTreeWithScope();
  109. Table10Peer::shiftRLValues(1, 100, null, 1);
  110. Table10Peer::clearInstancePool();
  111. $expected = array(
  112. 't1' => array(1, 14, 0),
  113. 't2' => array(2, 3, 1),
  114. 't3' => array(4, 13, 1),
  115. 't4' => array(5, 6, 2),
  116. 't5' => array(7, 12, 2),
  117. 't6' => array(8, 9, 3),
  118. 't7' => array(10, 11, 3),
  119. );
  120. $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues does not shift anything when the first parameter is higher than the highest right value');
  121. $expected = array(
  122. 't8' => array(1, 6, 0),
  123. 't9' => array(2, 3, 1),
  124. 't10' => array(4, 5, 1),
  125. );
  126. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
  127. $this->initTreeWithScope();
  128. Table10Peer::shiftRLValues(1, 1, null, 1);
  129. Table10Peer::clearInstancePool();
  130. $expected = array(
  131. 't1' => array(2, 15, 0),
  132. 't2' => array(3, 4, 1),
  133. 't3' => array(5, 14, 1),
  134. 't4' => array(6, 7, 2),
  135. 't5' => array(8, 13, 2),
  136. 't6' => array(9, 10, 3),
  137. 't7' => array(11, 12, 3),
  138. );
  139. $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the right');
  140. $expected = array(
  141. 't8' => array(1, 6, 0),
  142. 't9' => array(2, 3, 1),
  143. 't10' => array(4, 5, 1),
  144. );
  145. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
  146. $this->initTreeWithScope();
  147. Table10Peer::shiftRLValues(-1, 1, null, 1);
  148. Table10Peer::clearInstancePool();
  149. $expected = array(
  150. 't1' => array(0, 13, 0),
  151. 't2' => array(1, 2, 1),
  152. 't3' => array(3, 12, 1),
  153. 't4' => array(4, 5, 2),
  154. 't5' => array(6, 11, 2),
  155. 't6' => array(7, 8, 3),
  156. 't7' => array(9, 10, 3),
  157. );
  158. $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift all nodes to the left');
  159. $expected = array(
  160. 't8' => array(1, 6, 0),
  161. 't9' => array(2, 3, 1),
  162. 't10' => array(4, 5, 1),
  163. );
  164. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
  165. $this->initTreeWithScope();
  166. Table10Peer::shiftRLValues(1, 5, null, 1);
  167. Table10Peer::clearInstancePool();
  168. $expected = array(
  169. 't1' => array(1, 15, 0),
  170. 't2' => array(2, 3, 1),
  171. 't3' => array(4, 14, 1),
  172. 't4' => array(6, 7, 2),
  173. 't5' => array(8, 13, 2),
  174. 't6' => array(9, 10, 3),
  175. 't7' => array(11, 12, 3),
  176. );
  177. $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftRLValues can shift some nodes to the right');
  178. $expected = array(
  179. 't8' => array(1, 6, 0),
  180. 't9' => array(2, 3, 1),
  181. 't10' => array(4, 5, 1),
  182. );
  183. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftRLValues does not shift anything out of the scope');
  184. }
  185. public function testShiftLevel()
  186. {
  187. $this->initTreeWithScope();
  188. Table10Peer::shiftLevel($delta = 1, $first = 7, $last = 12, $scope = 1);
  189. Table10Peer::clearInstancePool();
  190. $expected = array(
  191. 't1' => array(1, 14, 0),
  192. 't2' => array(2, 3, 1),
  193. 't3' => array(4, 13, 1),
  194. 't4' => array(5, 6, 2),
  195. 't5' => array(7, 12, 3),
  196. 't6' => array(8, 9, 4),
  197. 't7' => array(10, 11, 4),
  198. );
  199. $this->assertEquals($this->dumpTreeWithScope(1), $expected, 'shiftLevel can shift level whith a scope');
  200. $expected = array(
  201. 't8' => array(1, 6, 0),
  202. 't9' => array(2, 3, 1),
  203. 't10' => array(4, 5, 1),
  204. );
  205. $this->assertEquals($this->dumpTreeWithScope(2), $expected, 'shiftLevel does not shift anything out of the scope');
  206. }
  207. public function testMakeRoomForLeaf()
  208. {
  209. $this->assertTrue(method_exists('Table10Peer', 'makeRoomForLeaf'), 'nested_set adds a makeRoomForLeaf() method');
  210. $fixtures = $this->initTreeWithScope();
  211. /* Tree used for tests
  212. Scope 1
  213. t1
  214. | \
  215. t2 t3
  216. | \
  217. t4 t5
  218. | \
  219. t6 t7
  220. Scope 2
  221. t8
  222. | \
  223. t9 t10
  224. */
  225. $t = Table10Peer::makeRoomForLeaf(5, 1); // first child of t3
  226. $expected = array(
  227. 't1' => array(1, 16, 0),
  228. 't2' => array(2, 3, 1),
  229. 't3' => array(4, 15, 1),
  230. 't4' => array(7, 8, 2),
  231. 't5' => array(9, 14, 2),
  232. 't6' => array(10, 11, 3),
  233. 't7' => array(12, 13, 3),
  234. );
  235. $this->assertEquals($expected, $this->dumpTreeWithScope(1), 'makeRoomForLeaf() shifts the other nodes correctly');
  236. $expected = array(
  237. 't8' => array(1, 6, 0),
  238. 't9' => array(2, 3, 1),
  239. 't10' => array(4, 5, 1),
  240. );
  241. $this->assertEquals($expected, $this->dumpTreeWithScope(2), 'makeRoomForLeaf() does not shift anything out of the scope');
  242. }
  243. }