Problem/Motivation

We currently have simpletest module in contrib (dev version) and simpletest module in core (fully deprecated).

While simpletest is in core, it is hard to confidently say that modules can run simpletest tests with the contrib module, since every install gets simpletest.

Additionally, there may still be issues getting the contributed module working, and some may involve conflicts with the core version (composer? autoloading?).

Proposed resolution

1. Commit a patch that does rm -rf on the simpletest module.

2. Leave run-tests.sh support for simpletest in core for now.

3. Open a new beta blocking tracking issue to ensure the contrib module works.

4. Any further refactoring like moving run-tests.sh to contrib would be non-release-blocking.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Simpletest module is removed from core in Drupal 9.

  1. If your tests rely on a component of simpletest module, such as Drupal\simpletest\WebTestBase then your tests will not work anymore with Drupal core only.
  2. If you ran tests from the web user interface, that is not possible in Drupal core anymore. See https://www.drupal.org/docs/8/phpunit/running-phpunit-tests for instructions on how to run tests from the command line.

Follow #3093621: [META] Plan to get a stable D8/D9 release of the SimpleTest module and contribute there to make the formerly core base classes and the web user interface available in a contributed module. If that route does not work out, simpletest will be added back to Drupal core before the first beta release, see #3110983: Verify that simpletest tests can be run in contrib, or add simpletest back to core.

Comments

catch created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new363.17 KB

git rm -r core/modules/simpletest

longwave’s picture

StatusFileSize
new364.33 KB
new1.17 KB

Status: Needs review » Needs work

The last submitted patch, 3: 3110862-3.patch, failed testing. View results

xjm’s picture

Issue tags: +Needs followup

This needs the beta must-have followup to make sure we've solved everything for it.

catch’s picture

Issue tags: -Needs followup

The upgrade path database dumps have simpletest module installed.

We have two choices:

1. Leave a stub simpletest.info.yml (hidden) so that those pass with minimal changes. This will also allow any rogue sites with simpletest module enabled to still be upgraded to 9.0.x

2. Remove it from the database dumps.

#1 is probably less work and easier to revert, although it'll need a follow-up to to #2 later.

There's also this failure which just looks like an assertion needs changing:

 Drupal\Tests\system\Functional\Form\ModulesListFormWebTest::testModuleListForm
"simpletest" found

I've opened #3110983: Verify that simpletest tests can be run in contrib, or add simpletest back to core for the tracking issue, and added it to the issue summary of #3079680: [META] Requirements for tagging Drupal 9.0.0-beta1

berdir’s picture

I think we also need to do that for existing actual sites that have it enabled?

And I think we also need to remove ""drupal/simpletest": "self.version"," from core/composer.json, that's not in the patch yet from what I see?

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new371.63 KB
new7.3 KB

This should deal with most fails except the upgrade path ones, plus #7. There are probably some remaining references that need updating as well.

catch’s picture

