You are here

public function EntityConverterTest::testConvert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php \Drupal\Tests\Core\ParamConverter\EntityConverterTest::testConvert()

Tests the convert() method.

@dataProvider providerTestConvert

@covers ::convert

File

core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php, line 84
Contains \Drupal\Tests\Core\ParamConverter\EntityConverterTest.

Class

EntityConverterTest
@coversDefaultClass \Drupal\Core\ParamConverter\EntityConverter @group ParamConverter @group Entity

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvert($value, array $definition, array $defaults, $expected_result) {
  $entity_storage = $this
    ->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $this->entityManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('entity_test')
    ->willReturn($entity_storage);
  $entity_storage
    ->expects($this
    ->any())
    ->method('load')
    ->willReturnMap([
    [
      'valid_id',
      (object) [
        'id' => 'valid_id',
      ],
    ],
    [
      'invalid_id',
      NULL,
    ],
  ]);
  $this
    ->assertEquals($expected_result, $this->entityConverter
    ->convert($value, $definition, 'foo', $defaults));
}