function CommentAdminTest::testCommentedTranslationDeletion

Same name in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testCommentedTranslationDeletion()
  2. 10 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testCommentedTranslationDeletion()
  3. 11.x core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testCommentedTranslationDeletion()

Tests commented translation deletion admin view.

File

core/modules/comment/tests/src/Functional/CommentAdminTest.php, line 245

Class

CommentAdminTest
Tests comment approval functionality.

Namespace

Drupal\Tests\comment\Functional

Code

public function testCommentedTranslationDeletion() {
    \Drupal::service('module_installer')->install([
        'language',
        'locale',
    ]);
    \Drupal::service('router.builder')->rebuildIfNeeded();
    ConfigurableLanguage::createFromLangcode('ur')->save();
    // Rebuild the container to update the default language container variable.
    $this->rebuildContainer();
    // Ensure that doesn't require contact info.
    $this->setCommentAnonymous('0');
    $this->drupalLogin($this->webUser);
    $count_query = \Drupal::entityTypeManager()->getStorage('comment')
        ->getQuery()
        ->count();
    $before_count = $count_query->execute();
    // Post 2 anonymous comments without contact info.
    $comment1 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
    $comment2 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
    $comment1->addTranslation('ur', [
        'subject' => 'ur ' . $comment1->label(),
    ])
        ->save();
    $comment2->addTranslation('ur', [
        'subject' => 'ur ' . $comment1->label(),
    ])
        ->save();
    $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    // Delete multiple comments in one operation.
    $edit = [
        'operation' => 'delete',
        "comments[{$comment1->id()}]" => 1,
        "comments[{$comment2->id()}]" => 1,
    ];
    $this->drupalPostForm('admin/content/comment', $edit, t('Update'));
    $this->assertRaw(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', [
        '@label' => $comment1->label(),
    ]));
    $this->assertRaw(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', [
        '@label' => $comment2->label(),
    ]));
    $this->assertText('English');
    $this->assertText('Urdu');
    $this->drupalPostForm(NULL, [], t('Delete'));
    $after_count = $count_query->execute();
    $this->assertEqual($after_count, $before_count, 'No comment or translation found.');
}

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