View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\taxonomy\Entity\Term;
use Drupal\lingotek\Lingotek;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekTaxonomyTermLongTitleTranslationTest extends LingotekTestBase {
use TaxonomyTestTrait;
public static $modules = [
'block',
'taxonomy',
'dblog',
];
protected $vocabulary;
protected $term;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('page_title_block');
$this->vocabulary = $this
->createVocabulary();
ConfigurableLanguage::createFromLangcode('es')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $this->vocabulary
->id())
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('taxonomy_term', $this->vocabulary
->id(), TRUE);
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$bundle = $this->vocabulary
->id();
$this
->saveLingotekContentTranslationSettings([
'taxonomy_term' => [
$bundle => [
'profiles' => 'automatic',
'fields' => [
'name' => 1,
'description' => 1,
],
],
],
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'taxonomy_term_long_title');
}
public function testTermTranslation() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['description[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$this
->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
$this->term = Term::load(1);
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertTrue(isset($data['name'][0]['value']));
$this
->assertEqual(1, count($data['description'][0]));
$this
->assertTrue(isset($data['description'][0]['value']));
$this
->drupalGet('taxonomy/term/1');
$this
->clickLink('Translate');
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->clickLink('Request translation');
$this
->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");
$this
->clickLink('Check translation status');
$this
->assertText('The es_ES translation for taxonomy_term Llamas are cool is ready for download.');
$this
->clickLink('Download completed translation');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('ES', 'error');
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
->getTargetStatus($this->term, 'es'));
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
}
public function testTermTranslationViaAPIWithAutomatedUpload() {
$this
->drupalLogin($this->rootUser);
$this->term = Term::create([
'name' => 'Llamas are cool',
'description' => 'Llamas are very cool',
'langcode' => 'en',
'vid' => $this->vocabulary
->id(),
]);
$this->term
->save();
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertTrue(isset($data['name'][0]['value']));
$this
->assertEqual(1, count($data['description'][0]));
$this
->assertTrue(isset($data['description'][0]['value']));
$this
->drupalGet('taxonomy/term/1');
$this
->clickLink('Translate');
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->clickLink('Request translation');
$this
->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");
$this
->clickLink('Check translation status');
$this
->assertText('The es_ES translation for taxonomy_term Llamas are cool is ready for download.');
$this
->clickLink('Download completed translation');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('ES', 'error');
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
->getTargetStatus($this->term, 'es'));
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
}
public function testTermTranslationViaAPIWithManualUpload() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$this
->saveLingotekContentTranslationSettings([
'taxonomy_term' => [
$bundle => [
'profiles' => 'manual',
'fields' => [
'name' => 1,
'description' => 1,
],
],
],
]);
$this->term = Term::create([
'name' => 'Llamas are cool',
'description' => 'Llamas are very cool',
'langcode' => 'en',
'vid' => $this->vocabulary
->id(),
]);
$this->term
->save();
$this
->drupalGet('taxonomy/term/1');
$this
->clickLink('Translate');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Uploaded 1 document to Lingotek.');
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertTrue(isset($data['name'][0]['value']));
$this
->assertEqual(1, count($data['description'][0]));
$this
->assertTrue(isset($data['description'][0]['value']));
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->clickLink('Request translation');
$this
->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");
$this
->clickLink('Check translation status');
$this
->assertText('The es_ES translation for taxonomy_term Llamas are cool is ready for download.');
$this
->clickLink('Download completed translation');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('ES', 'error');
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
->getTargetStatus($this->term, 'es'));
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
}
public function testBulkTermTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$this
->saveLingotekContentTranslationSettings([
'taxonomy_term' => [
$bundle => [
'profiles' => 'manual',
'fields' => [
'name' => 1,
'description' => 1,
],
],
],
]);
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['description[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$this
->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertLingotekUploadLink(1, 'taxonomy_term');
$this
->assertNoLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
$this
->clickLink('EN');
$this
->assertText('Taxonomy_term Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'taxonomy_term');
$this
->assertLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
$this
->clickLink('EN');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_ES' was added as a translation target for taxonomy_term Llamas are cool.");
$this
->assertIdentical('es_ES', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
$this
->clickLink('ES');
$this
->assertIdentical('es_ES', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_ES translation for taxonomy_term Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_ES', 'dummy-document-hash-id', 'taxonomy_term');
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('ES', 'error');
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
->getTargetStatus($this->term, 'es'));
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (es_ES) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
}
public function testBulkTermTranslationUsingActions() {
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$bundle = $this->vocabulary
->id();
$this
->saveLingotekContentTranslationSettings([
'taxonomy_term' => [
$bundle => [
'profiles' => 'manual',
'fields' => [
'name' => 1,
'description' => 1,
],
],
],
]);
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['description[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$this
->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertLingotekUploadLink(1, 'taxonomy_term');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForUpload('taxonomy_term'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLingotekCheckSourceStatusLink('dummy-document-hash-id', 'taxonomy_term');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForCheckUpload('taxonomy_term'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertLingotekRequestTranslationLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => $this
->getBulkOperationNameForRequestTranslation('de', 'taxonomy_term'),
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'check_translation:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertLingotekDownloadTargetLink('de_AT', 'dummy-document-hash-id', 'taxonomy_term');
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'download:de',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.');
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('DE', Lingotek::STATUS_ERROR);
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_ERROR, $content_translation_service
->getTargetStatus($this->term, 'de'));
$this
->clickLink('DE');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.');
$status = (bool) \Drupal::database()
->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [
':message' => "The download for taxonomy_term Llamas are cool failed because of the length of one field translation (de_AT) value: name.",
]);
$this
->assert($status, 'A watchdog message was logged for the length of the field.');
}
public function testTermTranslationWithUTF8MultiByteChars() {
\Drupal::state()
->set('lingotek.uploaded_content_type', 'taxonomy_term_long_title_he');
ConfigurableLanguage::createFromLangcode('he')
->setThirdPartySetting('lingotek', 'locale', 'he_IL')
->save();
ConfigurableLanguage::load('es')
->delete();
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$edit = [];
$edit['name[0][value]'] = 'Llamas are cool';
$edit['description[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$this
->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
$this->term = Term::load(1);
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertTrue(isset($data['name'][0]['value']));
$this
->assertEqual(1, count($data['description'][0]));
$this
->assertTrue(isset($data['description'][0]['value']));
$this
->drupalGet('taxonomy/term/1');
$this
->clickLink('Translate');
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->clickLink('Request translation');
$this
->assertText("Locale 'he_IL' was added as a translation target for taxonomy_term Llamas are cool.");
$this
->clickLink('Check translation status');
$this
->assertText('The he_IL translation for taxonomy_term Llamas are cool is ready for download.');
$this
->clickLink('Download completed translation');
$this
->assertText('The translation of taxonomy_term Llamas are cool into he_IL has been downloaded.');
$this
->goToContentBulkManagementForm('taxonomy_term');
$this
->assertTargetStatus('HE', 'current');
$this->term = Term::load(1);
$content_translation_service = \Drupal::service('lingotek.content_translation');
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
->getTargetStatus($this->term, 'he'));
}
}