+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -263,6 +263,20 @@ function common_test_page_attachments_alter(array &$page) {
+ */
+function common_test_js_alter(&$javascript, AttachedAssetsInterface $assets) {
+  // Since SimpleTest is a special use case for the table select, stick the
+  // SimpleTest JavaScript above the table select.
+  $simpletest = drupal_get_path('module', 'common_test') . '/alter.js';
+  if (array_key_exists($simpletest, $javascript) && array_key_exists('core/misc/tableselect.js', $javascript)) {
+    $javascript[$simpletest]['weight'] = $javascript['core/misc/tableselect.js']['weight'] - 1;
+  }
+}
+

Could use comments/variable names updating.

I think we also need to do that for existing actual sites that have it enabled?

We can require sites to uninstall on 8.x first, but it's probably nicer. We might want a 9.x-only update that uninstalls simpletest too so we can just remove it entirely in 10.0.x (can be a follow-up).Probably a hook_requirements() to stop it being enabled as well (again, could be done in the same follow-up).

Status: Needs review » Needs work

The last submitted patch, 8: 3110862-8.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new370.26 KB
new3.01 KB

Thanks for review. Addressed #9 and added back a stub simpletest.info.yml, we also need the config schema as simpletest.settings.yml is tested. Also reverted composer.json as we are shipping a stub (we still include entity_reference in composer.json so I thought this was more consistent)

Though does having the stub allow the full contrib module to still be installed? How does module discovery deal with duplicate modules?

lendude’s picture

What we need is basically what we have here https://www.drupal.org/project/drupal/issues/3075490#comment-13333900
Right? Except rerolled for D9....

Duplicate modules are no problem, it will use the one from contrib, tested this with the patch in that issue

longwave’s picture

@Lendude that patch changes run-tests.sh which we are trying to avoid for the time being, but most of it is remarkably similar. That issue also hardcodes the TestDiscovery class; here we provide test discovery as a service in core.services.yml, contrib simpletest can then swap in its own test discovery service as required. Not sure about the changes in TestRunnerKernel though, will something be required here to get the contrib simpletest to boot?

Actually, that made me notice that this comment can be removed here:

    // @todo Use \Drupal\Core\Test\TestDiscovery when we no longer need BC for
    //   hook_simpletest_alter().
catch’s picture

Addressed #9 and added back a stub simpletest.info.yml, we also need the config schema as simpletest.settings.yml is tested. Also reverted composer.json as we are shipping a stub (we still include entity_reference in composer.json so I thought this was more consistent)

We should remove simpletest.settings.yml and the associated test and config schema IMO - leaving only the .info.yml.

We should also remove the composer.json entry since this is the most likely thing to conflict with the contributed simpletest module - we didn't have that problem with entity_reference since its functionality was simply moved into core/lib.

longwave’s picture

Status: Needs review » Needs work

> We should remove simpletest.settings.yml and the associated test and config schema IMO

simpletest.settings is actually config in the filled dump; if we remove the schema then SchemaCheckTestTrait fails when called from UpdatePathTestBaseFilledTest. We could skip it but it feels like we are working around the issue of providing a new filled dump that doesn't contain simpletest? If we do decide to skip it I think we can add something like this to UpdatePathTestBaseFilledTest:

  /**
   * SimpleTest has been removed in Drupal 9.
   *
   * @todo Remove this when the database dump is replaced.
   */
  protected $configSchemaCheckerExclusions = ['simpletest.settings'];

However, I think any other test that uses drupal-8.8.0.filled.standard.php.gz and calls runUpdates() will run into the same failure.

NW for the composer.json change in #14 and comment noted in #13

catch’s picture

simpletest.settings is actually config in the filled dump; if we remove the schema then SchemaCheckTestTrait fails when called from UpdatePathTestBaseFilledTest. We could skip it but it feels like we are working around the issue of providing a new filled dump that doesn't contain simpletest?

Arghh OK. So... we should maybe add a post-update to system to uninstall simpletest module and delete simpletest.settings - we'll need to do that anyway eventually and it might be the least involved change to make here.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new375.01 KB
new4.74 KB

Addressed #13-16.

Please add commit credit to @Lendude and @Mile23 who did a lot of the groundwork for this in #3075490: Move simpletest module to contrib.

longwave’s picture

StatusFileSize
new376.92 KB
new1.92 KB

Removed the CSS include from Stable, but didn't remove the CSS itself.

The last submitted patch, 17: 3110862-17.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 18: 3110862-18.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new377.93 KB
new1 KB

> We should also remove the composer.json entry since this is the most likely thing to conflict with the contributed simpletest module

So this is the cause of the remaining test failure; ComposerIntegrationTest::testAllModulesReplaced() wants to ensure that each core module appears in composer.json. I modified the test to skip hidden modules, which I think is OK and lets us remove other modules the same way in the future.

Do we need to keep parts of simpletest.install around, so the uninstall is clean? simpletest_uninstall() does some cleanup and I assume the presence of simpletest_schema() would drop the database tables too. Otherwise, I think users might run into "table already exists" when installing the contrib SimpleTest.

catch’s picture

Do we need to keep parts of simpletest.install around, so the uninstall is clean? simpletest_uninstall() does some cleanup and I assume the presence of simpletest_schema() would drop the database tables too.

Yes let's do that. If it was any other module we were moving to contrib, it would be better not to do that so the contrib module can inherit/preserve the data, but we don't care about simpletest data so better to have the clean uninstall especially for sites that never install the contrib module but did have the core one enabled for whatever reason.

lendude’s picture

Looks really good, just some observations:

  1. +++ b/core/core.services.yml
    @@ -1713,3 +1713,6 @@ services:
    +  test_discovery:
    +    class: Drupal\Core\Test\TestDiscovery
    +    arguments: ['@app.root', '@class_loader']
    
    +++ b/core/scripts/run-tests.sh
    @@ -1040,9 +1026,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
    +  /** @var \Drupal\Core\Test\TestDiscovery $test_discovery */
       $test_discovery = \Drupal::service('test_discovery');
    

    I think we require that all service classes have an interface, TestDiscovery doesn't have this right now.

    And then we can use the interface in the type hint.

    But don't know how hard of a rule this is really.

  2. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -84,6 +85,14 @@ public function testAllModulesReplaced() {
    +        // Skip any modules marked as hidden.
    +        $info_yml = $module_path . '/' . $file_name . '/' . $file_name . '.info.yml';
    +        if (file_exists($info_yml)) {
    +          $info = Yaml::parseFile($info_yml);
    +          if (!empty($info['hidden'])) {
    +            continue;
    +          }
    +        }
             $module_names[] = $file_name;
    

    Should we add an assertNotEmpty(module_names) after this to make sure we are not accidentally skipping everything?

longwave’s picture

Thanks for review.

#23.1 I think that is out of scope. I only changed that line because it referred to a now removed class, and it was an incorrectly formatted typehint anyway:

-  /** $test_discovery \Drupal\simpletest\TestDiscovery */
+  /** @var \Drupal\Core\Test\TestDiscovery $test_discovery */

#23.2 is a good idea, will add this later if nobody else gets there first. I tried to be careful here to not skip modules where the info.yml is not named the same as the directory; this is always the case in core but it doesn't have to be from what I remember.

longwave’s picture

StatusFileSize
new378.67 KB
new1.99 KB

Addressed #22 and #23.2.

simpletest_uninstall() must skip if drupal_valid_test_ua() returns TRUE or update tests end up destroying their own environment; I am not sure what we can do here except some manual testing.

catch’s picture

Status: Needs review » Reviewed & tested by the community
  1. 
    
    +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
    +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
    @@ -35,11 +35,9 @@ public function __construct($environment, $class_loader, $allow_dumping = FALSE,
    
    @@ -35,11 +35,9 @@ public function __construct($environment, $class_loader, $allow_dumping = FALSE,
         //   DateFormatter::formatInterval() cause a plugin not found exception.
         $this->moduleList = [
           'system' => 0,
    -      'simpletest' => 0,
         ];
         $this->moduleData = [
           'system' => new Extension($this->root, 'module', 'core/modules/system/system.info.yml', 'system.module'),
    -      'simpletest' => new Extension($this->root, 'module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'),
         ];
       }
    

    I wonder if this is going to make it tricky for the contrib module to run tests, but then that's a good reason to remove this now - the contrib module (unless we some how force it to be) won't be in core/modules anyway.

  2. 
    +++ b/core/modules/simpletest/simpletest.info.yml
    +++ b/core/modules/simpletest/simpletest.info.yml
    @@ -1,6 +1,6 @@
    
    @@ -1,6 +1,6 @@
     name: Testing
     type: module
    -description: 'Provides a framework for unit and functional testing.'
    +description: 'Deprecated. SimpleTest has been removed from core.'
     package: Core
     version: VERSION
    -configure: simpletest.settings
    +hidden: true
    

    This looks fine for now.

  3. +++ b/core/modules/simpletest/simpletest.info.yml
    diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install
    index 373876807b..69ddb8a56c 100644
    
    index 373876807b..69ddb8a56c 100644
    --- a/core/modules/simpletest/simpletest.install
    
    --- a/core/modules/simpletest/simpletest.install
    +++ b/core/modules/simpletest/simpletest.install
    
    +++ b/core/modules/simpletest/simpletest.install
    +++ b/core/modules/simpletest/simpletest.install
    @@ -2,85 +2,13 @@
    
    @@ -2,85 +2,13 @@
     
     /**
      * @file
    - * Install, update and uninstall functions for the simpletest module.
    + * Uninstall functions for the simpletest module.
      */
     
    

    In a follow-up, we should add a hook_requirements() to prevent simpletest being installed, and a system update to uninstall it - to prepare 9.x sites for its actual removal in 10.x. Opened that here #3112432: Prevent core, stub simpletest module from being installed on new sites

92 files changed, 80 insertions, 9907 deletions.

Whoo!

I think this is actually ready to go, so marking as such.

lendude’s picture

RTBC +1

longwave’s picture

+++ b/core/modules/system/system.post_update.php
@@ -267,3 +267,12 @@ function system_post_update_entity_reference_autocomplete_match_limit(&$sandbox
+/**
+ * Uninstall SimpleTest.
+ *
+ * @see https://www.drupal.org/project/drupal/issues/3110862
+ */
+function system_post_update_uninstall_simpletest() {
+  \Drupal::service('module_installer')->uninstall(['simpletest']);
+}

The update to uninstall it was already added here.

gábor hojtsy’s picture

Yay! Needs a change record to explain developers how they can restore the functionality. If that is not immediately possible then we need to stay clear of committing this close before a tagged release to let enough time to figure out a contrib experience that people can try with (even if its not the final one for Drupal 9). Also needs a release notes snippet. This is a big step :)

longwave’s picture

To repeat my comment from #17 which might get missed:

Please add commit credit to @Lendude and @Mile23 who did a lot of the groundwork for this in #3075490: Move simpletest module to contrib

gábor hojtsy’s picture

Just credited both :)

catch’s picture

If that is not immediately possible

It is not immediately possible. There is #3093621: [META] Plan to get a stable D8/D9 release of the SimpleTest module and more specifically #3093620: When installing with composer the module is installed in the simpletest-simpletest folder tracking various things to get something working.

Someone last week (I think it was Mixologic, but apologies if it was someone else) suggested uploading an issue to a contrib module with remaining simpletests, which patches drupalci.yml to apply the final patch here. That will tell us what the immediate fallout of this patch will be on projects with simpletests.

gábor hojtsy’s picture

Issue summary: View changes
Issue tags: -Needs change record, -Needs release note

Just to clarify what I meant, especially if we are to put this in a tagged release before figuring out what contrib needs to ultimately/eventually do, it would be useful to document the interim (possibly ugly) steps. Something like "Simpletest is removed from core, while we figure out how to make this easily available in contrib, apply these 5 dirty steps to your projects including undoing a core patch and dancing around the room twice".

I personally think if this is to be included in a tagged core release without even a 5-step dirty workaround for now to get it back, then we would be making people chase down rabbits that they would not need to otherwise. "Here, we removed simpletest, so if you have tests that relied on it, just ignore this tagged release" is IMHO worse than "Here, we removed simpletest, so for now you need to apply these 5 steps, it will get better promise".

If figuring out the eventual solution precedes putting this into a tagged core release, then we don't need to document any workarounds IMHO. That said, I am not a release manager, so these are personal opinions :)

Attempted to summarise the state of things to the best of my knowledge in this release notes snippet, added to issue summary:

Simpletest module is removed from core in Drupal 9.

  1. If your tests rely on a component of simpletest module, such as Drupal\simpletest\WebTestBase then your tests will not work anymore with Drupal core only.
  2. If you ran tests from the web user interface, that is not possible in Drupal core anymore. See https://www.drupal.org/docs/8/phpunit/running-phpunit-tests for instructions on how to run tests from the command line.

Follow #3093621: [META] Plan to get a stable D8/D9 release of the SimpleTest module and contribute there to make the formerly core base classes and the web user interface available in a contributed module. If that route does not work out, simpletest will be added back to Drupal core before the first beta release, see #3110983: Verify that simpletest tests can be run in contrib, or add simpletest back to core.

mile23’s picture

+++ b/core/core.services.yml
@@ -1713,3 +1713,6 @@ services:
+  test_discovery:
+    class: Drupal\Core\Test\TestDiscovery
+    arguments: ['@app.root', '@class_loader']

+++ b/core/scripts/run-tests.sh
@@ -66,8 +66,6 @@
-    // @todo Use \Drupal\Core\Test\TestDiscovery when we no longer need BC for
-    //   hook_simpletest_alter().
     $groups = \Drupal::service('test_discovery')->getTestClasses($args['module']);

@@ -95,21 +93,9 @@
+  $test_classes = \Drupal::service('test_discovery')->findAllClassFiles();

@@ -1040,9 +1026,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
+  /** @var \Drupal\Core\Test\TestDiscovery $test_discovery */
   $test_discovery = \Drupal::service('test_discovery');

Please don't make TestDiscovery a service. Just instantiate the class in run-tests.sh.

That way:

1) We don't have a wholly unnecessary dependency on the kernel/service locator in the test runner script. run-tests.sh is the only place TestDiscovery is used.

2) We're not stuck with an unchangeable TestDiscovery class until Drupal 11.

