diff --git a/core/modules/comment/config/views.view.comments_recent.yml b/core/modules/comment/config/views.view.comments_recent.yml index 52e939b..7650bf4 100644 --- a/core/modules/comment/config/views.view.comments_recent.yml +++ b/core/modules/comment/config/views.view.comments_recent.yml @@ -184,6 +184,18 @@ display: operator: false group: 1 sorts: + created: + id: created + table: comment + field: created + relationship: none + group_type: group + admin_label: '' + order: DESC + exposed: false + expose: + label: '' + plugin_id: date cid: id: cid table: comment @@ -195,7 +207,7 @@ display: exposed: false expose: label: '' - plugin_id: date + plugin_id: standard title: 'Recent comments' empty: area_text_custom: diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php index c60e153..9fa5ea8 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\comment\Tests; +use Drupal\Component\Utility\String; /** * Tests the Comment module blocks. @@ -51,9 +52,12 @@ function testRecentCommentBlock() { // Add some test comments, with and without subjects. Because the 10 newest // comments should be shown by the block, we create 11 to test that behavior // below. + $timestamp = REQUEST_TIME; for ($i = 0; $i < 11; ++$i) { $subject = ($i % 2) ? $this->randomName() : ''; $comments[$i] = $this->postComment($this->node, $this->randomName(), $subject); + $comments[$i]->created->value = $timestamp--; + $comments[$i]->save(); } // Test that a user without the 'access comments' permission cannot see the @@ -74,13 +78,13 @@ function testRecentCommentBlock() { $this->assertText(t('Recent comments')); // Test the only the 10 latest comments are shown and in the proper order. - $this->assertNoText($comments[0]->subject->value, 'Comment 11 not found in block.'); - for ($i = 1; $i < 11; $i++) { - $this->assertText($comments[$i]->subject->value, format_string('Comment @number found in block.', array('@number' => 11 - $i))); + $this->assertNoText($comments[10]->subject->value, 'Comment 11 not found in block.'); + for ($i = 0; $i < 10; $i++) { + $this->assertText($comments[$i]->subject->value, String::format('Comment @number found in block.', array('@number' => 10 - $i))); if ($i > 1) { $previous_position = $position; $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); - $this->assertTrue($position < $previous_position, format_string('Comment @a appears before comment @b', array('@a' => 11 - $i, '@b' => 12 - $i))); + $this->assertTrue($position > $previous_position, String::format('Comment @a appears after comment @b', array('@a' => 10 - $i, '@b' => 11 - $i))); } $position = strpos($this->drupalGetContent(), $comments[$i]->subject->value); } @@ -88,7 +92,7 @@ function testRecentCommentBlock() { // Test that links to comments work when comments are across pages. $this->setCommentsPerPage(1); - for ($i = 1; $i < 11; $i++) { + for ($i = 0; $i < 10; $i++) { $this->clickLink($comments[$i]->subject->value); $this->assertText($comments[$i]->subject->value, 'Comment link goes to correct page.'); $this->assertRaw('