You are here

public function SqlContentEntityStorageTest::testLoadMultiplePersistentCached in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultiplePersistentCached()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultiplePersistentCached()

@covers ::doLoadMultiple @covers ::buildCacheId @covers ::getFromPersistentCache

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1187
Contains \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest.

Class

SqlContentEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testLoadMultiplePersistentCached() {
  $this
    ->setUpModuleHandlerNoImplementations();
  $key = 'values:' . $this->entityTypeId . ':1';
  $id = 1;
  $entity = $this
    ->getMockBuilder('\\Drupal\\Tests\\Core\\Entity\\Sql\\SqlContentEntityStorageTestEntityInterface')
    ->getMockForAbstractClass();
  $entity
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue($id));
  $this->entityType
    ->expects($this
    ->atLeastOnce())
    ->method('isPersistentlyCacheable')
    ->will($this
    ->returnValue(TRUE));
  $this->entityType
    ->expects($this
    ->atLeastOnce())
    ->method('id')
    ->will($this
    ->returnValue($this->entityTypeId));
  $this->entityType
    ->expects($this
    ->atLeastOnce())
    ->method('getClass')
    ->will($this
    ->returnValue(get_class($entity)));
  $this->cache
    ->expects($this
    ->once())
    ->method('getMultiple')
    ->with([
    $key,
  ])
    ->will($this
    ->returnValue([
    $key => (object) [
      'data' => $entity,
    ],
  ]));
  $this->cache
    ->expects($this
    ->never())
    ->method('set');
  $this
    ->setUpEntityStorage();
  $entities = $this->entityStorage
    ->loadMultiple([
    $id,
  ]);
  $this
    ->assertEquals($entity, $entities[$id]);
}