View source
<?php
namespace Drupal\Tests\conditional_fields\FunctionalJavascript;
use Drupal\conditional_fields\ConditionalFieldsInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldValueInterface;
class ConditionalFieldLanguageSelectTest extends ConditionalFieldTestBase implements ConditionalFieldValueInterface {
public static $modules = [
'conditional_fields',
'language',
'node',
'options',
];
protected $screenshotPath = 'sites/simpletest/conditional_fields/language_select/';
protected $fieldName = 'langcode';
protected $fieldSelector;
protected $field;
protected $defaultLanguage;
protected $langcodes = [
'und',
'zxx',
];
protected function setUp() {
parent::setUp();
$this->fieldSelector = "[name=\"{$this->fieldName}[0][value]\"]";
$this->defaultLanguage = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->setDefaultLangcode($this->defaultLanguage)
->save();
}
public function testVisibleValueWidget() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET,
$this->fieldName . '[0][value]' => $this->defaultLanguage,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
public function testVisibleValueRegExp() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
"regex" => '^' . $this->langcodes[0] . '$',
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
public function testVisibleValueAnd() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
"values" => implode("\r\n", $this->langcodes),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
public function testVisibleValueOr() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
"values" => implode("\r\n", $this->langcodes),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
}
public function testVisibleValueNot() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT,
"values" => implode("\r\n", $this->langcodes),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
public function testVisibleValueXor() {
$this
->baseTestSteps();
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-language-select-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
"values" => implode("\r\n", $this->langcodes),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-language-select-post-add-list-options-filed-conditions.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-language-select-submit-list-options-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[0]);
$this
->createScreenshot($this->screenshotPath . '05-language-select-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->defaultLanguage);
$this
->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->langcodes[1]);
$this
->createScreenshot($this->screenshotPath . '07-language-select-body-invisible-when-controlled-field-has-wrong-value-again.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
}
}