Commit 35778ab2 authored by catch's avatar catch

Issue #2730973 by Wim Leers, larowlan, JonasRMuc, andypost: Comment permalinks...

Issue #2730973 by Wim Leers, larowlan, JonasRMuc, andypost: Comment permalinks are cached incorrectly when multiple pages exist
parent 85aea4e6
......@@ -79,8 +79,7 @@ public static function create(ContainerInterface $container) {
* @param \Drupal\comment\CommentInterface $comment
* A comment entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
* Redirects to the permalink URL for this comment.
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function commentApprove(CommentInterface $comment) {
$comment->setPublished(TRUE);
......@@ -125,9 +124,8 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
// Find the current display page for this comment.
$page = $this->entityManager()->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
// @todo: Cleaner sub request handling.
$subrequest_url = $entity->urlInfo()->toString(TRUE);
$subrequest_url = $entity->urlInfo()->setOption('query', ['page' => $page])->toString(TRUE);
$redirect_request = Request::create($subrequest_url->getGeneratedUrl(), 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$redirect_request->query->set('page', $page);
// Carry over the session to the subrequest.
if ($session = $request->getSession()) {
$redirect_request->setSession($session);
......
......@@ -90,6 +90,38 @@ function testCommentPaging() {
$this->drupalLogout();
}
/**
* Confirms comment paging works correctly with flat and threaded comments.
*/
function testCommentPermalink() {
$this->drupalLogin($this->adminUser);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentPreview(DRUPAL_DISABLED);
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
$comments[] = $this->postComment($node, 'comment 1: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 2: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 3: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
$this->setCommentsPerPage(1);
// Navigate to each comment permalink as anonymous and assert it appears on
// the page.
foreach ($comments as $index => $comment) {
$this->drupalGet($comment->toUrl());
$this->assertTrue($this->commentExists($comment), sprintf('Comment %d appears on page %d.', $index + 1, $index + 1));
}
}
/**
* Tests comment ordering and threading.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment