public function CckSelectOtherFieldTypeTest::testField in CCK Select Other 8
Asserts that a user can save regular and other field values.
@dataProvider typeProvider
Parameters
string $field_type: The field type plugin ID.
mixed $other_value: The other value to set.
Throws
\Drupal\Core\Entity\EntityStorageException
\Exception
File
- tests/
src/ Functional/ CckSelectOtherFieldTypeTest.php, line 25
Class
- CckSelectOtherFieldTypeTest
- Tests a basic text field.
Namespace
Drupal\Tests\cck_select_other\FunctionalCode
public function testField($field_type, $other_value) {
$options = $this
->createOptions(5, $field_type);
$storage_values = [
'settings' => [
'allowed_values' => $options,
],
'cardinality' => 1,
];
$config_values = [
'required' => 0,
];
$field = $this
->createSelectOtherListField($field_type, $storage_values, $config_values);
$this
->assertEqual(5, count($field
->getSettings()['allowed_values']));
$field_name = $field
->getName();
// Create a new node with other value after logging in.
$this
->drupalLogin($this->webUser);
$edit = [
'title[0][value]' => $this
->randomString(25),
$field_name . '[0][select_other_list]' => 'other',
$field_name . '[0][select_other_text_input]' => $other_value,
];
$this
->drupalPostForm('/node/add/' . $this->contentType
->id(), $edit, 'Save');
$this
->assertSession()
->elementTextContains('css', 'div', $other_value);
// Edit node with other value to list value.
list($value, $label) = $this
->getRandomOption($options);
$edit = [
$field_name . '[0][select_other_list]' => $value,
$field_name . '[0][select_other_text_input]' => '',
];
$this
->drupalPostForm('/node/1/edit', $edit, 'Save');
$this
->assertSession()
->elementTextContains('css', 'div', $label);
}