AdministrationEmptyDirsTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php declare(strict_types=1);
  2. use PHPUnit\Framework\TestCase;
  3. class AdministrationEmptyDirsTest extends TestCase
  4. {
  5. private $_path;
  6. public function setUp(): void
  7. {
  8. $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin administration';
  9. Helper::rmDir($this->_path);
  10. mkdir($this->_path);
  11. mkdir($this->_path . DIRECTORY_SEPARATOR . 'cfg');
  12. $dataPath = $this->_path . DIRECTORY_SEPARATOR . 'data with spaces';
  13. mkdir($dataPath);
  14. mkdir($dataPath . DIRECTORY_SEPARATOR . 'empty' . DIRECTORY_SEPARATOR . 'nested', 0777, true);
  15. file_put_contents($dataPath . DIRECTORY_SEPARATOR . 'keep.txt', 'keep');
  16. $options = parse_ini_file(CONF_SAMPLE, true);
  17. $options['model_options']['dir'] = $dataPath;
  18. Helper::createIniFile(
  19. $this->_path . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php',
  20. $options
  21. );
  22. }
  23. public function tearDown(): void
  24. {
  25. Helper::rmDir($this->_path);
  26. }
  27. public function testEmptyDirsSupportsStoragePathsWithSpaces()
  28. {
  29. $command = 'CONFIG_PATH=' .
  30. escapeshellarg($this->_path . DIRECTORY_SEPARATOR . 'cfg') . ' ' .
  31. escapeshellarg(PHP_BINARY) . ' ' .
  32. escapeshellarg(realpath(PATH . 'bin' . DIRECTORY_SEPARATOR . 'administration')) .
  33. ' --empty-dirs 2>&1';
  34. exec($command, $output, $exitCode);
  35. $this->assertSame(0, $exitCode, implode(PHP_EOL, $output));
  36. $this->assertDirectoryDoesNotExist(
  37. $this->_path . DIRECTORY_SEPARATOR . 'data with spaces' .
  38. DIRECTORY_SEPARATOR . 'empty'
  39. );
  40. $this->assertFileExists(
  41. $this->_path . DIRECTORY_SEPARATOR . 'data with spaces' .
  42. DIRECTORY_SEPARATOR . 'keep.txt'
  43. );
  44. }
  45. }