diff --git a/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php b/core/modules/contextual/tests/src/Functional/ContextualDynamicContextTest.php similarity index 81% rename from core/modules/contextual/src/Tests/ContextualDynamicContextTest.php rename to core/modules/contextual/tests/src/Functional/ContextualDynamicContextTest.php index 00ade5a5ac9f7f666bd28efe237a0891ec97bcb7..340b60821fb0da11c9398f0460d33229106a8d91 100644 --- a/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php +++ b/core/modules/contextual/tests/src/Functional/ContextualDynamicContextTest.php @@ -1,12 +1,12 @@ assertContextualLinkPlaceHolder($ids[$i]); } - $this->renderContextualLinks([], 'node'); - $this->assertResponse(400); - $this->assertRaw('No contextual ids specified.'); + $response = $this->renderContextualLinks([], 'node'); + $this->assertSame(400, $response->getStatusCode()); + $this->assertContains('No contextual ids specified.', (string) $response->getBody()); $response = $this->renderContextualLinks($ids, 'node'); - $this->assertResponse(200); - $json = Json::decode($response); + $this->assertSame(200, $response->getStatusCode()); + $json = Json::decode((string) $response->getBody()); $this->assertIdentical($json[$ids[0]], ''); $this->assertIdentical($json[$ids[1]], ''); $this->assertIdentical($json[$ids[2]], ''); @@ -112,12 +112,12 @@ public function testDifferentPermissions() { for ($i = 0; $i < count($ids); $i++) { $this->assertContextualLinkPlaceHolder($ids[$i]); } - $this->renderContextualLinks([], 'node'); - $this->assertResponse(400); - $this->assertRaw('No contextual ids specified.'); + $response = $this->renderContextualLinks([], 'node'); + $this->assertSame(400, $response->getStatusCode()); + $this->assertContains('No contextual ids specified.', (string) $response->getBody()); $response = $this->renderContextualLinks($ids, 'node'); - $this->assertResponse(200); - $json = Json::decode($response); + $this->assertSame(200, $response->getStatusCode()); + $json = Json::decode((string) $response->getBody()); $this->assertIdentical($json[$ids[0]], ''); $this->assertIdentical($json[$ids[1]], ''); $this->assertIdentical($json[$ids[2]], ''); @@ -129,10 +129,10 @@ public function testDifferentPermissions() { for ($i = 0; $i < count($ids); $i++) { $this->assertNoContextualLinkPlaceHolder($ids[$i]); } - $this->renderContextualLinks([], 'node'); - $this->assertResponse(403); + $response = $this->renderContextualLinks([], 'node'); + $this->assertSame(403, $response->getStatusCode()); $this->renderContextualLinks($ids, 'node'); - $this->assertResponse(403); + $this->assertSame(403, $response->getStatusCode()); // Get a page where contextual links are directly rendered. $this->drupalGet(Url::fromRoute('menu_test.contextual_test')); @@ -174,15 +174,23 @@ protected function assertNoContextualLinkPlaceHolder($id) { * @param string $current_path * The Drupal path for the page for which the contextual links are rendered. * - * @return string - * The response body. + * @return \Psr\Http\Message\ResponseInterface + * The response object. */ protected function renderContextualLinks($ids, $current_path) { - $post = []; - for ($i = 0; $i < count($ids); $i++) { - $post['ids[' . $i . ']'] = $ids[$i]; - } - return $this->drupalPostWithFormat('contextual/render', 'json', $post, ['query' => ['destination' => $current_path]]); + $http_client = $this->getHttpClient(); + $url = Url::fromRoute('contextual.render', [], [ + 'query' => [ + '_format' => 'json', + 'destination' => $current_path, + ], + ]); + + return $http_client->request('POST', $this->buildUrl($url), [ + 'cookies' => $this->getSessionCookies(), + 'form_params' => ['ids' => $ids], + 'http_errors' => FALSE, + ]); } }