3 namespace Drupal\Tests\config_translation\Unit;
5 use Drupal\config_translation\ConfigFieldMapper;
6 use Drupal\Tests\UnitTestCase;
9 * Tests the functionality provided by the configuration field mapper.
11 * @group config_translation
13 * @coversDefaultClass \Drupal\config_translation\ConfigFieldMapper
15 class ConfigFieldMapperTest extends UnitTestCase {
18 * The configuration field mapper to test.
20 * @var \Drupal\config_translation\ConfigFieldMapper
22 protected $configFieldMapper;
25 * The field config instance used for testing.
27 * @var \Drupal\field\FieldConfigInterface|\PHPUnit_Framework_MockObject_MockObject
32 * The entity manager used for testing.
34 * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
36 protected $entityManager;
41 protected function setUp() {
42 $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
43 $this->entity = $this->getMock('Drupal\field\FieldConfigInterface');
46 'class' => '\Drupal\config_translation\ConfigFieldMapper',
47 'base_route_name' => 'entity.field_config.node_field_edit_form',
48 'title' => '@label field',
50 'entity_type' => 'field_config',
53 $locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
54 ->disableOriginalConstructor()
57 $this->configFieldMapper = new ConfigFieldMapper(
60 $this->getConfigFactoryStub(),
61 $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface'),
62 $locale_config_manager,
63 $this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
64 $this->getMock('Drupal\Core\Routing\RouteProviderInterface'),
65 $this->getStringTranslationStub(),
67 $this->getMock('Drupal\Core\Language\LanguageManagerInterface')
72 * Tests ConfigFieldMapper::setEntity().
76 public function testSetEntity() {
77 $entity_type = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
79 ->expects($this->any())
80 ->method('getConfigPrefix')
81 ->will($this->returnValue('config_prefix'));
84 ->expects($this->any())
85 ->method('getDefinition')
86 ->will($this->returnValue($entity_type));
88 $field_storage = $this->getMock('Drupal\field\FieldStorageConfigInterface');
90 ->expects($this->any())
92 ->will($this->returnValue('field_storage_id'));
95 ->expects($this->any())
96 ->method('getFieldStorageDefinition')
97 ->will($this->returnValue($field_storage));
99 $result = $this->configFieldMapper->setEntity($this->entity);
100 $this->assertTrue($result);
102 // Ensure that the configuration name was added to the mapper.
103 $plugin_definition = $this->configFieldMapper->getPluginDefinition();
104 $this->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names']));
106 // Make sure setEntity() returns FALSE when called a second time.
107 $result = $this->configFieldMapper->setEntity($this->entity);
108 $this->assertFalse($result);