You are here

public function NodeAccessLanguageFallbackTest::checkRecords in Drupal 8

Same name and namespace in other branches
  1. 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.

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 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
    ->assertEquals(count($records), $count);

  // 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);
  }
}