Commit 8f2aadc0 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2869415 by Wim Leers, tstoeckler, dawehner:...

Issue #2869415 by Wim Leers, tstoeckler, dawehner: EntityResourceTestBase::getUrl() overrides BrowserTestBase::getUrl(), yet offers different functionality
parent 582208f0
......@@ -269,7 +269,7 @@ public function testPostDxWithoutCriticalBaseFields() {
$this->provisionEntityResource();
$this->setUpAuthorization('POST');
$url = $this->getPostUrl()->setOption('query', ['_format' => static::$format]);
$url = $this->getEntityResourcePostUrl()->setOption('query', ['_format' => static::$format]);
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = static::$mimeType;
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
......
......@@ -306,7 +306,7 @@ public function testGet() {
// - to first test all mistakes a developer might make, and assert that the
// error responses provide a good DX
// - to eventually result in a well-formed request that succeeds.
$url = $this->getUrl();
$url = $this->getEntityResourceUrl();
$request_options = [];
......@@ -327,7 +327,7 @@ public function testGet() {
$this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('GET'), $response);
}
else {
$this->assertResourceErrorResponse(404, 'No route found for "GET ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
$this->assertResourceErrorResponse(404, 'No route found for "GET ' . str_replace($this->baseUrl, '', $this->getEntityResourceUrl()->setAbsolute()->toString()) . '"', $response);
}
......@@ -651,7 +651,7 @@ public function testPost() {
// - to first test all mistakes a developer might make, and assert that the
// error responses provide a good DX
// - to eventually result in a well-formed request that succeeds.
$url = $this->getPostUrl();
$url = $this->getEntityResourcePostUrl();
$request_options = [];
......@@ -667,7 +667,7 @@ public function testPost() {
// DX: 404 when resource not provisioned.
$response = $this->request('POST', $url, $request_options);
$this->assertResourceErrorResponse(404, 'No route found for "POST ' . str_replace($this->baseUrl, '', $this->getPostUrl()->setAbsolute()->toString()) . '"', $response);
$this->assertResourceErrorResponse(404, 'No route found for "POST ' . str_replace($this->baseUrl, '', $this->getEntityResourcePostUrl()->setAbsolute()->toString()) . '"', $response);
$this->provisionEntityResource();
......@@ -841,7 +841,7 @@ public function testPatch() {
// - to first test all mistakes a developer might make, and assert that the
// error responses provide a good DX
// - to eventually result in a well-formed request that succeeds.
$url = $this->getUrl();
$url = $this->getEntityResourceUrl();
$request_options = [];
......@@ -865,10 +865,10 @@ public function testPatch() {
// DX: 404 when resource not provisioned, 405 if canonical route.
$response = $this->request('PATCH', $url, $request_options);
if ($has_canonical_url) {
$this->assertResourceErrorResponse(405, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
$this->assertResourceErrorResponse(405, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getEntityResourceUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
}
else {
$this->assertResourceErrorResponse(404, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
$this->assertResourceErrorResponse(404, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getEntityResourceUrl()->setAbsolute()->toString()) . '"', $response);
}
......@@ -1029,7 +1029,7 @@ public function testDelete() {
// - to first test all mistakes a developer might make, and assert that the
// error responses provide a good DX
// - to eventually result in a well-formed request that succeeds.
$url = $this->getUrl();
$url = $this->getEntityResourceUrl();
$request_options = [];
......@@ -1054,10 +1054,10 @@ public function testDelete() {
$response = $this->request('DELETE', $url, $request_options);
if ($has_canonical_url) {
$this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow'));
$this->assertResourceErrorResponse(405, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
$this->assertResourceErrorResponse(405, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getEntityResourceUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
}
else {
$this->assertResourceErrorResponse(404, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
$this->assertResourceErrorResponse(404, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getEntityResourceUrl()->setAbsolute()->toString()) . '"', $response);
}
$this->provisionEntityResource();
......@@ -1102,7 +1102,7 @@ public function testDelete() {
$this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE);
$this->refreshTestStateAfterRestConfigChange();
$this->entity = $this->createEntity();
$url = $this->getUrl()->setOption('query', $url->getOption('query'));
$url = $this->getEntityResourceUrl()->setOption('query', $url->getOption('query'));
// DX: 403 when unauthorized.
......@@ -1162,7 +1162,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
* @return \Drupal\Core\Url
* The URL to GET/PATCH/DELETE.
*/
protected function getUrl() {
protected function getEntityResourceUrl() {
$has_canonical_url = $this->entity->hasLinkTemplate('canonical');
return $has_canonical_url ? $this->entity->toUrl() : Url::fromUri('base:entity/' . static::$entityTypeId . '/' . $this->entity->id());
}
......@@ -1173,7 +1173,7 @@ protected function getUrl() {
* @return \Drupal\Core\Url
* The URL to POST to.
*/
protected function getPostUrl() {
protected function getEntityResourcePostUrl() {
$has_canonical_url = $this->entity->hasLinkTemplate('https://www.drupal.org/link-relations/create');
return $has_canonical_url ? $this->entity->toUrl() : Url::fromUri('base:entity/' . static::$entityTypeId);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment