From b31bcec20d85bca40597d170a163513691ac8538 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 25 Jan 2024 10:24:37 +0000 Subject: [PATCH] Issue #3415769 by Spokje, smustgrave: Use random user IDs in tests only only when intended to --- .../src/Functional/ContentTranslationSyncImageTest.php | 2 +- .../Update/SqlContentEntityStorageSchemaColumnTest.php | 2 +- .../KernelTests/Core/Entity/EntityTranslationTest.php | 6 ++++-- .../KernelTests/Core/TempStore/TempStoreDatabaseTest.php | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php index fb1f3c18bf61..7f159bba81e7 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php @@ -138,7 +138,7 @@ public function testImageFieldSync() { // Populate the test entity with some random initial values. $values = [ 'name' => $this->randomMachineName(), - 'user_id' => mt_rand(1, 128), + 'user_id' => 2, 'langcode' => $default_langcode, ]; $entity = \Drupal::entityTypeManager() diff --git a/core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php b/core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php index 1f3233f28de5..b466017a1862 100644 --- a/core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php +++ b/core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php @@ -88,7 +88,7 @@ protected function setUp(): void { // Create an entity with field data. $this->entity = EntityTestRev::create([ - 'user_id' => mt_rand(1, 10), + 'user_id' => 2, 'name' => $this->randomMachineName(), $field_name => $this->randomString(), ]); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php index fe4e5e95eed0..c31a29fd5180 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php @@ -158,7 +158,7 @@ protected function doTestMultilingualProperties($entity_type) { $langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode'); $default_langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('default_langcode'); $name = $this->randomMachineName(); - $uid = mt_rand(0, 127); + $uid = 2; $langcode = $this->langcodes[0]; // Create a language neutral entity and check that properties are stored @@ -206,6 +206,8 @@ protected function doTestMultilingualProperties($entity_type) { if ($langcode != $default_langcode) { $properties[$langcode] = [ 'name' => [0 => $this->randomMachineName()], + // Note that the user ID here is intentionally random, which is not + // what we normally do in tests. 'user_id' => [0 => mt_rand(128, 256)], ]; } @@ -593,7 +595,7 @@ protected function doTestLanguageFallback($entity_type) { $values = []; foreach ($this->langcodes as $langcode) { $values[$langcode]['name'] = $this->randomMachineName(); - $values[$langcode]['user_id'] = mt_rand(0, 127); + $values[$langcode]['user_id'] = 2; } $default_langcode = $this->langcodes[0]; diff --git a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php index d1b16c59deec..20acd1083b6c 100644 --- a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php @@ -39,7 +39,8 @@ public function testSharedTempStore() { ); $collection = $this->randomMachineName(); - // Create two mock users. + // Create two mock user IDs. Note that the user IDs are intentionally + // random, which is not what we normally do in tests. for ($i = 0; $i <= 1; $i++) { $users[$i] = mt_rand(500, 5000000); -- GitLab