? .cache
? .settings
Index: modules/field/field.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.test,v
retrieving revision 1.67
diff -u -p -r1.67 field.test
--- modules/field/field.test	12 Nov 2009 20:07:06 -0000	1.67
+++ modules/field/field.test	19 Nov 2009 00:56:39 -0000
@@ -1593,6 +1593,65 @@ class FieldFormTestCase extends FieldTes
   }
 
   /**
+   * Tests fields with no 'edit' access.
+   */
+  function testFieldFormAccess() {
+    // Create a "regular" field.
+    $field = $this->field_single;
+    $field_name = $field['field_name'];
+    $instance = $this->instance;
+    $instance['field_name'] = $field_name;
+    field_create_field($field);
+    field_create_instance($instance);
+
+    // Create a field with no edit access - see field_test_field_access().
+    $field_no_access = array(
+      'field_name' => 'field_no_edit_access',
+      'type' => 'test_field',
+    );
+    $field_name_no_access = $field_no_access['field_name'];
+    $instance_no_access = array(
+      'field_name' => $field_name_no_access,
+      'object_type' => 'test_entity',
+      'bundle' => 'test_bundle',
+      'default_value' => array(0 => array('value' => 99)),
+    );
+    field_create_field($field_no_access);
+    field_create_instance($instance_no_access);
+
+    $langcode = FIELD_LANGUAGE_NONE;
+
+    // Display creation form.
+    $this->drupalGet('test-entity/add/test-bundle');
+    $this->assertNoFieldByName("{$field_name_no_access}[$langcode][0][value]", '', t('Widget is not displayed if field access is denied.'));
+
+    // Create entity
+    $edit = array("{$field_name}[$langcode][0][value]" => 1);
+    $this->drupalPost(NULL, $edit, t('Save'));
+    preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
+    $id = $match[1];
+
+    // Check that the default value was saved.
+    $entity = field_test_entity_test_load($id);
+    $this->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, t('Default value was saved for the field with no edit access.'));
+    $this->assertEqual($entity->{$field_name}[$langcode][0]['value'], 1, t('Entered value vas saved for the field with edit access.'));
+
+    // Create a new revision.
+    $edit = array("{$field_name}[$langcode][0][value]" => 2, 'revision' => TRUE);
+    $this->drupalPost('test-entity/' . $id . '/edit', $edit, t('Save'));
+
+    // Check that the new revision has the expected values.
+    $entity = field_test_entity_test_load($id);
+    $this->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, t('New revision has the expected value for the field with no edit access.'));
+    $this->assertEqual($entity->{$field_name}[$langcode][0]['value'], 2, t('New revision has the expected value for the field with edit access.'));
+
+    // Check that the revision is also saved in the revisions table.
+    $entity = field_test_entity_test_load($id, $entity->ftvid);
+    $this->assertEqual($entity->{$field_name_no_access}[$langcode][0]['value'], 99, t('New revision has the expected value for the field with no edit access.'));
+    $this->assertEqual($entity->{$field_name}[$langcode][0]['value'], 2, t('New revision has the expected value for the field with edit access.'));
+  }
+
+  /**
    * Execute a POST request on a AHAH callback.
    *
    * Stolen from poll.test. The JSON result is parsed into HTML and placed in
Index: modules/simpletest/tests/field_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/field_test.module,v
retrieving revision 1.38
diff -u -p -r1.38 field_test.module
--- modules/simpletest/tests/field_test.module	2 Nov 2009 03:41:58 -0000	1.38
+++ modules/simpletest/tests/field_test.module	19 Nov 2009 01:01:54 -0000
@@ -49,6 +49,15 @@ function field_test_menu() {
   return $items;
 }
 
+/**
+ * Implements hook_field_access().
+ */
+function field_test_field_access($op, $field, $obj_type, $object, $account) {
+  if ($field['field_name'] == "field_no_{$op}_access") {
+    return FALSE;
+  }
+  return TRUE;
+}
 
 /**
  *
@@ -312,7 +321,7 @@ function field_test_entity_add($fttype) 
   $fttype = str_replace('-', '_', $fttype);
   $entity = (object)array('fttype' => $fttype);
   drupal_set_title(t('Create test_entity @bundle', array('@bundle' => $fttype)), PASS_THROUGH);
-  return drupal_get_form('field_test_entity_form', $entity);
+  return drupal_get_form('field_test_entity_form', $entity, TRUE);
 }
 
 function field_test_entity_edit($entity) {
@@ -323,7 +332,7 @@ function field_test_entity_edit($entity)
 /**
  * Form to set the value of fields attached to our entity.
  */
-function field_test_entity_form($form, &$form_state, $entity) {
+function field_test_entity_form($form, &$form_state, $entity, $add = FALSE) {
   if (isset($form_state['test_entity'])) {
     $entity = $form_state['test_entity'] + (array)$entity;
   }
@@ -340,13 +349,15 @@ function field_test_entity_form($form, &
   $form['#builder_function'] = 'field_test_entity_form_submit_builder';
   field_attach_form('test_entity', $entity, $form, $form_state);
 
-  $form['revision'] = array(
-    '#access' => user_access('administer field_test content'),
-    '#type' => 'checkbox',
-    '#title' => t('Create new revision'),
-    '#default_value' => FALSE,
-    '#weight' => 100,
-  );
+  if (!$add) {
+    $form['revision'] = array(
+      '#access' => user_access('administer field_test content'),
+      '#type' => 'checkbox',
+      '#title' => t('Create new revision'),
+      '#default_value' => FALSE,
+      '#weight' => 100,
+    );
+  }
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -391,6 +402,7 @@ function field_test_entity_form_submit($
  */
 function field_test_entity_form_submit_builder($form, &$form_state) {
   $entity = field_test_create_stub_entity($form_state['values']['ftid'], $form_state['values']['ftvid'], $form_state['values']['fttype']);
+  $entity->revision = !empty($form_state['values']['revision']);
   field_attach_submit('test_entity', $entity, $form, $form_state);
 
   $form_state['test_entity'] = (array)$entity;
