function HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous
Same name in other branches
- 9 core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous()
- 8.9.x core/modules/user/tests/src/Kernel/Views/HandlerFilterCurrentUserTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterCurrentUserTest::testFilterCurrentUserAsAnonymous()
- 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 44
Class
- HandlerFilterCurrentUserTest
- Tests the current user filter handler.
Namespace
Drupal\Tests\user\Kernel\ViewsCode
public function testFilterCurrentUserAsAnonymous() : void {
$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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.