function NodeAccessLanguageFallbackTest::checkRecords

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

Queries the node_access table and checks for proper storage.

Parameters

int $count: The number of rows expected by the query (equal to the translation count).

$langcode: The expected language code set as the fallback property.

1 call to NodeAccessLanguageFallbackTest::checkRecords()
NodeAccessLanguageFallbackTest::testNodeAccessLanguageFallback in core/modules/node/tests/src/Functional/NodeAccessLanguageFallbackTest.php
Tests node access fallback handling with multiple node languages.

File

core/modules/node/tests/src/Functional/NodeAccessLanguageFallbackTest.php, line 126

Class

NodeAccessLanguageFallbackTest
Tests that the node_access system stores the proper fallback marker.

Namespace

Drupal\Tests\node\Functional

Code

public function checkRecords($count, $langcode = 'hu') : void {
    $select = \Drupal::database()->select('node_access', 'na')
        ->fields('na', [
        'nid',
        'fallback',
        'langcode',
        'grant_view',
    ])
        ->condition('na.realm', 'node_access_test', '=')
        ->condition('na.gid', 8888, '=');
    $records = $select->execute()
        ->fetchAll();
    // Check that the expected record count is returned.
    $this->assertCount($count, $records);
    // The fallback value is 'hu' and should be set to 1. For other languages,
    // it should be set to 0. Casting to boolean lets us run that comparison.
    foreach ($records as $record) {
        $this->assertEquals((bool) $record->fallback, $record->langcode === $langcode);
    }
}

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