diff --git a/tests/src/Functional/ResourceTestBase.php b/tests/src/Functional/ResourceTestBase.php index 30f8a5d..6891ec7 100644 --- a/tests/src/Functional/ResourceTestBase.php +++ b/tests/src/Functional/ResourceTestBase.php @@ -34,7 +34,6 @@ use Drupal\path\Plugin\Field\FieldType\PathItem; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; use Drupal\user\Entity\Role; -use Drupal\user\Entity\User; use Drupal\user\EntityOwnerInterface; use Drupal\user\RoleInterface; use Drupal\user\UserInterface; @@ -1675,7 +1674,7 @@ abstract class ResourceTestBase extends BrowserTestBase { ); return static::getAccessDeniedResponse($this->entity, $access, $via_link, $relationship_field_name, 'The current user is not allowed to view this relationship.', FALSE); } - $expected_document = $this->getExpectedGetRelationshipDocument($relationship_field_name); + $expected_document = $this->getExpectedGetRelationshipDocument($relationship_field_name, $entity); $expected_cacheability = (new CacheableMetadata()) ->addCacheTags($this->getExpectedCacheTags([])) ->addCacheContexts(['url.site']) @@ -2802,7 +2801,9 @@ abstract class ResourceTestBase extends BrowserTestBase { $entity->set('field_revisionable_number', 42); // Change a relationship field so revisions can be tested on related and // relationship routes. - $entity->set('field_jsonapi_test_entity_ref', User::load(0)); + $new_user = $this->createUser(); + $new_user->save(); + $entity->set('field_jsonapi_test_entity_ref', ['target_id' => $new_user->id()]); $entity->set('moderation_state', 'draft'); $entity->setNewRevision(); $entity->save(); @@ -2880,6 +2881,7 @@ abstract class ResourceTestBase extends BrowserTestBase { foreach ($test_relationship_urls as $revision_case) { list($revision_id, $test_url) = $revision_case; // Load the revision that will be requested. + $this->entityStorage->resetCache([$entity->id()]); $revision = is_null($revision_id) ? $this->entityStorage->load($entity->id()) : $this->entityStorage->loadRevision($revision_id); @@ -2896,6 +2898,7 @@ abstract class ResourceTestBase extends BrowserTestBase { foreach ($test_relationship_urls as $revision_case) { list($revision_id, $test_url) = $revision_case; // Load the revision that will be requested. + $this->entityStorage->resetCache([$entity->id()]); $revision = is_null($revision_id) ? $this->entityStorage->load($entity->id()) : $this->entityStorage->loadRevision($revision_id); @@ -2905,7 +2908,6 @@ abstract class ResourceTestBase extends BrowserTestBase { $expected_response = $this->getExpectedGetRelationshipResponse('field_jsonapi_test_entity_ref', $revision); $expected_document = $expected_response->getResponseData(); $expected_cacheability = $expected_response->getCacheableMetadata(); - $expected_document['links']['self']['href'] = $test_url->toString(); $this->assertResourceResponse(200, $expected_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), FALSE, 'MISS'); } }