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() : void {
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() {
$assert_session = $this
->assertSession();
$this
->drupalGet('lingotek/views/node_and_lingotek_metadata');
$assert_session
->elementTextContains('css', 'h1.page-title', 'Node view with metadata relationship');
$assert_session
->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');
$assert_session
->elementExists('css', '.view-node-and-lingotek-metadata');
$assert_session
->linkExists('Llamas are cool');
$assert_session
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$assert_session
->elementTextNotContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$assert_session
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$assert_session
->linkExists('Manual');
$this
->saveAndKeepPublishedNodeForm([
'lingotek_translation_management[lingotek_translation_profile]' => 'automatic',
], 1);
$this
->drupalGet('lingotek/views/node_and_lingotek_metadata');
$assert_session
->elementExists('css', '.view-node-and-lingotek-metadata');
$assert_session
->linkExists('Llamas are cool');
$assert_session
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$assert_session
->elementTextContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$assert_session
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$assert_session
->elementTextContains('css', 'td.views-field-translation-status-value', 'ES');
$assert_session
->linkExists('Automatic');
}
public function testMetadataView() {
$assert_session = $this
->assertSession();
$this
->drupalGet('lingotek/views/lingotek_metadata');
$assert_session
->elementTextContains('css', 'h1.page-title', 'Lingotek Metadata view');
$assert_session
->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');
$assert_session
->elementExists('css', '.view-lingotek-metadata');
$assert_session
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$assert_session
->elementTextNotContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$assert_session
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$assert_session
->linkExists('Manual');
$this
->saveAndKeepPublishedNodeForm([
'lingotek_translation_management[lingotek_translation_profile]' => 'automatic',
], 1);
$this
->drupalGet('lingotek/views/lingotek_metadata');
$assert_session
->elementExists('css', '.view-lingotek-metadata');
$assert_session
->elementTextContains('css', 'td.views-field-translation-source', 'EN');
$assert_session
->elementTextContains('css', 'td.views-field-document-id', 'dummy-document-hash-id');
$assert_session
->elementTextNotContains('css', 'td.views-field-translation-status-value', 'EN');
$assert_session
->elementTextContains('css', 'td.views-field-translation-status-value', 'ES');
$assert_session
->linkExists('Automatic');
}
}