function FileDeleteRecursiveTest::testSymlinksToDirectoryViaStreamWrapper
Tests trying to delete symlinks to directories via stream wrappers.
Note that this tests unexpected behavior.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ File/ FileDeleteRecursiveTest.php, line 147
Class
- FileDeleteRecursiveTest
- Tests the unmanaged file delete recursive function.
Namespace
Drupal\KernelTests\Core\FileCode
public function testSymlinksToDirectoryViaStreamWrapper() : void {
$file_system = $this->container
->get('file_system');
// Create files to link to.
$file_system->mkdir('public://dir1');
file_put_contents('public://dir1/test1.txt', 'test');
// Symlink to a directory outside dir2.
$public_path = realpath($this->siteDirectory . '/files');
symlink($public_path . '/dir1', $public_path . '/dir2');
$this->assertFileExists($public_path . '/dir1/test1.txt');
$this->assertFileExists('public://dir2/test1.txt');
// The stream wrapper system resolves 'public://dir2' to 'files/dir1'.
// Therefore, this call results in removing dir1 and does not remove the
// dir2 symlink.
$this->container
->get('file_system')
->deleteRecursive('public://dir2');
$this->assertFileDoesNotExist($public_path . '/dir1/test1.txt');
// The directory is now a broken link.
$this->assertTrue(is_link($public_path . '/dir2'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.