function NodeQueryAlterTest::testNodeQueryAlterLowLevelWithAccess

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\NodeQueryAlterTest::testNodeQueryAlterLowLevelWithAccess()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\NodeQueryAlterTest::testNodeQueryAlterLowLevelWithAccess()
  3. 10 core/modules/node/tests/src/Functional/NodeQueryAlterTest.php \Drupal\Tests\node\Functional\NodeQueryAlterTest::testNodeQueryAlterLowLevelWithAccess()

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

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

File

core/modules/node/tests/src/Functional/NodeQueryAlterTest.php, line 85

Class

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

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeQueryAlterLowLevelWithAccess() : void {
    // User with access should be able to view 4 nodes.
    try {
        $query = Database::getConnection()->select('node', 'n')
            ->fields('n');
        $query->addTag('node_access');
        $query->addMetaData('op', 'view');
        $query->addMetaData('account', $this->accessUser);
        $result = $query->execute()
            ->fetchAll();
        $this->assertCount(4, $result, 'User with access can see correct nodes');
    } catch (\Exception) {
        $this->fail('Altered query is malformed');
    }
}

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