function ContentTranslationHandlerTest::testEntityFormSharedElements

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::testEntityFormSharedElements()
  2. 8.9.x core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::testEntityFormSharedElements()
  3. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::testEntityFormSharedElements()

Tests ContentTranslationHandler::entityFormSharedElements()

@dataProvider providerTestEntityFormSharedElements

@covers ::entityFormSharedElements @covers ::addTranslatabilityClue

Parameters

array $element: The element that will be altered.

bool $default_translation_affected: Whether or not only the default translation of the entity is affected.

bool $default_translation: Whether or not the entity is the default translation.

bool $translation_form: Whether or not the form is a translation form.

array $expected: The expected altered element.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationHandlerTest.php, line 106

Class

ContentTranslationHandlerTest
Tests the content translation handler.

Namespace

Drupal\Tests\content_translation\Kernel

Code

public function testEntityFormSharedElements(array $element, $default_translation_affected, $default_translation, $translation_form, array $expected) : void {
    $this->state
        ->set('entity_test.translation', TRUE);
    $this->state
        ->set('entity_test.untranslatable_fields.default_translation_affected', $default_translation_affected);
    $this->entityTypeBundleInfo
        ->clearCachedBundles();
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->entityTypeManager
        ->getStorage($this->entityTypeId)
        ->create();
    if (!$default_translation) {
        $entity = $entity->addTranslation($this->translationLangcode);
    }
    $entity->save();
    $form_object = $this->entityTypeManager
        ->getFormObject($this->entityTypeId, 'default');
    $form_object->setEntity($entity);
    $form_state = new FormState();
    $form_state->addBuildInfo('callback_object', $form_object)
        ->set([
        'content_translation',
        'translation_form',
    ], $translation_form);
    $handler = $this->entityTypeManager
        ->getHandler($this->entityTypeId, 'translation');
    $actual = $handler->entityFormSharedElements($element, $form_state, $element);
    $this->assertEquals($expected, $actual);
}

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