Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / user / tests / src / Functional / Views / UserDataTest.php
diff --git a/web/core/modules/user/tests/src/Functional/Views/UserDataTest.php b/web/core/modules/user/tests/src/Functional/Views/UserDataTest.php
new file mode 100644 (file)
index 0000000..d15e6f3
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+namespace Drupal\Tests\user\Functional\Views;
+
+use Drupal\views\Views;
+
+/**
+ * Tests the user data service field handler.
+ *
+ * @group user
+ * @see \Drupal\user\Plugin\views\field\UserData
+ */
+class UserDataTest extends UserTestBase {
+
+  /**
+   * Provides the user data service object.
+   *
+   * @var \Drupal\user\UserDataInterface
+   */
+  protected $userData;
+
+  /**
+   * Views used by this test.
+   *
+   * @var array
+   */
+  public static $testViews = ['test_user_data'];
+
+  /**
+   * Tests field handler.
+   */
+  public function testDataField() {
+    // But some random values into the user data service.
+    $this->userData = $this->container->get('user.data');
+    $random_value = $this->randomMachineName();
+    $this->userData->set('views_test_config', $this->users[0]->id(), 'test_value_name', $random_value);
+
+    $view = Views::getView('test_user_data');
+    $this->executeView($view);
+
+    $output = $view->field['data']->render($view->result[0]);
+    $this->assertEqual($output, $random_value, 'A valid user data got rendered.');
+
+    $view->field['data']->options['data_name'] = $this->randomMachineName();
+    $output = $view->field['data']->render($view->result[0]);
+    $this->assertFalse($output, 'An invalid configuration does not return anything');
+
+  }
+
+}