You are here

protected function BaseFieldDefinitionTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php, line 41
Contains \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest.

Class

BaseFieldDefinitionTest
Unit test for BaseFieldDefinition.

Namespace

Drupal\Tests\Core\Entity

Code

protected function setUp() {

  // Mock the field type manager and place it in the container.
  $field_type_manager = $this
    ->getMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
  $this->fieldType = $this
    ->randomMachineName();
  $this->fieldTypeDefinition = array(
    'id' => $this->fieldType,
    'storage_settings' => array(
      'some_setting' => 'value 1',
    ),
    'field_settings' => array(
      'some_instance_setting' => 'value 2',
    ),
  );
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue(array(
    $this->fieldType => $this->fieldTypeDefinition,
  )));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultStorageSettings')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition['storage_settings']));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultFieldSettings')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition['field_settings']));
  $container = new ContainerBuilder();
  $container
    ->set('plugin.manager.field.field_type', $field_type_manager);
  \Drupal::setContainer($container);
}