3 namespace Drupal\KernelTests\Core\File;
6 * Tests the unmanaged file delete recursive function.
10 class UnmanagedDeleteRecursiveTest extends FileTestBase {
12 * Delete a normal file.
14 public function testSingleFile() {
15 // Create a file for testing
16 $filepath = file_default_scheme() . '://' . $this->randomMachineName();
17 file_put_contents($filepath, '');
20 $this->assertTrue(file_unmanaged_delete_recursive($filepath), 'Function reported success.');
21 $this->assertFalse(file_exists($filepath), 'Test file has been deleted.');
25 * Try deleting an empty directory.
27 public function testEmptyDirectory() {
28 // A directory to operate on.
29 $directory = $this->createDirectory();
31 // Delete the directory.
32 $this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
33 $this->assertFalse(file_exists($directory), 'Directory has been deleted.');
37 * Try deleting a directory with some files.
39 public function testDirectory() {
40 // A directory to operate on.
41 $directory = $this->createDirectory();
42 $filepathA = $directory . '/A';
43 $filepathB = $directory . '/B';
44 file_put_contents($filepathA, '');
45 file_put_contents($filepathB, '');
47 // Delete the directory.
48 $this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
49 $this->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
50 $this->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
51 $this->assertFalse(file_exists($directory), 'Directory has been deleted.');
55 * Try deleting subdirectories with some files.
57 public function testSubDirectory() {
58 // A directory to operate on.
59 $directory = $this->createDirectory();
60 $subdirectory = $this->createDirectory($directory . '/sub');
61 $filepathA = $directory . '/A';
62 $filepathB = $subdirectory . '/B';
63 file_put_contents($filepathA, '');
64 file_put_contents($filepathB, '');
66 // Delete the directory.
67 $this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
68 $this->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
69 $this->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
70 $this->assertFalse(file_exists($subdirectory), 'Subdirectory has been deleted.');
71 $this->assertFalse(file_exists($directory), 'Directory has been deleted.');