PhpTestBase.php in PHP 8
File
src/Tests/Functional/PhpTestBase.php
View source
<?php
namespace Drupal\Tests\php\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
abstract class PhpTestBase extends BrowserTestBase {
public static $modules = [
'node',
'php',
];
protected $phpCodeFormat;
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => t('Basic page'),
]);
$admin_user = $this
->drupalCreateUser([
'administer filters',
]);
$this
->drupalLogin($admin_user);
$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.');
$filters = $this->phpCodeFormat
->filters();
$this
->assertTrue($filters
->get('php_code')->status, 'PHP code filter is enabled.');
$this
->drupalGet('admin/config/content/formats');
$this
->assertText('PHP code', 'PHP code text format was created.');
$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.');
}
public function createNodeWithCode() {
return $this
->drupalCreateNode([
'body' => [
[
'value' => '<?php print "SimpleTest PHP was executed!";print "Current state is " . Drupal::state()->get("php_state_test", "empty"); ?>',
],
],
]);
}
}