Skip to content
Snippets Groups Projects
Commit df05bd62 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3363035 by fenstrat, webdrips, DudeWeb, apaderno, fgm, loze: Drupal 10 Support

parent ee469ef5
Branches
Tags
No related merge requests found
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:
......
......@@ -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');
......
......@@ -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() . '">');
}
}
......@@ -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');
}
}
......@@ -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);
}
/**
......
......@@ -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.'));
}
}
......@@ -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']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment