/**
  * Test importing and rolling back translated entities.
  */
 public function testTranslated()
 {
     // Create a destination.
     $this->createDestination(['translations' => TRUE]);
     // Create some pre-existing entities.
     $this->storage->create(['id' => 1, 'langcode' => 'en'])->save();
     $this->storage->create(['id' => 2, 'langcode' => 'fr'])->save();
     $translated = $this->storage->create(['id' => 3, 'langcode' => 'en']);
     $translated->save();
     $translated->addTranslation('fr')->save();
     // Pre-assert that things are as expected.
     $this->assertTranslations(1, 'en');
     $this->assertTranslations(2, 'fr');
     $this->assertTranslations(3, 'en', ['fr']);
     $this->assertFalse($this->storage->load(4));
     $destination_rows = [['id' => 1, 'langcode' => 'en', 'action' => MigrateIdMapInterface::ROLLBACK_PRESERVE], ['id' => 2, 'langcode' => 'en', 'action' => MigrateIdMapInterface::ROLLBACK_DELETE], ['id' => 3, 'langcode' => 'fr', 'action' => MigrateIdMapInterface::ROLLBACK_PRESERVE], ['id' => 4, 'langcode' => 'fr', 'action' => MigrateIdMapInterface::ROLLBACK_DELETE]];
     $rollback_actions = [];
     // Import some rows.
     foreach ($destination_rows as $idx => $destination_row) {
         $row = new Row([], []);
         foreach ($destination_row as $key => $value) {
             $row->setDestinationProperty($key, $value);
         }
         $this->destination->import($row);
         // Check that the rollback action is correct, and save it.
         $this->assertEquals($destination_row['action'], $this->destination->rollbackAction());
         $rollback_actions[$idx] = $this->destination->rollbackAction();
     }
     $this->assertTranslations(1, 'en');
     $this->assertTranslations(2, 'fr', ['en']);
     $this->assertTranslations(3, 'en', ['fr']);
     $this->assertTranslations(4, 'fr');
     // Rollback the rows.
     foreach ($destination_rows as $idx => $destination_row) {
         if ($rollback_actions[$idx] == MigrateIdMapInterface::ROLLBACK_DELETE) {
             $this->destination->rollback($destination_row);
         }
     }
     // No change, update of existing translation.
     $this->assertTranslations(1, 'en');
     // Remove added translation.
     $this->assertTranslations(2, 'fr');
     // No change, update of existing translation.
     $this->assertTranslations(3, 'en', ['fr']);
     // No change, can't remove default translation.
     $this->assertTranslations(4, 'fr');
 }
 /**
  * Tests correct field method invocation order.
  */
 public function testFieldMethodInvocationOrder()
 {
     // Create a test entity.
     $entity = $this->entityTestFieldMethodsStorage->create(['name' => $this->randomString(), 'langcode' => 'de']);
     $entity->save();
     $entity->addTranslation('fr')->save();
     // Reset the current value of the test field.
     foreach (['de', 'fr'] as $langcode) {
         $entity->getTranslation($langcode)->test_invocation_order->value = 0;
     }
     $entity->getTranslation('de')->save();
     $this->assertTrue($entity->getTranslation('fr')->test_invocation_order->value > $entity->getTranslation('de')->test_invocation_order->value, 'The field presave method has been invoked in the correct entity translation order.');
     // Reset the current value of the test field.
     foreach (['de', 'fr'] as $langcode) {
         $entity->getTranslation($langcode)->test_invocation_order->value = 0;
     }
     $entity->getTranslation('fr')->save();
     $this->assertTrue($entity->getTranslation('de')->test_invocation_order->value > $entity->getTranslation('fr')->test_invocation_order->value, 'The field presave method has been invoked in the correct entity translation order.');
 }