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\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekTaxonomyTermTranslationTest extends LingotekTestBase {
use TaxonomyTestTrait;
public static $modules = [
'block',
'taxonomy',
];
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');
}
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 translation of taxonomy_term Llamas are cool into es_ES has been downloaded.');
$this
->clickLink('Las llamas son chulas');
$this
->assertText('Las llamas son chulas');
$this
->assertText('Las llamas son muy chulas');
}
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 translation of taxonomy_term Llamas are cool into es_ES has been downloaded.');
$this
->clickLink('Las llamas son chulas');
$this
->assertText('Las llamas son chulas');
$this
->assertText('Las llamas son muy chulas');
}
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 translation of taxonomy_term Llamas are cool into es_ES has been downloaded.');
$this
->clickLink('Las llamas son chulas');
$this
->assertText('Las llamas son chulas');
$this
->assertText('Las llamas son muy chulas');
}
}