You are here

public function FieldConfigEntityUnitTest::testCalculateDependenciesIncorrectBundle in Zircon Profile 8

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

Test that invalid bundles are handled.

@expectedException \LogicException @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 167
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
    ->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
  $storage
    ->expects($this
    ->any())
    ->method('load')
    ->with('test_bundle_not_exists')
    ->will($this
    ->returnValue(NULL));
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('bundle_entity_type')
    ->will($this
    ->returnValue($storage));
  $target_entity_type = new EntityType(array(
    'id' => 'test_entity_type',
    'bundle_entity_type' => 'bundle_entity_type',
  ));
  $this->entityManager
    ->expects($this
    ->at(0))
    ->method('getDefinition')
    ->with($this->entityTypeId)
    ->willReturn($this->entityType);
  $this->entityManager
    ->expects($this
    ->at(1))
    ->method('getDefinition')
    ->with($this->entityTypeId)
    ->willReturn($this->entityType);
  $this->entityManager
    ->expects($this
    ->at(2))
    ->method('getDefinition')
    ->with($this->entityTypeId)
    ->willReturn($this->entityType);
  $this->entityManager
    ->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(array(
    'field_name' => $this->fieldStorage
      ->getName(),
    'entity_type' => 'test_entity_type',
    'bundle' => 'test_bundle_not_exists',
    'field_type' => 'test_field',
  ), $this->entityTypeId);
  $field
    ->calculateDependencies();
}