<?php
namespace Drupal\Tests\tmgmt_local\Functional;
use Drupal\tmgmt\Entity\Translator;
class LocalTranslatorPreviewTest extends LocalTranslatorTestBase {
protected static $modules = [
'tmgmt_content',
];
public function testPreview() {
$this
->createNodeType('article', 'Article', TRUE);
$node = $this
->createTranslatableNode('article', 'en');
$node
->setUnpublished();
$node
->save();
$translator = Translator::load('local');
$job = $this
->createJob('en', 'de');
$job->translator = $translator;
$job
->save();
$job_item = tmgmt_job_item_create('content', $node
->getEntityTypeId(), $node
->id(), array(
'tjid' => $job
->id(),
));
$job_item
->save();
$this
->loginAsAdmin($this->localManagerPermissions);
$this
->drupalGet($this->admin_user
->toUrl('edit-form'));
$edit = array(
'tmgmt_translation_skills[0][language_from]' => 'en',
'tmgmt_translation_skills[0][language_to]' => 'de',
);
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/tmgmt/jobs/' . $job
->id());
$edit = [
'settings[translator]' => $this->admin_user
->id(),
];
$this
->submitForm($edit, 'Submit to provider');
$this
->drupalGet('translate');
$this
->clickLink('View');
$this
->clickLink('Translate');
$edit = array(
'title|0|value[translation]' => $translation1 = 'German translation of title',
'body|0|value[translation][value]' => $translation2 = 'German translation of body',
);
$this
->submitForm($edit, 'Preview');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($translation1);
$this
->assertSession()
->pageTextContains($translation2);
$this
->drupalGet('translate');
$this
->clickLink('View');
$this
->clickLink('Translate');
$this
->assertSession()
->linkExists($node
->getTitle());
$this
->clickLink($node
->getTitle());
$this
->assertSession()
->pageTextContains($node
->getTitle());
$this
->drupalGet('admin/tmgmt/items/' . $job_item
->id());
$this
->assertSession()
->pageTextContains('The translations below are in preliminary state and can not be changed.');
$elements = $this
->xpath('//*[@id="edit-save-as-completed"]');
$this
->assertTrue(empty($elements), "'Save as completed' button does not appear.");
$elements = $this
->xpath('//*[@id="edit-save"]');
$this
->assertTrue(empty($elements), "'Save' button does not appear.");
$elements = $this
->xpath('//*[@id="edit-validate"]');
$this
->assertFalse(empty($elements), "'Validate' button appears.");
$elements = $this
->xpath('//*[@id="edit-validate-html"]');
$this
->assertFalse(empty($elements), "'Validate HTML tags' button appears.");
$elements = $this
->xpath('//*[@id="edit-preview"]');
$this
->assertFalse(empty($elements), "'Preview' button appears.");
$elements = $this
->xpath('//*[@id="edit-title0value-actions-finish-title0value"]');
$this
->assertTrue(empty($elements), "'✓' button does not appear.");
$this
->assertSession()
->responseContains('data-drupal-selector="edit-title0value-translation" disabled="disabled"');
}
}