PageRenderTime 79ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/file/mv.php

https://github.com/samphippen/srobo-ide
PHP | 117 lines | 90 code | 18 blank | 9 comment | 2 complexity | 587cd082f4a72773ac9728befeef0206 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("modules", array("file", 'proj'));
  8. //do a quick authentication
  9. $auth = AuthBackend::getInstance();
  10. test_true($auth->authUser('bees','face'), "authentication failed");
  11. //setup the required input keys
  12. $input = Input::getInstance();
  13. $input->setInput("team", 1);
  14. $input->setInput("project", "monkies");
  15. function getRepoPath()
  16. {
  17. $config = Configuration::getInstance();
  18. $input = Input::getInstance();
  19. return $config->getConfig("repopath") . "/" . $input->getInput("team") . "/users/bees/" . $input->getInput("project");
  20. }
  21. $repopath = getRepoPath();
  22. $projectManager = ProjectManager::getInstance();
  23. $projectManager->createRepository($input->getInput("team"), $input->getInput("project"));
  24. $repo = $projectManager->getUserRepository($input->getInput("team"), $input->getInput("project"), 'bees');
  25. test_true(is_dir($repopath), "created repo did not exist");
  26. $mm = ModuleManager::getInstance();
  27. $mm->importModules();
  28. function createAndAssertFileMoved($newPath)
  29. {
  30. static $oldPath = 'robot.py'; // guarunteed to exist at the start, from then on we just use the same file.
  31. $input = Input::getInstance();
  32. $output = Output::getInstance();
  33. $moveMsg = "move file '$oldPath' to '$newPath'";
  34. section('Testing: '.$moveMsg);
  35. echo 'team: ', $input->getInput('team'), ', project: ', $input->getInput('project'), ".\n";
  36. $repopath = getRepoPath();
  37. // need this for testing, not for the actual implementation.
  38. $subDir = '.';
  39. if (($pos = strrpos($newPath, '/')) !== FALSE)
  40. {
  41. $subDir = substr($newPath, 0, $pos);
  42. }
  43. mkdir_full("$repopath/$subDir");
  44. $input->setInput('path', $subDir);
  45. // get the modules
  46. $mm = ModuleManager::getInstance();
  47. test_true($mm->moduleExists('file'), 'file module does not exist');
  48. test_true($mm->moduleExists('proj'), 'proj module does not exist');
  49. $file = $mm->getModule('file');
  50. $proj = $mm->getModule('proj');
  51. test_nonnull($file, 'file module does not exist');
  52. test_nonnull($proj, 'proj module does not exist');
  53. // assert the original file exists to start with, and that the new one doesn't
  54. $absOldPath = "$repopath/$oldPath";
  55. test_existent($absOldPath, "Original file before move");
  56. $absNewPath = "$repopath/$newPath";
  57. test_nonexistent($absNewPath, "New file before move");
  58. // move the file
  59. subsection('Move');
  60. $input->setInput('old-path', $oldPath);
  61. $input->setInput('new-path', $newPath);
  62. test_true($file->dispatchCommand('mv'), "Failed to $moveMsg.");
  63. test_nonexistent($absOldPath, "Original file after move");
  64. test_existent($absNewPath, "New file after move");
  65. // commit it
  66. subsection('Commit');
  67. $input->setInput('paths', array($oldPath, $newPath));
  68. $input->setInput('message', $moveMsg);
  69. test_true($proj->dispatchCommand('commit'), "Failed to commit: $moveMsg.");
  70. test_nonexistent($absOldPath, "Original file after commit");
  71. test_existent($absNewPath, "New file after commit");
  72. // get the file-list to check that it's really moved
  73. subsection('Assert listing');
  74. test_true($file->dispatchCommand('list'), "Failed to get file list after: $moveMsg.");
  75. $list = $output->getOutput('files');
  76. var_dump($list);
  77. $oldBasename = basename($oldPath);
  78. $newBasename = basename($newPath);
  79. test_false(in_array($oldBasename, $list), "File '$oldBasename' listed after: $moveMsg.");
  80. test_true(in_array($newBasename, $list), "File '$newBasename' not listed after: $moveMsg.");
  81. // assign the newPath to the oldPath so that things work the next time around
  82. $oldPath = $newPath;
  83. }
  84. createAndAssertFileMoved('simple-file-name');
  85. createAndAssertFileMoved('spacey path');
  86. createAndAssertFileMoved('subdir/file');
  87. createAndAssertFileMoved('subdir/spacey path');
  88. createAndAssertFileMoved('spacey subdir/other spacey path');
  89. createAndAssertFileMoved('variable $file name');
  90. $chars = '$%@~{}][()';
  91. for($i=0; $i < strlen($chars); $i++)
  92. {
  93. createAndAssertFileMoved('char \''.$chars[$i].'\'.');
  94. }
  95. $unicodes = array('£', '❝', '♞');
  96. foreach($unicodes as $char)
  97. {
  98. createAndAssertFileMoved('char \''.$char.'\'.');
  99. }