You are here

protected function FilterFormatAccessTest::setUp in Drupal 9

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

Overrides BrowserTestBase::setUp

File

core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php, line 71

Class

FilterFormatAccessTest
Tests access to text formats.

Namespace

Drupal\Tests\filter\Functional

Code

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

  // Create a user who can administer text formats, but does not have
  // specific permission to use any of them.
  $this->filterAdminUser = $this
    ->drupalCreateUser([
    'administer filters',
    'create page content',
    'edit any page content',
  ]);

  // Create three text formats. Two text formats are created for all users so
  // that the drop-down list appears for all tests.
  $this
    ->drupalLogin($this->filterAdminUser);
  $formats = [];
  for ($i = 0; $i < 3; $i++) {
    $edit = [
      'format' => mb_strtolower($this
        ->randomMachineName()),
      'name' => $this
        ->randomMachineName(),
    ];
    $this
      ->drupalGet('admin/config/content/formats/add');
    $this
      ->submitForm($edit, 'Save configuration');
    $this
      ->resetFilterCaches();
    $formats[] = FilterFormat::load($edit['format']);
  }
  list($this->allowedFormat, $this->secondAllowedFormat, $this->disallowedFormat) = $formats;
  $this
    ->drupalLogout();

  // Create a regular user with access to two of the formats.
  $this->webUser = $this
    ->drupalCreateUser([
    'create page content',
    'edit any page content',
    $this->allowedFormat
      ->getPermissionName(),
    $this->secondAllowedFormat
      ->getPermissionName(),
  ]);

  // Create an administrative user who has access to use all three formats.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer filters',
    'create page content',
    'edit any page content',
    $this->allowedFormat
      ->getPermissionName(),
    $this->secondAllowedFormat
      ->getPermissionName(),
    $this->disallowedFormat
      ->getPermissionName(),
  ]);
  $this
    ->drupalPlaceBlock('local_tasks_block');
}