You are here

function NodeQueryAlterTest::testNodeQueryAlterLowLevelNoAccess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeQueryAlterTest.php \Drupal\node\Tests\NodeQueryAlterTest::testNodeQueryAlterLowLevelNoAccess()

Tests 'node_access' query alter, for user without access.

Verifies that a non-standard table alias can be used, and that a user without node access cannot view the nodes.

File

core/modules/node/src/Tests/NodeQueryAlterTest.php, line 81
Contains \Drupal\node\Tests\NodeQueryAlterTest.

Class

NodeQueryAlterTest
Tests that node access queries are properly altered by the node module.

Namespace

Drupal\node\Tests

Code

function testNodeQueryAlterLowLevelNoAccess() {

  // User without access should be able to view 0 nodes.
  try {
    $query = db_select('node', 'mytab')
      ->fields('mytab');
    $query
      ->addTag('node_access');
    $query
      ->addMetaData('op', 'view');
    $query
      ->addMetaData('account', $this->noAccessUser);
    $result = $query
      ->execute()
      ->fetchAll();
    $this
      ->assertEqual(count($result), 0, 'User with no access cannot see nodes');
  } catch (\Exception $e) {
    $this
      ->fail(t('Altered query is malformed'));
  }
}