You are here

public function FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()
  2. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()

Tests that invalid bundles are handled.

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 155
Contains \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest.

Class

FieldConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldConfig @group field

Namespace

Drupal\Tests\field\Unit

Code

public function testCalculateDependenciesIncorrectBundle() {
  $storage = $this
    ->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
  $storage
    ->expects($this
    ->any())
    ->method('load')
    ->with('test_bundle_not_exists')
    ->will($this
    ->returnValue(NULL));
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('bundle_entity_type')
    ->will($this
    ->returnValue($storage));
  $target_entity_type = new EntityType([
    'id' => 'test_entity_type',
    'bundle_entity_type' => 'bundle_entity_type',
  ]);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->willReturnMap([
    [
      $this->entityTypeId,
      TRUE,
      $this->entityType,
    ],
    [
      'test_entity_type',
      TRUE,
      $target_entity_type,
    ],
  ]);
  $this->fieldTypePluginManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('test_field')
    ->willReturn([
    'provider' => 'test_module',
    'config_dependencies' => [
      'module' => [
        'test_module2',
      ],
    ],
    'class' => '\\Drupal\\Tests\\field\\Unit\\DependencyFieldItem',
  ]);
  $field = new FieldConfig([
    'field_name' => $this->fieldStorage
      ->getName(),
    'entity_type' => 'test_entity_type',
    'bundle' => 'test_bundle_not_exists',
    'field_type' => 'test_field',
  ], $this->entityTypeId);
  $this
    ->expectException(\LogicException::class);
  $this
    ->expectExceptionMessage('Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.');
  $field
    ->calculateDependencies();
}