Commit 73e755d6 authored by webchick's avatar webchick

#323112 follow-up by yched: Oops, Vertical Tabs broke field widgets (with...

#323112 follow-up by yched: Oops, Vertical Tabs broke field widgets (with tests so we don't do it again).
parent 7ec6429c
......@@ -291,7 +291,7 @@ function number_field_widget_error($element, $error) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function number_process($element, $edit, $form_state, $form) {
function number_process($element, $form_state, $form) {
$field_name = $element['#field_name'];
$field = field_info_field($element['#field_name']);
$instance = field_info_instance($element['#field_name'], $element['#bundle']);
......
......@@ -125,7 +125,7 @@ function options_field_widget_error($element, $error) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function options_buttons_process($element, $edit, &$form_state, $form) {
function options_buttons_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -182,7 +182,7 @@ function options_buttons_process($element, $edit, &$form_state, $form) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function options_select_process($element, $edit, &$form_state, $form) {
function options_select_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -223,7 +223,7 @@ function options_select_process($element, $edit, &$form_state, $form) {
* Build the form element. When creating a form using FAPI #process,
* note that $element['#value'] is already set.
*/
function options_onoff_process($element, $edit, &$form_state, $form) {
function options_onoff_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......
......@@ -111,7 +111,7 @@ function text_field_sanitize($obj_type, $object, $field, $instance, &$items) {
// TODO D7 : this code is really node-related.
if (!empty($instance['settings']['text_processing'])) {
$check = is_null($object) || (isset($object->build_mode) && $object->build_mode == NODE_BUILD_PREVIEW);
$text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language, $check) : '';
$text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language->language, $check) : '';
}
else {
$text = check_plain($item['value']);
......@@ -305,7 +305,7 @@ function text_field_widget_error($element, $error) {
* information needed to adjust the behavior of the 'element' should be
* extracted in hook_field_widget() above.
*/
function text_textfield_process($element, $edit, $form_state, $form) {
function text_textfield_process($element, $form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -348,7 +348,7 @@ function text_textfield_process($element, $edit, $form_state, $form) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function text_textarea_process($element, $edit, $form_state, $form) {
function text_textarea_process($element, $form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -375,6 +375,8 @@ function text_textarea_process($element, $edit, $form_state, $form) {
$parents = array_merge($element['#parents'] , array($filter_key));
$element[$filter_key] = filter_form($format, 1, $parents);
}
return $element;
}
/**
......
......@@ -14,6 +14,9 @@ class TextFieldTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('field', 'text', 'field_test');
$web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
$this->drupalLogin($web_user);
}
// Test fields.
......@@ -41,21 +44,134 @@ class TextFieldTestCase extends DrupalWebTestCase {
}
}
// Test widgets.
/**
* Test widgets.
*/
function testTextfieldWidgets() {
$this->_testTextfieldWidgets('text', 'text_textfield');
$this->_testTextfieldWidgets('text_long', 'text_textarea');
}
/**
* Test textfield widget.
* Helper function for testTextfieldWidgets().
*/
function testTextfieldWidget() {
// Create a field
$field = $this->drupalCreateField('text');
$this->instance = $this->drupalCreateFieldInstance($field['field_name'], 'text_textfield', 'text_default', FIELD_TEST_BUNDLE);
function _testTextfieldWidgets($field_type, $widget_type) {
// Setup a field and instance
$entity_type = 'test_entity';
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
'bundle' => FIELD_TEST_BUNDLE,
'label' => $this->randomName() . '_label',
'settings' => array(
'text_processing' => TRUE,
),
'widget' => array(
'type' => $widget_type,
)
);
field_create_instance($this->instance);
// Display creation form.
$this->drupalGet('test-entity/add/test-bundle');
$this->assertFieldByName($this->field_name . '[0][value]', '', t('Widget is displayed'));
$this->assertNoFieldByName($this->field_name . '[0][format]', '1', t('Format selector is not displayed'));
// Submit with some value.
$value = $this->randomName();
$edit = array(
$this->field_name . '[0][value]' => $value,
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), t('Entity was created'));
// Display the object.
$entity = field_test_entity_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertText($value, 'Filtered tags are not displayed');
}
/**
* Test widgets + 'formatted_text' setting.
*/
function testTextfieldWidgetsFormatted() {
$this->_testTextfieldWidgetsFormatted('text', 'text_textfield');
$this->_testTextfieldWidgetsFormatted('text_long', 'text_textarea');
}
/**
* Test textarea widget.
* Helper function for testTextfieldWidgetsFormatted().
*/
function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
// Setup a field and instance
$entity_type = 'test_entity';
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
'bundle' => FIELD_TEST_BUNDLE,
'label' => $this->randomName() . '_label',
'settings' => array(
'text_processing' => TRUE,
),
'widget' => array(
'type' => $widget_type,
)
);
field_create_instance($this->instance);
// Display creation form.
// By default, the user only has access to 'Filtered HTML', and no format
// selector is displayed
$this->drupalGet('test-entity/add/test-bundle');
$this->assertFieldByName($this->field_name . '[0][value]', '', t('Widget is displayed'));
$this->assertNoFieldByName($this->field_name . '[0][format]', '1', t('Format selector is not displayed'));
// Submit with data that should be filtered.
$value = $this->randomName() . '<br />' . $this->randomName();
$edit = array(
$this->field_name . '[0][value]' => $value,
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), t('Entity was created'));
// Display the object.
$entity = field_test_entity_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertNoRaw($value, 'Filtered tags are not displayed');
$this->assertRaw(str_replace('<br />', '', $value), t('Filtered value is displayed correctly'));
// Allow the user to use the 'Full HTML' format.
db_update('filter_format')->fields(array('roles' => ',2,'))->condition('format', 2)->execute();
// Display edition form.
// We should now have a 'text format' selector.
$this->drupalGet('test-entity/' . $id . '/edit');
$this->assertFieldByName($this->field_name . '[0][value]', '', t('Widget is displayed'));
$this->assertFieldByName($this->field_name . '[0][format]', '1', t('Format selector is displayed'));
// Edit and change the format to 'Full HTML'.
$edit = array(
$this->field_name . '[0][format]' => 2,
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), t('Entity was updated'));
// Display the object.
$entity = field_test_entity_load($id);
$entity->content = field_attach_view($entity_type, $entity);
$this->content = drupal_render($entity->content);
$this->assertRaw($value, t('Value is displayed unfiltered'));
}
// Test formatters.
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment