/lib/limb/tests_runner/tests/cases/lmbTestTreeDirNodeTest.class.php

https://github.com/limb-php-framework/limb-app-buildman · PHP · 461 lines · 338 code · 107 blank · 16 comment · 0 complexity · de9dac266ad1249904383c036332006d MD5 · raw file

  1. <?php
  2. /**
  3. * Limb Web Application Framework
  4. *
  5. * @link http://limb-project.com
  6. *
  7. * @copyright Copyright &copy; 2004-2007 BIT
  8. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  9. * @version $Id: lmbTestTreeDirNodeTest.class.php 5006 2007-02-08 15:37:13Z pachanga $
  10. * @package tests_runner
  11. */
  12. require_once(dirname(__FILE__) . '/../common.inc.php');
  13. require_once(dirname(__FILE__) . '/../../src/lmbTestTreeDirNode.class.php');
  14. require_once(dirname(__FILE__) . '/../../src/lmbTestFileFilter.class.php');
  15. class lmbTestTreeDirNodeTest extends lmbTestsUtilitiesBase
  16. {
  17. function setUp()
  18. {
  19. $this->_rmdir(LIMB_VAR_DIR);
  20. mkdir(LIMB_VAR_DIR);
  21. }
  22. function tearDown()
  23. {
  24. $this->_rmdir(LIMB_VAR_DIR);
  25. }
  26. function testGetChildren()
  27. {
  28. mkdir(LIMB_VAR_DIR . '/a');
  29. mkdir(LIMB_VAR_DIR . '/a/b');
  30. touch(LIMB_VAR_DIR . '/a/b/bar_test.php');
  31. touch(LIMB_VAR_DIR . '/a/b/foo_test.php');
  32. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  33. $child_nodes = $node->getChildren();
  34. $this->assertEqual(sizeof($child_nodes), 1);
  35. $this->assertEqual($child_nodes[0]->getDir(), LIMB_VAR_DIR . '/a');
  36. $this->assertFalse($child_nodes[0]->isTerminal());
  37. $sub_child_nodes = $child_nodes[0]->getChildren();
  38. $this->assertEqual(sizeof($sub_child_nodes), 1);
  39. $this->assertEqual($sub_child_nodes[0]->getDir(), LIMB_VAR_DIR . '/a/b');
  40. $this->assertFalse($sub_child_nodes[0]->isTerminal());
  41. $terminal_nodes = $sub_child_nodes[0]->getChildren();
  42. $this->assertTrue($terminal_nodes[0]->getFile(), LIMB_VAR_DIR . '/a/b/bar_test.php');
  43. $this->assertTrue($terminal_nodes[0]->isTerminal());
  44. $this->assertTrue($terminal_nodes[1]->getFile(), LIMB_VAR_DIR . '/a/b/foo_test.php');
  45. $this->assertTrue($terminal_nodes[1]->isTerminal());
  46. }
  47. function testUseFileFilter()
  48. {
  49. touch(LIMB_VAR_DIR . '/bar_test.php');
  50. touch(LIMB_VAR_DIR . '/bah.php');
  51. touch(LIMB_VAR_DIR . '/junk.php');
  52. touch(LIMB_VAR_DIR . '/FooYo.class.php');
  53. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR, array('*test.php', '*Yo.class.php'));
  54. $nodes = $node->getChildren();
  55. $this->assertEqual(sizeof($nodes), 2);
  56. $this->assertEqual($nodes[0]->getFile(), LIMB_VAR_DIR . '/FooYo.class.php');
  57. $this->assertEqual($nodes[1]->getFile(), LIMB_VAR_DIR . '/bar_test.php');
  58. }
  59. function testUseFileFilterAndClassFormat()
  60. {
  61. $foo = new GeneratedTestClass();
  62. touch(LIMB_VAR_DIR . '/junk.php');
  63. touch(LIMB_VAR_DIR . '/' . $foo->getClass() . '.class.php');
  64. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR, array('*.class.php'), '%s.class.php');
  65. $nodes = $node->getChildren();
  66. $this->assertEqual(sizeof($nodes), 1);
  67. $this->assertEqual($nodes[0]->getFile(), LIMB_VAR_DIR . '/' . $foo->getClass() . '.class.php');
  68. $this->assertEqual($nodes[0]->getClass(), $foo->getClass());
  69. }
  70. function testFileFilterIsInherited()
  71. {
  72. mkdir(LIMB_VAR_DIR . '/a');
  73. touch(LIMB_VAR_DIR . '/a/BarTest.class.php');
  74. touch(LIMB_VAR_DIR . '/a/garbage.php');
  75. touch(LIMB_VAR_DIR . '/bar_test.php');
  76. touch(LIMB_VAR_DIR . '/bah.php');
  77. touch(LIMB_VAR_DIR . '/junk.php');
  78. touch(LIMB_VAR_DIR . '/FooTest.class.php');
  79. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR, array('*test.php', '*Test.class.php'));
  80. $nodes = $node->getChildren();
  81. $this->assertEqual(sizeof($nodes), 3);
  82. $this->assertEqual($nodes[0]->getDir(), LIMB_VAR_DIR . '/a');
  83. $a_nodes = $nodes[0]->getChildren();
  84. $this->assertEqual(sizeof($a_nodes), 1);
  85. $this->assertEqual($a_nodes[0]->getFile(), LIMB_VAR_DIR . '/a/BarTest.class.php');
  86. $this->assertEqual($nodes[1]->getFile(), LIMB_VAR_DIR . '/FooTest.class.php');
  87. $this->assertEqual($nodes[2]->getFile(), LIMB_VAR_DIR . '/bar_test.php');
  88. }
  89. function testFileFilterAndClassFormatAreInherited()
  90. {
  91. mkdir(LIMB_VAR_DIR . '/a');
  92. touch(LIMB_VAR_DIR . '/a/BarTest.klass.php');
  93. touch(LIMB_VAR_DIR . '/a/garbage.php');
  94. touch(LIMB_VAR_DIR . '/bar_test.php');
  95. touch(LIMB_VAR_DIR . '/bah.php');
  96. touch(LIMB_VAR_DIR . '/junk.php');
  97. touch(LIMB_VAR_DIR . '/FooTest.klass.php');
  98. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR, array('*test.php', '*Test.klass.php'), '%s.klass.php');
  99. $nodes = $node->getChildren();
  100. $this->assertEqual(sizeof($nodes), 3);
  101. $this->assertEqual($nodes[0]->getDir(), LIMB_VAR_DIR . '/a');
  102. $a_nodes = $nodes[0]->getChildren();
  103. $this->assertEqual(sizeof($a_nodes), 1);
  104. $this->assertEqual($a_nodes[0]->getFile(), LIMB_VAR_DIR . '/a/BarTest.klass.php');
  105. $this->assertEqual($a_nodes[0]->getClass(), 'BarTest');
  106. $this->assertEqual($nodes[1]->getFile(), LIMB_VAR_DIR . '/FooTest.klass.php');
  107. $this->assertEqual($nodes[1]->getClass(), 'FooTest');
  108. $this->assertEqual($nodes[2]->getFile(), LIMB_VAR_DIR . '/bar_test.php');
  109. }
  110. function testFindChildByPath()
  111. {
  112. mkdir(LIMB_VAR_DIR . '/a');
  113. touch(LIMB_VAR_DIR . '/a/bar_test.php');
  114. touch(LIMB_VAR_DIR . '/a/foo_test.php');
  115. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  116. $child_node = $node->findChildByPath('/0/1');
  117. $this->assertTrue($child_node->isTerminal());
  118. $this->assertEqual($child_node->getFile(), LIMB_VAR_DIR . '/a/foo_test.php');
  119. }
  120. function testFindNonTerminalGroupByPath()
  121. {
  122. mkdir(LIMB_VAR_DIR . '/a');
  123. mkdir(LIMB_VAR_DIR . '/a/b');
  124. touch(LIMB_VAR_DIR . '/a/b/bar_test.php');
  125. touch(LIMB_VAR_DIR . '/a/b/foo_test.php');
  126. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  127. $child_node = $node->findChildByPath('/0/0');
  128. $this->assertFalse($child_node->isTerminal());
  129. $this->assertEqual($child_node->getDir(), LIMB_VAR_DIR . '/a/b');
  130. }
  131. function testFindChildByOnlySlashPath()
  132. {
  133. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  134. $child_node = $node->findChildByPath('/');
  135. $this->assertEqual($child_node, $node);
  136. }
  137. function testCreateTestGroup()
  138. {
  139. mkdir(LIMB_VAR_DIR . '/a');
  140. $test1 = new GeneratedTestClass();
  141. $test2 = new GeneratedTestClass();
  142. file_put_contents(LIMB_VAR_DIR . '/a/.setup.php', '<?php echo "wow"; ?>');
  143. file_put_contents(LIMB_VAR_DIR . '/a/.teardown.php', '<?php echo "hey"; ?>');
  144. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test1->generate());
  145. file_put_contents(LIMB_VAR_DIR . '/a/foo_test.php', $test2->generate());
  146. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  147. //we check for any possible garbage during php includes
  148. ob_start();
  149. $group = $node->createTestGroup();
  150. $group->run(new SimpleReporter());
  151. $str = ob_get_contents();
  152. ob_end_clean();
  153. $this->assertEqual($str, "wow" . $test1->getClass() . $test2->getClass() . "hey");
  154. }
  155. function testCreateTestGroupWithParentsForTerminalNode()
  156. {
  157. mkdir(LIMB_VAR_DIR . '/a');
  158. mkdir(LIMB_VAR_DIR . '/a/b');
  159. $test1 = new GeneratedTestClass();
  160. $test2 = new GeneratedTestClass();
  161. file_put_contents(LIMB_VAR_DIR . '/a/.setup.php', '<?php echo "wow"; ?>');
  162. file_put_contents(LIMB_VAR_DIR . '/a/.teardown.php', '<?php echo "hey"; ?>');
  163. file_put_contents(LIMB_VAR_DIR . '/a/b/bar_test.php', $test1->generate());
  164. file_put_contents(LIMB_VAR_DIR . '/a/b/foo_test.php', $test2->generate());
  165. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  166. $terminal_node = $root_node->findChildByPath('/0/0/1');
  167. //we check for any possible garbage during php includes
  168. ob_start();
  169. $group = $terminal_node->createTestGroupWithParents();
  170. $group->run(new SimpleReporter());
  171. $str = ob_get_contents();
  172. ob_end_clean();
  173. $this->assertEqual($str, "wow" . $test2->getClass() . "hey");
  174. }
  175. function testCreateTestGroupWithParentsForTopLevelTerminalNode()
  176. {
  177. mkdir(LIMB_VAR_DIR . '/a');
  178. $test = new GeneratedTestClass();
  179. file_put_contents(LIMB_VAR_DIR . '/a/.setup.php', '<?php echo "wow"; ?>');
  180. file_put_contents(LIMB_VAR_DIR . '/a/.teardown.php', '<?php echo "hey"; ?>');
  181. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test->generate());
  182. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR . '/a');
  183. $terminal_node = $root_node->findChildByPath('/0');
  184. //we check for any possible garbage during php includes
  185. ob_start();
  186. $group = $terminal_node->createTestGroupWithParents();
  187. $group->run(new SimpleReporter());
  188. $str = ob_get_contents();
  189. ob_end_clean();
  190. $this->assertEqual($str, "wow" . $test->getClass() . "hey");
  191. }
  192. function testCreateTestGroupWithParents()
  193. {
  194. mkdir(LIMB_VAR_DIR . '/a');
  195. mkdir(LIMB_VAR_DIR . '/a/b');
  196. $test1 = new GeneratedTestClass();
  197. $test2 = new GeneratedTestClass();
  198. $skipped_test1 = new GeneratedTestClass();
  199. $skipped_test2 = new GeneratedTestClass();
  200. file_put_contents(LIMB_VAR_DIR . '/a/.setup.php', '<?php echo "|wow_start|"; ?>');
  201. file_put_contents(LIMB_VAR_DIR . '/a/.teardown.php', '<?php echo "|wow_end|"; ?>');
  202. file_put_contents(LIMB_VAR_DIR . '/a/skipped1_test.php', $skipped_test1->generate());
  203. file_put_contents(LIMB_VAR_DIR . '/a/skipped2_test.php', $skipped_test2->generate());
  204. file_put_contents(LIMB_VAR_DIR . '/a/b/.setup.php', '<?php echo "|hey_start|"; ?>');
  205. file_put_contents(LIMB_VAR_DIR . '/a/b/.teardown.php', '<?php echo "|hey_end|"; ?>');
  206. file_put_contents(LIMB_VAR_DIR . '/a/b/bar_test.php', $test1->generate());
  207. file_put_contents(LIMB_VAR_DIR . '/a/b/foo_test.php', $test2->generate());
  208. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  209. $b_node = $root_node->findChildByPath('/0/0');
  210. $this->assertFalse($b_node->isTerminal());
  211. $this->assertEqual($b_node->getDir(), LIMB_VAR_DIR . '/a/b');
  212. //we check for any possible garbage during php includes
  213. ob_start();
  214. $group = $b_node->createTestGroupWithParents();
  215. $group->run(new SimpleReporter());
  216. $str = ob_get_contents();
  217. ob_end_clean();
  218. $this->assertEqual($str, "|wow_start|" . "|hey_start|" .
  219. $test1->getClass() . $test2->getClass() .
  220. "|hey_end|" . "|wow_end|");
  221. }
  222. function testGetTestLabel()
  223. {
  224. file_put_contents(LIMB_VAR_DIR . '/.description', 'Foo');
  225. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  226. $this->assertEqual($node->getTestLabel(), 'Foo');
  227. $group = $node->createTestGroup();
  228. $this->assertEqual($group->getLabel(), 'Foo');
  229. }
  230. function testGetDefaultTestLabel()
  231. {
  232. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  233. $this->assertEqual($node->getTestLabel(), 'Group test in "' . LIMB_VAR_DIR . '"');
  234. $group = $node->createTestGroup();
  235. $this->assertEqual($group->getLabel(), 'Group test in "' . LIMB_VAR_DIR . '"');
  236. }
  237. function testBootstrap()
  238. {
  239. file_put_contents(LIMB_VAR_DIR . '/.init.php', '<?php echo "hey!"; ?>');
  240. $node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  241. ob_start();
  242. $group = $node->bootstrap();
  243. $str = ob_get_contents();
  244. ob_end_clean();
  245. $this->assertEqual($str, "hey!");
  246. }
  247. function testBootstrapPath()
  248. {
  249. mkdir(LIMB_VAR_DIR . '/a');
  250. mkdir(LIMB_VAR_DIR . '/a/b');
  251. $test1 = new GeneratedTestClass();
  252. file_put_contents(LIMB_VAR_DIR . '/a/.init.php', '<?php echo "wow"; ?>');
  253. file_put_contents(LIMB_VAR_DIR . '/a/b/bar_test.php', $test1->generate());
  254. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  255. ob_start();
  256. $root_node->bootstrapPath('/0/0/0');
  257. $str = ob_get_contents();
  258. ob_end_clean();
  259. $this->assertEqual($str, "wow");
  260. $terminal_node = $root_node->findChildByPath('/0/0/0');
  261. ob_start();
  262. //we check for any possible garbage during php includes
  263. $group = $terminal_node->createTestGroupWithParents();
  264. $group->run(new SimpleReporter());
  265. $str = ob_get_contents();
  266. ob_end_clean();
  267. $this->assertEqual($str, $test1->getClass());
  268. }
  269. function testBootstrapForChildDirectories()
  270. {
  271. mkdir(LIMB_VAR_DIR . '/a');
  272. mkdir(LIMB_VAR_DIR . '/a/b');
  273. mkdir(LIMB_VAR_DIR . '/a/c');
  274. $test1 = new GeneratedTestClass();
  275. file_put_contents(LIMB_VAR_DIR . '/a/b/bar_test.php', $test1->generate());
  276. file_put_contents(LIMB_VAR_DIR . '/a/c/.init.php', '<?php echo "wow"; ?>');
  277. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  278. $node = $root_node->findChildByPath('/0');
  279. ob_start();
  280. //we check for any possible garbage during php includes
  281. $group = $node->createTestGroupWithParents();
  282. $group->run(new SimpleReporter());
  283. $str = ob_get_contents();
  284. ob_end_clean();
  285. $this->assertEqual($str, 'wow' . $test1->getClass());
  286. }
  287. function testIgnoreTestsDirectory()
  288. {
  289. mkdir(LIMB_VAR_DIR . '/a');
  290. mkdir(LIMB_VAR_DIR . '/a/b');
  291. $test1 = new GeneratedTestClass();
  292. $test2 = new GeneratedTestClass();
  293. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test1->generate());
  294. file_put_contents(LIMB_VAR_DIR . '/a/b/foo_test.php', $test2->generate());
  295. touch(LIMB_VAR_DIR . '/a/b/.ignore');
  296. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  297. $group = $root_node->createTestGroup();
  298. ob_start();
  299. $group->run(new SimpleReporter());
  300. $str = ob_get_contents();
  301. ob_end_clean();
  302. $this->assertEqual($str, $test1->getClass());
  303. }
  304. function testIgnoreConditionalTrueTestsDirectory()
  305. {
  306. mkdir(LIMB_VAR_DIR . '/a');
  307. mkdir(LIMB_VAR_DIR . '/a/b');
  308. $test1 = new GeneratedTestClass();
  309. $test2 = new GeneratedTestClass();
  310. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test1->generate());
  311. file_put_contents(LIMB_VAR_DIR . '/a/b/foo_test.php', $test2->generate());
  312. file_put_contents(LIMB_VAR_DIR . '/a/b/.ignore.php', '<?php return true; ?>');
  313. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  314. $group = $root_node->createTestGroup();
  315. ob_start();
  316. $group->run(new SimpleReporter());
  317. $str = ob_get_contents();
  318. ob_end_clean();
  319. $this->assertEqual($str, $test1->getClass());
  320. }
  321. function testIgnoreConditionalFalseTestsDirectory()
  322. {
  323. mkdir(LIMB_VAR_DIR . '/a');
  324. mkdir(LIMB_VAR_DIR . '/a/b');
  325. $test1 = new GeneratedTestClass();
  326. $test2 = new GeneratedTestClass();
  327. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test1->generate());
  328. file_put_contents(LIMB_VAR_DIR . '/a/b/foo_test.php', $test2->generate());
  329. file_put_contents(LIMB_VAR_DIR . '/a/b/.ignore.php', '<?php return false; ?>');
  330. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  331. $group = $root_node->createTestGroup();
  332. ob_start();
  333. $group->run(new SimpleReporter());
  334. $str = ob_get_contents();
  335. ob_end_clean();
  336. $this->assertEqual($str, $test2->getClass() . $test1->getClass());
  337. }
  338. function testIgnoredDirFixtureIgnoredToo()
  339. {
  340. mkdir(LIMB_VAR_DIR . '/a');
  341. $test = new GeneratedTestClass();
  342. file_put_contents(LIMB_VAR_DIR . '/a/.setup.php', '<?php echo "No!" ?>');
  343. file_put_contents(LIMB_VAR_DIR . '/a/bar_test.php', $test->generate());
  344. file_put_contents(LIMB_VAR_DIR . '/a/.ignore.php', '<?php return true; ?>');
  345. $root_node = new lmbTestTreeDirNode(LIMB_VAR_DIR);
  346. $group = $root_node->createTestGroup();
  347. ob_start();
  348. $group->run(new SimpleReporter());
  349. $str = ob_get_contents();
  350. ob_end_clean();
  351. $this->assertEqual($str, '');
  352. }
  353. }
  354. ?>