You are here

public function ResourceTypeRepositoryTest::testMappingNameConflictCheck in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testMappingNameConflictCheck()

Ensures that a naming conflict in the mapping causes an exception to be thrown.

@covers ::getFieldMapping @dataProvider getFieldMappingProvider

File

core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php, line 123

Class

ResourceTypeRepositoryTest
@coversDefaultClass \Drupal\jsonapi\ResourceType\ResourceTypeRepository @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\ResourceType

Code

public function testMappingNameConflictCheck($field_name_list) {
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition('node');
  $bundle = 'article';
  $reflection_class = new \ReflectionClass($this->resourceTypeRepository);
  $reflection_method = $reflection_class
    ->getMethod('getFields');
  $reflection_method
    ->setAccessible(TRUE);
  $this
    ->expectException(\LogicException::class);
  $this
    ->expectExceptionMessage("The generated alias '{$field_name_list[1]}' for field name '{$field_name_list[0]}' conflicts with an existing field. Please report this in the JSON:API issue queue!");
  $reflection_method
    ->invokeArgs($this->resourceTypeRepository, [
    $field_name_list,
    $entity_type,
    $bundle,
  ]);
}