You are here

public function QueryAccessTest::testNoFiltering in Entity API 8

Tests no filtering when query access is disabled.

File

tests/src/Kernel/QueryAccess/QueryAccessTest.php, line 290

Class

QueryAccessTest
Test query access filtering for EntityQuery and Views.

Namespace

Drupal\Tests\entity\Kernel\QueryAccess

Code

public function testNoFiltering() {

  // EntityQuery.
  $result = $this->storage
    ->getQuery()
    ->sort('id')
    ->accessCheck(FALSE)
    ->execute();
  $this
    ->assertEquals([
    $this->entities[0]
      ->id(),
    $this->entities[1]
      ->id(),
    $this->entities[2]
      ->id(),
  ], array_values($result));

  // Views.
  $view = Views::getView('entity_test_enhanced');
  $display = $view
    ->getDisplay();
  $display_options = $display
    ->getOption('query');
  $display_options['options']['disable_sql_rewrite'] = TRUE;
  $display
    ->setOption('query', $display_options);
  $view
    ->save();
  $view
    ->execute();
  $this
    ->assertIdenticalResultset($view, [
    [
      'id' => $this->entities[0]
        ->id(),
    ],
    [
      'id' => $this->entities[1]
        ->id(),
    ],
    [
      'id' => $this->entities[2]
        ->id(),
    ],
  ], [
    'id' => 'id',
  ]);
  $view = Views::getView('entity_test_enhanced');
  $display = $view
    ->getDisplay();
  $display_options['options']['disable_sql_rewrite'] = FALSE;
  $display
    ->setOption('query', $display_options);
  $view
    ->save();
}