Index: modules/node/node.test =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.test,v retrieving revision 1.19 diff -r1.19 node.test 639a640,676 > > 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, and hook_node_access_records_alter. > parent::setUp('node_test'); > } > > 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, '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 a page node. > $node2 = $this->drupalCreateNode(array('type' => 'page')); > $this->assertTrue(node_load($node2->nid), t('Page node created.')); > > // Check to see if grant added by node_test_node_access_records got altered by node_test_node_access_records_alter. > $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, '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.')); > } > } Index: modules/node/tests/node_test.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/tests/node_test.module,v retrieving revision 1.1 diff -r1.1 node_test.module 18a19,71 > > /* > * Implementation of hook_node_grants(). > */ > function node_test_node_grants($account, $op) { > // This dummy hook needs to be here or else node_access_write_grants will write nothing. > return array(); > } > > /** > * Implementation of hook_node_access_records(). > */ > function node_test_node_access_records($node) { > $grants = array(); > if ($node->type == 'article') { > // Create grant in arbitrary article_realm for article nodes. > $grants[] = array( > 'realm' => 'article_realm', > 'gid' => 1, > 'grant_view' => 1, > 'grant_update' => 0, > 'grant_delete' => 0, > 'priority' => 0, > ); > } > elseif ($node->type == 'page') { > // Create grant in arbitrary page_realm for page nodes. > $grants[] = array( > 'realm' => 'page_realm', > 'gid' => 1, > 'grant_view' => 1, > 'grant_update' => 0, > 'grant_delete' => 0, > 'priority' => 0, > ); > } > return $grants; > } > > /** > * Implementation of hook_node_access_records_alter(). > */ > function node_test_node_access_records_alter(&$grants) { > if (!empty($grants)) { > foreach ($grants as $key => $grant) { > // Alter grant from page_realm to alter_realm and modify the gid. > if ($grant['realm'] == 'page_realm') { > $grants[$key]['realm'] = 'alter_realm'; > $grants[$key]['gid'] = 2; > } > } > } > }