select_or_other_text.test in Select (or other) 7.3
File
tests/select_or_other_text.test
View source
<?php
class SelectOrOtherTextTestCase extends SelectOrOtherTestBase {
public static function getInfo() {
return array(
'name' => 'Select or Other Text',
'description' => 'Ensure that Select or Other functions correctly while used in combination with text fields.',
'group' => 'Select or Other',
);
}
public function setUp() {
parent::setUp();
$widgets = array(
'select_or_other',
'select_or_other_buttons',
);
$widget_settings = array(
'available_options' => "keyed|Keyed\r\nunkeyed",
'other_unknown_new_option' => TRUE,
);
$this
->prepareTestFields('text', array(), $widgets, $widget_settings, 'text_default');
$user = $this
->drupalCreateUser($this->defaultPermissions);
$this
->drupalLogin($user);
}
function testNoOtherSelected() {
foreach ($this->fields as $field_name => $field) {
$this
->setFieldValue($field_name, 'keyed');
$this
->assertRaw('keyed');
$this
->assertNoRaw('select_or_other');
}
}
function testOtherSelected() {
foreach ($this->fields as $field_name => $field) {
$other_value = $this
->randomName();
$this
->setFieldValue($field_name, 'select_or_other', $other_value);
$this
->assertRaw($other_value);
$this
->assertNoRaw('select_or_other');
}
}
function testOtherSelectedWithPreExistingKey() {
foreach ($this->fields as $field_name => $field) {
$this
->setFieldValue($field_name, 'select_or_other', 'keyed');
$this
->assertRaw('keyed');
$this
->assertNoRaw('select_or_other');
$this
->clickLink(t('Edit'));
if ($field['widget'] === 'select_or_other') {
$this
->assertOptionSelected("edit-{$field_name}-und-select", 'keyed');
}
else {
$this
->assertFieldChecked("edit-{$field_name}-und-select-keyed");
}
$this
->assertFieldByName("{$field_name}[und][other]", '');
}
}
function testEmptyOption($other_option = '') {
parent::testEmptyOption('My cool new value');
}
function testSpecialCharHandling() {
foreach ($this->fields as $field_name => $field) {
$parts = array(
$this
->randomName(),
$this
->randomName(),
);
$other_value = implode('&', $parts);
$this
->setFieldValue($field_name, 'select_or_other', $other_value);
$this
->assertText(filter_xss($other_value));
$this
->assertNoRaw('select_or_other');
$this
->clickLink(t('Edit'));
$option = strtolower(implode($parts));
if ($field['widget'] === 'select_or_other') {
$this
->assertOptionSelected("edit-{$field_name}-und-select", $other_value);
}
else {
$this
->assertFieldChecked("edit-{$field_name}-und-select-{$option}");
}
}
}
}