View source
<?php
namespace Drupal\Tests\cck_select_other\Functional;
class CckSelectOtherFieldTypeTest extends CckSelectOtherTestBase {
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();
$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);
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);
}
public function typeProvider() {
return [
'text' => [
'list_string',
'blah',
],
'integer' => [
'list_integer',
10,
],
];
}
}