diff --git a/core/modules/user/src/UserData.php b/core/modules/user/src/UserData.php
index 3418c83..498b360 100644
--- a/core/modules/user/src/UserData.php
+++ b/core/modules/user/src/UserData.php
@@ -29,49 +29,42 @@ public function __construct(Connection $connection) {
   /**
    * {@inheritdoc}
    */
-  public function get($module, $uid = NULL, $name = NULL) {
+  public function get($module, $uid = NULL, $name = NULL, $value = NULL) {
+    $args = ['uid' => $uid, 'name' => $name, 'value' => $value];
+    if (!$args_not_set = array_filter($args, 'is_null')) {
+      throw new \InvalidArgumentException('All four arguments can not be set at the same time.');
+    }
+    $args_set = array_diff_key($args, $args_not_set);
     $query = $this->connection->select('users_data', 'ud')
       ->fields('ud')
       ->condition('module', $module);
-    if (isset($uid)) {
-      $query->condition('uid', $uid);
-    }
-    if (isset($name)) {
-      $query->condition('name', $name);
+    foreach ($args_set as $name => $arg) {
+      $query->condition($name, $arg);
     }
-    $result = $query->execute();
-    // If $module, $uid, and $name was passed, return the value.
-    if (isset($name) && isset($uid)) {
-      $result = $result->fetchAllAssoc('uid');
-      if (isset($result[$uid])) {
-        return $result[$uid]->serialized ? unserialize($result[$uid]->value) : $result[$uid]->value;
+    $result = [];
+    $args_not_set = array_keys($args_not_set);
+    $arg_not_set = $args_not_set[0];
+    $n = count($args_set);
+    foreach ($query->execute() as $row) {
+      if ($row->serialized) {
+        $row->value = unserialize($row->value);
       }
-      return NULL;
-    }
-    // If $module and $uid was passed, return the name/value pairs.
-    elseif (isset($uid)) {
-      $return = array();
-      foreach ($result as $record) {
-        $return[$record->name] = ($record->serialized ? unserialize($record->value) : $record->value);
-      }
-      return $return;
-    }
-    // If $module and $name was passed, return the uid/value pairs.
-    elseif (isset($name)) {
-      $return = array();
-      foreach ($result as $record) {
-        $return[$record->uid] = ($record->serialized ? unserialize($record->value) : $record->value);
+      switch ($n) {
+        case 2:
+          $result[] = $row->$arg_not_set;
+          break;
+        case 1:
+          $result[$row->$arg_not_set] = $row->{$args_not_set[1]};
+          break;
+        case 0:
+          $result[$row->uid][$row->name] = $row->value;
+          break;
       }
-      return $return;
     }
-    // If only $module was passed, return data keyed by uid and name.
-    else {
-      $return = array();
-      foreach ($result as $record) {
-        $return[$record->uid][$record->name] = ($record->serialized ? unserialize($record->value) : $record->value);
-      }
-      return $return;
+    if ($n == 2 && $arg_not_set == 'value') {
+      return $result ? reset($result) : NULL;
     }
+    return $result;
   }
 
   /**
diff --git a/core/modules/user/src/UserDataInterface.php b/core/modules/user/src/UserDataInterface.php
index eb20167..2d93016 100644
--- a/core/modules/user/src/UserDataInterface.php
+++ b/core/modules/user/src/UserDataInterface.php
@@ -16,18 +16,26 @@
    *   (optional) The user account ID the data is associated with.
    * @param string $name
    *   (optional) The name of the data key.
+   * @param string $value
+   *   (optional) The value of the data key.
    *
    * @return mixed|array
    *   The requested user account data, depending on the arguments passed:
    *   - For $module, $name, and $uid, the stored value is returned, or NULL if
    *     no value was found.
+   *   - For $module, $name, and $value, a list of uids is returned.
+   *   - For $module, $uid, and $value, a list of names is returned.
    *   - For $module and $uid, an associative array is returned that contains
    *     the stored data name/value pairs.
    *   - For $module and $name, an associative array is returned whose keys are
    *     user IDs and whose values contain the stored values.
+   *   - For $module and $value, an associative array is returned whose keys
+   *     are user IDs and whose values contain the names.
    *   - For $module only, an associative array is returned that contains all
    *     existing data for $module in all user accounts, keyed first by user ID
    *     and $name second.
+   *
+   * @see \Drupal\Tests\user\Unit\UserDataTest::getDataProvider() 
    */
   public function get($module, $uid = NULL, $name = NULL);
 
diff --git a/core/modules/user/tests/src/Unit/UserDataTest.php b/core/modules/user/tests/src/Unit/UserDataTest.php
new file mode 100644
index 0000000..e8e7622
--- /dev/null
+++ b/core/modules/user/tests/src/Unit/UserDataTest.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Drupal\Tests\user\Unit;
+
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Database\Query\Select;
+use Drupal\Tests\UnitTestCase;
+use Drupal\user\UserData;
+
+/**
+ * @coversDefaultClass \Drupal\user\UserData
+ * @group user
+ */
+class UserDataTest extends UnitTestCase {
+
+  /**
+   * @var \Prophecy\Prophecy\ObjectProphecy
+   */
+  protected $select;
+
+  /**
+   * @var \Drupal\user\UserData
+   */
+  protected $userData;
+
+  /**
+   * @var string
+   */
+  protected $module;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    $this->module = $this->randomMachineName();
+    $connection = $this->prophesize(Connection::class);
+    $this->select = $this->prophesize(Select::class);
+    $connection->select('users_data', 'ud')->willReturn($this->select->reveal());
+    $this->select->fields('ud')->willReturn($this->select);
+    $this->select->condition('module', $this->module)->willReturn($this->select);
+    $this->userData = new UserData($connection->reveal());
+  }
+
+  /**
+   * @expectedException \InvalidArgumentException
+   * @expectedExceptionMessage All four arguments can not be set at the same time.
+   */
+  public function testGetUidNameValue() {
+    $this->userData->get($this->randomMachineName(), $this->randomMachineName(), $this->randomMachineName(), $this->randomMachineName());
+  }
+
+  /**
+   * @covers ::get
+   * @dataProvider getDataProvider
+   */
+  public function testGet($contents, $uid, $name, $value, $expected) {
+    if (isset($uid)) {
+      $this->select->condition('uid', $uid)->willReturn($this->select);
+    }
+    if (isset($name)) {
+      $this->select->condition('name', $name)->willReturn($this->select);
+    }
+    if (isset($value)) {
+      $this->select->condition('value', $value)->willReturn($this->select);
+    }
+    $this->select->execute()->willReturn($contents);
+    $results = $this->userData->get($this->module, $uid, $name, $value);
+    $this->assertSame($expected, $results);
+  }
+
+  /**
+   * Data provider for testGet.
+   *
+   * @return array
+   */
+  public function getDataProvider() {
+    $uid = mt_rand(1, 10);
+    $name = $this->randomMachineName();
+    $value = mt_rand(20, 30);
+    $contents = [
+      (object) [
+        'serialized' => 0,
+        'uid' => $uid,
+        'name' => $name,
+        'value' => $value
+      ]
+    ];
+    return [
+      [$contents, $uid, $name, NULL, $value],
+      [$contents, $uid, NULL, $value, [$name]],
+      [$contents, NULL, $name, $value, [$uid]],
+      [$contents, $uid, NULL, NULL, [$name => $value]],
+      [$contents, NULL, $name, NULL, [$uid => $value]],
+      [$contents, NULL, NULL, $value, [$uid => $name]],
+      [$contents, NULL, NULL, NULL, [$uid => [$name => $value]]],
+    ];
+  }
+
+}
