diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index ba07282..4c4d630 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -706,7 +706,7 @@ function simpletest_clean_temporary_directories($directory = NULL) { if (is_dir($simpletest_root)) { // If the $directory is not valid string or NULL then get the type of it for - // debugging purposes in the watchdog error message below. + // debugging purposes in the error message below. $path = is_string($directory) && !empty($directory) ? $directory : gettype($directory); // Do not recognize any, except expected directory pattern as wrong // directory being passed accidentally may cause catastrophic consequences. diff --git a/core/modules/simpletest/src/Tests/UiCleanTemporaryDirectoriesTest.php b/core/modules/simpletest/src/Tests/UiCleanTemporaryDirectoriesTest.php index 05235f4..c5931c6 100644 --- a/core/modules/simpletest/src/Tests/UiCleanTemporaryDirectoriesTest.php +++ b/core/modules/simpletest/src/Tests/UiCleanTemporaryDirectoriesTest.php @@ -31,15 +31,19 @@ public function testCleanTemporaryDirectories() { $simpletest = \Drupal::root() . '/sites/simpletest'; $test_site_directory = basename($this->siteDirectory); $clean_environment = t('Clean environment'); - $this->drupalGet('admin/config/development/testing'); - $this->assertFieldByXPath('//input', $clean_environment, 'Displayed the "Clean environment" button.'); $this->assertNull(simpletest_clean_temporary_directories('sites/simpletest/test_site_directory'), 'The sites/simpletest/test_site_directory folder does not exist.'); - $this->recurse_copy_test_site_directory("$simpletest/$test_site_directory", "$simpletest/test_site_directory"); + $this->recurseCopyTestSiteDirectory("$simpletest/$test_site_directory", "$simpletest/test_site_directory"); + $original = scandir("$simpletest/$test_site_directory"); + $copied = scandir("$simpletest/test_site_directory"); - $this->assertTrue(is_dir("$simpletest/test_site_directory"), 'The test site directory is copied to the sites/simpletest/test_site_directory folder.'); + $this->assertEqual($original, $copied, 'The original and copied test site directories exist in the sites/simpletest folder and have the same structure.'); + + $this->drupalGet('admin/config/development/testing'); + $this->assertFieldByXPath('//input', $clean_environment, 'Displayed the "Clean environment" button.'); +sleep(30); $this->drupalPostForm(NULL, [], $clean_environment); $this->assertText(t('Removed @count temporary directory.', ['@count' => 1]), 'Displayed a message: "Removed 1 temporary directory.".'); @@ -49,22 +53,33 @@ public function testCleanTemporaryDirectories() { /** * Creates the exact copy of the test site temporary directory. + * + * The permissions on the copied directory structure are intentionally lowered + * in order to check if the chmod() works as as expected in the + * simpletest_clean_temporary_directories() function. */ - protected function recurse_copy_test_site_directory($source, $destination) { + protected function recurseCopyTestSiteDirectory($source, $destination) { $directory = opendir($source); - mkdir($destination); + if (!mkdir($destination)) { + throw new \Exception("The $destination directory cannot be created."); + } - while(($file = readdir($directory)) !== FALSE) { + while (($file = readdir($directory)) !== FALSE) { if ($file != '.' && $file != '..') { if (is_dir("$source/$file")) { - $this->recurse_copy_test_site_directory("$source/$file", "$destination/$file"); + $this->recurseCopyTestSiteDirectory("$source/$file", "$destination/$file"); } else { - copy("$source/$file", "$destination/$file"); + if (!copy("$source/$file", "$destination/$file") || !chmod("$destination/$file", 0444)) { + throw new \Exception("The $file cannot be copied to $destination with 0444 permissions."); + } } } } closedir($directory); + if (!chmod($destination, 0555)) { + throw new \Exception("The permissions 0555 cannot be set on the $destination directory."); + } } } diff --git a/core/modules/simpletest/tests/modules/testing_page_test/testing_page_test.module b/core/modules/simpletest/tests/modules/testing_page_test/testing_page_test.module index da2d82b..f52be67 100644 --- a/core/modules/simpletest/tests/modules/testing_page_test/testing_page_test.module +++ b/core/modules/simpletest/tests/modules/testing_page_test/testing_page_test.module @@ -18,5 +18,8 @@ function testing_page_test_form_alter(&$form, $form_state, $form_id) { * Removes test site directory when the 'Clean environment' button is pressed. */ function testing_page_test_submit() { - simpletest_clean_temporary_directories('sites/simpletest/test_site_directory'); + $cleaned = simpletest_clean_temporary_directories('sites/simpletest/test_site_directory'); + if ($cleaned !== TRUE) { + throw new \Exception("The sites/simpletest/test_site_directory cannot be removed because of unsufficient permissions."); + } }