View source
<?php
namespace Drupal\Tests\tmgmt_smartling\Functional;
class PushBackControllerTest extends SmartlingTestBase {
public function testPushBackNonExistingJob() {
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("tmgmt-smartling-callback/100500", [
'query' => [
'fileUri' => $fileName,
'locale' => 'fr-FR',
],
]);
$this
->assertResponse(404);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testPushBackExistingJobWithoutLocaleAndFileUri() {
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("tmgmt-smartling-callback/{$job->id()}");
$this
->assertResponse(404);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testPushBackExistingJobWithoutLocale() {
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("tmgmt-smartling-callback/{$job->id()}", [
'query' => [
'fileUri' => $fileName,
],
]);
$this
->assertResponse(404);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testPushBackExistingJobWithoutFileUri() {
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("tmgmt-smartling-callback/{$job->id()}", [
'query' => [
'locale' => 'fr-FR',
],
]);
$this
->assertResponse(404);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testPushBackExistingJobWithParameters() {
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
->drupalGet("tmgmt-smartling-callback/{$job->id()}", [
'query' => [
'fileUri' => $fileName,
'locale' => 'fr-FR',
],
]);
$this
->assertResponse(200);
$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 testUseCallbackUrlDoNotOverrideHost() {
if (!empty($this->smartlingPluginProviderSettings)) {
global $base_url;
$providerSettings = $this->smartlingPluginProviderSettings;
$providerSettings['settings[callback_url_use]'] = TRUE;
$providerSettings['settings[callback_url_host]'] = '';
$translator = $this
->setUpSmartlingProviderSettings($providerSettings);
$job = $this
->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
$translatorPlugin = $job
->getTranslatorPlugin();
$callbackUrl = $this
->invokeMethod($translatorPlugin, 'getCallbackUrl', [
$job,
]);
$this
->assertTrue($base_url . '/tmgmt-smartling-callback/1', $callbackUrl);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testUseCallbackUrlOverrideHost() {
if (!empty($this->smartlingPluginProviderSettings)) {
global $base_url;
$testHost = 'https://example.com';
$providerSettings = $this->smartlingPluginProviderSettings;
$providerSettings['settings[callback_url_use]'] = TRUE;
$providerSettings['settings[callback_url_host]'] = $testHost;
$translator = $this
->setUpSmartlingProviderSettings($providerSettings);
$job = $this
->requestTranslationForNode($this->testNodeId, $this->targetLanguage, $translator);
$translatorPlugin = $job
->getTranslatorPlugin();
$callbackUrl = $this
->invokeMethod($translatorPlugin, 'getCallbackUrl', [
$job,
]);
$this
->assertNotEqual($base_url, $testHost);
$this
->assertTrue($testHost . '/tmgmt-smartling-callback/1', $callbackUrl);
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
}