View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekViewsFunctionalTests extends LingotekTestBase {
protected $defaultTheme = 'classy';
public static $modules = [
'block',
'node',
'views',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$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();
\Drupal::getContainer()
->get('module_installer')
->install([
'lingotek_views_test',
], TRUE);
}
public function testNodeWithMetadataView() {
$this
->drupalGet('lingotek/views/node_and_lingotek_metadata');
$this
->assertSession()
->elementTextContains('css', 'h1.page-title', 'Node view with metadata relationship');
$this
->assertSession()
->elementExists('css', '.view-node-and-lingotek-metadata');
$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('lingotek/views/node_and_lingotek_metadata');
$this
->assertSession()
->elementExists('css', '.view-node-and-lingotek-metadata');
$this
->assertLink('Llamas are cool');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$this
->assertLink('Manual');
$this
->saveAndKeepPublishedNodeForm([
'lingotek_translation_management[lingotek_translation_profile]' => 'automatic',
], 1);
$this
->drupalGet('lingotek/views/node_and_lingotek_metadata');
$this
->assertSession()
->elementExists('css', '.view-node-and-lingotek-metadata');
$this
->assertLink('Llamas are cool');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-status-value', 'ES');
$this
->assertLink('Automatic');
}
public function testMetadataView() {
$this
->drupalGet('lingotek/views/lingotek_metadata');
$this
->assertSession()
->elementTextContains('css', 'h1.page-title', 'Lingotek Metadata view');
$this
->assertSession()
->elementExists('css', '.view-lingotek-metadata');
$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('lingotek/views/lingotek_metadata');
$this
->assertSession()
->elementExists('css', '.view-lingotek-metadata');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$this
->assertLink('Manual');
$this
->saveAndKeepPublishedNodeForm([
'lingotek_translation_management[lingotek_translation_profile]' => 'automatic',
], 1);
$this
->drupalGet('lingotek/views/lingotek_metadata');
$this
->assertSession()
->elementExists('css', '.view-lingotek-metadata');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$this
->assertSession()
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$this
->assertSession()
->elementTextContains('css', 'td.views-field-translation-status-value', 'ES');
$this
->assertLink('Automatic');
}
}