diff options
Diffstat (limited to 'modules/simpletest/tests/file.test')
-rw-r--r-- | modules/simpletest/tests/file.test | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 66fadfba5..c42d69e20 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -850,6 +850,83 @@ class FileUnmanagedDeleteTest extends FileTestCase { /** + * Deletion related tests. + */ +class FileUnmanagedDeleteRecursiveTest extends FileTestCase { + function getInfo() { + return array( + 'name' => t('Unmanaged recursive file delete'), + 'description' => t('Tests the unmanaged file delete recursive function.'), + 'group' => t('File'), + ); + } + + /** + * Delete a normal file. + */ + function testSingleFile() { + // Create a file for testing + $filepath = file_directory_path() . '/' . $this->randomName(); + file_put_contents($filepath, ''); + + // Delete the file. + $this->assertTrue(file_unmanaged_delete_recursive($filepath), t('Function reported success.')); + $this->assertFalse(file_exists($filepath), t('Test file has been deleted.')); + } + + /** + * Try deleting an empty directory. + */ + function testEmptyDirectory() { + // A directory to operate on. + $directory = $this->createDirectory(); + + // Delete the directory. + $this->assertTrue(file_unmanaged_delete_recursive($directory), t('Function reported success.')); + $this->assertFalse(file_exists($directory), t('Directory has been deleted.')); + } + + /** + * Try deleting a directory with some files. + */ + function testDirectory() { + // A directory to operate on. + $directory = $this->createDirectory(); + $filepathA = $directory . '/A'; + $filepathB = $directory . '/B'; + file_put_contents($filepathA, ''); + file_put_contents($filepathB, ''); + + // Delete the directory. + $this->assertTrue(file_unmanaged_delete_recursive($directory), t('Function reported success.')); + $this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.')); + $this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.')); + $this->assertFalse(file_exists($directory), t('Directory has been deleted.')); + } + + /** + * Try deleting subdirectories with some files. + */ + 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(file_unmanaged_delete_recursive($directory), t('Function reported success.')); + $this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.')); + $this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.')); + $this->assertFalse(file_exists($subdirectory), t('Subdirectory has been deleted.')); + $this->assertFalse(file_exists($directory), t('Directory has been deleted.')); + } +} + + +/** * Unmanaged move related tests. */ class FileUnmanagedMoveTest extends FileTestCase { |