ArgumentDefaultTest.php

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

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() {
        $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.');
    }

}

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.