public function CrudTest::testPreliminaryState

Tests that with the preliminary state the item does not change.

File

tests/src/Kernel/CrudTest.php, line 637

Class

CrudTest
Basic crud operations for jobs and translators

Namespace

Drupal\Tests\tmgmt\Kernel

Code

public function testPreliminaryState() {
  $translator = $this
    ->createTranslator();
  $job = $this
    ->createJob();
  $job->translator = $translator
    ->id();
  $job
    ->save();

  // Add some test items.
  $item = $job
    ->addItem('test_source', 'test', 1);
  $key = array(
    'dummy',
    'deep_nesting',
  );

  // Test with preliminary state.
  $translation['dummy']['deep_nesting']['#text'] = 'translated';
  $item
    ->addTranslatedData($translation, [], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
  $this
    ->assertEquals(TMGMT_DATA_ITEM_STATE_PRELIMINARY, $item
    ->getData($key)['#status']);
  $this
    ->assertTrue($item
    ->isActive());

  // Test with empty state.
  $item
    ->addTranslatedData($translation);
  $this
    ->assertEquals(TMGMT_DATA_ITEM_STATE_PRELIMINARY, $item
    ->getData($key)['#status']);
  $this
    ->assertTrue($item
    ->isActive());

  // Test without state.
  $item
    ->addTranslatedData($translation, [], TMGMT_DATA_ITEM_STATE_TRANSLATED);
  $this
    ->assertEquals(TMGMT_DATA_ITEM_STATE_TRANSLATED, $item
    ->getData($key)['#status']);
  $this
    ->assertTrue($item
    ->isNeedsReview());
}