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 LingotekNodeBulkDebugTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
protected $node;
protected function setUp() {
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::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 testDebugOptionsDisplay() {
$this
->drupalLogin($this->rootUser);
$this
->goToContentBulkManagementForm();
$this
->assertFalse($this
->xpath('//select[@id=:id]//optgroup[@label=:label]', array(
':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
->assertTrue($this
->xpath('//select[@id=:id]//optgroup[@label=:label]', array(
':id' => 'edit-operation',
':label' => 'debug',
)), 'There is a debug group.');
$this
->assertTrue($this
->xpath('//select[@id=:id]//option[@value=:value]', array(
':id' => 'edit-operation',
':value' => 'debug.export',
)), 'There is a debug export option.');
}
public function testDebugExport() {
$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
->drupalGet('admin/lingotek/settings');
$this
->drupalPostForm(NULL, [], t('Enable debug operations'));
$this
->goToContentBulkManagementForm();
$edit = [
'table[1]' => TRUE,
'operation' => 'debug.export',
];
$this
->drupalPostForm(NULL, $edit, t('Execute'));
$this
->assertText('Exports available');
$this
->clickLink('node.article.1.json');
$response = json_decode($this->content, 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']);
}
}