You are here

protected function FilterFormatAccessTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/filter/src/Tests/FilterFormatAccessTest.php \Drupal\filter\Tests\FilterFormatAccessTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides WebTestBase::setUp

File

core/modules/filter/src/Tests/FilterFormatAccessTest.php, line 71
Contains \Drupal\filter\Tests\FilterFormatAccessTest.

Class

FilterFormatAccessTest
Tests access to text formats.

Namespace

Drupal\filter\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('page_title_block');
  $this
    ->drupalCreateContentType(array(
    '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(array(
    '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 = array();
  for ($i = 0; $i < 3; $i++) {
    $edit = array(
      'format' => Unicode::strtolower($this
        ->randomMachineName()),
      'name' => $this
        ->randomMachineName(),
    );
    $this
      ->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
    $this
      ->resetFilterCaches();
    $formats[] = entity_load('filter_format', $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(array(
    '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(array(
    'administer filters',
    'create page content',
    'edit any page content',
    $this->allowedFormat
      ->getPermissionName(),
    $this->secondAllowedFormat
      ->getPermissionName(),
    $this->disallowedFormat
      ->getPermissionName(),
  ));
  $this
    ->drupalPlaceBlock('local_tasks_block');
}