diff --git a/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php index 89eb312..c5b298a 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php @@ -53,7 +53,7 @@ public function testCreate() { // Get the new entity ID from the location header and try to read it from // the database. - $location_url = $this->responseHeaders['location']; + $location_url = $this->drupalGetHeader('location'); $url_parts = explode('/', $location_url); $id = end($url_parts); $loaded_entity = entity_load($entity_type, $id); @@ -68,11 +68,7 @@ public function testCreate() { $this->assertEqual($send_value, $actual_value, 'Created property ' . $property . ' expected: ' . $send_value . ', actual: ' . $actual_value); } - // Reset cURL here because it is confused from our previously used cURL - // options. - $this->drupalLogout(); - unset($this->curlHandle); - $this->drupalLogin($account); + $loaded_entity->delete(); // Try to create an entity without the CSRF token. $this->curlExec(array( CURLOPT_HTTPGET => FALSE, @@ -84,20 +80,20 @@ public function testCreate() { CURLOPT_HTTPHEADER => array('Content-Type: application/vnd.drupal.ld+json'), )); $this->assertResponse(403); + $this->assertFalse(entity_load_multiple($entity_type, NULL, TRUE), 'No entity has been created in the database.'); // Try to create an entity without proper permissions. $this->drupalLogout(); $this->httpRequest('entity/' . $entity_type, 'POST', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(403); + $this->assertFalse(entity_load_multiple($entity_type, NULL, TRUE), 'No entity has been created in the database.'); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); // Try to create a resource which is not web API enabled. $this->enableService(FALSE); $this->drupalLogin($account); $this->httpRequest('entity/entity_test', 'POST', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(404); + $this->assertFalse(entity_load_multiple($entity_type, NULL, TRUE), 'No entity has been created in the database.'); // @todo Once EntityNG is implemented for other entity types add a security // test. It should not be possible for example to create a test entity on a diff --git a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php index 66f85c4..ed2d04d 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php @@ -40,9 +40,6 @@ public function testDelete() { // Create a user account that has the required permissions to delete // resources via the web API. $account = $this->drupalCreateUser(array('restful delete entity:' . $entity_type)); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); // Create an entity programmatically. @@ -74,9 +71,6 @@ public function testDelete() { // Try to delete a resource which is not web API enabled. $this->enableService(FALSE); $account = $this->drupalCreateUser(); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); $this->httpRequest('entity/user/' . $account->id(), 'DELETE'); $user = entity_load('user', $account->id(), TRUE); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php index 57a3f00..f7dbdb6 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php @@ -15,13 +15,6 @@ abstract class RESTTestBase extends WebTestBase { /** - * Stores HTTP response headers from the last HTTP request. - * - * @var array - */ - protected $responseHeaders; - - /** * Helper function to issue a HTTP request with simpletest's cURL. * * @param string $url @@ -203,7 +196,20 @@ protected function enableService($resource_type) { * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertHeader($header, $value, $message = '', $group = 'Browser') { - $match = isset($this->responseHeaders[$header]) && $this->responseHeaders[$header] == $value; - return $this->assertTrue($match, $message ? $message : 'HTTP response header ' . $header . ' with value ' . $value . ' found.', $group); + $header_value = $this->drupalGetHeader($header); + return $this->assertTrue($header_value == $value, $message ? $message : 'HTTP response header ' . $header . ' with value ' . $value . ' found.', $group); + } + + /** + * Overrides WebTestBase::drupalLogin(). + */ + protected function drupalLogin($user) { + if (isset($this->curlHandle)) { + // cURL quirk: when setting CURLOPT_CUSTOMREQUEST to anything other than + // POST in httpRequest() it has to be restored to POST here. Otherwise the + // POST request to login a user will not work. + curl_setopt($this->curlHandle, CURLOPT_CUSTOMREQUEST, 'POST'); + } + parent::drupalLogin($user); } } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php index 874ad13..0578fc3 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php @@ -42,9 +42,6 @@ public function testRead() { // Create a user account that has the required permissions to delete // resources via the web API. $account = $this->drupalCreateUser(array('restful get entity:' . $entity_type)); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); // Create an entity programmatically. @@ -80,9 +77,6 @@ public function testRead() { } // Try to read a resource which is not web API enabled. $account = $this->drupalCreateUser(); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); $response = $this->httpRequest('entity/user/' . $account->id(), 'GET', NULL, 'application/vnd.drupal.ld+json'); $this->assertResponse(404); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php index 83729aa..fa65a2f 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php @@ -89,9 +89,6 @@ public function testPatchUpdate() { // Try to update a resource which is not web API enabled. $this->enableService(FALSE); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PATCH', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(404); @@ -162,9 +159,6 @@ public function testPutUpdate() { // Try to update a resource which is not web API enabled. $this->enableService(FALSE); - // Reset cURL here because it is confused from our previously used cURL - // options. - unset($this->curlHandle); $this->drupalLogin($account); $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(404);