diff --git a/core/modules/image/tests/src/Functional/QuickEditImageControllerTest.php b/core/modules/image/tests/src/Functional/QuickEditImageControllerTest.php index c598b0e293..b3ed60c3c1 100644 --- a/core/modules/image/tests/src/Functional/QuickEditImageControllerTest.php +++ b/core/modules/image/tests/src/Functional/QuickEditImageControllerTest.php @@ -128,11 +128,8 @@ public function testValidImageUpload() { $this->assertTrue($valid_image); $this->drupalLogin($this->contentAuthorUser); - $response = $this->uploadImage($valid_image, $node->id(), $this->fieldName, $node->language()->getId()); - - $this->assertEqual($response->getStatusCode(), 200); - $this->assertEqual($response->getReasonPhrase(), 'OK'); - $this->assertContains('"fid":"1"', $response->getBody()->getContents(), t('Valid upload completed successfully.')); + $this->uploadImage($valid_image, $node->id(), $this->fieldName, $node->language()->getId()); + $this->assertContains('"fid":"1"', $this->getSession()->getPage()->getContent(), 'Valid upload completed successfully.'); } /** @@ -160,11 +157,8 @@ public function testInvalidUpload() { $this->assertTrue($invalid_image); $this->drupalLogin($this->contentAuthorUser); - $response = $this->uploadImage($invalid_image, $node->id(), $this->fieldName, $node->language()->getId()); - - $this->assertEqual($response->getStatusCode(), 200); - $this->assertEqual($response->getReasonPhrase(), 'OK'); - $this->assertContains('"main_error":"The image failed validation."', $response->getBody()->getContents(), t('Invalid upload returned errors.')); + $this->uploadImage($invalid_image, $node->id(), $this->fieldName, $node->language()->getId()); + $this->assertContains('"main_error":"The image failed validation."', $this->getSession()->getPage()->getContent(), 'Invalid upload returned errors.'); } /** @@ -178,43 +172,14 @@ public function testInvalidUpload() { * The target field machine name. * @param string $langcode * The langcode to use when setting the field's value. - * - * @return \Psr\Http\Message\ResponseInterface - * The request response. */ public function uploadImage($image, $nid, $field_name, $langcode) { $filepath = $this->container->get('file_system')->realpath($image->uri); $path = 'quickedit/image/upload/node/' . $nid . '/' . $field_name . '/' . $langcode . '/default'; - // We assemble the curl request ourselves as drupalPost cannot process file - // uploads, and drupalPostForm only works with typical Drupal forms. - $client = $this->getHttpClient(); - // Perform HTTP request. - return $client->post($this->buildUrl($path, []), [ - 'multipart' => [ - [ - 'name' => 'files[image]', - 'contents' => fopen($filepath, 'r') - ] - ], - 'http_errors' => FALSE, - 'cookies' => $this->cookies, - ]); - } - - /** - * Obtain the HTTP client and set the cookies. - * - * @return \GuzzleHttp\Client - * The client with BrowserTestBase configuration. - */ - protected function getHttpClient() { - // Similar code is also employed to test CSRF tokens. - // @see \Drupal\Tests\system\Functional\CsrfRequestHeaderTest::testRouteAccess() - $domain = parse_url($this->getUrl(), PHP_URL_HOST); - $session_id = $this->getSession()->getCookie($this->getSessionName()); - $this->cookies = CookieJar::fromArray([$this->getSessionName() => $session_id], $domain); - return $this->getSession()->getDriver()->getClient()->getClient(); + $this->prepareRequest(); + $client = $this->getSession()->getDriver()->getClient(); + $client->request('POST', $this->buildUrl($path, []), [], ['files[image]' => $filepath]); } }