Skip to content
Snippets Groups Projects
Unverified Commit 96763379 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3042472 by claudiu.cristea, phenaproxima, Lendude: Convert...

Issue #3042472 by claudiu.cristea, phenaproxima, Lendude: Convert HandlerArgumentUserUidTest into a kernel test and clean up the surrounding code
parent 1cb3315f
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -9,7 +9,7 @@ module: views
description: ''
tag: ''
base_table: users_field_data
base_field: nid
base_field: uid
core: '8'
display:
default:
......
<?php
namespace Drupal\Tests\user\Functional\Views;
namespace Drupal\Tests\user\Kernel\Views;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
......@@ -9,12 +13,24 @@
*
* @group user
*/
class HandlerArgumentUserUidTest extends UserTestBase {
class HandlerArgumentUserUidTest extends KernelTestBase {
use UserCreationTrait;
/**
* Views used by this test.
* {@inheritdoc}
*/
public static $modules = [
'system',
'user',
'user_test_views',
'views',
];
/**
* Test views.
*
* @var array
* @var string[]
*/
public static $testViews = ['test_user_uid_argument'];
......@@ -22,33 +38,39 @@ class HandlerArgumentUserUidTest extends UserTestBase {
* Tests the generated title of an 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.
$this->executeView($view, [rand(1000, 10000)]);
$view->preview(NULL, [rand(1000, 10000)]);
$this->assertFalse($view->getTitle());
$view->destroy();
// Tests a valid user.
$account = $this->drupalCreateUser();
$this->executeView($view, [$account->id()]);
$this->assertEqual($view->getTitle(), $account->label());
$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');
$this->executeView($view, [0]);
$this->assertEqual($view->getTitle(), $anonymous);
$view->preview(NULL, [0]);
$this->assertEquals($anonymous, $view->getTitle());
$view->destroy();
$view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
$this->executeView($view, [$account->id() . ',0']);
$this->assertEqual($view->getTitle(), $account->label() . ', ' . $anonymous);
$view->preview(NULL, [$account->id() . ',0']);
$this->assertEquals($account->label() . ', ' . $anonymous, $view->getTitle());
$view->destroy();
$view->getDisplay()->getHandler('argument', 'uid')->options['break_phrase'] = TRUE;
$this->executeView($view, ['0,' . $account->id()]);
$this->assertEqual($view->getTitle(), $anonymous . ', ' . $account->label());
$view->preview(NULL, ['0,' . $account->id()]);
$this->assertEquals($anonymous . ', ' . $account->label(), $view->getTitle());
$view->destroy();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment