FileDeleteRecursiveTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php
View source
<?php
namespace Drupal\KernelTests\Core\File;
class FileDeleteRecursiveTest extends FileTestBase {
public function testSingleFile() {
$filepath = 'public://' . $this
->randomMachineName();
file_put_contents($filepath, '');
$this
->assertTrue(\Drupal::service('file_system')
->deleteRecursive($filepath), 'Function reported success.');
$this
->assertFileDoesNotExist($filepath);
}
public function testEmptyDirectory() {
$directory = $this
->createDirectory();
$this
->assertTrue(\Drupal::service('file_system')
->deleteRecursive($directory), 'Function reported success.');
$this
->assertDirectoryDoesNotExist($directory);
}
public function testDirectory() {
$directory = $this
->createDirectory();
$filepathA = $directory . '/A';
$filepathB = $directory . '/B';
file_put_contents($filepathA, '');
file_put_contents($filepathB, '');
$this
->assertTrue(\Drupal::service('file_system')
->deleteRecursive($directory), 'Function reported success.');
$this
->assertFileDoesNotExist($filepathA);
$this
->assertFileDoesNotExist($filepathB);
$this
->assertDirectoryDoesNotExist($directory);
}
public function testSubDirectory() {
$directory = $this
->createDirectory();
$subdirectory = $this
->createDirectory($directory . '/sub');
$filepathA = $directory . '/A';
$filepathB = $subdirectory . '/B';
file_put_contents($filepathA, '');
file_put_contents($filepathB, '');
$this
->assertTrue(\Drupal::service('file_system')
->deleteRecursive($directory), 'Function reported success.');
$this
->assertFileDoesNotExist($filepathA);
$this
->assertFileDoesNotExist($filepathB);
$this
->assertDirectoryDoesNotExist($subdirectory);
$this
->assertDirectoryDoesNotExist($directory);
}
}