<?php
namespace Drupal\Tests\paragraphs_collection\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTestBase;
class ParagraphsLanguagePluginTest extends ParagraphsTestBase {
use \Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
protected static $modules = [
'paragraphs_collection',
'language',
];
public function testVisibilityForLanguageSelection() {
$content_type = 'test_content_type';
$paragraphs_field = 'test_paragraphs_field';
$this
->addParagraphedContentType($content_type, $paragraphs_field);
$this
->loginAsAdmin([
'create ' . $content_type . ' content',
'edit any ' . $content_type . ' content',
'edit behavior plugin settings',
]);
$paragraphs_type = 'test_paragraphs_type';
$this
->addParagraphsType($paragraphs_type);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraphs_type, 'test_text_field', 'Text', 'text_long', [], []);
$this
->drupalGet('admin/structure/paragraphs_type/' . $paragraphs_type);
$edit = [
'behavior_plugins[language][enabled]' => TRUE,
];
$this
->submitForm($edit, t('Save'));
$this
->drupalGet('node/add/' . $content_type);
$this
->submitForm([], $paragraphs_field . '_' . $paragraphs_type . '_add_more');
$node_title = 'Test Node';
$node_text = 'This is a text.';
$edit = [
'title[0][value]' => $node_title,
$paragraphs_field . '[0][subform][field_test_text_field][0][value]' => $node_text,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->titleEquals($node_title . ' | Drupal');
$this
->assertSession()
->pageTextContains($node_text);
$node_id = $this
->drupalGetNodeByTitle($node_title)
->id();
$node_edit_path = 'node/' . $node_id . '/edit';
$this
->drupalGet($node_edit_path);
$language_manager = \Drupal::service('language_manager');
$this
->assertFalse($language_manager
->isMultilingual(), 'The site is not multilingual.');
$this
->assertSession()
->responseNotContains('Language visibility');
ConfigurableLanguage::createFromLangcode('de')
->save();
$this
->drupalGet($node_edit_path);
$edit = [
$paragraphs_field . '[0][behavior_plugins][language][container][visibility]' => 'hide',
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet($node_edit_path);
$this
->assertTrue($language_manager
->isMultilingual(), 'The site is multilingual.');
$this
->assertSession()
->pageTextContains('Language visibility');
$edit = [
$paragraphs_field . '[0][behavior_plugins][language][container][visibility]' => 'hide',
$paragraphs_field . '[0][behavior_plugins][language][container][languages][]' => [
'en',
],
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->titleEquals($node_title . ' | Drupal');
$this
->assertSession()
->responseNotContains($node_text);
$this
->drupalGet($node_edit_path);
$this
->assertSession()
->responseContains('<span class="summary-plugin-label">Hide for</span>English</span');
$edit = [
$paragraphs_field . '[0][behavior_plugins][language][container][visibility]' => 'show',
$paragraphs_field . '[0][behavior_plugins][language][container][languages][]' => [
'de',
],
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->titleEquals($node_title . ' | Drupal');
$this
->assertSession()
->responseNotContains($node_text);
$this
->assertSession()
->responseNotContains('paragraph--type--test-paragraphs-type');
$this
->assertSession()
->responseNotContains('<div class="field__label">test_paragraphs_field</div>');
$this
->drupalGet($node_edit_path);
$this
->assertSession()
->responseContains('<span class="summary-plugin-label">Show for</span>German</span');
}
}