/tests/basic/compat-tree.php

https://github.com/srobo/srobo-ide · PHP · 97 lines · 78 code · 17 blank · 2 comment · 0 complexity · e878acdbe51709d7fedb306de371e353 MD5 · raw file

  1. <?php
  2. $config = Configuration::getInstance();
  3. $config->override("repopath", $testWorkPath);
  4. $config->override("user.default", "bees");
  5. $config->override("user.default.teams", array(1, 2));
  6. $config->override("auth_module", "single");
  7. $config->override("keyfile", "$testWorkPath/test.key");
  8. $config->override('modules.always', array("file"));
  9. //do a quick authentication
  10. $auth = AuthBackend::getInstance();
  11. test_true($auth->authUser('bees','face'), "authentication failed");
  12. $projectManager = ProjectManager::getInstance();
  13. $projectManager->createRepository(1, 'cake');
  14. $repo = $projectManager->getUserRepository(1, 'cake', 'bees');
  15. function check_initial($tree)
  16. {
  17. var_dump($tree);
  18. test_equal($tree[0]['kind'], 'FILE', 'tested file had incorrect kind');
  19. test_equal($tree[0]['name'], 'robot.py', 'tested file had incorrect name');
  20. test_equal($tree[0]['path'], '/cake/robot.py', 'tested file had incorrect path');
  21. test_false(isset($tree[0]['autosave']), 'Autosave should not be set (file)');
  22. test_equal(count($tree), 1, 'Should only be a single item in the initial tree');
  23. }
  24. function mkdir_and_holder($repo, $path)
  25. {
  26. // simulate 'file/mkdir'
  27. $placeholder = $path.'/.directory';
  28. $repo->gitMKDir($path);
  29. $repo->createFile($placeholder);
  30. return $placeholder;
  31. }
  32. $masterRepo = $projectManager->getMasterRepository(1, 'cake');
  33. $tree = $masterRepo->fileTreeCompat('cake');
  34. check_initial($tree);
  35. $dir_holders[] = mkdir_and_holder($repo, 'ninjas');
  36. $repo->putFile('ninjas/nuns', "the cake is a lie\n");
  37. $dir_holders[] = mkdir_and_holder($repo, 'ninjas/z-ninjaChildren');
  38. $repo->putFile('ninjas/z-ninjaChildren/pirates', 'Captain Jack');
  39. $dir_holders[] = mkdir_and_holder($repo, 'spacey empty-dir');
  40. $dir_holders[] = mkdir_and_holder($repo, 'z-last');
  41. $repo->putFile('z-last/bacon', 'tasty');
  42. $repo->stage('ninjas/nuns');
  43. $repo->stage('ninjas/z-ninjaChildren/pirates');
  44. $repo->stage('z-last/bacon');
  45. array_map(array($repo, 'stage'), $dir_holders);
  46. $repo->commit('needed since we removed autosave', 'test-user', 'test@example.com');
  47. $repo->push();
  48. $tree = $masterRepo->fileTreeCompat('cake');
  49. var_dump($tree);
  50. test_equal($tree[0]['kind'], 'FOLDER', 'tested folder had incorrect kind');
  51. test_equal($tree[0]['name'], 'ninjas', 'tested folder had incorrect name');
  52. test_equal($tree[0]['path'], '/cake/ninjas', 'tested folder had incorrect path');
  53. test_equal($tree[0]['children'][0]['kind'], 'FILE', 'tested sub-file had incorrect kind');
  54. test_equal($tree[0]['children'][0]['name'], 'nuns', 'tested sub-file had incorrect name');
  55. test_equal($tree[0]['children'][0]['path'], '/cake/ninjas/nuns', 'tested sub-file had incorrect path');
  56. test_equal($tree[0]['children'][1]['kind'], 'FOLDER', 'tested sub-folder had incorrect kind');
  57. test_equal($tree[0]['children'][1]['name'], 'z-ninjaChildren', 'tested sub-folder had incorrect name');
  58. test_equal($tree[0]['children'][1]['path'], '/cake/ninjas/z-ninjaChildren', 'tested sub-folder had incorrect path');
  59. test_equal($tree[0]['children'][1]['children'][0]['kind'], 'FILE', 'tested sub-sub-file had incorrect kind');
  60. test_equal($tree[0]['children'][1]['children'][0]['name'], 'pirates', 'tested sub-sub-file had incorrect name');
  61. test_equal($tree[0]['children'][1]['children'][0]['path'], '/cake/ninjas/z-ninjaChildren/pirates', 'tested sub-sub-file had incorrect path');
  62. test_equal($tree[1]['kind'], 'FILE', 'tested file had incorrect kind');
  63. test_equal($tree[1]['name'], 'robot.py', 'tested file had incorrect name');
  64. test_equal($tree[1]['path'], '/cake/robot.py', 'tested file had incorrect path');
  65. test_equal($tree[2]['kind'], 'FOLDER', 'tested folder had incorrect kind');
  66. test_equal($tree[2]['name'], 'spacey empty-dir', 'tested folder had incorrect name');
  67. test_equal($tree[2]['path'], '/cake/spacey empty-dir', 'tested folder had incorrect path');
  68. test_equal($tree[2]['children'], array(), 'empty folder should be empty');
  69. test_equal($tree[3]['kind'], 'FOLDER', 'tested folder had incorrect kind');
  70. test_equal($tree[3]['name'], 'z-last', 'tested folder had incorrect name');
  71. test_equal($tree[3]['path'], '/cake/z-last', 'tested folder had incorrect path');
  72. test_equal($tree[3]['children'][0]['kind'], 'FILE', 'tested sub-file had incorrect kind');
  73. test_equal($tree[3]['children'][0]['name'], 'bacon', 'tested sub-file had incorrect name');
  74. test_equal($tree[3]['children'][0]['path'], '/cake/z-last/bacon', 'tested sub-file had incorrect path');
  75. test_false(isset($tree[0]['autosave']), 'Autosave should not be set (folder)');
  76. test_false(isset($tree[0]['children'][0]['autosave']), 'Autosave should not be set (child file)');
  77. test_false(isset($tree[1]['autosave']), 'Autosave should not be set (root file)');
  78. test_equal(count($tree), 4, 'Should be four root items in the main test tree');
  79. $tree = $masterRepo->fileTreeCompat('cake', 'HEAD^');
  80. check_initial($tree);