class ConfigFieldMapperTest

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

Tests the functionality provided by the configuration field mapper.

Attributes

#[CoversClass(ConfigFieldMapper::class)] #[Group('config_translation')]

Hierarchy

Expanded class hierarchy of ConfigFieldMapperTest

File

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

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\Stub
   */
  protected $entity;
  
  /**
   * The entity type manager used for testing.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\Stub
   */
  protected $entityTypeManager;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->entityTypeManager = $this->createStub(EntityTypeManagerInterface::class);
    $this->entity = $this->createStub(FieldConfigInterface::class);
    $definition = [
      'class' => '\\Drupal\\config_translation\\ConfigFieldMapper',
      'base_route_name' => 'entity.field_config.node_field_edit_form',
      'title' => '@label field',
      'names' => [],
      'entity_type' => 'field_config',
    ];
    $this->configFieldMapper = new ConfigFieldMapper('node_fields', $definition, $this->getConfigFactoryStub(), $this->createStub(TypedConfigManagerInterface::class), $this->createStub(LocaleConfigManager::class), $this->createStub(ConfigMapperManagerInterface::class), $this->createStub(RouteProviderInterface::class), $this->getStringTranslationStub(), $this->entityTypeManager, $this->createStub(LanguageManagerInterface::class), $this->createStub(EventDispatcherInterface::class));
  }
  
  /**
   * Tests ConfigFieldMapper::setEntity().
   */
  public function testSetEntity() : void {
    $entity_type = $this->createStub(ConfigEntityTypeInterface::class);
    $entity_type->method('getConfigPrefix')
      ->willReturn('config_prefix');
    $this->entityTypeManager
      ->method('getDefinition')
      ->willReturn($entity_type);
    $field_storage = $this->createStub(FieldStorageConfigInterface::class);
    $field_storage->method('id')
      ->willReturn('field_storage_id');
    $this->entity
      ->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 Overrides
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::setUp protected function Overrides UnitTestCase::setUp
ConfigFieldMapperTest::testSetEntity public function Tests ConfigFieldMapper::setEntity().
DrupalTestCaseTrait::checkErrorHandlerOnTearDown public function Checks the test error handler after test execution. 1
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::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::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.

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