You are here

public function HandlerFilterCurrentUserTest::testFilterCurrentUserAsUser 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::testFilterCurrentUserAsUser()
  2. 10 core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterCurrentUserTest::testFilterCurrentUserAsUser()

Tests the current user filter handler with logged-in user.

File

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

Class

HandlerFilterCurrentUserTest
Tests the current user filter handler.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testFilterCurrentUserAsUser() {
  $column_map = [
    'uid' => 'uid',
  ];
  $user = reset($this->users);
  $this->currentUser
    ->setAccount($user);
  $view = Views::getView('test_filter_current_user');
  $view
    ->initHandlers();
  $view->filter['uid_current']->value = 0;
  $this
    ->executeView($view);
  $expected = [];
  $expected[] = [
    'uid' => 2,
  ];
  $expected[] = [
    'uid' => 3,
  ];
  $expected[] = [
    'uid' => 4,
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $column_map, 'User can view all users except itself 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 = [];
  $expected[] = [
    'uid' => 1,
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $column_map, 'User can only view itself when current filter is TRUE.');
  $view
    ->destroy();
}