function EntityFilteringThemeTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/EntityFilteringThemeTest.php \Drupal\Tests\system\Functional\Theme\EntityFilteringThemeTest::setUp()
  2. 10 core/modules/system/tests/src/Functional/Theme/EntityFilteringThemeTest.php \Drupal\Tests\system\Functional\Theme\EntityFilteringThemeTest::setUp()
  3. 11.x core/modules/system/tests/src/Functional/Theme/EntityFilteringThemeTest.php \Drupal\Tests\system\Functional\Theme\EntityFilteringThemeTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/system/tests/src/Functional/Theme/EntityFilteringThemeTest.php, line 84

Class

EntityFilteringThemeTest
Tests themed output for each entity type in all available themes to ensure entity labels are filtered for XSS.

Namespace

Drupal\Tests\system\Functional\Theme

Code

protected function setUp() {
    parent::setUp();
    // Install all available non-testing themes.
    $listing = new ExtensionDiscovery(\Drupal::root());
    $this->themes = $listing->scan('theme', FALSE);
    \Drupal::service('theme_installer')->install(array_keys($this->themes));
    // Create a test user.
    $this->user = $this->drupalCreateUser([
        'access content',
        'access user profiles',
    ]);
    $this->user->name = $this->xssLabel;
    $this->user
        ->save();
    $this->drupalLogin($this->user);
    // Create a test term.
    $this->term = Term::create([
        'name' => $this->xssLabel,
        'vid' => 1,
    ]);
    $this->term
        ->save();
    // Add a comment field.
    $this->addDefaultCommentField('node', 'article', 'comment', CommentItemInterface::OPEN);
    // Create a test node tagged with the test term.
    $this->node = $this->drupalCreateNode([
        'title' => $this->xssLabel,
        'type' => 'article',
        'promote' => NodeInterface::PROMOTED,
        'field_tags' => [
            [
                'target_id' => $this->term
                    ->id(),
            ],
        ],
    ]);
    // Create a test comment on the test node.
    $this->comment = Comment::create([
        'entity_id' => $this->node
            ->id(),
        'entity_type' => 'node',
        'field_name' => 'comment',
        'status' => CommentInterface::PUBLISHED,
        'subject' => $this->xssLabel,
        'comment_body' => [
            $this->randomMachineName(),
        ],
    ]);
    $this->comment
        ->save();
}

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