class ConfigFieldMapperTest

Same name in other branches
  1. 9 core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest
  2. 8.9.x core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest
  3. 10 core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigFieldMapperTest

Tests the functionality provided by the configuration field mapper.

@group config_translation

@coversDefaultClass \Drupal\config_translation\ConfigFieldMapper

Hierarchy

Expanded class hierarchy of ConfigFieldMapperTest

File

core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php, line 17

Namespace

Drupal\Tests\config_translation\Unit
View source
class ConfigFieldMapperTest extends UnitTestCase {
    
    /**
     * The configuration field mapper to test.
     *
     * @var \Drupal\config_translation\ConfigFieldMapper
     */
    protected $configFieldMapper;
    
    /**
     * The field config instance used for testing.
     *
     * @var \Drupal\field\FieldConfigInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $entity;
    
    /**
     * The entity type manager used for testing.
     *
     * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $entityTypeManager;
    
    /**
     * The mocked event dispatcher.
     *
     * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $eventDispatcher;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->entityTypeManager = $this->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
        $this->entity = $this->createMock('Drupal\\field\\FieldConfigInterface');
        $definition = [
            'class' => '\\Drupal\\config_translation\\ConfigFieldMapper',
            'base_route_name' => 'entity.field_config.node_field_edit_form',
            'title' => '@label field',
            'names' => [],
            'entity_type' => 'field_config',
        ];
        $locale_config_manager = $this->getMockBuilder('Drupal\\locale\\LocaleConfigManager')
            ->disableOriginalConstructor()
            ->getMock();
        $this->eventDispatcher = $this->createMock('Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface');
        $this->configFieldMapper = new ConfigFieldMapper('node_fields', $definition, $this->getConfigFactoryStub(), $this->createMock('Drupal\\Core\\Config\\TypedConfigManagerInterface'), $locale_config_manager, $this->createMock('Drupal\\config_translation\\ConfigMapperManagerInterface'), $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface'), $this->getStringTranslationStub(), $this->entityTypeManager, $this->createMock('Drupal\\Core\\Language\\LanguageManagerInterface'), $this->eventDispatcher);
    }
    
    /**
     * Tests ConfigFieldMapper::setEntity().
     *
     * @covers ::setEntity
     */
    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);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ConfigFieldMapperTest::$configFieldMapper protected property The configuration field mapper to test.
ConfigFieldMapperTest::$entity protected property The field config instance used for testing.
ConfigFieldMapperTest::$entityTypeManager protected property The entity type manager used for testing.
ConfigFieldMapperTest::$eventDispatcher protected property The mocked event dispatcher.
ConfigFieldMapperTest::setUp protected function Overrides UnitTestCase::setUp
ConfigFieldMapperTest::testSetEntity public function Tests ConfigFieldMapper::setEntity().
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function

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