summaryrefslogtreecommitdiff
path: root/modules/node/tests/node_test.module
blob: 27a303e06a355b19440d898720ec1a589793d42b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
// $Id$

/**
 * @file
 * Dummy module implementing node related hooks to test API interaction with
 * the Node module.
 */

/**
 * Implementation of hook_node_view().
 */
function node_test_node_view($node, $teaser) {
  if ($node->build_mode == NODE_BUILD_RSS) {
    // Add RSS elements and namespaces when building the RSS feed.
    $node->rss_elements[] = array(
      'key' => 'testElement',
      'value' => t('Value of testElement RSS element for node !nid.', array('!nid' => $node->nid)),
    );
    $node->rss_namespaces['xmlns:drupaltest'] = 'http://example.com/test-namespace';

    // Add content that should be displayed only in the RSS feed.
    $node->content['extra_feed_content'] = array(
      '#markup' => '<p>' . t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->nid)) . '</p>',
      '#weight' => 10,
    );
  }

  if ($node->build_mode != NODE_BUILD_RSS) {
    // Add content that should NOT be displayed in the RSS feed.
    $node->content['extra_non_feed_content'] = array(
      '#markup' => '<p>' . t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->nid)) . '</p>',
    );
  }
}

/**
 * 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();
}