The rest looks good. Glad to see this happening. :-)

longwave’s picture

@Mile23: does making it a service allow Simpletest in contrib to swap it out? Simpletest has/had its own extended test discovery class, so I figured by making it a service it could swap in the extended version and still use run-tests.sh? (all untested, but in theory!)

edit: I guess if all it provided before was hook_simpletest_alter() and the contrib version is not going to provide that, swappability doesn't matter?

mile23’s picture

Right, the service in the module is there for BC, and to provide the BC alter hooks.

Since we don't need to do that any more, we don't need a service. We only need to discover tests in run-tests.sh. (And we also use TestDiscovery a little in the test suite discovery for phpunit.)

It's very unlikely that contrib will add back the alter hooks, but they can if they want to by providing the same type of shim service we're removing here.

The only other contrib concern is how to inject test_discovery into the UI form. That's their problem. :-) But they can declare the service in the module and swap out for testing as needed.

gábor hojtsy’s picture

@mixologic suggested this for testing what next steps should be:

  1. Find a module that still has simpletest testing requirements.
  2. Patch that modules drupalci.yml file such that it applies a core patch that makes all of the simpletest changes that we're proposing.
  3. Figure out what the next steps are for that module.

This link provides some ideas for which modules could one pick: http://grep.xnddx.ru/search?text=WebTestBase&filename=

