diff --git a/core/modules/user/src/UserDataQuery.php b/core/modules/user/src/UserDataQuery.php index c6e5ea1..ff834e8 100644 --- a/core/modules/user/src/UserDataQuery.php +++ b/core/modules/user/src/UserDataQuery.php @@ -67,9 +67,6 @@ public function setValue($value) { $value = serialize($value); } $this->setter('value', $value); - if (!$is_scalar_value) { - $this->select->condition('serialized', 1); - } return $this; } diff --git a/core/modules/user/tests/src/Kernel/UserDataQueryTest.php b/core/modules/user/tests/src/Kernel/UserDataQueryTest.php index a722427..8a136ac 100644 --- a/core/modules/user/tests/src/Kernel/UserDataQueryTest.php +++ b/core/modules/user/tests/src/Kernel/UserDataQueryTest.php @@ -149,12 +149,12 @@ public function testEmpty() { */ public function testSetValue() { $contents = [ - [ - 'module' => 'test', - 'uid' => '100', - 'name' => 'foo', - 'value' => NULL, - ], + // Create a NULL value. + ['module' => 'test', 'uid' => '100', 'name' => 'nullable', 'value' => NULL], + // Create a non NULL value. + ['module' => 'test', 'uid' => '100', 'name' => 'foo', 'value' => 'bar'], + // A non-scalar value. + ['module' => 'test', 'uid' => '100', 'name' => 'foo_array', 'value' => ['bar']], ]; /** @var \Drupal\user\UserData $user_data */ $user_data = \Drupal::service('user.data'); @@ -167,6 +167,10 @@ public function testSetValue() { $user_data_query->setValue(NULL); $this->assertEquals([(object) $contents[0]], iterator_to_array($user_data_query->execute())); + $user_data_query = $user_data->getUserDataQuery(); + $user_data_query->setValue('bar'); + $this->assertEquals([(object) $contents[1]], iterator_to_array($user_data_query->execute())); + // Test that catching \Drupal\user\Exception\ConditionAlreadySetException // and re-running the query does not break is the value is not scalar. try { @@ -174,7 +178,12 @@ public function testSetValue() { } catch (ConditionAlreadySetException $e) { } - $this->assertEquals([(object) $contents[0]], iterator_to_array($user_data_query->execute())); + $this->assertEquals([(object) $contents[1]], iterator_to_array($user_data_query->execute())); + + // Test getting a pre-serialized value. + $user_data_query = $user_data->getUserDataQuery(); + $user_data_query->setValue(serialize(['bar'])); + $this->assertEquals([(object) $contents[2]], iterator_to_array($user_data_query->execute())); } }