You are here

protected function FieldConfigEntityUnitTest::setUp 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::setUp()

Overrides UnitTestCase::setUp

File

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

Class

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

Namespace

Drupal\Tests\field\Unit

Code

protected function setUp() {
  $this->entityTypeId = $this
    ->randomMachineName();
  $this->entityType = $this
    ->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $this->entityManager = $this
    ->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
  $this->uuid = $this
    ->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
  $this->typedConfigManager = $this
    ->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
  $this->fieldTypePluginManager = $this
    ->getMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
  $container = new ContainerBuilder();
  $container
    ->set('entity.manager', $this->entityManager);
  $container
    ->set('uuid', $this->uuid);
  $container
    ->set('config.typed', $this->typedConfigManager);
  $container
    ->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
  \Drupal::setContainer($container);

  // Create a mock FieldStorageConfig object.
  $this->fieldStorage = $this
    ->getMock('\\Drupal\\field\\FieldStorageConfigInterface');
  $this->fieldStorage
    ->expects($this
    ->any())
    ->method('getType')
    ->will($this
    ->returnValue('test_field'));
  $this->fieldStorage
    ->expects($this
    ->any())
    ->method('getName')
    ->will($this
    ->returnValue('field_test'));
  $this->fieldStorage
    ->expects($this
    ->any())
    ->method('getSettings')
    ->willReturn(array());

  // Place the field in the mocked entity manager's field registry.
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getFieldStorageDefinitions')
    ->with('test_entity_type')
    ->will($this
    ->returnValue(array(
    $this->fieldStorage
      ->getName() => $this->fieldStorage,
  )));
}