class UserDataTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Kernel/Views/UserDataTest.php \Drupal\Tests\user\Kernel\Views\UserDataTest
Tests the user data service field handler.
@group user
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \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 implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\user\Kernel\Views\UserDataTest implements \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of UserDataTest
See also
\Drupal\user\Plugin\views\field\UserData
File
-
core/
modules/ user/ tests/ src/ Kernel/ Views/ UserDataTest.php, line 17
Namespace
Drupal\Tests\user\Kernel\ViewsView source
class UserDataTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = [
'test_user_data',
];
/**
* {@inheritdoc}
*/
protected static $modules = [
'user_test_views',
];
/**
* Tests field handler.
*/
public function testDataField() {
ViewTestData::createTestViews(static::class, [
'user_test_views',
]);
$this->installEntitySchema('user');
$this->installSchema('user', [
'users_data',
]);
$user = User::create([
// Set 'uid' because the 'test_user_data' view filters the user with an ID
// equal to 2.
'uid' => 2,
'name' => $this->randomMachineName(),
]);
$user->save();
// Add some random value as user data.
$user_data = $this->container
->get('user.data');
$random_value = $this->randomMachineName();
$user_data->set('views_test_config', $user->id(), 'test_value_name', $random_value);
$view = Views::getView('test_user_data');
$this->executeView($view);
$output = $view->field['data']
->render($view->result[0]);
// Assert that using a valid user data key renders the value.
$this->assertEquals($random_value, $output);
$view->field['data']->options['data_name'] = $this->randomMachineName();
$output = $view->field['data']
->render($view->result[0]);
// An invalid configuration does not return anything.
$this->assertNull($output);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.