View source
<?php
namespace Drupal\Tests\conditional_fields\FunctionalJavascript;
use Drupal\conditional_fields\ConditionalFieldsInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldFilledEmptyInterface;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldValueInterface;
class ConditionalFieldEmailTest extends ConditionalFieldTestBase implements ConditionalFieldValueInterface, ConditionalFieldFilledEmptyInterface {
public static $modules = [
'conditional_fields',
'node',
];
protected $screenshotPath = 'sites/simpletest/conditional_fields/email/';
protected $displayOptions;
protected $fieldName = 'test_email';
protected $fieldSelector;
protected $fieldStorageDefinition;
protected $fieldStorage;
protected $field;
protected function setUp() {
parent::setUp();
$this->fieldSelector = '[name="field_' . $this->fieldName . '[0][value]"]';
FieldStorageConfig::create([
'field_name' => 'field_' . $this->fieldName,
'entity_type' => 'node',
'type' => 'email',
'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' => 'email_default',
'settings' => [
'prefix_suffix' => FALSE,
],
])
->save();
}
public function testVisibleValueWidget() {
$email = 'test@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET,
'field_' . $this->fieldName . '[0][value]' => $email,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->changeField($this->fieldSelector, 'wrongmail@drupal.org');
$this
->createScreenshot($this->screenshotPath . '04-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 500, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 500, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '06-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}
public function testVisibleValueRegExp() {
$email = 'test@drupal.org';
$email_wrong = 'wrongmail@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
'regex' => '^test@.+\\..+',
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->changeField($this->fieldSelector, $email_wrong);
$this
->createScreenshot($this->screenshotPath . '04-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 500, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 500, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '06-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}
public function testVisibleValueAnd() {
$email = 'first@drupal.org';
$email_2 = 'second@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailVisibleValueWidget.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => "{$email}\r\n{$email_2}",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailVisibleValueWidget.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 500, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 500, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email_2);
$this
->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 500, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '06-testEmailVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}
public function testVisibleValueOr() {
$email = 'test@drupal.org';
$email2 = 'test2@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailTimeVisibleValueOr.png');
$emails = implode("\r\n", [
$email,
$email2,
]);
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
'values' => $emails,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailTimeVisibleValueOr.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailTimeVisibleValueOr.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, 'wrongmail@drupal.org');
$this
->createScreenshot($this->screenshotPath . '05-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '06-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 500, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $email2);
$this
->createScreenshot($this->screenshotPath . '07-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
}
public function testVisibleValueNot() {
$email = 'test@drupal.org';
$email2 = 'test2@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailTimeVisibleValueOr.png');
$emails = implode("\r\n", [
$email,
$email2,
]);
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT,
'values' => $emails,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailTimeVisibleValueOr.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailTimeVisibleValueOr.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, 'wrongmail@drupal.org');
$this
->createScreenshot($this->screenshotPath . '05-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '06-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 500, '03. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email2);
$this
->createScreenshot($this->screenshotPath . '07-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
}
public function testVisibleValueXor() {
$email = 'test@drupal.org';
$email2 = 'test2@drupal.org';
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testEmailTimeVisibleValueOr.png');
$emails = implode("\r\n", [
$email,
$email2,
]);
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
'values' => $emails,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testEmailTimeVisibleValueOr.png');
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testEmailTimeVisibleValueOr.png');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, 'wrongmail@drupal.org');
$this
->createScreenshot($this->screenshotPath . '05-testEmailTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$this
->changeField($this->fieldSelector, $email);
$this
->createScreenshot($this->screenshotPath . '06-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 500, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $email2);
$this
->createScreenshot($this->screenshotPath . '07-testEmailTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testEmailTimeVisibleValueOr.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
->drupalGet('admin/structure/conditional_fields/node/article');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible !empty');
$this
->drupalGet('node/add/article');
$this
->waitUntilHidden('.field--name-body', 0, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, 'test@drupal.org');
$this
->waitUntilVisible('.field--name-body', 10, '02. Article Body field is visible');
}
public function testVisibleEmpty() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'empty');
$this
->drupalGet('admin/structure/conditional_fields/node/article');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible empty');
$this
->drupalGet('node/add/article');
$this
->waitUntilVisible('.field--name-body', 0, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, 'test@drupal.org');
$this
->waitUntilHidden('.field--name-body', 10, '02. Article Body field is not visible');
}
public function testInvisibleFilled() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', '!empty');
$this
->drupalGet('admin/structure/conditional_fields/node/article');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' !visible !empty');
$this
->drupalGet('node/add/article');
$this
->waitUntilVisible('.field--name-body', 0, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, 'test@drupal.org');
$this
->waitUntilHidden('.field--name-body', 10, '02. Article Body field is not visible');
}
public function testInvisibleEmpty() {
$this
->baseTestSteps();
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', 'empty');
$this
->drupalGet('admin/structure/conditional_fields/node/article');
$this
->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' !visible empty');
$this
->drupalGet('node/add/article');
$this
->waitUntilHidden('.field--name-body', 0, '01. Article Body field is not visible');
$this
->changeField($this->fieldSelector, 'test@drupal.org');
$this
->waitUntilVisible('.field--name-body', 10, '02. Article Body field is visible');
}
}