function EntityStorageBaseTest::testLoadMultiple
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php \Drupal\Tests\Core\Entity\EntityStorageBaseTest::testLoadMultiple()
- 11.x core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php \Drupal\Tests\Core\Entity\EntityStorageBaseTest::testLoadMultiple()
Test loadMultiple().
Does not cover statically-cached results.
@covers ::loadMultiple
@dataProvider providerLoadMultiple
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityStorageBaseTest.php, line 140
Class
- EntityStorageBaseTest
- @coversDefaultClass \Drupal\Core\Entity\EntityStorageBase @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testLoadMultiple($expected, $load_multiple, $query) {
// Make our EntityStorageBase mock.
$mock_base = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageBase')
->disableOriginalConstructor()
->onlyMethods([
'doLoadMultiple',
'postLoad',
])
->getMockForAbstractClass();
// For all non-cached queries, we call doLoadMultiple().
$mock_base->expects($this->once())
->method('doLoadMultiple')
->with($query)
->willReturn($load_multiple);
// Make our EntityTypeInterface mock so that we can turn off static caching.
$mock_entity_type = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeInterface')
->onlyMethods([
'isStaticallyCacheable',
])
->getMockForAbstractClass();
// Disallow caching.
$mock_entity_type->expects($this->any())
->method('isStaticallyCacheable')
->willReturn(FALSE);
// Add the EntityTypeInterface to the storage object.
$ref_entity_type = new \ReflectionProperty($mock_base, 'entityType');
$ref_entity_type->setAccessible(TRUE);
$ref_entity_type->setValue($mock_base, $mock_entity_type);
// Set up expectations for postLoad(), which we only call if there are
// results from loadMultiple().
$mock_base->expects($this->exactly(empty($load_multiple) ? 0 : 1))
->method('postLoad');
$this->assertEquals($expected, $mock_base->loadMultiple($query));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.