You are here

protected function NodeContextualLinksTest::renderContextualLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/Views/NodeContextualLinksTest.php \Drupal\node\Tests\Views\NodeContextualLinksTest::renderContextualLinks()

Get server-rendered contextual links for the given contextual link ids.

Copied from \Drupal\contextual\Tests\ContextualDynamicContextTest::renderContextualLinks().

Parameters

array $ids: An array of contextual link ids.

string $current_path: The Drupal path for the page for which the contextual links are rendered.

Return value

string The response body.

1 call to NodeContextualLinksTest::renderContextualLinks()
NodeContextualLinksTest::testNodeContextualLinks in core/modules/node/src/Tests/Views/NodeContextualLinksTest.php
Tests contextual links.

File

core/modules/node/src/Tests/Views/NodeContextualLinksTest.php, line 69
Contains \Drupal\node\Tests\Views\NodeContextualLinksTest.

Class

NodeContextualLinksTest
Tests views contextual links on nodes.

Namespace

Drupal\node\Tests\Views

Code

protected function renderContextualLinks($ids, $current_path) {

  // Build POST values.
  $post = array();
  for ($i = 0; $i < count($ids); $i++) {
    $post['ids[' . $i . ']'] = $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('contextual.render', [], [
      'absolute' => TRUE,
      'query' => array(
        'destination' => $current_path,
      ),
    ]),
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_HTTPHEADER => array(
      'Accept: application/json',
      'Content-Type: application/x-www-form-urlencoded',
    ),
  ));
}