function FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle

Same name in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()
  2. 10 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()
  3. 11.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle()

Test that invalid bundles are handled.

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 165

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->at(0))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(1))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(2))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(3))
        ->method('getDefinition')
        ->with('test_entity_type')
        ->willReturn($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.