function HandlerArgumentUserUidTest::testArgumentTitle
Same name in other branches
- 9 core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest::testArgumentTitle()
- 8.9.x core/modules/user/tests/src/Kernel/Views/HandlerArgumentUserUidTest.php \Drupal\Tests\user\Kernel\Views\HandlerArgumentUserUidTest::testArgumentTitle()
- 10 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 42
Class
- HandlerArgumentUserUidTest
- Tests the handler of the user: uid Argument.
Namespace
Drupal\Tests\user\Kernel\ViewsCode
public function testArgumentTitle() : void {
$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.