diff --git a/core/modules/node/lib/Drupal/node/Tests/Views/NodeContextualLinksTest.php b/core/modules/node/lib/Drupal/node/Tests/Views/NodeContextualLinksTest.php index 8589bf7..50964ee 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Views/NodeContextualLinksTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Views/NodeContextualLinksTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests\Views; +use Drupal\Component\Utility\Json; use Symfony\Component\HttpFoundation\Request; /** @@ -46,13 +47,55 @@ public function testNodeContextualLinks() { $user = $this->drupalCreateUser(array('administer nodes', 'access contextual links')); $this->drupalLogin($user); - $data = $this->drupalPostAJAX('contextual/render', array('ids' => array('node:node:1:')), NULL, NULL, array(), array(), NULL, array()); - - $this->drupalSetContent($data->{'node:node:1:'}); + $response = $this->renderContextualLinks(array('node:node:1:'), 'node'); + $this->assertResponse(200); + $json = Json::decode($response); + $this->drupalSetContent($json['node:node:1:']); $result = $this->xpath("//a[contains(@href, 'node/1/contextual-links')]"); $this->assertEqual(count($result), 1, 'One contextual link found.'); $this->assertEqual((string) $result[0], 'Test contextual link', 'Ensure the right link text was returned'); } + /** + * Get server-rendered contextual links for the given contextual link ids. + * + * Copied from \Drupal\contextual\Tests\ContextualDynamicContextTest::renderContextualLinks(). + * + * @param array $ids + * An array of contextual link ids. + * @param string $current_path + * The Drupal path for the page for which the contextual links are rendered. + * + * @return string + * The response body. + */ + 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', + ), + )); + } + }