You are here

protected function EntityFilteringThemeTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php \Drupal\system\Tests\Theme\EntityFilteringThemeTest::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/system/src/Tests/Theme/EntityFilteringThemeTest.php, line 81
Contains \Drupal\system\Tests\Theme\EntityFilteringThemeTest.

Class

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

Namespace

Drupal\system\Tests\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_handler')
    ->install(array_keys($this->themes));

  // Create a test user.
  $this->user = $this
    ->drupalCreateUser(array(
    'access content',
    'access user profiles',
  ));
  $this->user->name = $this->xssLabel;
  $this->user
    ->save();
  $this
    ->drupalLogin($this->user);

  // Create a test term.
  $this->term = entity_create('taxonomy_term', array(
    '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(array(
    'title' => $this->xssLabel,
    'type' => 'article',
    'promote' => NODE_PROMOTED,
    'field_tags' => array(
      array(
        'target_id' => $this->term
          ->id(),
      ),
    ),
  ));

  // Create a test comment on the test node.
  $this->comment = entity_create('comment', array(
    'entity_id' => $this->node
      ->id(),
    'entity_type' => 'node',
    'field_name' => 'comment',
    'status' => CommentInterface::PUBLISHED,
    'subject' => $this->xssLabel,
    'comment_body' => array(
      $this
        ->randomMachineName(),
    ),
  ));
  $this->comment
    ->save();
}