You are here

function TMGMTUiTest::testCheckoutFunction in Translation Management Tool 8

Tests the tmgmt_job_checkout() function.

File

tests/src/Functional/TMGMTUiTest.php, line 375

Class

TMGMTUiTest
Verifies basic functionality of the user interface

Namespace

Drupal\Tests\tmgmt\Functional

Code

function testCheckoutFunction() {
  $job = $this
    ->createJob();

  /** @var \Drupal\tmgmt\JobCheckoutManager $job_checkout_manager */
  $job_checkout_manager = \Drupal::service('tmgmt.job_checkout_manager');

  // Check out a job when only the test translator is available. That one has
  // settings, so a checkout is necessary.
  $jobs = $job_checkout_manager
    ->checkoutMultiple(array(
    $job,
  ));
  $this
    ->assertEqual($job
    ->id(), $jobs[0]
    ->id());
  $this
    ->assertTrue($job
    ->isUnprocessed());
  $job
    ->delete();

  // Hide settings on the test translator.
  $default_translator = Translator::load('test_translator');
  $default_translator
    ->setSetting('expose_settings', FALSE)
    ->save();

  // Create a job but do not save yet, to simulate how this works in the UI.
  $job = tmgmt_job_create('en', 'de', 0, []);
  $jobs = $job_checkout_manager
    ->checkoutMultiple(array(
    $job,
  ));
  $this
    ->assertEmpty($jobs);
  $this
    ->assertTrue($job
    ->isActive());

  // A job without target (not specified) language needs to be checked out.
  $job = $this
    ->createJob('en', LanguageInterface::LANGCODE_NOT_SPECIFIED);
  $jobs = $job_checkout_manager
    ->checkoutMultiple(array(
    $job,
  ));
  $this
    ->assertEqual($job
    ->id(), $jobs[0]
    ->id());
  $this
    ->assertTrue($job
    ->isUnprocessed());

  // Create a second file translator. This should check
  // out immediately.
  $job = $this
    ->createJob();
  $second_translator = $this
    ->createTranslator();
  $second_translator
    ->setSetting('expose_settings', FALSE)
    ->save();
  $jobs = $job_checkout_manager
    ->checkoutMultiple(array(
    $job,
  ));
  $this
    ->assertEqual($job
    ->id(), $jobs[0]
    ->id());
  $this
    ->assertTrue($job
    ->isUnprocessed());
}