You are here

protected function CommentFullViewFiltersFieldsTest::setUp in Translation Views 8

Overrides ViewTestBase::setUp

File

tests/src/Functional/CommentFullViewFiltersFieldsTest.php, line 130

Class

CommentFullViewFiltersFieldsTest
Tests for fields, filters and sorting for comment entity.

Namespace

Drupal\Tests\translation_views\Functional

Code

protected function setUp($import_test_views = TRUE) {
  parent::setUp($import_test_views);
  $user = $this
    ->drupalCreateUser([
    'administer content types',
    'edit own comments',
    'administer comments',
    'administer comment types',
    'administer comment fields',
    'administer comment display',
    'post comments',
    'access comments',
    'skip comment approval',
    'access content',
    'administer site configuration',
    'administer nodes',
    'administer views',
    'create article content',
    'edit any article content',
    'administer content translation',
    'translate any entity',
    'create content translations',
    'administer languages',
  ]);
  $this
    ->drupalLogin($user);
  ViewTestData::createTestViews(get_class($this), [
    'translation_views_test_views',
  ]);

  // Add two languages.
  $this
    ->addLanguages([
    'de',
    'fr',
  ]);

  // Enable translation for Comment entity type.
  $this
    ->enableTranslation('comment', 'comment');

  // Add 3 nodes.
  $this
    ->drupalPostForm('node/add/article', [
    'title[0][value]' => 'node 1',
    'created[0][value][date]' => '2018-04-01',
  ], t('Save'));
  $this
    ->drupalPostForm('node/add/article', [
    'title[0][value]' => 'node 2',
    'created[0][value][date]' => '2018-04-02',
  ], t('Save'));
  $this
    ->drupalPostForm('node/add/article', [
    'title[0][value]' => 'node 3',
    'created[0][value][date]' => '2018-04-03',
  ], t('Save'));

  // Add comments and translations.
  // Comment 1.
  $edit = [
    'langcode[0][value]' => 'en',
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 1 en comment',
  ];
  $this
    ->drupalPostForm('node/1', $edit, 'Save');

  // Comment 2.
  $edit = [
    'langcode[0][value]' => 'de',
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 1 de comment',
  ];
  $this
    ->drupalPostForm('node/1', $edit, 'Save');

  // Comment 3.
  $edit = [
    'langcode[0][value]' => 'de',
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 2 de comment',
  ];
  $this
    ->drupalPostForm('node/2', $edit, 'Save');

  // Comment 4.
  $edit = [
    'langcode[0][value]' => 'fr',
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 2 fr comment',
  ];
  $this
    ->drupalPostForm('node/2', $edit, 'Save');

  // Comment 5.
  $edit = [
    'langcode[0][value]' => 'fr',
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 3 fr comment',
  ];
  $this
    ->drupalPostForm('node/3', $edit, 'Save');

  // Comment 6.
  $edit = [
    'content_translation[retranslate]' => 1,
    'comment_body[0][value]' => $this->loremIpsum,
    'subject[0][value]' => 'node 3 en from fr comment',
  ];
  $this
    ->drupalPostForm('comment/5/translations/add/fr/en', $edit, 'Save');
}