ConfigFieldMapperTest.php in Zircon Profile 8.0
File
core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php
View source
<?php
namespace Drupal\Tests\config_translation\Unit;
use Drupal\config_translation\ConfigFieldMapper;
use Drupal\Tests\UnitTestCase;
class ConfigFieldMapperTest extends UnitTestCase {
protected $configFieldMapper;
protected $entity;
protected $entityManager;
protected function setUp() {
$this->entityManager = $this
->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entity = $this
->getMock('Drupal\\field\\FieldConfigInterface');
$definition = array(
'class' => '\\Drupal\\config_translation\\ConfigFieldMapper',
'base_route_name' => 'entity.field_config.node_field_edit_form',
'title' => '@label field',
'names' => array(),
'entity_type' => 'field_config',
);
$locale_config_manager = $this
->getMockBuilder('Drupal\\locale\\LocaleConfigManager')
->disableOriginalConstructor()
->getMock();
$this->configFieldMapper = new ConfigFieldMapper('node_fields', $definition, $this
->getConfigFactoryStub(), $this
->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface'), $locale_config_manager, $this
->getMock('Drupal\\config_translation\\ConfigMapperManagerInterface'), $this
->getMock('Drupal\\Core\\Routing\\RouteProviderInterface'), $this
->getStringTranslationStub(), $this->entityManager, $this
->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'));
}
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);
$plugin_definition = $this->configFieldMapper
->getPluginDefinition();
$this
->assertTrue(in_array('config_prefix.field_storage_id', $plugin_definition['names']));
$result = $this->configFieldMapper
->setEntity($this->entity);
$this
->assertFalse($result);
}
}