View source
<?php
namespace Drupal\lingotek\Tests;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
class LingotekNodeBulkLocaleTranslationTest extends LingotekTestBase {
public static $modules = [
'node',
'comment',
];
protected $node;
protected function setUp() {
parent::setUp();
ConfigurableLanguage::create([
'id' => 'de-at',
'name' => 'German (AT)',
])
->save();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$post = [
'code' => 'es_AR',
'language' => 'Spanish',
'native' => 'Español',
'direction' => '',
];
$this
->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
$post = [
'code' => 'es_ES',
'language' => 'Spanish',
'native' => 'Español',
'direction' => '',
];
$this
->drupalPost('/admin/lingotek/dashboard_endpoint', 'application/json', $post);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
drupal_static_reset();
\Drupal::entityManager()
->clearCachedDefinitions();
\Drupal::service('entity.definition_update_manager')
->applyUpdates();
$this
->rebuildContainer();
$edit = [
'node[article][enabled]' => 1,
'node[article][profiles]' => 'automatic',
'node[article][fields][title]' => 1,
'node[article][fields][body]' => 1,
];
$this
->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
}
public function testNodeTranslationUsingLinks() {
$this
->drupalLogin($this->rootUser);
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'manual';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_AR?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_AR?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('de_AT', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_ES?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_AR?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_AR' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_AR', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/es_AR?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertText('The es_AR translation for node Llamas are cool is ready for download.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_AR?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_AR has been downloaded.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/es_AR');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/es_AR' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
$target_links = $this
->xpath("//a[contains(@class,'language-icon')]");
$this
->assertEqual(count($target_links), 3, 'The three languages appear as targets');
$this
->assertEqual('DE-AT', (string) $target_links[0], 'DE-AT is the first language');
$this
->assertEqual('ES', (string) $target_links[1], 'ES is the second language');
$this
->assertEqual('ES-ES', (string) $target_links[2], 'ES-ES is the third language');
}
public function testSourceUpdatedAfterRequestingTranslation() {
$this
->drupalLogin($this->rootUser);
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'automatic';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('DE-AT');
$this
->assertText("Locale 'de_AT' was added as a translation target for node Llamas are cool.");
$this
->assertNoLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
}
}