PhpFilterTest.php in PHP 8
File
src/Tests/Functional/PhpFilterTest.php
View source
<?php
namespace Drupal\Tests\php\Functional;
class PhpFilterTest extends PhpTestBase {
public function testPhpFilter() {
$php_code_permission = \Drupal::service('entity_type.manager')
->getStorage('filter_format')
->load('php_code')
->getPermissionName();
$permissions = [
'access content',
'create page content',
'edit own page content',
$php_code_permission,
];
$web_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($web_user);
$node = $this
->createNodeWithCode();
$this
->drupalGet('node/' . $node
->id());
$this
->assertText('php print');
$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
->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed.");
$this
->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.');
$this
->assertText('Current state is empty', 'PHP code has been evaluated once.');
\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.');
}
}
Classes
Name |
Description |
PhpFilterTest |
Tests to make sure the PHP filter actually evaluates PHP code when used. |