diff -u b/tests/src/Kernel/CrudTest.php b/tests/src/Kernel/CrudTest.php --- b/tests/src/Kernel/CrudTest.php +++ b/tests/src/Kernel/CrudTest.php @@ -240,18 +240,13 @@ $job->save(); $job_item = tmgmt_job_item_create('test_source', 'test_type', 1, ['tjid' => $job->id()]); $job_item->save(); - $job_item->updateData(['dummy', 'deep_nesting'], ['#text' => 'Invalid translation that will cause an exception']); - $job_item->save(); - - // Request translation. Here it fails. - $job->requestTranslation(); - $items = $job->getItems(); - /** @var \Drupal\tmgmt\Entity\JobItem $item */ - $item = reset($items); + // Add translated data to the job item. + $translation['dummy']['deep_nesting']['#text'] = 'Invalid translation that will cause an exception'; + $job_item->addTranslatedData($translation); // If it was set to Auto Accept but there was an error, the Job Item should // be set as Needs Review. - $this->assertEqual($item->getState(), JobItemInterface::STATE_REVIEW); - + $this->assertEqual($job_item->getState(), JobItemInterface::STATE_REVIEW); + // There should be a message if auto accept has failed. $messages = $job->getMessages(); $last_message = end($messages); $this->assertEqual('Failed to automatically accept translation, error: @error', $last_message->message->value); diff -u b/tmgmt_test/src/Plugin/tmgmt/Source/TestSource.php b/tmgmt_test/src/Plugin/tmgmt/Source/TestSource.php --- b/tmgmt_test/src/Plugin/tmgmt/Source/TestSource.php +++ b/tmgmt_test/src/Plugin/tmgmt/Source/TestSource.php @@ -101,7 +101,7 @@ public function saveTranslation(JobItemInterface $job_item, $target_langcode) { // Set a variable that can be checked later for a given job item. $data = $job_item->getData(); - if (isset($data['dummy']['deep_nesting']['#text']) && $data['dummy']['deep_nesting']['#text'] == 'Invalid translation that will cause an exception') { + if (isset($data['dummy']['deep_nesting']['#translation']['#text']) && $data['dummy']['deep_nesting']['#translation']['#text'] == 'Invalid translation that will cause an exception') { throw new \Exception('The translation cannot be saved.'); } \Drupal::state()->set('tmgmt_test_saved_translation_' . $job_item->getItemType() . '_' . $job_item->getItemId(), $job_item->getData());