3 namespace Drupal\user\Tests\Views;
5 use Drupal\views\Views;
8 * Tests the user data service field handler.
11 * @see \Drupal\user\Plugin\views\field\UserData
13 class UserDataTest extends UserTestBase {
16 * Provides the user data service object.
18 * @var \Drupal\user\UserDataInterface
23 * Views used by this test.
27 public static $testViews = ['test_user_data'];
30 * Tests field handler.
32 public function testDataField() {
33 // But some random values into the user data service.
34 $this->userData = $this->container->get('user.data');
35 $random_value = $this->randomMachineName();
36 $this->userData->set('views_test_config', $this->users[0]->id(), 'test_value_name', $random_value);
38 $view = Views::getView('test_user_data');
39 $this->executeView($view);
41 $output = $view->field['data']->render($view->result[0]);
42 $this->assertEqual($output, $random_value, 'A valid user data got rendered.');
44 $view->field['data']->options['data_name'] = $this->randomMachineName();
45 $output = $view->field['data']->render($view->result[0]);
46 $this->assertFalse($output, 'An invalid configuration does not return anything');