You are here

public function ConfigFieldMapperTest::testSetEntity in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest::testSetEntity()

Tests ConfigFieldMapper::setEntity().

@covers ::setEntity

File

core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php, line 81
Contains \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest.

Class

ConfigFieldMapperTest
Tests the functionality provided by the configuration field mapper.

Namespace

Drupal\Tests\config_translation\Unit

Code

public function testSetEntity() {
  $entity_type = $this
    ->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $entity_type
    ->expects($this
    ->any())
    ->method('getConfigPrefix')
    ->will($this
    ->returnValue('config_prefix'));
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->will($this
    ->returnValue($entity_type));
  $field_storage = $this
    ->getMock('Drupal\\field\\FieldStorageConfigInterface');
  $field_storage
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue('field_storage_id'));
  $this->entity
    ->expects($this
    ->any())
    ->method('getFieldStorageDefinition')
    ->will($this
    ->returnValue($field_storage));
  $result = $this->configFieldMapper
    ->setEntity($this->entity);
  $this
    ->assertTrue($result);

  // Ensure that the configuration name was added to the mapper.
  $plugin_definition = $this->configFieldMapper
    ->getPluginDefinition();
  $this
    ->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names']));

  // Make sure setEntity() returns FALSE when called a second time.
  $result = $this->configFieldMapper
    ->setEntity($this->entity);
  $this
    ->assertFalse($result);
}