You are here

public function LoggingTest::testRequestTranslationEventLogging in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/LoggingTest.php \Drupal\Tests\tmgmt_smartling\Functional\LoggingTest::testRequestTranslationEventLogging()

Test request translation logging.

File

tests/src/Functional/LoggingTest.php, line 60

Class

LoggingTest
Logging tests.

Namespace

Drupal\Tests\tmgmt_smartling\Functional

Code

public function testRequestTranslationEventLogging() {
  if (!empty($this->smartlingPluginProviderSettings)) {
    $this
      ->drupalPostForm('/admin/tmgmt/sources', [
      'items[1]' => 1,
    ], t('Request translation'));
    $this
      ->drupalPostForm(NULL, [
      'target_language' => 'de',
      'settings[create_new_job_tab][name]' => 'Drupal TMGMT connector test ' . mt_rand(),
      'settings[create_new_job_tab][due_date][date]' => '2020-12-12',
      'settings[create_new_job_tab][due_date][time]' => '12:12:12',
      'settings[create_new_job_tab][authorize]' => TRUE,
      'settings[smartling_users_time_zone]' => 'Europe/Kiev',
    ], t('Submit to provider'));
    $this
      ->drupalGet('/admin/reports/dblog');

    // File triggered/queued.
    $this
      ->assertRaw('File upload triggered (request translation). Job id: 1, file name: JobID1_en_de.xml.');
    $this
      ->assertNoRaw('File upload queued (track entity changes). Job id: 1, file name: JobID1_en_de.xml.');

    // File uploaded.
    $this
      ->assertRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
    $this
      ->assertNoRaw('File uploaded. Job id: 2, file name: JobID2_en_fr.xml.');
    $api_wrapper = Drupal::service('tmgmt_smartling.smartling_api_wrapper');
    $api_wrapper
      ->setSettings([
      'user_id' => $this->smartlingPluginProviderSettings['settings[user_id]'],
      'project_id' => $this->smartlingPluginProviderSettings['settings[project_id]'],
      'token_secret' => $this->smartlingPluginProviderSettings['settings[token_secret]'],
    ]);
    $jobs = $api_wrapper
      ->listJobs(NULL, [
      JobStatus::AWAITING_AUTHORIZATION,
      JobStatus::IN_PROGRESS,
    ]);
    if (!empty($jobs['items'])) {
      foreach ($jobs['items'] as $job) {
        if (strpos($job['jobName'], 'Drupal TMGMT connector test') !== FALSE) {
          $api_wrapper
            ->cancelJob($job['translationJobUid']);
        }
      }
    }
  }
  else {
    $this
      ->fail("Smartling settings file for simpletests not found.");
  }
}