You are here

BaseFlowTest.php in TMGMT Translator Smartling 8.2

File

src/Tests/BaseFlowTest.php
View source
<?php

namespace Drupal\tmgmt_smartling\Tests;


/**
 * Basic flow tests.
 *
 * @group tmgmt_smartling
 */
class BaseFlowTest extends SmartlingTestBase {

  /**
   * Test upload and download translation.
   */
  public function testUploadFileAndDownloadTranslation() {
    if (!empty($this->smartlingPluginProviderSettings)) {
      $translator = $this
        ->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
      $job = $this
        ->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
      $fileName = $job
        ->getTranslatorPlugin()
        ->getFileName($job);
      $this
        ->checkGeneratedFile($fileName, $this->testNodeTitle);

      // Check fr node title before translation (should be same as en title).
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertText($this->testNodeTitle);

      // Download translated file.
      $this
        ->downloadAndCheckTranslatedFile($job
        ->id(), $fileName);

      // Check translation.
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertNoText($this->testNodeTitle);
      $this
        ->deleteTestFile($fileName);
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

  /**
   * Test uploading/downloading xml file: rely on file name in tmgmt_job.
   */
  public function testUploadXmlChangeToXlfDownloadXml() {
    if (!empty($this->smartlingPluginProviderSettings)) {
      $translator = $this
        ->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
      $job = $this
        ->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
      $fileName = $job
        ->getTranslatorPlugin()
        ->getFileName($job);
      $this
        ->checkGeneratedFile($fileName, $this->testNodeTitle);

      // Check fr node title before translation (should be same as en title).
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertText($this->testNodeTitle);

      // Change export format to xlf and download translated file.
      $translator
        ->setSetting('export_format', 'xlf');
      $translator
        ->save();
      $this
        ->downloadAndCheckTranslatedFile($job
        ->id(), $fileName);

      // Check translation.
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertNoText($this->testNodeTitle);
      $this
        ->deleteTestFile($fileName);
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

  /**
   * Test uploading/downloading xlf file: rely on file name in tmgmt_job.
   */
  public function testUploadXlfChangeToXmlDownloadXlf() {
    if (!empty($this->smartlingPluginProviderSettings)) {
      $providerSettings = $this->smartlingPluginProviderSettings;
      $providerSettings['settings[export_format]'] = 'xlf';
      $translator = $this
        ->setUpSmartlingProviderSettings($providerSettings);
      $job = $this
        ->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
      $fileName = $job
        ->getTranslatorPlugin()
        ->getFileName($job);
      $this
        ->checkGeneratedFile($fileName, $this->testNodeTitle);

      // Check fr node title before translation (should be same as en title).
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertText($this->testNodeTitle);

      // Change export format to xml and download translated file.
      $translator
        ->setSetting('export_format', 'xml');
      $translator
        ->save();
      $this
        ->downloadAndCheckTranslatedFile($job
        ->id(), $fileName);

      // Check translation.
      $this
        ->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
      $this
        ->assertResponse(200);
      $this
        ->assertNoText($this->testNodeTitle);
      $this
        ->deleteTestFile($fileName);
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

  /**
   * Test revision inflation.
   */
  public function testRevisionInflation() {
    if (!empty($this->smartlingPluginProviderSettings)) {
      $providerSettings = $this->smartlingPluginProviderSettings;
      $translator = $this
        ->setUpSmartlingProviderSettings($providerSettings);
      $job = $this
        ->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
      $this
        ->drupalGet("/admin/tmgmt/jobs/1");
      $this
        ->assertResponse(200);
      $this
        ->assertNoText("has been accepted as");
      $this
        ->assertNoText("Import of downloaded file was skipped: downloaded and existing translations are equal.");
      $job
        ->getTranslatorPlugin()
        ->downloadTranslation($job);
      $this
        ->drupalGet("/admin/tmgmt/jobs/1");
      $this
        ->assertResponse(200);
      $this
        ->assertText("has been accepted as");
      $this
        ->assertNoText("Import of downloaded file was skipped: downloaded and existing translations are equal.");
      $job
        ->getTranslatorPlugin()
        ->downloadTranslation($job);
      $this
        ->drupalGet("/admin/tmgmt/jobs/1");
      $this
        ->assertResponse(200);
      $this
        ->assertText("Import of downloaded file was skipped: downloaded and existing translations are equal.");
      $this
        ->deleteTestFile($job
        ->getTranslatorPlugin()
        ->getFileName($job));
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

}

Classes

Namesort descending Description
BaseFlowTest Basic flow tests.