From df05bd62f7a981b204cc3263edd9bce940c144e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=CC=81bor=20Hojtsy?= <gabor@hojtsy.hu> Date: Wed, 3 Apr 2024 19:13:22 +0200 Subject: [PATCH] Issue #3363035 by fenstrat, webdrips, DudeWeb, apaderno, fgm, loze: Drupal 10 Support --- php.info.yml | 3 +-- src/Tests/Condition/PhpConditionTest.php | 4 ++-- src/Tests/Functional/PhpAccessTest.php | 4 ++-- src/Tests/Functional/PhpFilterTest.php | 15 ++++++++------- src/Tests/Functional/PhpTestBase.php | 12 ++++++------ src/Tests/Functional/PhpUninstallTest.php | 13 +++++++------ .../Plugin/views/PhpArgumentValidatorTest.php | 4 ++-- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/php.info.yml b/php.info.yml index 2f18009..3834e48 100644 --- a/php.info.yml +++ b/php.info.yml @@ -1,8 +1,7 @@ name: PHP Filter type: module description: Allows embedded PHP code/snippets to be evaluated. Enabling this can cause security and performance issues as it allows users to execute PHP code on your site. -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^9 || ^10 package: 'Filters' configure: filter.admin_overview dependencies: diff --git a/src/Tests/Condition/PhpConditionTest.php b/src/Tests/Condition/PhpConditionTest.php index 96ad52b..09a7827 100644 --- a/src/Tests/Condition/PhpConditionTest.php +++ b/src/Tests/Condition/PhpConditionTest.php @@ -23,12 +23,12 @@ class PhpConditionTest extends KernelTestBase { * * @var array */ - public static $modules = ['filter', 'system', 'php']; + protected static $modules = ['filter', 'system', 'php']; /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->manager = $this->container->get('plugin.manager.condition'); diff --git a/src/Tests/Functional/PhpAccessTest.php b/src/Tests/Functional/PhpAccessTest.php index 7fd9618..2c7bab4 100644 --- a/src/Tests/Functional/PhpAccessTest.php +++ b/src/Tests/Functional/PhpAccessTest.php @@ -25,11 +25,11 @@ class PhpAccessTest extends PhpTestBase { // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->id()); - $this->assertText('print', 'PHP code was not evaluated.'); + $this->assertSession()->pageTextContains('print'); // Make sure that user doesn't have access to filter. $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoRaw('<option value="' . $this->phpCodeFormat->id() . '">', 'PHP code format not available.'); + $this->assertSession()->responseNotContains('<option value="' . $this->phpCodeFormat->id() . '">'); } } diff --git a/src/Tests/Functional/PhpFilterTest.php b/src/Tests/Functional/PhpFilterTest.php index 069f6dd..86b0e3b 100644 --- a/src/Tests/Functional/PhpFilterTest.php +++ b/src/Tests/Functional/PhpFilterTest.php @@ -29,23 +29,24 @@ class PhpFilterTest extends PhpTestBase { // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->id()); - $this->assertText('php print'); + $this->assertSession()->pageTextContains('php print'); // Change filter to PHP filter and see that PHP code is evaluated. $edit = []; $edit['body[0][format]'] = $this->phpCodeFormat->id(); - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); - $this->assertRaw(t('@type %title has been updated.', ['@type' => 'Basic page', '%title' => $node->toLink($node->getTitle())->toString()]), 'PHP code filter turned on.'); + $this->drupalGet('node/' . $node->id() . '/edit'); + $this->submitForm($edit, t('Save')); + $this->assertSession()->responseContains(t('@type %title has been updated.', ['@type' => 'Basic page', '%title' => $node->toLink($node->getTitle())->toString()])); // Make sure that the PHP code shows up as text. - $this->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed."); - $this->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.'); + $this->assertSession()->pageTextNotContains('print "SimpleTest PHP was executed!"'); + $this->assertSession()->pageTextContains('SimpleTest PHP was executed!'); // Verify that cache is disabled for PHP evaluates. - $this->assertText('Current state is empty', 'PHP code has been evaluated once.'); + $this->assertSession()->pageTextContains('Current state is empty'); \Drupal::state()->set('php_state_test', 'not empty'); $this->drupalGet('node/' . $node->id()); - $this->assertText('Current state is not empty', 'PHP code has been evaluated again.'); + $this->assertSession()->pageTextContains('Current state is not empty'); } } diff --git a/src/Tests/Functional/PhpTestBase.php b/src/Tests/Functional/PhpTestBase.php index da256e3..1fde3c8 100644 --- a/src/Tests/Functional/PhpTestBase.php +++ b/src/Tests/Functional/PhpTestBase.php @@ -17,14 +17,14 @@ abstract class PhpTestBase extends BrowserTestBase { * * @var array */ - public static $modules = ['node', 'php']; + protected static $modules = ['node', 'php']; protected $phpCodeFormat; /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create Basic page node type. @@ -38,7 +38,7 @@ abstract class PhpTestBase extends BrowserTestBase { $php_format_id = 'php_code'; $this->phpCodeFormat = \Drupal::entityTypeManager()->getStorage('filter_format')->load($php_format_id); - $this->assertEqual($this->phpCodeFormat->label(), 'PHP code', 'PHP code text format was created.'); + $this->assertEquals($this->phpCodeFormat->label(), 'PHP code', 'PHP code text format was created.'); // Verify that the format has the PHP code filter enabled. $filters = $this->phpCodeFormat->filters(); @@ -46,12 +46,12 @@ abstract class PhpTestBase extends BrowserTestBase { // Verify that the format exists on the administration page. $this->drupalGet('admin/config/content/formats'); - $this->assertText('PHP code', 'PHP code text format was created.'); + $this->assertSession()->pageTextContains('PHP code'); // Verify that anonymous and authenticated user roles do not have access. $this->drupalGet('admin/config/content/formats/manage/' . $php_format_id); - $this->assertFieldByName('roles[' . RoleInterface::ANONYMOUS_ID . ']', FALSE, 'Anonymous users do not have access to PHP code format.'); - $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', FALSE, 'Authenticated users do not have access to PHP code format.'); + $this->assertSession()->fieldValueEquals('roles[' . RoleInterface::ANONYMOUS_ID . ']', FALSE); + $this->assertSession()->fieldValueEquals('roles[' . RoleInterface::AUTHENTICATED_ID . ']', FALSE); } /** diff --git a/src/Tests/Functional/PhpUninstallTest.php b/src/Tests/Functional/PhpUninstallTest.php index 589271d..8ffe379 100644 --- a/src/Tests/Functional/PhpUninstallTest.php +++ b/src/Tests/Functional/PhpUninstallTest.php @@ -16,12 +16,12 @@ class PhpUninstallTest extends BrowserTestBase { * * @var array */ - public static $modules = ['php']; + protected static $modules = ['php']; /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $permissions = [ @@ -46,10 +46,11 @@ class PhpUninstallTest extends BrowserTestBase { // Uninstall the module. $edit = []; $edit['uninstall[php]'] = TRUE; - $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall')); - $this->assertText(t('Would you like to continue with uninstalling the above?')); - $this->drupalPostForm(NULL, [], t('Uninstall')); - $this->assertText(t('The selected modules have been uninstalled.')); + $this->drupalGet('admin/modules/uninstall'); + $this->submitForm($edit, t('Uninstall')); + $this->assertSession()->pageTextContains(t('Would you like to continue with uninstalling the above?')); + $this->submitForm([], t('Uninstall')); + $this->assertSession()->pageTextContains(t('The selected modules have been uninstalled.')); } } diff --git a/src/Tests/Plugin/views/PhpArgumentValidatorTest.php b/src/Tests/Plugin/views/PhpArgumentValidatorTest.php index c31fa6c..70da2a6 100644 --- a/src/Tests/Plugin/views/PhpArgumentValidatorTest.php +++ b/src/Tests/Plugin/views/PhpArgumentValidatorTest.php @@ -27,12 +27,12 @@ class PhpArgumentValidatorTest extends ViewsKernelTestBase { * * @var array */ - public static $modules = ['filter', 'php', 'php_views_test_config']; + protected static $modules = ['filter', 'php', 'php_views_test_config']; /** * {@inheritdoc} */ - protected function setUp($import_test_views = TRUE) { + protected function setUp($import_test_views = TRUE): void { parent::setUp(); if ($import_test_views) { ViewTestData::createTestViews(get_class($this), ['php_views_test_config']); -- GitLab