function SqlContentEntityStorageTest::testLoadMultiplePersistentCacheMiss

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultiplePersistentCacheMiss()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultiplePersistentCacheMiss()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultiplePersistentCacheMiss()

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

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1282

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testLoadMultiplePersistentCacheMiss() {
    $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(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)));
    // In case of a cache miss, the entity is loaded from the storage and then
    // set in the cache.
    $key = 'values:' . $this->entityTypeId . ':1';
    $this->cache
        ->expects($this->once())
        ->method('getMultiple')
        ->with([
        $key,
    ])
        ->will($this->returnValue([]));
    $this->cache
        ->expects($this->once())
        ->method('set')
        ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, [
        $this->entityTypeId . '_values',
        'entity_field_info',
    ]);
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getActiveDefinition')
        ->will($this->returnValue($this->entityType));
    $entity_storage = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
        ->setConstructorArgs([
        $this->entityType,
        $this->connection,
        $this->entityFieldManager,
        $this->cache,
        $this->languageManager,
        new MemoryCache(),
        $this->entityTypeBundleInfo,
        $this->entityTypeManager,
    ])
        ->setMethods([
        'getFromStorage',
        'invokeStorageLoadHook',
        'initTableLayout',
    ])
        ->getMock();
    $entity_storage->method('invokeStorageLoadHook')
        ->willReturn(NULL);
    $entity_storage->method('initTableLayout')
        ->willReturn(NULL);
    $entity_storage->expects($this->once())
        ->method('getFromStorage')
        ->with([
        $id,
    ])
        ->will($this->returnValue([
        $id => $entity,
    ]));
    $entities = $entity_storage->loadMultiple([
        $id,
    ]);
    $this->assertEquals($entity, $entities[$id]);
}

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