function CommentAdminTest::testCommentedTranslationDeletion
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testCommentedTranslationDeletion()
- 8.9.x core/modules/comment/tests/src/Functional/CommentAdminTest.php \Drupal\Tests\comment\Functional\CommentAdminTest::testCommentedTranslationDeletion()
- 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 247
Class
- CommentAdminTest
- Tests comment approval functionality.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentedTranslationDeletion() : void {
\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(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
$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.