Exemplo n.º 1
0
 /**
  * Test if temp directory can be removed if it holds files with changed mode.
  *
  * @depends testTempDirectoryClass
  */
 public function testTempPermissions()
 {
     $dir = new TempDirectory('testTempPermissions');
     $root = $dir->getRoot();
     $protectedFolder = $dir->getPath('protectedFolder');
     $protectedFile = $dir->getPath('protectedFile.txt');
     $fileInProtectedFolder = $dir->getPath('protectedFolder/file.txt');
     $protectedFileInProtectedFolder = $dir->getPath('protectedFolder/protectedFile.txt');
     mkdir($protectedFolder);
     file_put_contents($protectedFile, '');
     file_put_contents($fileInProtectedFolder, '');
     file_put_contents($protectedFileInProtectedFolder, '');
     $this->assertIsDir($root);
     $this->assertIsDir($protectedFolder);
     $this->assertFileExists($protectedFile);
     $this->assertFileExists($protectedFileInProtectedFolder);
     $this->assertFileExists($fileInProtectedFolder);
     chmod($protectedFile, 0400);
     chmod($protectedFileInProtectedFolder, 0400);
     chmod($protectedFolder, 0400);
     // After unsetting the temp directory, the folder should be removed completely.
     unset($dir);
     $this->assertFileNotExists($root);
 }
 /**
  * Tests preservation and rollback on tricky path permissions.
  *
  * @depends testPreserveAndRollback
  */
 public function testFileModes()
 {
     $workingDirectory = new TempDirectory(__METHOD__);
     $cacheDirectory = new TempDirectory(__METHOD__ . '-cache');
     // Create directory to test.
     $folder1 = $workingDirectory->getPath('folder1');
     mkdir($folder1);
     $subfolder1 = $workingDirectory->getPath('folder1/subfolder1');
     mkdir($subfolder1);
     $file1 = $workingDirectory->getPath('folder1/file1.txt');
     file_put_contents($file1, 'Test content');
     $file2 = $workingDirectory->getPath('folder1/file2.txt');
     file_put_contents($file2, 'Test content 2');
     // After changing some permissions we test if the given paths can be
     // restored.
     chmod($file2, 0400);
     // For checking if file exists, we need to set the permission for the folder
     // differently
     // @see http://stackoverflow.com/questions/11834629/glob-lists-files-file-exists-says-they-dont-exist
     chmod($folder1, 0500);
     $this->assertIsDir($folder1, 'Folder created.');
     $this->assertIsDir($subfolder1, 'Subfolder 1 created.');
     $this->assertFileExists($file1, 'File 1 created.');
     $this->assertFileExists($file2, 'File 2 created.');
     $installPaths = array($folder1);
     $preservePaths = array($subfolder1, $file1, $file2);
     $preserver = new PathPreserver($installPaths, $preservePaths, $cacheDirectory->getRoot(), $this->fs, $this->io);
     // We check if preservation works even with restrictive permissions.
     chmod($folder1, 0400);
     $preserver->preserve();
     chmod($folder1, 0500);
     $this->assertIsDir($folder1, 'Folder not removed for backup.');
     $this->assertFileNotExists($subfolder1, 'Subfolder removed for backup.');
     $this->assertFileNotExists($file1, 'File 1 was removed for backup.');
     $this->assertFileNotExists($file2, 'File 2 was removed for backup.');
     // We check if rollback works even with restrictive permissions.
     chmod($folder1, 0400);
     $preserver->rollback();
     chmod($folder1, 0500);
     $this->assertFileExists($subfolder1, 'Subfolder 1 recreated.');
     $this->assertFileExists($file1, 'File 1 recreated.');
     $this->assertFileExists($file2, 'File 2 recreated.');
 }