You are here

protected function SmartlingTestBase::requestTranslationForNode in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/SmartlingTestBase.php \Drupal\Tests\tmgmt_smartling\Functional\SmartlingTestBase::requestTranslationForNode()

Requests translation for a given node.

Parameters

$nid:

$language:

$translator:

Return value

\Drupal\tmgmt\JobInterface

25 calls to SmartlingTestBase::requestTranslationForNode()
BaseFlowTest::testJobRejectionOnFileNotFoundExceptionWhileCheckingStatus in tests/src/Functional/BaseFlowTest.php
Test job rejection on "file.not.found" exception while checking status.
BaseFlowTest::testJobRejectionOnLocaleDisabledExceptionWhileCheckingStatus in tests/src/Functional/BaseFlowTest.php
Test job rejection on "locale.disabled" exception while checking status.
BaseFlowTest::testJobRejectionOnLocaleNotFoundExceptionWhileCheckingStatus in tests/src/Functional/BaseFlowTest.php
Test job rejection on "locale.not.found" exception while checking status.
BaseFlowTest::testUploadFileAndDownloadTranslation in tests/src/Functional/BaseFlowTest.php
Test upload and download translation.
BaseFlowTest::testUploadXlfChangeToXmlDownloadXlf in tests/src/Functional/BaseFlowTest.php
Test uploading/downloading xlf file: rely on file name in tmgmt_job.

... See full list

File

tests/src/Functional/SmartlingTestBase.php, line 186

Class

SmartlingTestBase
Basic tests for the Smartling translator.

Namespace

Drupal\Tests\tmgmt_smartling\Functional

Code

protected function requestTranslationForNode($nid, $language, $translator) {
  if (!is_array($nid)) {
    $nid = [
      $nid,
    ];
  }
  $api_wrapper = $translator
    ->getPlugin()
    ->getApiWrapper($translator
    ->getSettings());
  $job_id = $api_wrapper
    ->createJob('Drupal TMGMT connector test ' . mt_rand(), '');
  $batch_uid = $api_wrapper
    ->createBatch($job_id, FALSE);
  $job = $this
    ->createJob($this->sourceLanguage, $language, 1, [
    'label' => 'Job for ' . implode(', ', $nid),
    'job_type' => Job::TYPE_NORMAL,
  ]);
  $job
    ->set('settings', [
    'batch_uid' => $batch_uid,
    'batch_execute_on_job' => $job
      ->id(),
  ]);
  $job->translator = $translator;
  foreach ($nid as $item) {
    $job
      ->addItem('content', 'node', $item);
  }
  $job
    ->setState(JobInterface::STATE_ACTIVE);
  $job
    ->requestTranslation();
  $api_wrapper
    ->cancelJob($job_id);
  return $job;
}