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 LingotekNodeExistingBulkTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected $node;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->rootUser);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
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();
$node = Node::load(1);
$node
->addTranslation('es', [
'title' => 'Llamas are cool ES',
'body' => 'Llamas are very cool ES',
]);
$node
->save();
$this
->drupalGet('node/1/translations');
$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 testNodeIsUntracked() {
$this
->goToContentBulkManagementForm();
$basepath = \Drupal::request()
->getBasePath();
$untracked = $this
->xpath("//span[contains(@class,'language-icon') and contains(@class, 'target-untracked') and contains(., 'ES')]");
$this
->assertEqual(count($untracked), 1, 'Untracked translation is shown.');
$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_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$untracked = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-untracked') and contains(text(), 'ES')]");
$this
->assertEqual(count($untracked), 1, 'Untracked translation is shown.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX?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/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_MX translation for node Llamas are cool is ready for download.');
$this
->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/es_MX?destination=' . $basepath . '/admin/lingotek/manage/node');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_MX has been downloaded.');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/es_MX');
$workbench_link = $this
->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/es_MX' and @target='_blank']");
$this
->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}
}