summaryrefslogtreecommitdiff
path: root/modules/node/tests
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-27 02:01:54 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-05-27 02:01:54 +0000
commite8364f5156decde5b6d5c9f79dbe01910c39a89a (patch)
tree8c00563b0557f12cab5a6aaac510d983bde2cdeb /modules/node/tests
parent9eeec33415ac04ac78431eae9e902aed385650b6 (diff)
downloadbrdo-e8364f5156decde5b6d5c9f79dbe01910c39a89a.tar.gz
brdo-e8364f5156decde5b6d5c9f79dbe01910c39a89a.tar.bz2
#309007 by moshe weitzman, agentrickard, and mcarbone: Add hook_node_access_records_alter() and hook_node_grants_alter() to allow complex interactions between two or more node access modules.
Diffstat (limited to 'modules/node/tests')
-rw-r--r--modules/node/tests/node_test.module67
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/node/tests/node_test.module b/modules/node/tests/node_test.module
index 1ad3227ff..27a303e06 100644
--- a/modules/node/tests/node_test.module
+++ b/modules/node/tests/node_test.module
@@ -33,3 +33,70 @@ function node_test_node_view($node, $teaser) {
);
}
}
+
+/**
+ * Implementation of hook_node_grants().
+ */
+function node_test_node_grants($account, $op) {
+ // Give everyone full grants so we don't break other node tests.
+ // Our node access tests asserts three realms of access.
+ // @see testGrantAlter()
+ return array(
+ 'test_article_realm' => array(1),
+ 'test_page_realm' => array(1),
+ 'test_alter_realm' => array(2),
+ );
+}
+
+/**
+ * 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' => 'test_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' => 'test_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, $node) {
+ if (!empty($grants)) {
+ foreach ($grants as $key => $grant) {
+ // Alter grant from test_page_realm to test_alter_realm and modify the gid.
+ if ($grant['realm'] == 'test_page_realm' && $node->promote) {
+ $grants[$key]['realm'] = 'test_alter_realm';
+ $grants[$key]['gid'] = 2;
+ }
+ }
+ }
+}
+
+/**
+ * Implementation of hook_node_grants_alter().
+ */
+function node_test_node_grants_alter(&$grants, $account, $op) {
+ // Return an empty array of grants to prove that we can alter by reference.
+ $grants = array();
+}