function EntityUnitTest::testLoadMultiple

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLoadMultiple()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLoadMultiple()
  3. 10 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testLoadMultiple()

Tests EntityBase::loadMultiple().

When called statically on a subclass of Entity.

@covers ::loadMultiple

File

core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php, line 291

Class

EntityUnitTest
@coversDefaultClass \Drupal\Core\Entity\EntityBase @group Entity @group Access

Namespace

Drupal\Tests\Core\Entity

Code

public function testLoadMultiple() : void {
    $this->setupTestLoad();
    $class_name = get_class($this->entity);
    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
    $entity_type_repository->expects($this->once())
        ->method('getEntityTypeFromClass')
        ->with($class_name)
        ->willReturn($this->entityTypeId);
    $storage = $this->createMock(EntityStorageInterface::class);
    $storage->expects($this->once())
        ->method('loadMultiple')
        ->with([
        1,
    ])
        ->willReturn([
        1 => $this->entity,
    ]);
    $this->entityTypeManager
        ->expects($this->once())
        ->method('getStorage')
        ->with($this->entityTypeId)
        ->willReturn($storage);
    \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
    // Call EntityBase::loadMultiple() statically and check that it returns the
    // mock entity.
    $this->assertSame([
        1 => $this->entity,
    ], $class_name::loadMultiple([
        1,
    ]));
}

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