### Eclipse Workspace Patch 1.0
#P drupal_test_7
Index: modules/field/modules/options/options.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/options/options.module,v
retrieving revision 1.4
diff -u -r1.4 options.module
--- modules/field/modules/options/options.module	26 Mar 2009 13:31:25 -0000	1.4
+++ modules/field/modules/options/options.module	12 Apr 2009 00:42:59 -0000
@@ -125,7 +125,7 @@
  *
  * 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 @@
  *
  * 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 @@
  * 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];
Index: modules/field/modules/text/text.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.test,v
retrieving revision 1.3
diff -u -r1.3 text.test
--- modules/field/modules/text/text.test	31 Mar 2009 01:49:52 -0000	1.3
+++ modules/field/modules/text/text.test	12 Apr 2009 00:43:00 -0000
@@ -14,6 +14,9 @@
 
   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.
@@ -43,19 +46,126 @@
 
   // Test widgets.
 
+  function testTextfieldWidgets() {
+    $this->_testTextfieldWidgets('text', 'text_textfield');
+    $this->_testTextfieldWidgets('text_long', 'text_textarea');
+  }
+
+  function _testTextfieldWidgets($field_type, $widget_type) {
+    $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 textfield widget.
+   * Test widgets + 'formatted_text' setting.
    */
-  function testTextfieldWidget() {
-    // Create a field
-    $field = $this->drupalCreateField('text');
-    $this->instance = $this->drupalCreateFieldInstance($field['field_name'], 'text_textfield', 'text_default', FIELD_TEST_BUNDLE);
-
+  function testTextfieldWidgetsFormatted() {
+    $this->_testTextfieldWidgetsFormatted('text', 'text_textfield');
+    $this->_testTextfieldWidgetsFormatted('text_long', 'text_textarea');
   }
 
   /**
-   * Test textarea widget.
+   * Helper function for testTextfieldFormattedForm().
    */
+  function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
+    $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.
   /**
Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.5
diff -u -r1.5 text.module
--- modules/field/modules/text/text.module	26 Mar 2009 13:31:25 -0000	1.5
+++ modules/field/modules/text/text.module	12 Apr 2009 00:43:00 -0000
@@ -111,7 +111,7 @@
     // 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 @@
  * 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 @@
  *
  * 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 @@
     $parents = array_merge($element['#parents'] , array($filter_key));
     $element[$filter_key] = filter_form($format, 1, $parents);
   }
+
+  return $element;
 }
 
 /**
Index: modules/field/modules/number/number.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/number/number.module,v
retrieving revision 1.5
diff -u -r1.5 number.module
--- modules/field/modules/number/number.module	26 Mar 2009 13:31:25 -0000	1.5
+++ modules/field/modules/number/number.module	12 Apr 2009 00:42:59 -0000
@@ -291,7 +291,7 @@
  *
  * 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']);
