diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php index aa876f5ef6..5db67e8626 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php @@ -72,7 +72,7 @@ protected function setUp($import_test_views = TRUE) { // Created admin role. $admin_role = Role::create([ 'id' => 'admin', - 'permissions' => ['administer comments'], + 'permissions' => ['administer comments', 'skip comment approval'], ]); $admin_role->save(); // Create the admin user. @@ -94,22 +94,19 @@ protected function setUp($import_test_views = TRUE) { $entity->save(); // Create some comments. - $comment_data = [ + $comment = Comment::create([ 'subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'entity_type' => 'entity_test', 'comment_type' => 'comment', 'status' => 1, 'entity_id' => $entity->id(), - ]; - $comment = Comment::create($comment_data); + ]); $comment->save(); - $comment_data['subject'] = 'My comment ur title'; - $comment_translation = $comment->addTranslation('ur', $comment_data); - $comment_translation->save(); + $this->comments[] = $comment; - $comment_anonymous_data = [ + $comment_anonymous = Comment::create([ 'subject' => 'Anonymous comment title', 'uid' => 0, 'name' => 'barry', @@ -120,12 +117,8 @@ protected function setUp($import_test_views = TRUE) { 'created' => 123456, 'status' => 1, 'entity_id' => $entity->id(), - ]; - $comment_anonymous = Comment::create($comment_anonymous_data); + ]); $comment_anonymous->save(); - $comment_anonymous_data['subject'] = 'Anonymous comment ur title'; - $comment_anonymous_translation = $comment_anonymous->addTranslation('ur', $comment_anonymous_data); - $comment_anonymous_translation->save(); $this->comments[] = $comment_anonymous; } @@ -138,9 +131,6 @@ public function testFilters() { foreach ($this->comments as $comment) { $comment->setUnpublished(); $comment->save(); - $comment_translation = $comment->getTranslation('ur'); - $comment_translation->setUnpublished(); - $comment_translation->save(); } $this->doTestFilters('page_unapproved'); } @@ -172,7 +162,7 @@ protected function doTestFilters($display_id) { $this->assertField('langcode'); $elements = $this->cssSelect('input[type="checkbox"]'); - $this->assertEquals(4, count($elements), 'There are four comments on the page.'); + $this->assertEquals(2, count($elements), 'There are two comments on the page.'); $this->assertText($comment->label()); $this->assertText($comment_anonymous->label()); $executable->destroy(); @@ -184,7 +174,7 @@ protected function doTestFilters($display_id) { $this->verbose($this->getRawContent()); $elements = $this->cssSelect('input[type="checkbox"]'); - $this->assertEquals(2, count($elements), 'Only anonymous comments are visible.'); + $this->assertEquals(1, count($elements), 'Only anonymous comment is visible.'); $this->assertNoText($comment->label()); $this->assertText($comment_anonymous->label()); $executable->destroy(); @@ -195,7 +185,7 @@ protected function doTestFilters($display_id) { $this->verbose($this->getRawContent()); $elements = $this->cssSelect('input[type="checkbox"]'); - $this->assertEquals(2, count($elements), 'Only admin comments are visible.'); + $this->assertEquals(1, count($elements), 'Only admin comment is visible.'); $this->assertText($comment->label()); $this->assertNoText($comment_anonymous->label()); $executable->destroy(); @@ -207,7 +197,7 @@ protected function doTestFilters($display_id) { $this->verbose($this->getRawContent()); $elements = $this->cssSelect('input[type="checkbox"]'); - $this->assertEquals(2, count($elements), 'Only anonymous comments are visible.'); + $this->assertEquals(1, count($elements), 'Only anonymous comment is visible.'); $this->assertNoText($comment->label()); $this->assertText($comment_anonymous->label()); $executable->destroy(); @@ -219,7 +209,7 @@ protected function doTestFilters($display_id) { $this->verbose($this->getRawContent()); $elements = $this->cssSelect('input[type="checkbox"]'); - $this->assertEquals(2, count($elements), 'Only admin comments are visible.'); + $this->assertEquals(1, count($elements), 'Only admin comment is visible.'); $this->assertText($comment->label()); $this->assertNoText($comment_anonymous->label()); $executable->destroy(); @@ -237,6 +227,29 @@ protected function doTestFilters($display_id) { $executable->destroy(); // Tests comment translation filter. + if (!$comment->hasTranslation('ur')) { + // If we don't have the translation then create one. + $comment_translation = $comment->addTranslation('ur', ['subject' => 'ur title']); + $comment_translation->save(); + } + else { + // If we have the translation then unpublish it. + $comment_translation = $comment->getTranslation('ur'); + $comment_translation->setUnpublished(); + $comment_translation->save(); + } + if (!$comment_anonymous->hasTranslation('ur')) { + // If we don't have the translation then create one. + $comment_anonymous_translation = $comment_anonymous->addTranslation('ur', ['subject' => 'ur Anonymous title']); + $comment_anonymous_translation->save(); + } + else { + // If we have the translation then unpublish it. + $comment_anonymous_translation = $comment_anonymous->getTranslation('ur'); + $comment_anonymous_translation->setUnpublished(); + $comment_anonymous_translation->save(); + } + $executable->setExposedInput(['langcode' => 'ur']); $build = $executable->preview($display_id); $this->setRawContent($renderer->renderRoot($build)); @@ -246,8 +259,8 @@ protected function doTestFilters($display_id) { $this->assertEquals(2, count($elements), 'Both comments are visible.'); $this->assertNoText($comment->label()); $this->assertNoText($comment_anonymous->label()); - $this->assertText($comment->getTranslation('ur')->label()); - $this->assertText($comment_anonymous->getTranslation('ur')->label()); + $this->assertText($comment_translation->label()); + $this->assertText($comment_anonymous_translation->label()); $executable->destroy(); }