summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/node/tests
diff options
context:
space:
mode:
authorTorsten Grote <grote@kolabsys.com>2014-01-29 15:00:00 (GMT)
committerTorsten Grote <grote@kolabsys.com>2014-01-29 15:00:00 (GMT)
commitd9e4a0f1b5f45b2e3fed0908a69dad264d40b15b (patch)
tree76d774e7d2ce4ba7c0754c590a6b730b6f6ceed9 /kolab.org/www/drupal-7.26/modules/node/tests
parent5145fb6b6b03f545d7b82db89850dac1b3b49d78 (diff)
downloadkolab.org-www-d9e4a0f1b5f45b2e3fed0908a69dad264d40b15b.tar.gz
add new drupal version
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/node/tests')
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.install42
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.module230
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_test.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_test.module181
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.info12
-rw-r--r--kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.module15
7 files changed, 504 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.info b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.info
new file mode 100644
index 0000000..d17db64
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.info
@@ -0,0 +1,12 @@
+name = "Node module access tests"
+description = "Support module for node permission testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.install b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.install
new file mode 100644
index 0000000..1f33d51
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.install
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the node_access_test module.
+ */
+
+/**
+ * Implements hook_schema().
+ */
+function node_access_test_schema() {
+ $schema['node_access_test'] = array(
+ 'description' => 'The base table for node_access_test.',
+ 'fields' => array(
+ 'nid' => array(
+ 'description' => 'The {node}.nid this record affects.',
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ 'private' => array(
+ 'description' => 'Boolean indicating whether the node is private (visible to administrator) or not (visible to non-administrators).',
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ ),
+ 'indexes' => array(
+ 'nid' => array('nid'),
+ ),
+ 'primary key' => array('nid'),
+ 'foreign keys' => array(
+ 'versioned_node' => array(
+ 'table' => 'node',
+ 'columns' => array('nid' => 'nid'),
+ ),
+ ),
+ );
+
+ return $schema;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.module b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.module
new file mode 100644
index 0000000..ec35c41
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_access_test.module
@@ -0,0 +1,230 @@
+<?php
+
+/**
+ * @file
+ * A dummy module implementing node access related hooks for testing purposes.
+ *
+ * A dummy module implementing node access related hooks to test API interaction
+ * with the Node module. This module restricts view permission to those with
+ * a special 'node test view' permission.
+ */
+
+/**
+ * Implements hook_node_grants().
+ */
+function node_access_test_node_grants($account, $op) {
+ $grants = array();
+ // First grant a grant to the author for own content.
+ $grants['node_access_test_author'] = array($account->uid);
+ if ($op == 'view' && user_access('node test view', $account)) {
+ $grants['node_access_test'] = array(8888, 8889);
+ }
+ if ($op == 'view' && $account->uid == variable_get('node_test_node_access_all_uid', 0)) {
+ $grants['node_access_all'] = array(0);
+ }
+ return $grants;
+}
+
+/**
+ * Implements hook_node_access_records().
+ */
+function node_access_test_node_access_records($node) {
+ $grants = array();
+ // For NodeAccessBaseTableTestCase, only set records for private nodes.
+ if (!variable_get('node_access_test_private') || $node->private) {
+ $grants[] = array(
+ 'realm' => 'node_access_test',
+ 'gid' => 8888,
+ 'grant_view' => 1,
+ 'grant_update' => 0,
+ 'grant_delete' => 0,
+ 'priority' => 0,
+ );
+ $grants[] = array(
+ 'realm' => 'node_access_test',
+ 'gid' => 8889,
+ 'grant_view' => 1,
+ 'grant_update' => 0,
+ 'grant_delete' => 0,
+ 'priority' => 0,
+ );
+ // For the author realm, the GID is equivalent to a UID, which
+ // means there are many many groups of just 1 user.
+ $grants[] = array(
+ 'realm' => 'node_access_test_author',
+ 'gid' => $node->uid,
+ 'grant_view' => 1,
+ 'grant_update' => 1,
+ 'grant_delete' => 1,
+ 'priority' => 0,
+ );
+ }
+
+ return $grants;
+}
+
+/**
+ * Implements hook_permission().
+ *
+ * Sets up permissions for this module.
+ */
+function node_access_test_permission() {
+ return array('node test view' => array('title' => 'View content'));
+}
+
+/**
+ * Implements hook_menu().
+ *
+ * Sets up a page that lists nodes.
+ */
+function node_access_test_menu() {
+ $items = array();
+ $items['node_access_test_page'] = array(
+ 'title' => 'Node access test',
+ 'page callback' => 'node_access_test_page',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_SUGGESTED_ITEM,
+ );
+ $items['node_access_entity_test_page'] = array(
+ 'title' => 'Node access test',
+ 'page callback' => 'node_access_entity_test_page',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_SUGGESTED_ITEM,
+ );
+ return $items;
+}
+
+/**
+ * Page callback for node access test page.
+ *
+ * Page should say "No nodes" if there are no nodes, and "Yes, # nodes" (with
+ * the number filled in) if there were nodes the user could access. Also, the
+ * database query is shown, and a list of the node IDs, for debugging purposes.
+ * And if there is a query exception, the page says "Exception" and gives the
+ * error.
+ */
+function node_access_test_page() {
+ $output = '';
+
+ try {
+ $query = db_select('node', 'mytab')
+ ->fields('mytab');
+ $query->addTag('node_access');
+ $result = $query->execute()->fetchAll();
+
+ if (count($result)) {
+ $output .= '<p>Yes, ' . count($result) . ' nodes</p>';
+ $output .= '<ul>';
+ foreach ($result as $item) {
+ $output .= '<li>' . $item->nid . '</li>';
+ }
+ $output .= '</ul>';
+ }
+ else {
+ $output .= '<p>No nodes</p>';
+ }
+
+ $output .= '<p>' . ((string) $query ) . '</p>';
+ }
+ catch (Exception $e) {
+ $output = '<p>Exception</p>';
+ $output .= '<p>' . $e->getMessage() . '</p>';
+ }
+
+ return $output;
+}
+
+/**
+ * Page callback for node access entity test page.
+ *
+ * Page should say "No nodes" if there are no nodes, and "Yes, # nodes" (with
+ * the number filled in) if there were nodes the user could access. Also, the
+ * database query is shown, and a list of the node IDs, for debugging purposes.
+ * And if there is a query exception, the page says "Exception" and gives the
+ * error.
+ *
+ * @see node_access_test_menu()
+ */
+function node_access_entity_test_page() {
+ $output = '';
+ try {
+ $query = new EntityFieldQuery;
+ $result = $query->fieldCondition('body', 'value', 'A', 'STARTS_WITH')->execute();
+ if (!empty($result['node'])) {
+ $output .= '<p>Yes, ' . count($result['node']) . ' nodes</p>';
+ $output .= '<ul>';
+ foreach ($result['node'] as $nid => $v) {
+ $output .= '<li>' . $nid . '</li>';
+ }
+ $output .= '</ul>';
+ }
+ else {
+ $output .= '<p>No nodes</p>';
+ }
+ }
+ catch (Exception $e) {
+ $output = '<p>Exception</p>';
+ $output .= '<p>' . $e->getMessage() . '</p>';
+ }
+
+ return $output;
+}
+
+/**
+ * Implements hook_form_BASE_FORM_ID_alter().
+ */
+function node_access_test_form_node_form_alter(&$form, $form_state) {
+ // Only show this checkbox for NodeAccessBaseTableTestCase.
+ if (variable_get('node_access_test_private')) {
+ $form['private'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Private'),
+ '#description' => t('Check here if this content should be set private and only shown to privileged users.'),
+ '#default_value' => isset($form['#node']->private) ? $form['#node']->private : FALSE,
+ );
+ }
+}
+
+/**
+ * Implements hook_node_load().
+ */
+function node_access_test_node_load($nodes, $types) {
+ $result = db_query('SELECT nid, private FROM {node_access_test} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
+ foreach ($result as $record) {
+ $nodes[$record->nid]->private = $record->private;
+ }
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+
+function node_access_test_node_delete($node) {
+ db_delete('node_access_test')->condition('nid', $node->nid)->execute();
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function node_access_test_node_insert($node) {
+ _node_access_test_node_write($node);
+}
+
+/**
+ * Implements hook_nodeapi_update().
+ */
+function node_access_test_node_update($node) {
+ _node_access_test_node_write($node);
+}
+
+/**
+ * Helper for node insert/update.
+ */
+function _node_access_test_node_write($node) {
+ if (isset($node->private)) {
+ db_merge('node_access_test')
+ ->key(array('nid' => $node->nid))
+ ->fields(array('private' => (int) $node->private))
+ ->execute();
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_test.info b/kolab.org/www/drupal-7.26/modules/node/tests/node_test.info
new file mode 100644
index 0000000..240a2b7
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_test.info
@@ -0,0 +1,12 @@
+name = "Node module tests"
+description = "Support module for node related testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_test.module b/kolab.org/www/drupal-7.26/modules/node/tests/node_test.module
new file mode 100644
index 0000000..edc175f
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_test.module
@@ -0,0 +1,181 @@
+<?php
+
+/**
+ * @file
+ * A dummy module for testing node related hooks.
+ *
+ * This is a dummy module that implements node related hooks to test API
+ * interaction with the Node module.
+ */
+
+/**
+ * Implements hook_node_load().
+ */
+function node_test_node_load($nodes, $types) {
+ // Add properties to each loaded node which record the parameters that were
+ // passed in to this function, so the tests can check that (a) this hook was
+ // called, and (b) the parameters were what we expected them to be.
+ $nids = array_keys($nodes);
+ ksort($nids);
+ sort($types);
+ foreach ($nodes as $node) {
+ $node->node_test_loaded_nids = $nids;
+ $node->node_test_loaded_types = $types;
+ }
+}
+
+/**
+ * Implements hook_node_view().
+ */
+function node_test_node_view($node, $view_mode) {
+ if ($view_mode == '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 ($view_mode != '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>',
+ );
+ }
+}
+
+/**
+ * Implements 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),
+ );
+}
+
+/**
+ * Implements hook_node_access_records().
+ */
+function node_test_node_access_records($node) {
+ // Return nothing when testing for empty responses.
+ if (!empty($node->disable_node_access)) {
+ return;
+ }
+ $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;
+}
+
+/**
+ * Implements 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;
+ }
+ }
+ }
+}
+
+/**
+ * Implements 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();
+}
+
+/**
+ * Implements hook_node_presave().
+ */
+function node_test_node_presave($node) {
+ if ($node->title == 'testing_node_presave') {
+ // Sun, 19 Nov 1978 05:00:00 GMT
+ $node->created = 280299600;
+ // Drupal 1.0 release.
+ $node->changed = 979534800;
+ }
+ // Determine changes.
+ if (!empty($node->original) && $node->original->title == 'test_changes') {
+ if ($node->original->title != $node->title) {
+ $node->title .= '_presave';
+ }
+ }
+}
+
+/**
+ * Implements hook_node_update().
+ */
+function node_test_node_update($node) {
+ // Determine changes on update.
+ if (!empty($node->original) && $node->original->title == 'test_changes') {
+ if ($node->original->title != $node->title) {
+ $node->title .= '_update';
+ }
+ }
+}
+
+/**
+ * Implements hook_entity_view_mode_alter().
+ */
+function node_test_entity_view_mode_alter(&$view_mode, $context) {
+ // Only alter the view mode if we are on the test callback.
+ if ($change_view_mode = variable_get('node_test_change_view_mode', '')) {
+ $view_mode = $change_view_mode;
+ }
+}
+
+/**
+ * Implements hook_node_insert().
+ *
+ * This tests saving a node on node insert.
+ *
+ * @see NodeSaveTest::testNodeSaveOnInsert()
+ */
+function node_test_node_insert($node) {
+ // Set the node title to the node ID and save.
+ if ($node->title == 'new') {
+ $node->title = 'Node '. $node->nid;
+ // Remove the is_new flag, so that the node is updated and not inserted
+ // again.
+ unset($node->is_new);
+ node_save($node);
+ }
+}
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.info b/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.info
new file mode 100644
index 0000000..b5a0dcd
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.info
@@ -0,0 +1,12 @@
+name = "Node module exception tests"
+description = "Support module for node related exception testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.module b/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.module
new file mode 100644
index 0000000..66bc717
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/node/tests/node_test_exception.module
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * A module implementing node related hooks to test API interaction.
+ */
+
+/**
+ * Implements hook_node_insert().
+ */
+function node_test_exception_node_insert($node) {
+ if ($node->title == 'testing_transaction_exception') {
+ throw new Exception('Test exception for rollback.');
+ }
+}