ArgumentDefaultTest.php

Same filename in this branch
  1. 11.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
  2. 11.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php
Same filename in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
  2. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php
  3. 9 core/modules/user/tests/src/Kernel/Views/ArgumentDefaultTest.php
  4. 8.9.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
  5. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php
  6. 8.9.x core/modules/user/tests/src/Kernel/Views/ArgumentDefaultTest.php
  7. 10 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
  8. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php
  9. 10 core/modules/user/tests/src/Kernel/Views/ArgumentDefaultTest.php

Namespace

Drupal\Tests\user\Kernel\Views

File

core/modules/user/tests/src/Kernel/Views/ArgumentDefaultTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\user\Kernel\Views;

use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;

/**
 * Tests views user argument default plugin.
 *
 * @group user
 */
class ArgumentDefaultTest extends KernelTestBase {
    use UserCreationTrait;
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
        'system',
        'user',
        'user_test_views',
        'views',
    ];
    
    /**
     * Views used by this test.
     *
     * @var array
     */
    public static $testViews = [
        'test_plugin_argument_default_current_user',
    ];
    
    /**
     * Tests the current user with argument default.
     */
    public function testPluginArgumentDefaultCurrentUser() : void {
        $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.');
    }

}

Classes

Title Deprecated Summary
ArgumentDefaultTest Tests views user argument default plugin.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.