You are here

public function CrudTest::testPreliminaryState in Translation Management Tool 8

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
    ->assertEqual($item
    ->getData($key)['#status'], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
  $this
    ->assertTrue($item
    ->isActive());

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

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