diff options
Diffstat (limited to 'modules/node/node.test')
-rw-r--r-- | modules/node/node.test | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/modules/node/node.test b/modules/node/node.test index 1e6d57e1e..1a77a4588 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -685,6 +685,72 @@ class NodeRSSContentTestCase extends DrupalWebTestCase { } /** + * Test case to verify hook_node_access_records_alter functionality. + */ +class NodeAccessRecordsAlterUnitTest extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => t('Node access records alter'), + 'description' => t('Test hook_node_access_records_alter when acquiring grants.'), + 'group' => t('Node'), + ); + } + + function setUp() { + // Enable dummy module that implements hook_node_grants(), + // hook_node_access_records(), hook_node_grants_alter() and + // hook_node_access_records_alter(). + parent::setUp('node_test'); + } + + /** + * Create a node and test the creation of node access rules. + */ + function testGrantAlter() { + // Create an article node. + $node1 = $this->drupalCreateNode(array('type' => 'article')); + $this->assertTrue(node_load($node1->nid), t('Article node created.')); + + // Check to see if grants added by node_test_node_access_records made it in. + $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node1->nid)->fetchAll(); + $this->assertEqual(count($records), 1, t('Returned the correct number of rows.')); + $this->assertEqual($records[0]->realm, 'test_article_realm', t('Grant with article_realm acquired for node without alteration.')); + $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.')); + + // Create an unpromoted page node. + $node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0)); + $this->assertTrue(node_load($node1->nid), t('Unpromoted page node created.')); + + // Check to see if grants added by node_test_node_access_records made it in. + $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node2->nid)->fetchAll(); + $this->assertEqual(count($records), 1, t('Returned the correct number of rows.')); + $this->assertEqual($records[0]->realm, 'test_page_realm', t('Grant with page_realm acquired for node without alteration.')); + $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.')); + + // Create a promoted page node. + $node3 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); + $this->assertTrue(node_load($node3->nid), t('Promoted page node created.')); + + // Check to see if grant added by node_test_node_access_records was altered + // by node_test_node_access_records_alter. + $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node3->nid)->fetchAll(); + $this->assertEqual(count($records), 1, t('Returned the correct number of rows.')); + $this->assertEqual($records[0]->realm, 'test_alter_realm', t('Altered grant with alter_realm acquired for node.')); + $this->assertEqual($records[0]->gid, 2, t('Altered grant with gid = 2 acquired for node.')); + + // Check to see if we can alter grants with hook_node_grants_alter(). + $operations = array('view', 'update', 'delete'); + // Create a user that is allowed to access content. + $web_user = $this->drupalCreateUser(array('access content')); + foreach ($operations as $op) { + $grants = node_test_node_grants($op, $web_user); + $altered_grants = drupal_alter($grants, $web_user, $op); + $this->assertNotEqual($grants, $altered_grants, t('Altered the %op grant for a user.', array('%op' => $op))); + } + } +} + +/** * Test case to check node save related functionality, including import-save */ class NodeSaveTestCase extends DrupalWebTestCase { |