function FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()
  2. 8.9.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()
  3. 10 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 154

Class

FieldConfigEntityUnitTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21field%21src%21Entity%21FieldConfig.php/class/FieldConfig/11.x" title="Defines the Field entity." class="local">\Drupal\field\Entity\FieldConfig</a> @group field

Namespace

Drupal\Tests\field\Unit

Code

public function testCalculateDependenciesIncorrectBundle() : void {
    $storage = $this->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
    $storage->expects($this->any())
        ->method('load')
        ->with('test_bundle_not_exists')
        ->willReturn(NULL);
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getStorage')
        ->with('bundle_entity_type')
        ->willReturn($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();
}

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