View source
<?php
namespace Drupal\Tests\tmgmt_smartling\Functional;
use Drupal\tmgmt\Entity\Job;
use Drupal\tmgmt\JobInterface;
class BaseFlowTest extends SmartlingTestBase {
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);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertText($this->testNodeTitle);
$this
->downloadAndCheckTranslatedFile($job
->id(), $fileName);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertNoText($this->testNodeTitle);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
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);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertText($this->testNodeTitle);
$translator
->setSetting('export_format', 'xlf');
$translator
->save();
$this
->downloadAndCheckTranslatedFile($job
->id(), $fileName);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertNoText($this->testNodeTitle);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
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, $providerSettings['settings[export_format]']);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertText($this->testNodeTitle);
$translator
->setSetting('export_format', 'xml');
$translator
->save();
$this
->downloadAndCheckTranslatedFile($job
->id(), $fileName);
$this
->drupalGet("{$this->targetLanguage}/node/{$this->testNodeId}");
$this
->assertResponse(200);
$this
->assertNoText($this->testNodeTitle);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testRequestTranslationWhenOneProviderAvailable() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this
->drupalPostForm('/admin/tmgmt/translators/manage/smartling', $this->smartlingPluginProviderSettings, t('Save'));
$this
->drupalPostForm('/admin/tmgmt/translators/manage/local/delete', [], t('Delete'));
$this
->drupalPostForm('/admin/tmgmt/translators/manage/file/delete', [], t('Delete'));
$this
->drupalPostForm('/admin/tmgmt/translators/manage/test_translator/delete', [], t('Delete'));
$this
->drupalPostForm('/admin/tmgmt/sources', [
'items[1]' => 1,
'target_language' => 'de',
], t('Request translation'));
$this
->assertText('One job needs to be checked out.');
$this
->assertText('Create new job');
$this
->assertText('Add to job');
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testJobRejectionOnFileNotFoundExceptionWhileCheckingStatus() {
if (!empty($this->smartlingPluginProviderSettings)) {
$translator = $this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$job = $this
->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
$this
->assertEqual($job
->getState(), JobInterface::STATE_ACTIVE);
$job->job_file_name = uniqid() . '_tmgmt_smartling_test_file_name.xml';
$job
->save();
$job
->getTranslatorPlugin()
->isReadyForDownload($job);
$job = Job::load($job
->id());
$this
->assertEqual($job
->getState(), JobInterface::STATE_REJECTED);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testJobRejectionOnLocaleNotFoundExceptionWhileCheckingStatus() {
if (!empty($this->smartlingPluginProviderSettings)) {
$translator = $this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$translator
->set('remoteLanguages', [
'af-ZA' => 'af-ZA',
]);
$translator
->set('remote_languages_mappings', [
'fr' => 'af-ZA',
]);
$translator
->save();
$job = $this
->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
$this
->assertEqual($job
->getState(), JobInterface::STATE_ACTIVE);
$job
->getTranslatorPlugin()
->isReadyForDownload($job);
$job = Job::load($job
->id());
$this
->assertEqual($job
->getState(), JobInterface::STATE_REJECTED);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testJobRejectionOnLocaleDisabledExceptionWhileCheckingStatus() {
if (!empty($this->smartlingPluginProviderSettings)) {
$translator = $this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$translator
->set('remoteLanguages', [
'fr-CA' => 'fr-CA',
]);
$translator
->set('remote_languages_mappings', [
'fr' => 'fr-CA',
]);
$translator
->save();
$job = $this
->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
$this
->assertEqual($job
->getState(), JobInterface::STATE_ACTIVE);
$job
->getTranslatorPlugin()
->isReadyForDownload($job);
$job = Job::load($job
->id());
$this
->assertEqual($job
->getState(), JobInterface::STATE_REJECTED);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
}