mile23’s picture

So #25 is passing, and has general consensus minus my complaint about adding a new service.

Examples has some remaining WTB tests, in its testing_example, though the branch isn't passing. https://www.drupal.org/node/594964/qa

mile23’s picture

Status: Reviewed & tested by the community » Needs work

I meant to set NW in the last comment. :-)

catch’s picture

catch’s picture

Started an issue here: https://www.drupal.org/project/taxonomy_term_depth/issues/3112696

Test discovery fatals if simpletest isn't in the file system. Had a go at getting drupalci.yml to composer require simpletest and then patch to add it back to the TestKernel but it's currently failing on finding simpletest.info.yml. Probably better to try things out there then report back summaries here.

catch’s picture

With some help from @alexpott we were able to get a green test run for that module, so I've added a change record with some instructions based on the current state of things here: https://www.drupal.org/node/3112907. Obviously needs to additionally apply the patch here if you wanted to test it prior to this getting committed.

The drupalci snippet currently has to apply the following core patch as well as composer requiring simpletest module: https://www.drupal.org/files/issues/2020-02-11/simpletest-3112696.patch

@alexpott suggested conditionally checking for the contributed simpletest module in core so avoid the need for patching core. This seems like a good idea, but for me I would do it in a follow-up postponed on #3093620: When installing with composer the module is installed in the simpletest-simpletest folder since that will require another core issue anyway to update the module folder name when that's fixed. Don't feel strongly about this though: either way we have a follow-up, it's just a question of what the follow-up is for.

