summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/drupal_web_test_case.php14
-rw-r--r--modules/simpletest/simpletest.module23
-rw-r--r--modules/simpletest/tests/file.test77
3 files changed, 85 insertions, 29 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 9aad62dd9..cd8b16216 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -902,7 +902,7 @@ class DrupalWebTestCase {
global $db_prefix, $user;
if (preg_match('/simpletest\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
- simpletest_clean_temporary_directory(file_directory_path());
+ file_unmanaged_delete_recursive(file_directory_path());
variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
@@ -1999,7 +1999,7 @@ class DrupalWebTestCase {
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser'));
}
-
+
/**
* TODO write documentation.
* @param $type
@@ -2017,13 +2017,13 @@ class DrupalWebTestCase {
);
$field_definition += $settings;
field_create_field($field_definition);
-
+
$field = field_read_field($field_name);
$this->assertTrue($field, t('Created field @field_name of type @type.', array('@field_name' => $field_name, '@type' => $type)));
-
+
return $field;
}
-
+
/**
* TODO write documentation.
* @param $field_name
@@ -2046,10 +2046,10 @@ class DrupalWebTestCase {
),
);
field_create_instance($instance_definition);
-
+
$instance = field_read_instance($field_name, $bundle);
$this->assertTrue($instance, t('Created instance of field @field_name on bundle @bundle.', array('@field_name' => $field_name, '@bundle' => $bundle)));
-
+
return $instance;
}
}
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
index 39c08fecb..5476a9795 100644
--- a/modules/simpletest/simpletest.module
+++ b/modules/simpletest/simpletest.module
@@ -550,7 +550,7 @@ function simpletest_clean_temporary_directories() {
foreach ($files as $file) {
$path = file_directory_path() . '/' . $file;
if (is_dir($path) && preg_match('/^simpletest\d+/', $file)) {
- simpletest_clean_temporary_directory($path);
+ file_unmanaged_delete_recursive($path);
$count++;
}
}
@@ -564,27 +564,6 @@ function simpletest_clean_temporary_directories() {
}
/**
- * Remove all files from specified directory and then remove directory.
- *
- * @param string $path Directory path.
- */
-function simpletest_clean_temporary_directory($path) {
- $files = scandir($path);
- foreach ($files as $file) {
- if ($file != '.' && $file != '..') {
- $file_path = "$path/$file";
- if (is_dir($file_path)) {
- simpletest_clean_temporary_directory($file_path);
- }
- else {
- file_unmanaged_delete($file_path);
- }
- }
- }
- rmdir($path);
-}
-
-/**
* Clear the test results tables.
*/
function simpletest_clean_results_table() {
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 {