You are here

public function EntityConverterTest::testConvertWithInvalidEntityType in Drupal 8

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

Tests the convert() method with an invalid entity type.

File

core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php, line 323

Class

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

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvertWithInvalidEntityType() {
  $this
    ->setUpMocks();
  $contexts = [
    EntityRepositoryInterface::CONTEXT_ID_LEGACY_CONTEXT_OPERATION => new Context(new ContextDefinition('string'), 'entity_upcast'),
  ];
  $plugin_id = 'invalid_id';
  $this->entityRepository
    ->expects($this
    ->once())
    ->method('getCanonical')
    ->with($plugin_id, 'id', $contexts)
    ->willThrowException(new PluginNotFoundException($plugin_id));
  $this
    ->expectException(PluginNotFoundException::class);
  $this->entityConverter
    ->convert('id', [
    'type' => 'entity:' . $plugin_id,
  ], 'foo', [
    'foo' => 'id',
  ]);
}