Once #3093620: When installing with composer the module is installed in the simpletest-simpletest folder and/or the core patch has landed, contrib modules will need to change the drupalci lines again. Or if we add composer require drupal/simpletest to Drupal CI itself, they could just remove the lines they added.

So very tl;dr:

Once the patch here is committed, contrib modules with simpletests will hit a fatal error on DrupalCI when they test against the Drupal 9 branch.

There is a two-line addition to drupalci.yml with the current state of the patch to get simpletests running again.

If we make the TestingKernel change here, it will be a one line change in drupalci.yml

If we composer require drupal/simpletest in DrupalCI + the TestingKernel change, there's no impact on contributed modules at all (except for ones that need to remove the drupalci.yml workarounds they've added already).

Regardless of the order of the steps, and how many we get done before beta, that's two line drupalci.yml change, a one-line drupalci.yml change or no drupalci.yml changes at all. For me that is minimal impact for contrib, and means we're not at risk of having to revert this once it's committed.

We definitely needed an RTBC patch here to be able to figure this out, but glad it was possible to verify prior to commit.

catch’s picture

Another option via @alexpott:

We check for both simpletest and simpletest-simpletest in TestingKernel, that way core has a redundant file_exists() check but changes with packagist won't require another core patch (until we eventually remove the redundant call, or the whole thing in 10.0.x).

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new3.31 KB
new379.14 KB

