Problem/Motivation

As of #3056118: Remove deprecated code from Upgrade Status, Upgrade Status only uses deprecated APIs in tests. It does need to do that to test that it actually finds them. As such Upgrade Status cannot be made to run on Drupal 9 and pass its current tests, because the deprecated APIs it is testing with are removed in Drupal 9. The time of this writing, there are no deprecated Drupal 9 APIs yet, so there is no way to test that the module would perform the operations it is supposed to perform on Drupal 9.

That said, while it would be possible to slap a core_version_requirement into the info file of the module and be done with it, it would be impossible to test that the module works on Drupal 9. We either need to wait on an API to get deprecated in Drupal 9 itself to have something to test against or figure out a workaround. For example, we can add our own test API that we deprecate for the sake of testing that we find when we use our own deprecated API.

Proposed resolution

1. Either wait for the first deprecation in Drupal 9 and adapt tests for that or
2. Add our own stub API that we deprecate so we can identify that finding it works. Then we can be Drupal 9 compatible cleanly.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy created an issue. See original summary.

rpayanm’s picture

Status: Active » Needs review
Issue tags: +ContributionWeekend2020
FileSize
7.62 KB
nathandentzau’s picture

RTBC +1 should probably get another pair of eyes on this and test.

rpayanm’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

The patch is on 8.x-2.x-dev.

Gábor Hojtsy’s picture

