function FileDeleteRecursiveTest::testSubDirectory

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php \Drupal\KernelTests\Core\File\FileDeleteRecursiveTest::testSubDirectory()
  2. 10 core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php \Drupal\KernelTests\Core\File\FileDeleteRecursiveTest::testSubDirectory()
  3. 11.x core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php \Drupal\KernelTests\Core\File\FileDeleteRecursiveTest::testSubDirectory()

Try deleting subdirectories with some files.

File

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

Class

FileDeleteRecursiveTest
Tests the unmanaged file delete recursive function.

Namespace

Drupal\KernelTests\Core\File

Code

public function testSubDirectory() {
    // A directory to operate on.
    $directory = $this->createDirectory();
    $subdirectory = $this->createDirectory($directory . '/sub');
    $filepathA = $directory . '/A';
    $filepathB = $subdirectory . '/B';
    file_put_contents($filepathA, '');
    file_put_contents($filepathB, '');
    // Delete the directory.
    $this->assertTrue(\Drupal::service('file_system')->deleteRecursive($directory), 'Function reported success.');
    $this->assertFileNotExists($filepathA);
    $this->assertFileNotExists($filepathB);
    $this->assertDirectoryNotExists($subdirectory);
    $this->assertDirectoryNotExists($directory);
}

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