You are here

protected function CommentNewIndicatorTest::renderNewCommentsNodeLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/CommentNewIndicatorTest.php \Drupal\comment\Tests\CommentNewIndicatorTest::renderNewCommentsNodeLinks()

Get node "x new comments" metadata from the server for the current user.

Parameters

array $node_ids: An array of node IDs.

Return value

string The response body.

1 call to CommentNewIndicatorTest::renderNewCommentsNodeLinks()
CommentNewIndicatorTest::testCommentNewCommentsIndicator in core/modules/comment/src/Tests/CommentNewIndicatorTest.php
Tests new comment marker.

File

core/modules/comment/src/Tests/CommentNewIndicatorTest.php, line 40
Contains \Drupal\comment\Tests\CommentNewIndicatorTest.

Class

CommentNewIndicatorTest
Tests the 'new' indicator posted on comments.

Namespace

Drupal\comment\Tests

Code

protected function renderNewCommentsNodeLinks(array $node_ids) {

  // Build POST values.
  $post = array();
  for ($i = 0; $i < count($node_ids); $i++) {
    $post['node_ids[' . $i . ']'] = $node_ids[$i];
  }
  $post['field_name'] = 'comment';

  // Serialize POST values.
  foreach ($post as $key => $value) {

    // Encode according to application/x-www-form-urlencoded
    // Both names and values needs to be urlencoded, according to
    // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
    $post[$key] = urlencode($key) . '=' . urlencode($value);
  }
  $post = implode('&', $post);

  // Perform HTTP request.
  return $this
    ->curlExec(array(
    CURLOPT_URL => \Drupal::url('comment.new_comments_node_links', array(), array(
      'absolute' => TRUE,
    )),
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));
}