protected function ContextualDynamicContextTest::renderContextualLinks

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

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 ContextualDynamicContextTest::renderContextualLinks()
ContextualDynamicContextTest::testDifferentPermissions in drupal/core/modules/contextual/lib/Drupal/contextual/Tests/ContextualDynamicContextTest.php
Tests contextual links with different permissions.

File

drupal/core/modules/contextual/lib/Drupal/contextual/Tests/ContextualDynamicContextTest.php, line 149
Contains \Drupal\contextual\Tests\ContextualDynamicContextTest.

Class

ContextualDynamicContextTest
Tests accessible links after inaccessible links on dynamic context.

Namespace

Drupal\contextual\Tests

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 => url('contextual/render', array(
      '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',
    ),
  ));
}