PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/test/testsuite/generator/behavior/nestedset/NestedSetBehaviorQueryBuilderModifierWithScopeTest.php

https://github.com/nextbigsound/propel-orm
PHP | 285 lines | 114 code | 16 blank | 155 comment | 0 complexity | 212f2f9a4c259cf5c506efec7d6e536c MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: NestedSetBehaviorQueryBuilderModifierTest.php 1347 2009-12-03 21:06:36Z 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 NestedSetBehaviorQueryBuilderModifier class with scope enabled
  13. *
  14. * @author François Zaninotto
  15. * @version $Revision$
  16. * @package generator.behavior.nestedset
  17. */
  18. class NestedSetBehaviorQueryBuilderModifierWithScopeTest extends BookstoreNestedSetTestBase
  19. {
  20. public function testTreeRoots()
  21. {
  22. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  23. /* Tree used for tests
  24. Scope 1
  25. t1
  26. | \
  27. t2 t3
  28. | \
  29. t4 t5
  30. | \
  31. t6 t7
  32. Scope 2
  33. t8
  34. | \
  35. t9 t10
  36. */
  37. $objs = Table10Query::create()
  38. ->treeRoots()
  39. ->find();
  40. $coll = $this->buildCollection(array($t1, $t8));
  41. $this->assertEquals($coll, $objs, 'treeRoots() filters by roots');
  42. }
  43. public function testInTree()
  44. {
  45. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  46. /* Tree used for tests
  47. Scope 1
  48. t1
  49. | \
  50. t2 t3
  51. | \
  52. t4 t5
  53. | \
  54. t6 t7
  55. Scope 2
  56. t8
  57. | \
  58. t9 t10
  59. */
  60. $tree = Table10Query::create()
  61. ->inTree(1)
  62. ->orderByBranch()
  63. ->find();
  64. $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
  65. $this->assertEquals($coll, $tree, 'inTree() filters by node');
  66. $tree = Table10Query::create()
  67. ->inTree(2)
  68. ->orderByBranch()
  69. ->find();
  70. $coll = $this->buildCollection(array($t8, $t9, $t10));
  71. $this->assertEquals($coll, $tree, 'inTree() filters by node');
  72. }
  73. public function testDescendantsOf()
  74. {
  75. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  76. /* Tree used for tests
  77. Scope 1
  78. t1
  79. | \
  80. t2 t3
  81. | \
  82. t4 t5
  83. | \
  84. t6 t7
  85. Scope 2
  86. t8
  87. | \
  88. t9 t10
  89. */
  90. $objs = Table10Query::create()
  91. ->descendantsOf($t1)
  92. ->orderByBranch()
  93. ->find();
  94. $coll = $this->buildCollection(array($t2, $t3, $t4, $t5, $t6, $t7));
  95. $this->assertEquals($coll, $objs, 'decendantsOf() filters by descendants of the same scope');
  96. }
  97. public function testBranchOf()
  98. {
  99. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  100. /* Tree used for tests
  101. Scope 1
  102. t1
  103. | \
  104. t2 t3
  105. | \
  106. t4 t5
  107. | \
  108. t6 t7
  109. Scope 2
  110. t8
  111. | \
  112. t9 t10
  113. */
  114. $objs = Table10Query::create()
  115. ->branchOf($t1)
  116. ->orderByBranch()
  117. ->find();
  118. $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
  119. $this->assertEquals($coll, $objs, 'branchOf() filters by branch of the same scope');
  120. }
  121. public function testChildrenOf()
  122. {
  123. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  124. /* Tree used for tests
  125. Scope 1
  126. t1
  127. | \
  128. t2 t3
  129. | \
  130. t4 t5
  131. | \
  132. t6 t7
  133. Scope 2
  134. t8
  135. | \
  136. t9 t10
  137. */
  138. $objs = Table10Query::create()
  139. ->childrenOf($t1)
  140. ->orderByBranch()
  141. ->find();
  142. $coll = $this->buildCollection(array($t2, $t3));
  143. $this->assertEquals($coll, $objs, 'childrenOf() filters by children of the same scope');
  144. }
  145. public function testSiblingsOf()
  146. {
  147. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  148. /* Tree used for tests
  149. Scope 1
  150. t1
  151. | \
  152. t2 t3
  153. | \
  154. t4 t5
  155. | \
  156. t6 t7
  157. Scope 2
  158. t8
  159. | \
  160. t9 t10
  161. */
  162. $desc = Table10Query::create()
  163. ->siblingsOf($t3)
  164. ->orderByBranch()
  165. ->find();
  166. $coll = $this->buildCollection(array($t2));
  167. $this->assertEquals($coll, $desc, 'siblingsOf() returns filters by siblings of the same scope');
  168. }
  169. public function testAncestorsOf()
  170. {
  171. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  172. /* Tree used for tests
  173. Scope 1
  174. t1
  175. | \
  176. t2 t3
  177. | \
  178. t4 t5
  179. | \
  180. t6 t7
  181. Scope 2
  182. t8
  183. | \
  184. t9 t10
  185. */
  186. $objs = Table10Query::create()
  187. ->ancestorsOf($t5)
  188. ->orderByBranch()
  189. ->find();
  190. $coll = $this->buildCollection(array($t1, $t3), 'ancestorsOf() filters by ancestors of the same scope');
  191. }
  192. public function testRootsOf()
  193. {
  194. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  195. /* Tree used for tests
  196. Scope 1
  197. t1
  198. | \
  199. t2 t3
  200. | \
  201. t4 t5
  202. | \
  203. t6 t7
  204. Scope 2
  205. t8
  206. | \
  207. t9 t10
  208. */
  209. $objs = Table10Query::create()
  210. ->rootsOf($t5)
  211. ->orderByBranch()
  212. ->find();
  213. $coll = $this->buildCollection(array($t1, $t3, $t5), 'rootsOf() filters by ancestors of the same scope');
  214. }
  215. public function testFindRoot()
  216. {
  217. $this->assertTrue(method_exists('Table10Query', 'findRoot'), 'nested_set adds a findRoot() method');
  218. Table10Query::create()->deleteAll();
  219. $this->assertNull(Table10Query::create()->findRoot(1), 'findRoot() returns null as long as no root node is defined');
  220. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  221. /* Tree used for tests
  222. Scope 1
  223. t1
  224. | \
  225. t2 t3
  226. | \
  227. t4 t5
  228. | \
  229. t6 t7
  230. Scope 2
  231. t8
  232. | \
  233. t9 t10
  234. */
  235. $this->assertEquals($t1, Table10Query::create()->findRoot(1), 'findRoot() returns a tree root');
  236. $this->assertEquals($t8, Table10Query::create()->findRoot(2), 'findRoot() returns a tree root');
  237. }
  238. public function testFindTree()
  239. {
  240. list($t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->initTreeWithScope();
  241. /* Tree used for tests
  242. Scope 1
  243. t1
  244. | \
  245. t2 t3
  246. | \
  247. t4 t5
  248. | \
  249. t6 t7
  250. Scope 2
  251. t8
  252. | \
  253. t9 t10
  254. */
  255. $tree = Table10Query::create()->findTree(1);
  256. $coll = $this->buildCollection(array($t1, $t2, $t3, $t4, $t5, $t6, $t7));
  257. $this->assertEquals($coll, $tree, 'findTree() retrieves the tree of a scope, ordered by branch');
  258. $tree = Table10Query::create()->findTree(2);
  259. $coll = $this->buildCollection(array($t8, $t9, $t10));
  260. $this->assertEquals($coll, $tree, 'findTree() retrieves the tree of a scope, ordered by branch');
  261. }
  262. protected function buildCollection($arr)
  263. {
  264. $coll = new PropelObjectCollection();
  265. $coll->setData($arr);
  266. $coll->setModel('Table10');
  267. return $coll;
  268. }
  269. }