You are here

protected function HistoryTest::getNodeReadTimestamps in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/history/src/Tests/HistoryTest.php \Drupal\history\Tests\HistoryTest::getNodeReadTimestamps()

Get node read timestamps 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 HistoryTest::getNodeReadTimestamps()
HistoryTest::testHistory in core/modules/history/src/Tests/HistoryTest.php
Verifies that the history endpoints work.

File

core/modules/history/src/Tests/HistoryTest.php, line 60
Contains \Drupal\history\Tests\HistoryTest.

Class

HistoryTest
Tests the History endpoints.

Namespace

Drupal\history\Tests

Code

protected function getNodeReadTimestamps(array $node_ids) {

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

  // 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('history.get_last_node_view', array(), array(
      'absolute' => TRUE,
    )),
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));
}