function ContentTranslationFieldSyncRevisionTest::assertLatestRevisionFieldValues

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

Asserts that the latest revision has the expected field values.

@internal

Parameters

$entity_id: The entity ID.

array $expected_values: An array of expected values in the following order:

  • revision ID
  • target ID (en)
  • target ID (it)
  • alt (en)
  • alt (it)
1 call to ContentTranslationFieldSyncRevisionTest::assertLatestRevisionFieldValues()
ContentTranslationFieldSyncRevisionTest::testFieldSynchronizationAndValidation in core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php
Checks that field synchronization works as expected with revisions.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php, line 486

Class

ContentTranslationFieldSyncRevisionTest
Tests the field synchronization logic when revisions are involved.

Namespace

Drupal\Tests\content_translation\Kernel

Code

protected function assertLatestRevisionFieldValues(int $entity_id, array $expected_values) : void {
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->storage
        ->loadRevision($this->storage
        ->getLatestRevisionId($entity_id));
    @([
        $revision_id,
        $target_id_en,
        $target_id_it,
        $alt_en,
        $alt_it,
    ] = $expected_values);
    $this->assertEquals($revision_id, $entity->getRevisionId());
    $this->assertEquals($target_id_en, $entity->get($this->fieldName)->target_id);
    $this->assertEquals($alt_en, $entity->get($this->fieldName)->alt);
    if ($entity->hasTranslation('it')) {
        $it_translation = $entity->getTranslation('it');
        $this->assertEquals($target_id_it, $it_translation->get($this->fieldName)->target_id);
        $this->assertEquals($alt_it, $it_translation->get($this->fieldName)->alt);
    }
}

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