View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\Node;
class LingotekNodeBulkDebugTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
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::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
}
public function testDebugOptionsDisplay() {
$this
->drupalLogin($this->rootUser);
$this
->goToContentBulkManagementForm();
$this
->assertEmpty($this
->xpath('//select[@id=:id]//optgroup[@label=:label]', [
':id' => 'edit-operation',
':label' => 'debug',
]), 'There is no debug group.');
$this
->drupalGet('admin/lingotek/settings');
$this
->drupalPostForm(NULL, [], t('Enable debug operations'));
$this
->goToContentBulkManagementForm();
$this
->assertNotEmpty($this
->xpath('//select[@id=:id]//optgroup[@label=:label]', [
':id' => 'edit-operation',
':label' => 'debug',
]), 'There is a debug group.');
$this
->assertNotEmpty($this
->xpath('//select[@id=:id]//option[@value=:value]', [
':id' => 'edit-operation',
':value' => 'debug.export',
]), 'There is a debug export option.');
}
public function testDebugExport() {
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->drupalGet('admin/lingotek/settings');
$this
->drupalPostForm(NULL, [], t('Enable debug operations'));
$this
->goToContentBulkManagementForm();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'debug.export',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('Exports available');
$this
->clickLink('node.article.1.json');
$response = json_decode($this
->getSession()
->getPage()
->getContent(), TRUE);
$this
->assertIdentical('Llamas are cool', $response['title'][0]['value']);
$this
->assertIdentical('Llamas are very cool', $response['body'][0]['value']);
$this
->assertIdentical('article (node): Llamas are cool', $response['_debug']['title']);
$this
->assertIdentical('manual', $response['_debug']['profile']);
$this
->assertIdentical('en_US', $response['_debug']['source_locale']);
}
public function testDebugExportError() {
$this
->drupalLogin($this->rootUser);
$node = Node::create([
'title' => 'Llamas are cool',
'type' => 'article',
]);
$node
->save();
$translation_service = \Drupal::service('lingotek.content_translation');
$translation_service
->deleteMetadata($node);
$this
->drupalGet('admin/lingotek/settings');
$this
->drupalPostForm(NULL, [], t('Enable debug operations'));
$this
->goToContentBulkManagementForm();
$key = $this
->getBulkSelectionKey('en', 1);
$edit = [
$key => TRUE,
$this
->getBulkOperationFormName() => 'debug.export',
];
$this
->drupalPostForm(NULL, $edit, $this
->getApplyActionsButtonLabel());
$this
->assertText('The Article Llamas are cool has no profile assigned so it was not processed.');
$this
->assertNoText('Exports available');
}
}