You are here

public function SmartlingTest::testUploadXlfChangeToXmlDownloadXlf in TMGMT Translator Smartling 8

Test uploading/downloading xlf file: rely on file name in tmgmt_job.

File

src/Tests/SmartlingTest.php, line 526
Contains \Drupal\tmgmt_smartling\Tests\SmartlingTest.

Class

SmartlingTest
Basic tests for the Smartling translator.

Namespace

Drupal\tmgmt_smartling\Tests

Code

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.");
  }
}