public function HandlerArgumentUserUidTest::testArgumentTitle in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest::testArgumentTitle()
Tests the generated title of a user: uid argument.
File
- core/
modules/ user/ tests/ src/ Kernel/ Views/ HandlerArgumentUserUidTest.php, line 40
Class
- HandlerArgumentUserUidTest
- Tests the handler of the user: uid Argument.
Namespace
Drupal\Tests\user\Kernel\ViewsCode
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();
}