This is a child issue of #3057420: [meta] How to deprecate Simpletest with minimal disruption

Problem/Motivation

We want to decouple the test running infrastructure from the simpletest module itself.

Many tests use Drupal\Core\StreamWrapper\PublicStream\TestFileCreationTrait::getTestFiles() to generate temporary fixture files.

TestFileCreationTrait::getTestFiles() uses some files within the simpletest module as fixtures.

We can easily see this in #3075490-11: Move simpletest module to contrib where we experimentally remove the simpletest module and then run a druaplci test build. Most of the test fails are related to TestFileCreationTrait.

Proposed resolution

Move the fixture files to a new location.

Change Drupal\Core\StreamWrapper\PublicStream\TestFileCreationTrait::getTestFiles() to use the new location.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mile23 created an issue. See original summary.

Mile23’s picture

Mile23’s picture

Issue summary: View changes
voleger’s picture

Status: Active » Needs review
FileSize
6.86 KB

Let's check the option when we move the files into /core/tests/fixtures/files folder.

Status: Needs review » Needs work

The last submitted patch, 4: 3080163-4.patch, failed testing. View results

voleger’s picture

Status: Needs work » Needs review
FileSize
20.79 KB
12.23 KB

Let`s fix failed tests

Status: Needs review » Needs work

The last submitted patch, 6: 3080163-6.patch, failed testing. View results

Mile23’s picture

Status: Needs work » Needs review
FileSize
24.37 KB
4.05 KB

Fixes some tests.

I couldn't figure out the migration ones.

Mile23’s picture

FileSize
4.05 KB

Not sure where that previous interdiff came from... Here's the real one.

Status: Needs review » Needs work

The last submitted patch, 8: 3080163_8.patch, failed testing. View results

Lendude’s picture

+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -49567,7 +49567,7 @@
-  'value' => 's:29:"core/modules/simpletest/files";',
+  'value' => 's:29:"core/tests/fixtures/files";',

String length changed, so the s:29 is wrong, hence the unserialize failure in the migrations I assume

Lendude’s picture

Status: Needs work » Needs review
FileSize
484 bytes
24.37 KB

Lets see how this does.

Status: Needs review » Needs work

The last submitted patch, 12: 3080163-12.patch, failed testing. View results

Mile23’s picture

Status: Needs work » Needs review
FileSize
27.12 KB
2.74 KB

The one remaining fail is Drupal\Tests\migrate_drupal_ui\Functional\d6\Upgrade6Test.

It turns out that whoever made that test base was one step ahead of us, and duplicated the fixture files into their own directory, mimicking the path to the simpletest fixture directory. See Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase::getSourceBasePath(). Congratulations to contributors to #2867304: Convert web tests to browser tests for migrate_drupal_ui module :-)

So this patch rearranges the fixtures in core/modules/migrate_drupal_ui/tests/src/Functional/d6/files to mimic core/tests/fixtures/files like the rest of core.

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Great) changes looks good. +1 for rtbc

Mile23’s picture

Priority: Normal » Critical
larowlan’s picture

So I was thinking about these files in that folder, should we have a .htaccess file in there with a deny from all directive to prevent people using them to fingerprint the version of Drupal?

Lendude’s picture

I think #17 is a little out of scope here? Isn't that something we should do/discuss in a broader scope? Not sure what the added value would be doing it just here (but maybe I'm missing something).

mondrake’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/tests/src/Functional/Views/RelationshipUserFileDataTest.php
@@ -67,7 +67,7 @@ public function testViewsHandlerRelationshipUserFileData() {
     ]);
     $file->enforceIsNew();
-    file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
+    file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
     $file->save();
 

Relative paths assume that cwd while running the test is Drupal root. That's fine for DrupalCI bots, but other testing workflow may fail in this context. IMHO we should have absolute paths and prepend an app.root or a __DIR__dance here (and all other cases).

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

#19 sounds like a good improvement, but also sounds out of scope here, the same problem already exists in HEAD. Can we do that in a follow-up? Or is there a good reason that this needs to be done here?

Tentatively setting back to RTBC.

mondrake’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
@@ -280,7 +280,7 @@ public function testManipulations() {
     foreach ($files as $file) {
       foreach ($operations as $op => $values) {
         // Load up a fresh image.
-        $image = $this->imageFactory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file);
+        $image = $this->imageFactory->get('core/tests/fixtures/files/' . $file);
         $toolkit = $image->getToolkit();
         if (!$image->isValid()) {
           $this->fail(new FormattableMarkup('Could not load image %file.', ['%file' => $file]));
@@ -426,14 +426,14 @@ public function testManipulations() {

Probably this case is more evident: I suspect (but am not sure) drupal_get_path('module', 'simpletest') will return an absolute path whereas after the change it will be relative. Not changing from RTBC, but I think #19 would avoid any risk.

mondrake’s picture

I tested patch in #14 by running PHPUnit from within the core subdirectory

$ cd $DRUPAL_PATH/core
$ ../vendor/bin/phpunit --group image,Image

and all turned OK, so my concerns in #19 and #21 are not relevant. All good. Sorry for the noise.

  • catch committed 90a550d on 8.8.x
    Issue #3080163 by Mile23, voleger, Lendude, mondrake: Decouple...
catch’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/tests/Drupal/Tests/TestFileCreationTrait.php
@@ -69,8 +69,8 @@ protected function getTestFiles($type, $size = NULL) {
         $file_system->copy($file->uri, PublicStream::basePath());
diff --git a/core/modules/simpletest/files/README.txt b/core/tests/fixtures/files/README.txt

diff --git a/core/modules/simpletest/files/README.txt b/core/tests/fixtures/files/README.txt
similarity index 100%

similarity index 100%
rename from core/modules/simpletest/files/README.txt

rename from core/modules/simpletest/files/README.txt
rename to core/tests/fixtures/files/README.txt

I thought about copying these instead of renaming, but can't really imagine that contrib is relying on these fixtures for tests. If it turns out they are, we might need to copy them back again, but committing this as is and making a note here.

Mile23’s picture

Thanks, @catch. Do we need a CR here?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Priority: Critical » Major