+++ b/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php
@@ -12,7 +13,7 @@ class UpgradeStatusTestContribErrorController extends ControllerBase {
-      '#markup' => format_string('I am @deprecated', ['@deprecated' => 'deprecated']),
+      '#markup' => new FormattableMarkup('I am @deprecated', ['@deprecated' => 'deprecated']),

+++ b/tests/modules/upgrade_status_test_error/src/Controller/UpgradeStatusTestErrorController.php
@@ -2,12 +2,41 @@
-    menu_cache_clear_all();
+    $this->cacheBackend->invalidateAll();

+++ b/tests/modules/upgrade_status_test_error/src/DummyTestClass.php
@@ -2,14 +2,14 @@
-class DummyTestClass extends WebTestBase {
+class DummyTestClass extends BrowserTestBase {

These are explicitly included as deprecated API uses to test them. If we are fixing them then the tests will fail because we are not finding any deprecated APIs.

Steps for this issue, as explained in the proposed resolution is:

  1. Either wait for the first deprecation in Drupal 9 and adapt tests for that or
  2. Add our own stub API that we deprecate so we can identify that finding it works. Then we can be Drupal 9 compatible cleanly.

Since (1) did not happen and may not happen for a while AFAIK, (2) would be the best to do. Add some dummy API of our own that we deprecate and use and can test that we found the use of said deprecated API. That would make our testing Drupal major version agnostic. Unfortunately fixing the use of deprecated APIs while we are still testing to find them even though they are not there does not move us forward.

Also the project page (https://www.drupal.org/project/upgrade_status) has a link to #3100361: Remove usage of file_directory_temp() if its not available for Drupal 9 compatibility where the file_directory_temp() part of the patch would belong.

Finally the REQUEST_TIME fix looks like is in order regardless of major version compatibility, please open a new issue about that with that part of the patch, thanks a lot.

Gábor Hojtsy’s picture

Gábor Hojtsy’s picture

Title: Drupal 9 compatibility of Upgrade Status (tests) » Make Upgrade Status tests Drupal 09 compatible

Ok I made the module Drupal 9 compatible in #3133544: Make Upgrade Status work on Drupal 9 (except tests), but tests are still not. So the module could theoretically be run on Drupal 9 but we cannot yet prove with tests, since our tests are heavily dependent on the availability of the Drupal 9 deprecated APIs in PHP, twig, etc. So this remains standing for full compatibility.

That said, there is no reason to run the module on Drupal 9 yet, so I am not very rushed to fix this ASAP. We need to have a plan for each area being tested how can we have version agnostic tests.

Gábor Hojtsy’s picture

Title: Make Upgrade Status tests Drupal 09 compatible » Make Upgrade Status tests Drupal 9 compatible
Kristen Pol’s picture

Status: Needs review » Needs work

Checked patch from #2 in simplytest.me and get:

Fatal error: Cannot redeclare Drupal\upgrade_status\DeprecationAnalyzer::$time in /var/www/html.original/modules/contrib/upgrade_status/src/DeprecationAnalyzer.php on line 115

when going to:

/admin/reports/upgrade-status. Moving back to "Needs work".

Gábor Hojtsy’s picture

Status: Needs work » Active

Yeah I already committed the time property and use in #3133544: Make Upgrade Status work on Drupal 9 (except tests) and elsewhere based on @fgm's patch. I should have credited @rpayanm if I would have collated the issues. Sorry for that. The tests still need fixing, but not the way proposed here :) If we fix the deprecated API use we are testing for, then our tests will not find them of course.

So moving to active, since this is back to the drawing board.

ressa’s picture

Even though it is mainly an aesthetical issue, it would be nice to be able to check all modules, and get a sea of green error-free messages, by fixing the three errors :-)

Upgrade Status report

Contributed projects

Upgrade Status 8.x-2.7

Scanned on Thu, 06/11/2020 - 09:47.
3 errors found. 19 warnings found.

Works on Drupal 9, even if there is no point yet. #3100308: Make Upgrade Status tests Drupal 9 compatible still stands.

File name Line Error
web/modules/contrib/upgrade_status/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php 13 Call to deprecated function drupal_set_message(). Deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
web/modules/contrib/upgrade_status/tests/modules/upgrade_status_test_error/src/Controller/UpgradeStatusTestErrorController.php 10 Call to deprecated function menu_cache_clear_all(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use \Drupal::cache('menu')->invalidateAll() instead.
web/modules/contrib/upgrade_status/tests/modules/upgrade_status_test_error/src/DummyTestClass.php 12 Class Drupal\upgrade_status_test_error\DummyTestClass extends deprecated class Drupal\simpletest\WebTestBase. Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/3030340. Replacement available from drupal:8.6.0.
Gábor Hojtsy’s picture

@ressa: if the module would not report errors in its test code, then how would we test that it finds errors? Without errors?

ressa’s picture

I see, I thought they just needed some work to get fixed. But reading the Issue Summary closer, I now understand that they are meant to fail.

ressa’s picture

Why not programmatically exclude the Upgrade Status module itself from the list of modules to check, under "Contributed projects" on admin/reports/upgrade-status?

Gábor Hojtsy’s picture

@ressa: do you have a patch proposal? We'd need to exclude it for the sake of runtime display then and not for the sake of testing.

Gábor Hojtsy’s picture

@ressa: also that would still not make the tests themselves Drupal 9 compatible, so would not resolve the goal of this issue and therefore should be its own issue to have cleaner reporting.

ressa’s picture

Gábor Hojtsy: Thanks for clarifying, I have created a new issue at #3152450: Exclude Upgrade Status module from it's own UI when not in tests.

andypost’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev

Tests could use split depending on core version, OTOH it makes maintenance harder

Other way is redo tests for D9 and create 4.x release specifically for it

Gábor Hojtsy’s picture

Status: Active » Needs review
FileSize
6.82 KB

Made some exploration to the extent of this. We are testing five things that are outside the bounds of this project:

1. drupal_set_message() ✅ We can replace with our own deprecated function.
2. menu_cache_clear_all() ✅ We can replace with our own deprecated function.
3. WebTestBase 🤔 I think this cannot be replaced 1-1.
4. Testing of Twig 1 deprecated stuff (raw in particular) 🤔 This definitely cannot be replaced as it is proving a third party deprecation is found.
5. Testing of deprecated theme function functionality ✅ While this is 8 to 9 specific, we have our own core-independent implementation, so we can keep it around as long as we want to detect extremely outdated code.

Let's see how does this patch fairs for now. I added a @todo for the ones that need to be revisited. In particular 3 and 4 need some solution to make the module compatible with Drupal 9.

Status: Needs review » Needs work

The last submitted patch, 19: 3100308.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
8.55 KB
4.54 KB

The fails were due to two things (a) we categorize errors by source version number for severity and using X.Y.0 did not fit that so did not pass that test, using a concrete version number for now (b) error line numbers of course changed where I added additional comments to file.

This passes locally. Still need to figure out what to do about the remaining 8 specific @todo items.

Gábor Hojtsy’s picture

Read up on the twig docs, and it is apparently possible to define our own deprecated filter to test that instead of raw. https://twig.symfony.com/doc/1.x/advanced.html#deprecated-filters -- would be great to get a helping hand in this. :)

Gábor Hojtsy’s picture

The raw tag deprecation is very hard coded in src/Lexer.php:

    protected function lexRawData($tag)
    {
        if ('raw' === $tag) {
            @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED);
        }
    }

I'll look into adding a custom twig filter though that we can check then. Fingers crossed.

Gábor Hojtsy’s picture

FileSize
9.73 KB

Ok went by the samples at https://symfony.com/doc/current/templating/twig_extension.html -- this is not yet passing, but posting as a work in progress. Kept the raw usage for now until this passes.

Status: Needs review » Needs work

The last submitted patch, 24: 31003080-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
11.28 KB
3 KB

Woah, woah. Turns out the fail was due to the twig error regexp not matching line numbers other than 0-9 :D. That's not good, alright.

Gábor Hojtsy’s picture

FileSize
10.89 KB
4.44 KB

Now removed uses of the raw tag, so we can be dependent of Drupal 8 / Twig 1 there too. Only WebTestBase left I think.

Gábor Hojtsy’s picture

FileSize
4 KB
13.53 KB

Aand now making it independent of WebTestBase also by defining our own deprecated base class. Wohoo!

Gábor Hojtsy’s picture

FileSize
13.98 KB
460 bytes

Let's allow to work on Drupal 9 in the info file so we can actually test with Drupal 9.

Status: Needs review » Needs work

The last submitted patch, 29: 3100308-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
14.85 KB
889 bytes

Duh that puts the module into the "relax" category.

Gábor Hojtsy’s picture

FileSize
15.19 KB
355 bytes

Should update composer.json too so composer can install it.

Gábor Hojtsy’s picture

FileSize
15.29 KB
417 bytes

Meh, stray comma.

Gábor Hojtsy’s picture

FileSize
18.21 KB
2.92 KB

We can remove the "core: 8.x" from test info files on 8 without affecting how it is tested. This will at least uncover the next layer of fails on Drupal 9.

Gábor Hojtsy’s picture

FileSize
19.11 KB
920 bytes

My limited grep did not find this 7.x core compatibility. It still does not affect D8 testing, let's see D9.

Gábor Hojtsy’s picture

FileSize
19.74 KB
1.36 KB

So due to the added Drupal compatibility info for test modules, this will get categorized as relax. Wondering why the others did not come up first... Hm.

andypost’s picture

Assigned: Unassigned » andypost

Used to run tests locally and getting other error in artifacts of HTML (end of batch scan screen)

User deprecated function: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of upgrade_status_test_theme_function(). See https://www.drupal.org/node/1831138 in Drupal\Core\Theme\Registry->processExtension() (line 498 of core/lib/Drupal/Core/Theme/Registry.php).

CR https://www.drupal.org/node/2575445

andypost’s picture

Assigned: andypost » Unassigned
FileSize
6 KB
22.81 KB

Filed related fix because I used to run on PHP 8 https://github.com/mglaman/phpstan-drupal/pull/163

Used to fix minors
- DeprecationCollector instead of \Twig_Util_DeprecationCollector
- $modules should be a protected property in test classes

  1. +++ b/tests/modules/upgrade_status_test_error/src/Controller/UpgradeStatusTestErrorController.php
    @@ -4,15 +4,13 @@ namespace Drupal\upgrade_status_test_error\Controller;
    +    upgrade_status_test_no_error_deprecated_function();
    

    I did rename this function and moved it out of "no_error" module to upgrade_status_test_deprecated_function module

  2. +++ b/tests/src/Functional/UpgradeStatusTestBase.php
    @@ -46,6 +46,7 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
    +    $drupal_major = (int) \Drupal::VERSION;
    
    @@ -56,8 +57,11 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
    +      ($drupal_major < 9 ? 'collaborate' : 'relax') . '[data][list][upgrade_status_test_contrib_error]' => TRUE,
    

    Could be added as protected method getDrupalCoreMajorVersion() to base test class

andypost’s picture

FileSize
3.1 KB
23.64 KB

Fix remaining test but others could be broken because self deprecations will not fire

andypost’s picture

+++ b/tests/src/Functional/UpgradeStatusAccessTest.php
@@ -17,7 +17,7 @@ class UpgradeStatusAccessTest extends BrowserTestBase {
-  public static $modules = ['upgrade_status'];
+  protected static $modules = ['upgrade_status'];

+++ b/tests/src/Functional/UpgradeStatusTestBase.php
@@ -15,12 +15,11 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
-  public static $modules = [
+  protected static $modules = [

Is 9.0 CR https://www.drupal.org/node/2909426

Additionally the setUp() method could use void type hint https://www.drupal.org/node/3114724 but it could use a follow-up to fix remaining self-deprecations

Remaining self deprecation notices (24)

  8x: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of upgrade_status_test_theme_function(). See https://www.drupal.org/node/1831138
    3x in UpgradeStatusAnalyzeTest::testAnalyzer from Drupal\Tests\upgrade_status\Functional
    3x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional
    2x in UpgradeStatusUiTest::testUiBeforeScan from Drupal\Tests\upgrade_status\Functional

  4x: Twig Filter "deprecatedfilter" is deprecated in modules/contrib/upgrade_status/tests/modules/upgrade_status_test_twig/templates/test.html.twig at line 10.
    2x in UpgradeStatusAnalyzeTest::testAnalyzer from Drupal\Tests\upgrade_status\Functional
    2x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional

  4x: Twig Filter "deprecatedfilter" is deprecated in modules/contrib/upgrade_status/tests/themes/upgrade_status_test_theme/templates/test.html.twig at line 2.
    2x in UpgradeStatusAnalyzeTest::testAnalyzer from Drupal\Tests\upgrade_status\Functional
    2x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional

  4x: Twig Filter "deprecatedfilter" is deprecated in modules/contrib/upgrade_status/tests/themes/upgrade_status_test_theme/templates/test.html.twig at line 4.
    2x in UpgradeStatusAnalyzeTest::testAnalyzer from Drupal\Tests\upgrade_status\Functional
    2x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional

  2x: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of upgrade_status_test_theme_upgrade_status_test_theme_function_theme_function_override(). See https://www.drupal.org/node/1831138
    1x in UpgradeStatusAnalyzeTest::testAnalyzer from Drupal\Tests\upgrade_status\Functional
    1x in UpgradeStatusUiTest::testUiAfterScan from Drupal\Tests\upgrade_status\Functional

  2x: Declaring ::setUp without a void return typehint in Drupal\Tests\upgrade_status\Functional\UpgradeStatusUiTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
    2x in DrupalListener::startTest from Drupal\Tests\Listeners

andypost’s picture

FileSize
2.03 KB
25.11 KB

Make sure new test module also covered and has no errors

andypost’s picture

Probably makes sense to add dependency on new module(upgrade_status_test_deprecated_function) to upgrade_status_test_contrib_error and upgrade_status_test_error

Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/tests/modules/upgrade_status_test_contrib_no_error/upgrade_status_test_contrib_no_error.info.yml
--- /dev/null
+++ b/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.module

Not convinced that this needs to be its own module, it looks way too granular. Eg. the twig test modules both define and use their deprecated things. We can also just move the definition of this to the "contrib" "error" modules as an alternative (and if we want to super correct add a dependency to the "custom" module). The test deprecated base class is also in the error module.

Otherwise looks great, thanks!

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
8.05 KB
22.7 KB

There we go.

Gábor Hojtsy’s picture

FileSize
805 bytes
22.76 KB

Actually I noticed one more accidental @andypost change. We intentionally test the 9.1 compatibility on one of the test modules. I don't think it would be a problem that 9.0 sites cannot run that test. Sites that run tests for deployment would usually not be outdated on 9.0 at this point.

  • Gábor Hojtsy committed 97f0523 on 8.x-3.x
    Issue #3100308 by Gábor Hojtsy, andypost, rpayanm: Make Upgrade Status...
Gábor Hojtsy’s picture

Category: Plan » Task
Status: Needs review » Fixed

All right, committed this!

Also credited @rpayanm for the $time replacement, because they were not credited for that elsewhere. (Even though that did not happen in this issue after all).

I opened #3201156: Make Upgrade Status logic make sense on Drupal 9 to continue with Drupal 9 to Drupal 10 support.

andypost’s picture

Thank you fixing remains! ++ latest changes

Status: Fixed » Closed (fixed)

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