comparison core/modules/user/src/Tests/Views/UserDataTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\user\Tests\Views;
4
5 use Drupal\views\Views;
6
7 /**
8 * Tests the user data service field handler.
9 *
10 * @group user
11 * @see \Drupal\user\Plugin\views\field\UserData
12 */
13 class UserDataTest extends UserTestBase {
14
15 /**
16 * Provides the user data service object.
17 *
18 * @var \Drupal\user\UserDataInterface
19 */
20 protected $userData;
21
22 /**
23 * Views used by this test.
24 *
25 * @var array
26 */
27 public static $testViews = ['test_user_data'];
28
29 /**
30 * Tests field handler.
31 */
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);
37
38 $view = Views::getView('test_user_data');
39 $this->executeView($view);
40
41 $output = $view->field['data']->render($view->result[0]);
42 $this->assertEqual($output, $random_value, 'A valid user data got rendered.');
43
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');
47
48 }
49
50 }