class HandlerArgumentUserUidTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest
- 10 core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest
- 8.9.x core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest
Tests the handler of the user: uid Argument.
@group user
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of HandlerArgumentUserUidTest
File
-
core/
modules/ user/ tests/ src/ Kernel/ Views/ HandlerArgumentUserUidTest.php, line 16
Namespace
Drupal\Tests\user\Kernel\ViewsView source
class HandlerArgumentUserUidTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'user',
'user_test_views',
'views',
];
/**
* Test views.
*
* @var string[]
*/
public static $testViews = [
'test_user_uid_argument',
];
/**
* Tests the generated title of a user: uid argument.
*/
public function testArgumentTitle() {
$this->installSchema('system', [
'sequences',
]);
$this->installEntitySchema('user');
$this->installConfig([
'user',
]);
User::create([
'uid' => 0,
'name' => '',
])->save();
ViewTestData::createTestViews(static::class, [
'user_test_views',
]);
$view = Views::getView('test_user_uid_argument');
// Tests an invalid user uid.
$view->preview(NULL, [
rand(1000, 10000),
]);
$this->assertEmpty($view->getTitle());
$view->destroy();
// Tests a valid user.
$account = $this->createUser();
$view->preview(NULL, [
$account->id(),
]);
$this->assertEquals($account->label(), $view->getTitle());
$view->destroy();
// Tests the anonymous user.
$anonymous = $this->config('user.settings')
->get('anonymous');
$view->preview(NULL, [
0,
]);
$this->assertEquals($anonymous, $view->getTitle());
$view->destroy();
$view->getDisplay()
->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
$view->preview(NULL, [
$account->id() . ',0',
]);
$this->assertEquals($account->label() . ', ' . $anonymous, $view->getTitle());
$view->destroy();
$view->getDisplay()
->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
$view->preview(NULL, [
'0,' . $account->id(),
]);
$this->assertEquals($anonymous . ', ' . $account->label(), $view->getTitle());
$view->destroy();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.