You are here

function NodeQueryAlterTest::testNodeQueryAlterLowLevelEditAccess in Zircon Profile 8.0

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

Tests 'node_access' query alter, for edit access.

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

File

core/modules/node/src/Tests/NodeQueryAlterTest.php, line 104
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 testNodeQueryAlterLowLevelEditAccess() {

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