protected function PhpTestBase::setUp in PHP 8
Overrides BrowserTestBase::setUp
File
- src/
Tests/ Functional/ PhpTestBase.php, line 27
Class
- PhpTestBase
- Test if PHP filter works in general.
Namespace
Drupal\Tests\php\FunctionalCode
protected function setUp() {
parent::setUp();
// Create Basic page node type.
$this
->drupalCreateContentType([
'type' => 'page',
'name' => t('Basic page'),
]);
// Create and login admin user.
$admin_user = $this
->drupalCreateUser([
'administer filters',
]);
$this
->drupalLogin($admin_user);
// Verify that the PHP code text format was inserted.
$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.');
// Verify that the format has the PHP code filter enabled.
$filters = $this->phpCodeFormat
->filters();
$this
->assertTrue($filters
->get('php_code')->status, 'PHP code filter is enabled.');
// 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.');
// 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.');
}