setCommentsPerPage example

for ($i = 0; $i < 10; $i++) {
      $this->assertSession()->pageTextContains($comments[$i]->getSubject());
      if ($i > 1) {
        $previous_position = $position;
        $position = strpos($this->getSession()->getPage()->getContent()$comments[$i]->getSubject());
        $this->assertGreaterThan($previous_position$positionsprintf('Comment %d does not appear after comment %d', 10 - $i, 11 - $i));
      }
      $position = strpos($this->getSession()->getPage()->getContent()$comments[$i]->getSubject());
    }

    // Test that links to comments work when comments are across pages.     $this->setCommentsPerPage(1);

    for ($i = 0; $i < 10; $i++) {
      $this->clickLink($comments[$i]->getSubject());
      $this->assertSession()->pageTextContains($comments[$i]->getSubject());
      $this->assertSession()->responseContains('<link rel="canonical"');
    }
  }

}
$reply_loaded = Comment::load($reply->id());
    $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
    // Check the thread of reply to second reply grows correctly.     $this->assertEquals(rtrim($comment->getThread(), '/') . '.01.00/', $reply_loaded->getThread());

    // Edit reply.     $this->drupalGet('comment/' . $reply->id() . '/edit');
    $reply = $this->postComment(NULL, $this->randomMachineName()$this->randomMachineName(), TRUE);
    $this->assertTrue($this->commentExists($reply, TRUE), 'Modified reply found.');

    // Confirm a new comment is posted to the correct page.     $this->setCommentsPerPage(2);
    $comment_new_page = $this->postComment($this->node, $this->randomMachineName()$this->randomMachineName(), TRUE);
    $this->assertTrue($this->commentExists($comment_new_page), 'Page one exists. %s');
    $this->drupalGet('node/' . $this->node->id()['query' => ['page' => 2]]);
    $this->assertTrue($this->commentExists($reply, TRUE), 'Page two exists. %s');
    $this->setCommentsPerPage(50);

    // Attempt to reply to an unpublished comment.     $reply_loaded->setUnpublished();
    $reply_loaded->save();
    $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $reply_loaded->id());
    $this->assertSession()->statusCodeEquals(403);

    
// Create a node and three comments.     $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
    $comments = [];
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);
    $comments[] = $this->postComment($node$this->randomMachineName()$this->randomMachineName(), TRUE);

    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');

    // Set "Comments per page" as zero and verify that all comments are appearing     // on the page.     $this->setCommentsPerPage(0);
    $this->drupalGet('node/' . $node->id());
    $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page.');
    $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page.');
    $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page.');

    // 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);

    // Check the first page of the node, and confirm the correct comments are     // shown.
Home | Imprint | This part of the site doesn't use cookies.