ListTest.php in Select (or other) 8
File
tests/src/Functional/ListTest.php
View source
<?php
namespace Drupal\Tests\select_or_other\Functional;
class ListTest extends TestBase {
public static $modules = [
'options',
];
public function setUp() {
parent::setUp();
$field_settings = [];
$widget = 'select_or_other_list';
$widgets = [
'select_or_other_select',
'select_or_other_buttons',
];
$this
->prepareTestFields('list_string', $field_settings, $widget, $widgets);
$user = $this
->drupalCreateUser($this->defaultPermissions);
$this
->drupalLogin($user);
}
public function testEmptyOption($empty_option = '') {
parent::testEmptyOption('My cool new value');
}
public function testIllegalChoice() {
foreach ($this->fields as $field_name => $field) {
$this
->drupalGet('node/add/' . $this
->getFieldContentType($field_name));
$select_type = $field['select_type'];
$multiple = $field['cardinality'] !== 1;
$required = $field['required'];
if ($select_type === 'select_or_other_buttons') {
if (!$required) {
if ($multiple) {
$this
->setFieldValue($field_name, 'select_or_other', 'multi_value');
$this
->clickLink(t('Edit'));
$this
->getSession()
->getPage()
->findButton('edit-preview')
->press();
$this
->clickLink(t('Back to content editing'));
$this
->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
$this
->setFieldValue($field_name, 'multi_value');
$this
->clickLink(t('Edit'));
$this
->getSession()
->getPage()
->findButton('edit-preview')
->press();
$this
->clickLink(t('Back to content editing'));
$this
->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
}
else {
$this
->setFieldValue($field_name, 'select_or_other', 'value');
$this
->clickLink(t('Edit'));
$this
->getSession()
->getPage()
->findButton('edit-preview')
->press();
$this
->clickLink(t('Back to content editing'));
$this
->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
$this
->setFieldValue($field_name, '');
$this
->clickLink(t('Back to content editing'));
$this
->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
}
}
}
}
}
}
Classes
Name |
Description |
ListTest |
Tests the the functionality of the Reference widget. |