You are here

protected function FilterAdminTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/tests/src/Functional/FilterAdminTest.php \Drupal\Tests\filter\Functional\FilterAdminTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/filter/tests/src/Functional/FilterAdminTest.php, line 54

Class

FilterAdminTest
Thoroughly test the administrative interface of the filter module.

Namespace

Drupal\Tests\filter\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'page',
    'name' => 'Basic page',
  ]);

  // Set up the filter formats used by this test.
  $basic_html_format = FilterFormat::create([
    'format' => 'basic_html',
    'name' => 'Basic HTML',
    'filters' => [
      'filter_html' => [
        'status' => 1,
        'settings' => [
          'allowed_html' => '<p> <br> <strong> <a> <em>',
        ],
      ],
    ],
  ]);
  $basic_html_format
    ->save();
  $restricted_html_format = FilterFormat::create([
    'format' => 'restricted_html',
    'name' => 'Restricted HTML',
    'filters' => [
      'filter_html' => [
        'status' => TRUE,
        'weight' => -10,
        'settings' => [
          'allowed_html' => '<p> <br> <strong> <a> <em> <h4>',
        ],
      ],
      'filter_autop' => [
        'status' => TRUE,
        'weight' => 0,
      ],
      'filter_url' => [
        'status' => TRUE,
        'weight' => 0,
      ],
      'filter_htmlcorrector' => [
        'status' => TRUE,
        'weight' => 10,
      ],
    ],
  ]);
  $restricted_html_format
    ->save();
  $full_html_format = FilterFormat::create([
    'format' => 'full_html',
    'name' => 'Full HTML',
    'weight' => 1,
    'filters' => [],
  ]);
  $full_html_format
    ->save();
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer filters',
    $basic_html_format
      ->getPermissionName(),
    $restricted_html_format
      ->getPermissionName(),
    $full_html_format
      ->getPermissionName(),
    'access site reports',
  ]);
  $this->webUser = $this
    ->drupalCreateUser([
    'create page content',
    'edit own page content',
  ]);
  user_role_grant_permissions('authenticated', [
    $basic_html_format
      ->getPermissionName(),
  ]);
  user_role_grant_permissions('anonymous', [
    $restricted_html_format
      ->getPermissionName(),
  ]);
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalPlaceBlock('local_actions_block');
}