View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekNodeParagraphsSettingsTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'image',
'paragraphs',
'lingotek_paragraphs_test',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_ES')
->save();
ConfigurableLanguage::createFromLangcode('es-ar')
->setThirdPartySetting('lingotek', 'locale', 'es_AR')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'paragraphed_content_demo')
->setLanguageAlterable(TRUE)
->save();
ContentLanguageSettings::loadByEntityTypeBundle('paragraph', 'image_text')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'paragraphed_content_demo', TRUE);
\Drupal::service('content_translation.manager')
->setEnabled('paragraph', 'image_text', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->setParagraphFieldsTranslatability();
$this
->saveLingotekContentTranslationSettings([
'node' => [
'paragraphed_content_demo' => [
'profiles' => 'automatic',
'fields' => [
'title' => 1,
'field_paragraphs_demo' => 1,
],
],
],
'paragraph' => [
'image_text' => [
'fields' => [
'field_image_demo' => [
'title',
'alt',
],
'field_text_demo' => 1,
],
],
],
]);
\Drupal::state()
->set('lingotek.uploaded_content_type', 'node+paragraphs');
}
public function testDisablingContentTranslationDoesntDisableLingotekTranslationForParagraphs() {
$this
->drupalGet('admin/lingotek/settings');
$this
->assertFieldByName('node[paragraphed_content_demo][fields][field_paragraphs_demo]', TRUE);
$this
->assertFieldByName('paragraph[image_text][fields][field_text_demo]', TRUE);
$edit = [];
$edit['settings[node][paragraphed_content_demo][fields][field_paragraphs_demo]'] = FALSE;
$edit['settings[paragraph][image_text][fields][field_text_demo]'] = FALSE;
$this
->drupalPostForm('/admin/config/regional/content-language', $edit, 'Save configuration');
$this
->assertSession()
->responseContains('Settings successfully updated.');
$this
->drupalGet('admin/lingotek/settings');
$this
->assertFieldByName('node[paragraphed_content_demo][fields][field_paragraphs_demo]', TRUE);
$lingotekConfig = \Drupal::service('lingotek.configuration');
$this
->assertFalse($lingotekConfig
->isFieldLingotekEnabled('paragraph', 'image_text', 'field_text_demo'));
$this
->assertNoFieldByName('paragraph[image_text][fields][field_text_demo]');
}
protected function setParagraphFieldsTranslatability() : void {
$edit = [];
$edit['settings[node][paragraphed_content_demo][fields][field_paragraphs_demo]'] = 1;
$edit['settings[paragraph][image_text][fields][field_text_demo]'] = 1;
$this
->drupalPostForm('/admin/config/regional/content-language', $edit, 'Save configuration');
$this
->assertSession()
->responseContains('Settings successfully updated.');
}
}