function TextFormatElementFormTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php \Drupal\Tests\filter\Kernel\TextFormatElementFormTest::setUp()
  2. 8.9.x core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php \Drupal\Tests\filter\Kernel\TextFormatElementFormTest::setUp()
  3. 10 core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php \Drupal\Tests\filter\Kernel\TextFormatElementFormTest::setUp()

Sets up the test.

Overrides KernelTestBase::setUp

File

core/modules/filter/tests/src/Kernel/TextFormatElementFormTest.php, line 42

Class

TextFormatElementFormTest
Tests PathElement validation and conversion functionality.

Namespace

Drupal\Tests\filter\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this->installEntitySchema('user');
  $this->installConfig([
    'filter',
    'filter_test',
  ]);
  // Create user 1 so that the user created later in the test has a different
  // user ID.
  // @todo Remove in https://www.drupal.org/node/540008.
  User::create([
    'uid' => 1,
    'name' => 'user1',
  ])->save();
  /** @var \Drupal\Core\Render\ElementInfoManager $manager */
  $manager = \Drupal::service('plugin.manager.element_info');
  $manager->clearCachedDefinitions();
  $manager->getDefinitions();
  /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
  $filter_test_format = FilterFormat::load('filter_test');
  $full_html_format = FilterFormat::load('full_html');
  $filtered_html_format = FilterFormat::load('filtered_html');
  /** @var \Drupal\user\RoleInterface $role */
  $role = Role::create([
    'id' => 'admin',
    'label' => 'admin',
  ]);
  $role->grantPermission($filter_test_format->getPermissionName());
  $role->grantPermission($full_html_format->getPermissionName());
  $role->grantPermission($filtered_html_format->getPermissionName());
  $role->save();
  $this->testUser = User::create([
    'name' => 'foobar',
    'mail' => 'foobar@example.com',
  ]);
  $this->testUser
    ->addRole($role->id())
    ->save();
  \Drupal::service('current_user')->setAccount($this->testUser);
}

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