summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-04-12 02:18:51 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-04-12 02:18:51 +0000
commit73e755d6c2c419f085eb0bc2c0a8d2d6b9276322 (patch)
tree49c816e498968d59cda57fb5393b086aa1876c94 /modules
parent7ec6429c1c6e0342b9f20298d191349388657f6d (diff)
downloadbrdo-73e755d6c2c419f085eb0bc2c0a8d2d6b9276322.tar.gz
brdo-73e755d6c2c419f085eb0bc2c0a8d2d6b9276322.tar.bz2
#323112 follow-up by yched: Oops, Vertical Tabs broke field widgets (with tests so we don't do it again).
Diffstat (limited to 'modules')
-rw-r--r--modules/field/modules/number/number.module2
-rw-r--r--modules/field/modules/options/options.module6
-rw-r--r--modules/field/modules/text/text.module8
-rw-r--r--modules/field/modules/text/text.test130
4 files changed, 132 insertions, 14 deletions
diff --git a/modules/field/modules/number/number.module b/modules/field/modules/number/number.module
index 1e693dac0..fba9accd0 100644
--- a/modules/field/modules/number/number.module
+++ b/modules/field/modules/number/number.module
@@ -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']);
diff --git a/modules/field/modules/options/options.module b/modules/field/modules/options/options.module
index 26dff4dda..686a3ce28 100644
--- a/modules/field/modules/options/options.module
+++ b/modules/field/modules/options/options.module
@@ -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];
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 182956c89..7b67b11c4 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -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;
}
/**
diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test
index c837b57c2..e86ac89cb 100644
--- a/modules/field/modules/text/text.test
+++ b/modules/field/modules/text/text.test
@@ -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.
/**