diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php index 827da77..095cd90 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -27,7 +27,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('bypass node access', 'view test_view_field content')); + $web_user = $this->drupalCreateUser(array('view test_view_field content')); $this->drupalLogin($web_user); // Create content type. @@ -53,23 +53,30 @@ function setUp() { ), ); field_create_instance($this->instance); + + // Create test node. + $this->test_view_field_value = 'This is the some text'; + $settings = array(); + $settings['type'] = $this->content_type; + $settings['title'] = 'Field view access test'; + $settings['test_view_field'] = array(LANGUAGE_NOT_SPECIFIED => array(array('value' => $this->test_view_field_value))); + $this->node = $this->drupalCreateNode($settings); } + /** + * Test that hook_field_access() is called. + */ function testFieldAccess() { - $field_value = 'This is the some text'; - - $edit = array( - 'title' => 'Field view access test', - 'test_view_field[und][0][value]' => $field_value - ); - $this->drupalPost('node/add/' . $this->content_type, $edit, t('Save')); - // Assert the text value is visible. - $this->assertText($field_value); + // Assert the text is visible. + $this->drupalGet('node/' . $this->node->nid); + $this->assertText($this->test_view_field_value); - // Assert the text value is not visible for anonymous users. + // Assert the text is not visible for anonymous users. + // The field_test module implements hook_field_access() which will + // specificaly target the 'test_view_field' field. $this->drupalLogout(); - $this->drupalGet('node/1'); - $this->assertNoText($field_value); + $this->drupalGet('node/' . $this->node->nid); + $this->assertNoText($this->test_view_field_value); } } diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 7c1a95a..f47ccad 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -189,6 +189,8 @@ function field_test_field_access($op, $field, $entity_type, $entity, $account) { return FALSE; } + // Only grant view access to test_view_field fields when the user has + // 'view test_view_field content' permission. if ($field['field_name'] == 'test_view_field' && $op == 'view' && !user_access('view test_view_field content')) { return FALSE; }