diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-05-12 18:26:43 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-05-12 18:26:43 -0700 |
commit | 2b8686151f2c2a32a77eca726c36c9b72260acd0 (patch) | |
tree | 9c36e8b46e83e38d61ff9eb565bde4caee387a19 /modules/node | |
parent | fffeb72bfd2802e8b5d4f0b514870d4b7fb23a29 (diff) | |
download | brdo-2b8686151f2c2a32a77eca726c36c9b72260acd0.tar.gz brdo-2b8686151f2c2a32a77eca726c36c9b72260acd0.tar.bz2 |
Issue #1302228 by xjm, yched, chx: Fixed Change notice for: field_has_data() returns inconsistent results – possible data loss.
Diffstat (limited to 'modules/node')
-rw-r--r-- | modules/node/node.test | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/modules/node/node.test b/modules/node/node.test index f46d2a108..6e458bb47 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -6,6 +6,26 @@ */ /** + * Defines a base class for testing the Node module. + */ +class NodeWebTestCase extends DrupalWebTestCase { + function setUp() { + $modules = func_get_args(); + if (isset($modules[0]) && is_array($modules[0])) { + $modules = $modules[0]; + } + $modules[] = 'node'; + parent::setUp($modules); + + // Create Basic page and Article node types. + if ($this->profile != 'standard') { + $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); + } + } +} + +/** * Test the node_load_multiple() function. */ class NodeLoadMultipleTestCase extends DrupalWebTestCase { @@ -2493,3 +2513,78 @@ class NodeAccessPagerTestCase extends DrupalWebTestCase { $this->assertNoRaw('page=2', t('No third page exists.')); } } + + +/** + * Tests the interaction of the node access system with fields. + */ +class NodeAccessFieldTestCase extends NodeWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Node access and fields', + 'description' => 'Tests the interaction of the node access system with fields.', + 'group' => 'Node', + ); + } + + public function setUp() { + parent::setUp('node_access_test', 'field_ui'); + node_access_rebuild(); + + // Create some users. + $this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access')); + $this->content_admin_user = $this->drupalCreateUser(array('access content', 'administer content types')); + + // Add a custom field to the page content type. + $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); + $this->field = field_create_field(array('field_name' => $this->field_name, 'type' => 'text')); + $this->instance = field_create_instance(array( + 'field_name' => $this->field_name, + 'entity_type' => 'node', + 'bundle' => 'page', + )); + } + + /** + * Tests administering fields when node access is restricted. + */ + function testNodeAccessAdministerField() { + // Create a page node. + $langcode = LANGUAGE_NONE; + $field_data = array(); + $value = $field_data[$langcode][0]['value'] = $this->randomName(); + $node = $this->drupalCreateNode(array($this->field_name => $field_data)); + + // Log in as the administrator and confirm that the field value is present. + $this->drupalLogin($this->admin_user); + $this->drupalGet("node/{$node->nid}"); + $this->assertText($value, 'The saved field value is visible to an administrator.'); + + // Log in as the content admin and try to view the node. + $this->drupalLogin($this->content_admin_user); + $this->drupalGet("node/{$node->nid}"); + $this->assertText('Access denied', 'Access is denied for the content admin.'); + + // Modify the field default as the content admin. + $edit = array(); + $default = 'Sometimes words have two meanings'; + $edit["{$this->field_name}[$langcode][0][value]"] = $default; + $this->drupalPost( + "admin/structure/types/manage/page/fields/{$this->field_name}", + $edit, + t('Save settings') + ); + + // Log in as the administrator. + $this->drupalLogin($this->admin_user); + + // Confirm that the existing node still has the correct field value. + $this->drupalGet("node/{$node->nid}"); + $this->assertText($value, 'The original field value is visible to an administrator.'); + + // Confirm that the new default value appears when creating a new node. + $this->drupalGet('node/add/page'); + $this->assertRaw($default, 'The updated default value is displayed when creating a new node.'); + } +} |