function node_access_test_page

7.x node_access_test.module node_access_test_page()

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.

2 string references to 'node_access_test_page'
NodeQueryAlter::testNodeQueryAlterWithUI in drupal-7.x/modules/node/node.test
Tests that node access permissions are followed.
node_access_test_menu in drupal-7.x/modules/node/tests/node_access_test.module
Implements hook_menu().

File

drupal-7.x/modules/node/tests/node_access_test.module, line 106
A dummy module implementing node access related hooks for testing purposes.

Code

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;
}