You are here

protected function ContentTranslationFieldSyncRevisionTest::assertLatestRevisionFieldValues in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationFieldSyncRevisionTest::assertLatestRevisionFieldValues()
  2. 9 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)

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);
  }
}