You are here

public function SqlContentEntityStorageTest::testLoadMultipleNoPersistentCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultipleNoPersistentCache()

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

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1101
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 testLoadMultipleNoPersistentCache() {
  $this
    ->setUpModuleHandlerNoImplementations();
  $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
    ->any())
    ->method('isPersistentlyCacheable')
    ->will($this
    ->returnValue(FALSE));
  $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)));

  // There should be no calls to the cache backend for an entity type without
  // persistent caching.
  $this->cache
    ->expects($this
    ->never())
    ->method('getMultiple');
  $this->cache
    ->expects($this
    ->never())
    ->method('set');
  $entity_storage = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
    ->setConstructorArgs(array(
    $this->entityType,
    $this->connection,
    $this->entityManager,
    $this->cache,
    $this->languageManager,
  ))
    ->setMethods(array(
    'getFromStorage',
    'invokeStorageLoadHook',
  ))
    ->getMock();
  $entity_storage
    ->method('invokeStorageLoadHook')
    ->willReturn(NULL);
  $entity_storage
    ->expects($this
    ->once())
    ->method('getFromStorage')
    ->with(array(
    $id,
  ))
    ->will($this
    ->returnValue(array(
    $id => $entity,
  )));
  $entities = $entity_storage
    ->loadMultiple(array(
    $id,
  ));
  $this
    ->assertEquals($entity, $entities[$id]);
}