You are here

function CommentFieldFilterTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php \Drupal\comment\Tests\Views\CommentFieldFilterTest::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 CommentTestBase::setUp

File

core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php, line 38
Contains \Drupal\comment\Tests\Views\CommentFieldFilterTest.

Class

CommentFieldFilterTest
Tests comment field filters with translations.

Namespace

Drupal\comment\Tests\Views

Code

function setUp() {
  parent::setUp();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access comments',
  ]));

  // Add two new languages.
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();
  ConfigurableLanguage::createFromLangcode('es')
    ->save();

  // Set up comment titles.
  $this->commentTitles = array(
    'en' => 'Food in Paris',
    'es' => 'Comida en Paris',
    'fr' => 'Nouriture en Paris',
  );

  // Create a new comment. Using the one created earlier will not work,
  // as it predates the language set-up.
  $comment = array(
    'uid' => $this->loggedInUser
      ->id(),
    'entity_id' => $this->nodeUserCommented
      ->id(),
    'entity_type' => 'node',
    'field_name' => 'comment',
    'cid' => '',
    'pid' => '',
    'node_type' => '',
  );
  $this->comment = entity_create('comment', $comment);

  // Add field values and translate the comment.
  $this->comment->subject->value = $this->commentTitles['en'];
  $this->comment->comment_body->value = $this->commentTitles['en'];
  $this->comment->langcode = 'en';
  $this->comment
    ->save();
  foreach (array(
    'es',
    'fr',
  ) as $langcode) {
    $translation = $this->comment
      ->addTranslation($langcode, array());
    $translation->comment_body->value = $this->commentTitles[$langcode];
    $translation->subject->value = $this->commentTitles[$langcode];
  }
  $this->comment
    ->save();
}