You are here

public function NodeAccessLanguageFallbackTest::checkRecords in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeAccessLanguageFallbackTest.php \Drupal\Tests\node\Functional\NodeAccessLanguageFallbackTest::checkRecords()
  2. 9 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.

File

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

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') {
  $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);
  }
}