function SqlContentEntityStorageTest::testLoadMultipleNoPersistentCache

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultipleNoPersistentCache()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testLoadMultipleNoPersistentCache()
  3. 10 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 1225

Class

SqlContentEntityStorageTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Sql%21SqlContentEntityStorage.php/class/SqlContentEntityStorage/11.x" title="A content entity database storage implementation." class="local">\Drupal\Core\Entity\Sql\SqlContentEntityStorage</a> @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testLoadMultipleNoPersistentCache() : void {
    $this->setUpModuleHandlerNoImplementations();
    $id = 1;
    $entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Entity\\Sql\\SqlContentEntityStorageTestEntityInterface')
        ->getMockForAbstractClass();
    $entity->expects($this->any())
        ->method('id')
        ->willReturn($id);
    $this->entityType
        ->expects($this->any())
        ->method('isPersistentlyCacheable')
        ->willReturn(FALSE);
    $this->entityType
        ->expects($this->atLeastOnce())
        ->method('id')
        ->willReturn($this->entityTypeId);
    // 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');
    $this->entityTypeManager
        ->getActiveDefinition($this->entityType
        ->id())
        ->willReturn($this->entityType);
    $entity_storage = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
        ->setConstructorArgs([
        $this->entityType,
        $this->connection,
        $this->entityFieldManager
            ->reveal(),
        $this->cache,
        $this->languageManager,
        new MemoryCache(new Time()),
        $this->entityTypeBundleInfo,
        $this->entityTypeManager
            ->reveal(),
    ])
        ->onlyMethods([
        '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,
    ])
        ->willReturn([
        $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.