View source
<?php
namespace Drupal\Tests\conditional_fields\FunctionalJavascript;
use Drupal\conditional_fields\ConditionalFieldsInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldValueInterface;
use Drupal\Tests\RandomGeneratorTrait;
class ConditionalFieldNumberTest extends ConditionalFieldTestBase implements ConditionalFieldValueInterface {
use RandomGeneratorTrait;
public static $modules = [
'conditional_fields',
'node',
];
protected $screenshotPath = 'sites/simpletest/conditional_fields/number_integer/';
protected $fieldName = 'number_integer';
protected $fieldSelector;
protected $validValue = '2019';
protected function setUp() {
parent::setUp();
$this->fieldSelector = '[name="field_' . $this->fieldName . '[0][value]"]';
FieldStorageConfig::create([
'field_name' => 'field_' . $this->fieldName,
'entity_type' => 'node',
'type' => 'integer',
'cardinality' => 1,
])
->save();
FieldConfig::create([
'field_name' => 'field_' . $this->fieldName,
'entity_type' => 'node',
'bundle' => 'article',
'settings' => [
'min' => '',
'max' => '',
'prefix' => '',
],
])
->save();
EntityFormDisplay::load('node.article.default')
->setComponent('field_' . $this->fieldName, [
'type' => 'number',
'settings' => [
'prefix_suffix' => FALSE,
],
])
->save();
}
public function testVisibleValueWidget() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET,
'field_' . $this->fieldName . '[0][value]' => $this->validValue,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is not visible');
}
public function testVisibleValueRegExp() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
'regex' => '^2019$',
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is not visible');
}
public function testVisibleValueAnd() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => "2017\r\n2019",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is not visible');
}
public function testVisibleValueOr() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
'values' => "2017\r\n2019",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is not visible');
}
public function testVisibleValueNot() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT,
'values' => "2017\r\n2019",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '06. Article Body field is not visible');
}
public function testVisibleValueXor() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
'values' => "2017\r\n2019",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, mt_rand(10, 100));
$this
->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
}
public function testVisibleFilled() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', '!empty');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible !empty');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}
public function testVisibleEmpty() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'empty');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' visible empty');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
}
public function testInvisibleFilled() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', '!empty');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' !visible !empty');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
}
public function testInvisibleEmpty() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', 'empty');
$this
->createScreenshot($this->screenshotPath . '01-testNumberInteger-testVisibleValueWidget.png');
$this
->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' !visible empty');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this->validValue);
$this
->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}
}