function FileDeleteRecursiveTest::testSymlinksInDirectory

Tests symlinks in directories do not result in unexpected deletions.

File

core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php, line 80

Class

FileDeleteRecursiveTest
Tests the unmanaged file delete recursive function.

Namespace

Drupal\KernelTests\Core\File

Code

public function testSymlinksInDirectory() : void {
    // Create files to link to.
    mkdir($this->siteDirectory . '/dir1');
    touch($this->siteDirectory . '/dir1/test1.txt');
    touch($this->siteDirectory . '/test2.txt');
    // Create directory to be deleted.
    mkdir($this->siteDirectory . '/dir2');
    // Symlink to a directory outside dir2.
    symlink(realpath($this->siteDirectory . '/dir1'), $this->siteDirectory . '/dir2/subdir');
    // Symlink to a file outside dir2.
    symlink(realpath($this->siteDirectory . '/test2.txt'), $this->siteDirectory . '/dir2/test2.text');
    $this->assertFileExists($this->siteDirectory . '/dir2/subdir/test1.txt');
    $this->assertFileExists($this->siteDirectory . '/dir2/test2.text');
    $this->container
        ->get('file_system')
        ->deleteRecursive($this->siteDirectory . '/dir2');
    $this->assertFileExists($this->siteDirectory . '/dir1/test1.txt');
    $this->assertFileExists($this->siteDirectory . '/test2.txt');
    $this->assertDirectoryDoesNotExist($this->siteDirectory . '/dir2');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.