function ConfigFieldMapperTest::testSetEntity

Same name in other branches
  1. 9 core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest::testSetEntity()
  2. 8.9.x core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest::testSetEntity()
  3. 11.x 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 90

Class

ConfigFieldMapperTest
Tests the functionality provided by the configuration field mapper.

Namespace

Drupal\Tests\config_translation\Unit

Code

public function testSetEntity() : void {
    $entity_type = $this->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
    $entity_type->expects($this->any())
        ->method('getConfigPrefix')
        ->willReturn('config_prefix');
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getDefinition')
        ->willReturn($entity_type);
    $field_storage = $this->createMock('Drupal\\field\\FieldStorageConfigInterface');
    $field_storage->expects($this->any())
        ->method('id')
        ->willReturn('field_storage_id');
    $this->entity
        ->expects($this->any())
        ->method('getFieldStorageDefinition')
        ->willReturn($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->assertContains('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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.