You are here

public function MultilingualTest::testComparison in Entity Share 8.2

Test state information.

File

modules/entity_share_client/tests/src/Functional/MultilingualTest.php, line 120

Class

MultilingualTest
General functional test class for multilingual scenarios.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

public function testComparison() {

  // 1: No import: en and fr channels data should indicate a new entity.
  $this
    ->expectedState(StateInformationInterface::INFO_ID_NEW, StateInformationInterface::INFO_ID_NEW);

  // 2: Import entity in en: en should indicate synchronized and fr should
  // indicate a new translation.
  $this
    ->pullChannel('node_es_test_en');
  $this->jsonapiHelper
    ->clearImportedEntities();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_SYNCHRONIZED, StateInformationInterface::INFO_ID_NEW_TRANSLATION);

  // 3: Import entity in fr: en and fr should indicate synchronized.
  $this
    ->pullChannel('node_es_test_fr');
  $this->jsonapiHelper
    ->clearImportedEntities();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_SYNCHRONIZED, StateInformationInterface::INFO_ID_SYNCHRONIZED);

  // 4: Edit the en translation (also this emulates a change on the client
  // website): en should indicate changed and fr should indicate synchronized.

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->loadEntity('node', 'es_test');
  $node_translation = $node
    ->getTranslation('en');
  $node_translation
    ->setChangedTime($this->faker
    ->unixTime());
  $node_translation
    ->save();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_CHANGED, StateInformationInterface::INFO_ID_SYNCHRONIZED);

  // 5: Import entity in en: en and fr should indicate synchronized.
  $this
    ->pullChannel('node_es_test_en');
  $this->jsonapiHelper
    ->clearImportedEntities();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_SYNCHRONIZED, StateInformationInterface::INFO_ID_SYNCHRONIZED);

  // 6: Edit the fr translation (also this emulates a change on the client
  // website): en should indicate synchronized and fr should indicate changed.

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->loadEntity('node', 'es_test');
  $node_translation = $node
    ->getTranslation('fr');
  $node_translation
    ->setChangedTime($this->faker
    ->unixTime());
  $node_translation
    ->save();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_SYNCHRONIZED, StateInformationInterface::INFO_ID_CHANGED);

  // 7: Import entity in fr: en and fr should indicate synchronized.
  $this
    ->pullChannel('node_es_test_fr');
  $this->jsonapiHelper
    ->clearImportedEntities();
  $this
    ->expectedState(StateInformationInterface::INFO_ID_SYNCHRONIZED, StateInformationInterface::INFO_ID_SYNCHRONIZED);
}