You are here

public function ArgumentDefaultTest::testPluginArgumentDefaultCurrentUser in Drupal 9

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

Tests the current user with argument default.

File

core/modules/user/tests/src/Kernel/Views/ArgumentDefaultTest.php, line 40

Class

ArgumentDefaultTest
Tests views user argument default plugin.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testPluginArgumentDefaultCurrentUser() {
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('user');
  ViewTestData::createTestViews(static::class, [
    'user_test_views',
  ]);

  // Create a user to test.
  $account = $this
    ->createUser();

  // Switch the user.
  $this->container
    ->get('account_switcher')
    ->switchTo($account);
  $view = Views::getView('test_plugin_argument_default_current_user');
  $view
    ->initHandlers();
  $this
    ->assertEquals($account
    ->id(), $view->argument['null']
    ->getDefaultArgument(), 'Uid of the current user is used.');
}