function ResourceTypeRepositoryTest::testCaching

Same name and namespace in other branches
  1. 10 core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testCaching()
  2. 9 core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testCaching()
  3. 8.9.x core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testCaching()

Ensures that the ResourceTypeRepository's cache does not become stale.

File

core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php, line 119

Class

ResourceTypeRepositoryTest
Tests Drupal\jsonapi\ResourceType\ResourceTypeRepository.

Namespace

Drupal\Tests\jsonapi\Kernel\ResourceType

Code

public function testCaching() : void {
  $this->assertEmpty($this->resourceTypeRepository
    ->get('node', 'article')
    ->getRelatableResourceTypesByField('field_relationship'));
  $this->createEntityReferenceField('node', 'article', 'field_relationship', 'Related entity', 'node');
  $this->assertCount(3, $this->resourceTypeRepository
    ->get('node', 'article')
    ->getRelatableResourceTypesByField('field_relationship'));
  NodeType::create([
    'type' => 'camelids',
    'name' => 'Camelids',
  ])->save();
  $this->assertCount(4, $this->resourceTypeRepository
    ->get('node', 'article')
    ->getRelatableResourceTypesByField('field_relationship'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.