function CommentAdminTest::testCommentedTranslationDeletion

Same name in other branches
  1. 8.9.x 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 248

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()
        ->accessCheck(FALSE)
        ->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->drupalGet('admin/content/comment');
    $this->submitForm($edit, 'Update');
    $this->assertSession()
        ->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', [
        '@label' => $comment1->label(),
    ]));
    $this->assertSession()
        ->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', [
        '@label' => $comment2->label(),
    ]));
    $this->assertSession()
        ->pageTextContains('English');
    $this->assertSession()
        ->pageTextContains('Urdu');
    $this->submitForm([], 'Delete');
    $after_count = $count_query->execute();
    $this->assertEquals($before_count, $after_count, 'No comment or translation found.');
}

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