function NodeQueryAlterTest::testNodeQueryAlterLowLevelEditAccess

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\NodeQueryAlterTest::testNodeQueryAlterLowLevelEditAccess()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\NodeQueryAlterTest::testNodeQueryAlterLowLevelEditAccess()
  3. 10 core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\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/tests/src/Functional/NodeQueryAlterTest.php, line 150

Class

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

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeQueryAlterLowLevelEditAccess() : void {
    // User with view-only access should not be able to edit nodes.
    try {
        $query = Database::getConnection()->select('node', 'n')
            ->fields('n');
        $query->addTag('node_access');
        $query->addMetaData('op', 'update');
        $query->addMetaData('account', $this->accessUser);
        $result = $query->execute()
            ->fetchAll();
        $this->assertCount(0, $result, 'User with view-only access cannot edit nodes');
    } catch (\Exception $e) {
        $this->fail($e->getMessage());
        $this->fail((string) $query);
        $this->fail('Altered query is malformed');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.