function FilterFormatAccessTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php \Drupal\Tests\filter\Functional\FilterFormatAccessTest::setUp()
  2. 8.9.x core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php \Drupal\Tests\filter\Functional\FilterFormatAccessTest::setUp()
  3. 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 76

Class

FilterFormatAccessTest
Tests access to text formats.

Namespace

Drupal\Tests\filter\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $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.
  $formats = [];
  for ($i = 0; $i < 3; $i++) {
    $format = FilterFormat::create([
      'format' => $this->randomMachineName(),
      'name' => $this->randomMachineName(),
    ]);
    $format->save();
    $formats[] = $format;
  }
  [
    $this->allowedFormat,
    $this->secondAllowedFormat,
    $this->disallowedFormat,
  ] = $formats;
  // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.