View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
class LingotekTaxonomyTermLongTitleTranslationTest extends LingotekTestBase {
use TaxonomyTestTrait;
public static $modules = [
'block',
'taxonomy',
];
protected $vocabulary;
protected $term;
protected function setUp() {
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);
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$bundle = $this->vocabulary
->id();
$edit = [
"taxonomy_term[{$bundle}][enabled]" => 1,
"taxonomy_term[{$bundle}][profiles]" => 'automatic',
"taxonomy_term[{$bundle}][fields][name]" => 1,
"taxonomy_term[{$bundle}][fields][description]" => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
\Drupal::state()
->set('lingotek.uploaded_content_type', 'taxonomy_term_long_title');
}
public function testTermTranslation() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$edit = array();
$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 value: name.');
}
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 value: name.');
}
public function testTermTranslationViaAPIWithManualUpload() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$edit = [
"taxonomy_term[{$bundle}][enabled]" => 1,
"taxonomy_term[{$bundle}][profiles]" => 'manual',
"taxonomy_term[{$bundle}][fields][name]" => 1,
"taxonomy_term[{$bundle}][fields][description]" => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
$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
->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 value: name.');
}
public function testBulkTermTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$bundle = $this->vocabulary
->id();
$edit = [
"taxonomy_term[{$bundle}][enabled]" => 1,
"taxonomy_term[{$bundle}][profiles]" => 'manual',
"taxonomy_term[{$bundle}][fields][name]" => 1,
"taxonomy_term[{$bundle}][fields][description]" => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
$edit = array();
$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');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/taxonomy_term/1?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/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
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$this
->clickLink('EN');
$this
->assertText('The import for taxonomy_term Llamas are cool is complete.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/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
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/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
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$this
->clickLink('ES');
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation value: name.');
}
public function testBulkTermTranslationUsingActions() {
$this
->drupalLogin($this->rootUser);
ConfigurableLanguage::createFromLangcode('de')
->setThirdPartySetting('lingotek', 'locale', 'de_AT')
->save();
$bundle = $this->vocabulary
->id();
$edit = [
"taxonomy_term[{$bundle}][enabled]" => 1,
"taxonomy_term[{$bundle}][profiles]" => 'manual',
"taxonomy_term[{$bundle}][fields][name]" => 1,
"taxonomy_term[{$bundle}][fields][description]" => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
$edit = array();
$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');
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/taxonomy_term/1?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$edit = [
'table[1]' => TRUE,
'operation' => 'upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$edit = [
'table[1]' => TRUE,
'operation' => 'check_upload',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$edit = [
'table[1]' => TRUE,
'operation' => 'request_translation:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$edit = [
'table[1]' => TRUE,
'operation' => 'check_translation:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
$edit = [
'table[1]' => TRUE,
'operation' => 'download:de',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation value: name.');
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.downloaded_locale'));
}
}