Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / File / UnmanagedDeleteRecursiveTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\File;
4
5 /**
6  * Tests the unmanaged file delete recursive function.
7  *
8  * @group File
9  */
10 class UnmanagedDeleteRecursiveTest extends FileTestBase {
11   /**
12    * Delete a normal file.
13    */
14   public function testSingleFile() {
15     // Create a file for testing
16     $filepath = file_default_scheme() . '://' . $this->randomMachineName();
17     file_put_contents($filepath, '');
18
19     // Delete the file.
20     $this->assertTrue(file_unmanaged_delete_recursive($filepath), 'Function reported success.');
21     $this->assertFalse(file_exists($filepath), 'Test file has been deleted.');
22   }
23
24   /**
25    * Try deleting an empty directory.
26    */
27   public function testEmptyDirectory() {
28     // A directory to operate on.
29     $directory = $this->createDirectory();
30
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.');
34   }
35
36   /**
37    * Try deleting a directory with some files.
38    */
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, '');
46
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.');
52   }
53
54   /**
55    * Try deleting subdirectories with some files.
56    */
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, '');
65
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.');
72   }
73
74 }