View source
<?php
class SelectOrOtherAdminTestCase extends DrupalWebTestCase {
protected $adminUser;
protected $field;
protected $instance;
public static function getInfo() {
return array(
'name' => 'Select or Other admin',
'description' => 'Ensure that Select or Other administration functions as expected.',
'group' => 'Select or Other',
);
}
public function setUp() {
parent::setUp(array(
'field_ui',
'text',
'select_or_other',
));
$this->adminUser = $this
->drupalCreateUser(array(
'create page content',
'edit own page content',
'administer content types',
'administer site configuration',
'administer fields',
));
$this
->drupalLogin($this->adminUser);
$field = array(
'field_name' => drupal_strtolower($this
->randomName()),
'type' => 'text',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
$this->field = field_create_field($field);
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'select_or_other',
'settings' => array(
'available_options' => "keyed|Keyed\r\nunkeyed",
),
),
);
$this->instance = field_create_instance($instance);
}
public function testAvailableOptions() {
$langcode = LANGUAGE_NONE;
$edit = array(
'instance[widget][settings][available_options]' => "keyed|Keyed\r\nunkeyed\r\n",
);
$this
->drupalpost("admin/structure/types/manage/page/fields/{$this->field['field_name']}", $edit, t('Save settings'));
$edit = array(
"fields[{$this->field['field_name']}][type]" => 'select_or_other_formatter',
);
$this
->drupalpost("admin/structure/types/manage/page/display/", $edit, t('Save'));
$edit = array(
"title" => $this
->randomName(8),
"{$this->field['field_name']}[{$langcode}][select][]" => 'keyed',
);
$this
->drupalPost('node/add/page', $edit, t('Save'));
$this
->assertRaw('Keyed');
}
}