UnmanagedDeleteRecursiveTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/File/UnmanagedDeleteRecursiveTest.php
View source
<?php
namespace Drupal\system\Tests\File;
class UnmanagedDeleteRecursiveTest extends FileTestBase {
function testSingleFile() {
$filepath = file_default_scheme() . '://' . $this
->randomMachineName();
file_put_contents($filepath, '');
$this
->assertTrue(file_unmanaged_delete_recursive($filepath), 'Function reported success.');
$this
->assertFalse(file_exists($filepath), 'Test file has been deleted.');
}
function testEmptyDirectory() {
$directory = $this
->createDirectory();
$this
->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this
->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
function testDirectory() {
$directory = $this
->createDirectory();
$filepathA = $directory . '/A';
$filepathB = $directory . '/B';
file_put_contents($filepathA, '');
file_put_contents($filepathB, '');
$this
->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this
->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
$this
->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
$this
->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
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(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this
->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
$this
->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
$this
->assertFalse(file_exists($subdirectory), 'Subdirectory has been deleted.');
$this
->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
}