You are here

public function HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous()
  2. 10 core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous()

Tests the current user filter handler with anonymous user.

File

core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php, line 42

Class

HandlerFilterCurrentUserTest
Tests the current user filter handler.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testFilterCurrentUserAsAnonymous() {
  $column_map = [
    'uid' => 'uid',
  ];
  $this->currentUser
    ->setAccount(new AnonymousUserSession());
  $view = Views::getView('test_filter_current_user');
  $view
    ->initHandlers();
  $view->filter['uid_current']->value = 0;
  $this
    ->executeView($view);
  $expected[] = [
    'uid' => 1,
  ];
  $expected[] = [
    'uid' => 2,
  ];
  $expected[] = [
    'uid' => 3,
  ];
  $expected[] = [
    'uid' => 4,
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $column_map, 'Anonymous account can view all accounts when current filter is FALSE.');
  $view
    ->destroy();
  $view = Views::getView('test_filter_current_user');
  $view
    ->initHandlers();
  $view->filter['uid_current']->value = 1;
  $this
    ->executeView($view);
  $expected = [];
  $this
    ->assertIdenticalResultset($view, $expected, $column_map, 'Anonymous account can view zero accounts when current filter is TRUE.');
  $view
    ->destroy();
}