diff --git a/composer.json b/composer.json index e26ee39..ff39e46 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,7 @@ "phpstan/phpstan-deprecation-rules": "^0.12.0", "mathieuviossat/arraytotexttable": "~1.0.0", "nikic/php-parser": "^4.0.0", - "webflo/drupal-finder": "^1.2", - "drupal/core": "^8.7.0" + "webflo/drupal-finder": "^1.2" }, "minimum-stability": "dev", "extra": { diff --git a/src/DeprecationAnalyzer.php b/src/DeprecationAnalyzer.php index 508a4df..635fb38 100644 --- a/src/DeprecationAnalyzer.php +++ b/src/DeprecationAnalyzer.php @@ -12,6 +12,7 @@ use Drupal\Core\Template\TwigEnvironment; use DrupalFinder\DrupalFinder; use GuzzleHttp\Client; use Psr\Log\LoggerInterface; +use Twig\Util\DeprecationCollector; final class DeprecationAnalyzer { @@ -322,7 +323,7 @@ final class DeprecationAnalyzer { $twig_deprecations = $this->analyzeTwigTemplates($extension->getPath()); foreach ($twig_deprecations as $twig_deprecation) { preg_match('/\s([a-zA-Z0-9\_\-\/]+.html\.twig)\s/', $twig_deprecation, $file_matches); - preg_match('/\s(\d).?$/', $twig_deprecation, $line_matches); + preg_match('/\s(\d+).?$/', $twig_deprecation, $line_matches); $twig_deprecation = preg_replace('! in (.+)\.twig at line \d+\.!', '.', $twig_deprecation); $twig_deprecation .= ' See https://drupal.org/node/3071078.'; $result['data']['files'][$file_matches[1]]['messages'][] = [ @@ -491,7 +492,7 @@ final class DeprecationAnalyzer { * @return array */ protected function analyzeTwigTemplates($directory) { - return (new \Twig_Util_DeprecationCollector($this->twigEnvironment))->collectDir($directory, '.html.twig'); + return (new DeprecationCollector($this->twigEnvironment))->collectDir($directory, '.html.twig'); } /** diff --git a/src/ThemeFunctionDeprecationAnalyzer.php b/src/ThemeFunctionDeprecationAnalyzer.php index 244bf84..512decd 100644 --- a/src/ThemeFunctionDeprecationAnalyzer.php +++ b/src/ThemeFunctionDeprecationAnalyzer.php @@ -20,6 +20,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * A theme function deprecation analyzer. + * + * @todo Remove once Drupal 8 to 9 deprecations are not a focus anymore. + * This is not dependent on Drupal 8 core itself though, so we can keep + * it in Drupal 9 to 10 for the sake of exposing extremely outdated code. */ final class ThemeFunctionDeprecationAnalyzer { @@ -144,7 +148,7 @@ final class ThemeFunctionDeprecationAnalyzer { $deprecation_messages[] = new DeprecationMessage(sprintf('The %s is defining %s theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.', $extension->getType(), $theme_function), $function_reflection->getFileName(), $node->getStartLine()); } - // Find theme functions that are being added to an existing array using + // Find theme functions that are being added to an existing array using // the array square bracket syntax. // @code // function hook_theme_registry_alter(&$theme_registry) { diff --git a/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php b/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php index 4324dec..0c756f4 100644 --- a/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php +++ b/tests/modules/upgrade_status_test_contrib_error/src/Controller/UpgradeStatusTestContribErrorController.php @@ -10,7 +10,7 @@ use Drupal\Core\Controller\ControllerBase; class UpgradeStatusTestContribErrorController extends ControllerBase { public function content() { - drupal_set_message('I am deprecated'); + upgrade_status_test_deprecated_function_call(); } } diff --git a/tests/modules/upgrade_status_test_contrib_error/upgrade_status_test_contrib_error.info.yml b/tests/modules/upgrade_status_test_contrib_error/upgrade_status_test_contrib_error.info.yml index cd6dd85..05e8e0d 100644 --- a/tests/modules/upgrade_status_test_contrib_error/upgrade_status_test_contrib_error.info.yml +++ b/tests/modules/upgrade_status_test_contrib_error/upgrade_status_test_contrib_error.info.yml @@ -3,5 +3,4 @@ type: module description: 'Support module for upgrade status module testing.' package: Testing version: VERSION -core: 8.x project: 'upgrade_status_test_contrib_error' diff --git a/tests/modules/upgrade_status_test_contrib_no_error/upgrade_status_test_contrib_no_error.info.yml b/tests/modules/upgrade_status_test_contrib_no_error/upgrade_status_test_contrib_no_error.info.yml index 2d05016..ecbc98a 100644 --- a/tests/modules/upgrade_status_test_contrib_no_error/upgrade_status_test_contrib_no_error.info.yml +++ b/tests/modules/upgrade_status_test_contrib_no_error/upgrade_status_test_contrib_no_error.info.yml @@ -3,5 +3,5 @@ type: module description: 'Support module for upgrade status module testing.' package: Testing version: VERSION -core_version_requirement: ^8 || ^9.1 +core_version_requirement: ^8 || ^9 project: 'upgrade_status_test_contributed_no_error' diff --git a/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml b/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.info.yml similarity index 77% copy from tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml copy to tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.info.yml index e303e13..135022d 100644 --- a/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml +++ b/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.info.yml @@ -1,7 +1,6 @@ -name: 'Upgrade status test Twig' +name: 'Upgrade status test function' type: module description: 'Support module for upgrade status module testing.' package: Testing version: VERSION -core: 8.x core_version_requirement: ^8 || ^9 diff --git a/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.module b/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.module new file mode 100644 index 0000000..7288816 --- /dev/null +++ b/tests/modules/upgrade_status_test_deprecated_function/upgrade_status_test_deprecated_function.module @@ -0,0 +1,11 @@ + 'markup', - '#markup' => $this->t('I am deprecated.'), - ]; + upgrade_status_test_deprecated_function_call(); } } diff --git a/tests/modules/upgrade_status_test_error/src/DeprecatedBaseClass.php b/tests/modules/upgrade_status_test_error/src/DeprecatedBaseClass.php new file mode 100644 index 0000000..e7a995e --- /dev/null +++ b/tests/modules/upgrade_status_test_error/src/DeprecatedBaseClass.php @@ -0,0 +1,15 @@ + TRUE])]; + } +} diff --git a/tests/modules/upgrade_status_test_twig/templates/test.html.twig b/tests/modules/upgrade_status_test_twig/templates/test.html.twig index bd24cb1..a13edfb 100644 --- a/tests/modules/upgrade_status_test_twig/templates/test.html.twig +++ b/tests/modules/upgrade_status_test_twig/templates/test.html.twig @@ -1,5 +1,10 @@ {{ attach_library('upgrade_status_test_library/deprecated_library') }} {{ attach_library('core/dynamic_value_is_skipped'|raw, 'upgrade_status_test_twig/deprecated_library') }} -{% raw %} - Kitten -{% endraw %} + + + + + +{# Moving the deprecated filter use to line 10 on purpose. #} +{% set kitten = 'Kitten' %} +{{kitten|deprecatedfilter}} diff --git a/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml b/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml index e303e13..55e3879 100644 --- a/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml +++ b/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.info.yml @@ -3,5 +3,4 @@ type: module description: 'Support module for upgrade status module testing.' package: Testing version: VERSION -core: 8.x core_version_requirement: ^8 || ^9 diff --git a/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.services.yml b/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.services.yml new file mode 100644 index 0000000..d2e19cd --- /dev/null +++ b/tests/modules/upgrade_status_test_twig/upgrade_status_test_twig.services.yml @@ -0,0 +1,5 @@ +services: + upgrade_status_test_twig.twig_extension: + class: Drupal\upgrade_status_test_twig\TwigExtension\DeprecatedFilter + tags: + - { name: twig.extension } diff --git a/tests/src/Functional/UpgradeStatusAccessTest.php b/tests/src/Functional/UpgradeStatusAccessTest.php index d508f37..8053c80 100644 --- a/tests/src/Functional/UpgradeStatusAccessTest.php +++ b/tests/src/Functional/UpgradeStatusAccessTest.php @@ -17,7 +17,7 @@ class UpgradeStatusAccessTest extends BrowserTestBase { * * @var array */ - public static $modules = ['upgrade_status']; + protected static $modules = ['upgrade_status']; /** * {@inheritdoc} diff --git a/tests/src/Functional/UpgradeStatusAnalyzeTest.php b/tests/src/Functional/UpgradeStatusAnalyzeTest.php index 04c2240..d35c6d2 100644 --- a/tests/src/Functional/UpgradeStatusAnalyzeTest.php +++ b/tests/src/Functional/UpgradeStatusAnalyzeTest.php @@ -38,12 +38,24 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase { $this->assertCount(4, $report['data']['files']); $file = reset($report['data']['files']); $message = $file['messages'][0]; + $this->assertEquals('fatal.php', basename(key($report['data']['files']))); $this->assertEquals("Syntax error, unexpected T_STRING on line 3", $message['message']); $this->assertEquals(3, $message['line']); $file = next($report['data']['files']); + $this->assertEquals('UpgradeStatusTestErrorController.php', basename(key($report['data']['files']))); $message = $file['messages'][0]; - $this->assertEquals("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.", $message['message']); + $this->assertEquals("Call to deprecated function upgrade_status_test_deprecated_function_call(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']); + $this->assertEquals(13, $message['line']); + $file = next($report['data']['files']); + $this->assertEquals('ExtendingClass.php', basename(key($report['data']['files']))); + $message = $file['messages'][0]; + $this->assertEquals("Class Drupal\upgrade_status_test_error\ExtendingClass extends deprecated class Drupal\upgrade_status_test_error\DeprecatedBaseClass. Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use so and so. See https://www.drupal.org/project/upgrade_status.", $message['message']); $this->assertEquals(10, $message['line']); + $file = next($report['data']['files']); + $this->assertEquals('upgrade_status_test_error.info.yml', basename(key($report['data']['files']))); + $message = $file['messages'][0]; + $this->assertEquals("Add core_version_requirement: ^8 || ^9 to designate that the module is compatible with Drupal 9. See https://drupal.org/node/3070687.", $message['message']); + $this->assertEquals(0, $message['line']); $report = $key_value->get('upgrade_status_test_no_error'); $this->assertNotEmpty($report); @@ -56,7 +68,7 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase { $this->assertCount(2, $report['data']['files']); $file = reset($report['data']['files']); $message = $file['messages'][0]; - $this->assertEquals("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.", $message['message']); + $this->assertEquals("Call to deprecated function upgrade_status_test_deprecated_function_call(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']); $this->assertEquals(13, $message['line']); $report = $key_value->get('upgrade_status_test_twig'); @@ -64,8 +76,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase { $this->assertEquals(3, $report['data']['totals']['file_errors']); $this->assertCount(1, $report['data']['files']); $file = reset($report['data']['files']); - $this->assertEquals('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead. See https://drupal.org/node/3071078.', $file['messages'][0]['message']); - $this->assertEquals(3, $file['messages'][0]['line']); + $this->assertEquals('Twig Filter "deprecatedfilter" is deprecated. See https://drupal.org/node/3071078.', $file['messages'][0]['message']); + $this->assertEquals(10, $file['messages'][0]['line']); $this->assertEquals('Template is attaching a deprecated library. The "upgrade_status_test_library/deprecated_library" asset library is deprecated for testing.', $file['messages'][1]['message']); $this->assertEquals(1, $file['messages'][1]['line']); $this->assertEquals('Template is attaching a deprecated library. The "upgrade_status_test_twig/deprecated_library" asset library is deprecated for testing.', $file['messages'][2]['message']); @@ -76,9 +88,9 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase { $this->assertEquals(5, $report['data']['totals']['file_errors']); $this->assertCount(3, $report['data']['files']); $file = reset($report['data']['files']); - foreach ([0 => 1, 1 => 4] as $index => $line) { + foreach ([0 => 2, 1 => 4] as $index => $line) { $message = $file['messages'][$index]; - $this->assertEquals('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead. See https://drupal.org/node/3071078.', $message['message']); + $this->assertEquals('Twig Filter "deprecatedfilter" is deprecated. See https://drupal.org/node/3071078.', $message['message']); $this->assertEquals($line, $message['line']); } $file = next($report['data']['files']); diff --git a/tests/src/Functional/UpgradeStatusTestBase.php b/tests/src/Functional/UpgradeStatusTestBase.php index 4fc97af..aa94d79 100644 --- a/tests/src/Functional/UpgradeStatusTestBase.php +++ b/tests/src/Functional/UpgradeStatusTestBase.php @@ -15,12 +15,11 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase { protected $defaultTheme = 'stark'; /** - * Modules to install. - * - * @var array + * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'upgrade_status', + 'upgrade_status_test_deprecated_function', 'upgrade_status_test_error', 'upgrade_status_test_no_error', 'upgrade_status_test_submodules_a', @@ -46,6 +45,7 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase { * Perform a full scan on all test modules. */ protected function runFullScan() { + $drupal_major = (int) \Drupal::VERSION; $edit = [ 'scan[data][list][upgrade_status_test_error]' => TRUE, 'scan[data][list][upgrade_status_test_no_error]' => TRUE, @@ -56,8 +56,11 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase { 'scan[data][list][upgrade_status_test_theme_functions]' => TRUE, 'scan[data][list][upgrade_status_test_library]' => TRUE, 'scan[data][list][upgrade_status_test_library_exception]' => TRUE, - 'collaborate[data][list][upgrade_status]' => TRUE, - 'collaborate[data][list][upgrade_status_test_contrib_error]' => TRUE, + // Due to the automated core compatibility assignment of test modules, + // the category of this module may be different based on major Drupal + // version. + ($drupal_major < 9 ? 'collaborate' : 'relax') . '[data][list][upgrade_status_test_contrib_error]' => TRUE, + 'relax[data][list][upgrade_status]' => TRUE, 'relax[data][list][upgrade_status_test_contrib_no_error]' => TRUE, ]; $this->drupalPostForm('admin/reports/upgrade-status', $edit, 'Scan selected'); diff --git a/tests/themes/upgrade_status_test_theme/templates/test.html.twig b/tests/themes/upgrade_status_test_theme/templates/test.html.twig index 3065fc1..06a225e 100644 --- a/tests/themes/upgrade_status_test_theme/templates/test.html.twig +++ b/tests/themes/upgrade_status_test_theme/templates/test.html.twig @@ -1,6 +1,4 @@ -{% raw %} - Kitten -{% endraw %} -{% raw %} - Panda -{% endraw %} +{% set kitten = 'Kitten' %} +{{kitten|deprecatedfilter}} +{% set panda = 'Panda' %} +{{panda|deprecatedfilter}} diff --git a/upgrade_status.info.yml b/upgrade_status.info.yml index 609eee0..ebb3bd3 100644 --- a/upgrade_status.info.yml +++ b/upgrade_status.info.yml @@ -3,8 +3,8 @@ name: 'Upgrade Status' description: 'Review Drupal 9 readiness of the environment and components of the site.' configure: upgrade_status.report package: Administration +core_version_requirement: ^8 || ^9 core: 8.x php: '7.1' dependencies: - drupal:update - - drupal:system (>=8.7)