Discussed further with catch and we decided that we we could make the change to TestingKernel here and then contrib only has one change to make.

I've also fixed up #35 - great point @Mile23 we shouldn't be adding that to core.

I wonder if we should add a build test to prove simpletest testing works. Yes it means that we'll couple the contrib simpletest module to core a bit - but I think we'll want to know when we break it's basic functionality. At least it would let us plan changes that impact it.

longwave’s picture

StatusFileSize
new378.92 KB
new2.99 KB

Addressed #35 and I like the idea of making this as simple as possible for contrib so I implemented #44 as well.

(crosspost from a train with patchy wifi signal!)

longwave’s picture

The ExtensionDiscovery approach in #45 is better than mine so go with that :)

alexpott’s picture

Here's proof that #45 works for contrib - #3112696-14: Drupal 9 compatibility and re-enable SimpleTests after core removal

Let's wait for green-ness.

alexpott’s picture

StatusFileSize
new2.81 KB
new381.94 KB

Cool so #45 is green - so lets add a unit test to show support for adding the simpletest module info at the very least - as we have no code in core that depends on this.

mile23’s picture

+1 on all the stuff from #45 on.

The patch has changed a little since #45, so I'd RTBC here except that #3112696: Drupal 9 compatibility and re-enable SimpleTests after core removal doesn't use the patch in #49.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

#3112696: Drupal 9 compatibility and re-enable SimpleTests after core removal now also green with the patch from #49. Awesome stuff!

Added a link to https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-tes... to the CR for people that don't have a drupalci.yml in their project yet.

All feedback has been addressed, we have green test results, we have follow ups. Ready?

  • catch committed a4f6e55 on 9.0.x
    Issue #3110862 by longwave, alexpott, catch, Mile23, Lendude, Gábor...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Have a nice peaceful retirement SimpleTest.

Committed a4f6e55 and pushed to 9.0.x. Thanks!

catch’s picture

Tagging retrospectively.

Status: Fixed » Closed (fixed)

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

quietone’s picture