From 9b71489a48a266df8efc1e462ec4dbd200e60ddf Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 20 Nov 2009 04:51:27 +0000 Subject: #636834 by yched: Fixed field revision data when user has no 'edit' access on the field (with tests). --- modules/field/field.test | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'modules/field/field.test') diff --git a/modules/field/field.test b/modules/field/field.test index b85c4c594..49a1a2452 100644 --- a/modules/field/field.test +++ b/modules/field/field.test @@ -1592,6 +1592,65 @@ class FieldFormTestCase extends FieldTestCase { $this->assertNoField("$this->field_name[$langcode][" . ($delta + 1) . '][value]', 'No extraneous widget is displayed'); } + /** + * 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. * -- cgit v1.2.3