Commit 97f05234 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3100308 by Gábor Hojtsy, andypost, rpayanm: Make Upgrade Status tests Drupal 9 compatible

parent 8bf145ec
......@@ -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');
}
/**
......
......@@ -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) {
......
......@@ -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_contrib_error_function();
}
}
......@@ -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'
<?php
/**
* Tests function deprecation detection.
*
* @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the
* replacement instead.
*/
function upgrade_status_test_contrib_error_function() {
@trigger_error("upgrade_status_test_contrib_error_function() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
}
......@@ -3,5 +3,7 @@ type: module
description: 'Support module for upgrade status module testing.'
package: Testing
version: VERSION
# Intentionally using a requirement that is slightly more specific to
# test handling of this case.
core_version_requirement: ^8 || ^9.1
project: 'upgrade_status_test_contributed_no_error'
......@@ -4,15 +4,13 @@ namespace Drupal\upgrade_status_test_error\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Test class which contains deprecation error.
*/
class UpgradeStatusTestErrorController extends ControllerBase {
public function content() {
menu_cache_clear_all();
return [
'#type' => 'markup',
'#markup' => $this->t('I am deprecated.'),
];
upgrade_status_test_contrib_error_function();
}
}
<?php
namespace Drupal\upgrade_status_test_error;
/**
* A deprecated class to allow testing extension of deprecated classes.
*
* @group upgrade_status_test_error
*
* @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.
*/
class DeprecatedBaseClass {
}
......@@ -2,20 +2,11 @@
namespace Drupal\upgrade_status_test_error;
use Drupal\simpletest\WebTestBase;
/**
* A DummyTestClass to test deprecation of WebTestBase.
* A dummy class to test that extension of a deprecated class is detected.
*
* @group upgrade_status_test_error
*/
class DummyTestClass extends WebTestBase {
/**
* No-op test method to make testbot happy.
*/
public function testNoop() {
}
class ExtendingClass extends DeprecatedBaseClass {
}
......@@ -3,4 +3,5 @@ type: module
description: 'Support module for upgrade status module testing.'
package: Testing
version: VERSION
core: 8.x
dependencies:
-drupal:upgrade_status_contrib_error
......@@ -3,6 +3,5 @@ type: module
description: 'Support module for upgrade status module testing.'
package: Testing
version: VERSION
core: 7.x
dependencies:
- upgrade_status:upgrade_status_test_submodules_with_error
......@@ -3,4 +3,3 @@ type: module
description: 'Support module for upgrade_status module testing for modules with submodules, both with errors.'
package: Testing
version: VERSION
core: 8.x
name: 'Upgrade Status Test module with theme functions'
type: module
description: 'Test module for testing theme function deprecation messages'
core: 8.x
core_version_requirement: ^8 || ^9
package: Testing
version: VERSION
<?php
namespace Drupal\upgrade_status_test_twig\TwigExtension;
use Twig\TwigFilter;
use Twig\Extension\AbstractExtension;
class DeprecatedFilter extends AbstractExtension {
public function getFilters() {
return [new TwigFilter('deprecatedfilter', 'strlen', ['deprecated' => TRUE])];
}
}
{{ 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}}
......@@ -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
services:
upgrade_status_test_twig.twig_extension:
class: Drupal\upgrade_status_test_twig\TwigExtension\DeprecatedFilter
tags:
- { name: twig.extension }
......@@ -17,7 +17,7 @@ class UpgradeStatusAccessTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['upgrade_status'];
protected static $modules = ['upgrade_status'];
/**
* {@inheritdoc}
......
......@@ -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_contrib_error_function(). 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_contrib_error_function(). 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']);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment