diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php index cd6fc7a12ce39902d3cb089de9d5bba9a82f3a11..50bb3cb1597114715eed888d028e3027c1e12534 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php @@ -40,7 +40,8 @@ public function testBlockMigration() { /** @var \Drupal\block_content\Entity\BlockContent $block */ $block = BlockContent::load(1); $this->assertSame('My block 1', $block->label()); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $requestTime = \Drupal::time()->getRequestTime(); + $this->assertGreaterThanOrEqual($requestTime, (int) $block->getChangedTime()); $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertSame('en', $block->language()->getId()); $this->assertSame('<h3>My first content block body</h3>', $block->body->value); @@ -48,7 +49,8 @@ public function testBlockMigration() { $block = BlockContent::load(2); $this->assertSame('My block 2', $block->label()); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertGreaterThanOrEqual($requestTime, (int) $block->getChangedTime()); + $this->assertGreaterThanOrEqual($requestTime, (int) $block->getChangedTime()); $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertSame('en', $block->language()->getId()); $this->assertSame('<h3>My second content block body</h3>', $block->body->value); diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php index cc249a9d1e81e4684f6c9be1f65fd09f3928f37e..d8748c7140ca59439b1fa509b9eea70884c33003 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php @@ -45,7 +45,7 @@ public function testCustomBlockContentTranslation() { /** @var \Drupal\block_content\Entity\BlockContent $block */ $block = BlockContent::load(1)->getTranslation('fr'); $this->assertSame('fr - Static Block', $block->label()); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $block->getChangedTime()); $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertSame('fr', $block->language()->getId()); $this->assertSame('<h3>fr - My first content block body</h3>', $block->body->value); @@ -53,7 +53,7 @@ public function testCustomBlockContentTranslation() { $block = $block->getTranslation('zu'); $this->assertSame('My block 1', $block->label()); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $block->getChangedTime()); $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertSame('zu', $block->language()->getId()); $this->assertSame('<h3>zu - My first content block body</h3>', $block->body->value); @@ -61,7 +61,7 @@ public function testCustomBlockContentTranslation() { $block = BlockContent::load(2)->getTranslation('fr'); $this->assertSame('Encore un bloc statique', $block->label()); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $block->getChangedTime()); $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertSame('fr', $block->language()->getId()); $this->assertSame('Nom de vocabulaire beaucoup plus long que trente-deux caractères', $block->body->value); diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php index f4fc987dcfb6ae9cdae4b40c70ad2fa5eece47fc..391533cec9c8b38057f9b7cb317e5e2ca14329a8 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php @@ -78,7 +78,7 @@ public function testCommentFields() { $this->assertFieldAccess('comment', 'homepage', 'https://example.com'); $this->assertFieldAccess('comment', 'uid', $user->getAccountName()); // $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456)); - // $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME)); + // $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime())); $this->assertFieldAccess('comment', 'status', 'On'); } diff --git a/core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php b/core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php index d1dc01e6c20afe7497dd1b11da5527ad3bad6e89..96d47dc432125a6ff202d737078e7a394c09acd5 100644 --- a/core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php +++ b/core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php @@ -38,7 +38,7 @@ class FilterDateTimeTest extends DateTimeHandlerTestBase { protected function setUp($import_test_views = TRUE): void { parent::setUp($import_test_views); - static::$date = REQUEST_TIME + 86400; + static::$date = \Drupal::time()->getRequestTime() + 86400; // Set the timezone. date_default_timezone_set(static::$timezone); diff --git a/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php b/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php index 709115c6e61b68060e3a9be8e50cd9c66a46ff96..5fa292746ad599f31e3f04f47e490d3cc5a2d5f0 100644 --- a/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php @@ -124,7 +124,7 @@ public function testTimestampFormatter() { $timezone = NULL; } - $value = REQUEST_TIME - 87654321; + $value = \Drupal::time()->getRequestTime() - 87654321; $expected = \Drupal::service('date.formatter')->format($value, $date_format, $custom_date_format, $timezone); $component = $this->display->getComponent($this->fieldName); diff --git a/core/modules/file/tests/src/Kernel/DeleteTest.php b/core/modules/file/tests/src/Kernel/DeleteTest.php index e3ca3f5e3c0a3c8d77162bd5c658a240ba17ea22..fb7345aeac770bc7020e313411512bcc4eea4fd5 100644 --- a/core/modules/file/tests/src/Kernel/DeleteTest.php +++ b/core/modules/file/tests/src/Kernel/DeleteTest.php @@ -65,7 +65,7 @@ public function testInUse() { // would set the timestamp. Database::getConnection()->update('file_managed') ->fields([ - 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), + 'changed' => \Drupal::time()->getRequestTime() - ($this->config('system.file')->get('temporary_maximum_age') + 3), ]) ->condition('fid', $file->id()) ->execute(); @@ -92,7 +92,7 @@ public function testCronDeleteNonExistingTemporary() { // configuration value. \Drupal::database()->update('file_managed') ->fields([ - 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), + 'changed' => \Drupal::time()->getRequestTime() - ($this->config('system.file')->get('temporary_maximum_age') + 3), ]) ->condition('fid', $file->id()) ->execute(); diff --git a/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php index 1430b700260337584834e2248991acc2f61c3560..374eff614ec31d192b70d42eb56a49755ff22732 100644 --- a/core/modules/file/tests/src/Kernel/UsageTest.php +++ b/core/modules/file/tests/src/Kernel/UsageTest.php @@ -163,7 +163,7 @@ public function createTempFiles() { $connection->update('file_managed') ->fields([ 'status' => 0, - 'changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1, + 'changed' => \Drupal::time()->getRequestTime() - $this->config('system.file')->get('temporary_maximum_age') - 1, ]) ->condition('fid', $temp_old->id()) ->execute(); @@ -180,7 +180,7 @@ public function createTempFiles() { // Permanent file that is old. $perm_old = $fileRepository->writeData('', $destination); $connection->update('file_managed') - ->fields(['changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1]) + ->fields(['changed' => \Drupal::time()->getRequestTime() - $this->config('system.file')->get('temporary_maximum_age') - 1]) ->condition('fid', $temp_old->id()) ->execute(); $this->assertFileExists($perm_old->getFileUri()); diff --git a/core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php b/core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php index 902ee67e4ee234876bfca7555689454c906e8652..43a904c7e90b900f2b1ef6354bd722b2bab32aee 100644 --- a/core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php +++ b/core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php @@ -64,7 +64,7 @@ public function testFileFields() { $this->assertFieldAccess('file', 'filesize', '4 bytes'); $this->assertFieldAccess('file', 'status', 'Permanent'); // $this->assertFieldAccess('file', 'created', \Drupal::service('date.formatter')->format(123456)); - // $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME)); + // $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime())); } } diff --git a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php index 30c8a8035135b82043afb314ee60fd937498fca0..50c2931c1be53a8ffe11ca74f9c8c17ea4ee1feb 100644 --- a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php +++ b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php @@ -69,18 +69,19 @@ public function testHandlers() { \Drupal::currentUser()->setAccount($account); $connection = Database::getConnection(); + $requestTime = \Drupal::time()->getRequestTime(); $connection->insert('history') ->fields([ 'uid' => $account->id(), 'nid' => $nodes[0]->id(), - 'timestamp' => REQUEST_TIME - 100, + 'timestamp' => $requestTime - 100, ])->execute(); $connection->insert('history') ->fields([ 'uid' => $account->id(), 'nid' => $nodes[1]->id(), - 'timestamp' => REQUEST_TIME + 100, + 'timestamp' => $requestTime + 100, ])->execute(); $column_map = [ diff --git a/core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php b/core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php index 528c2bbf62cc14cbf18bfee5ddd1dc50a0d34b78..ff9cc7f33691a4809989efe0c8f451358585f37b 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php @@ -146,7 +146,7 @@ public function testCreateLink() { $link = MenuLinkContent::create($options); $link->save(); // Make sure the changed timestamp is set. - $this->assertEquals(REQUEST_TIME, $link->getChangedTime(), 'Creating a menu link sets the "changed" timestamp.'); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $link->getChangedTime(), 'Creating a menu link sets the "changed" timestamp.'); $options = [ 'title' => 'Test Link', ]; @@ -154,7 +154,7 @@ public function testCreateLink() { $link->changed->value = 0; $link->save(); // Make sure the changed timestamp is updated. - $this->assertEquals(REQUEST_TIME, $link->getChangedTime(), 'Changing a menu link sets "changed" timestamp.'); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $link->getChangedTime(), 'Changing a menu link sets "changed" timestamp.'); } /** diff --git a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php index 0a6a56cf96b63eee469d3bc1fa88c126ad516244..a4b6a0e2b988e0962728863e2e7a11c518ec64b4 100644 --- a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php +++ b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php @@ -68,7 +68,7 @@ public function testNodeFields() { $this->assertFieldAccess('node', 'sticky', 'Off'); // $this->assertFieldAccess('node', 'created', \Drupal::service('date.formatter')->format(123456)); - // $this->assertFieldAccess('node', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME)); + // $this->assertFieldAccess('node', 'changed', \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime())); } } diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php index 0e0a46c16bb23f1b46607b719f033df0cf7c69e8..66b5b57f487e0d250be1a15a36c5adb4c46d7ef6 100644 --- a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php +++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php @@ -27,7 +27,7 @@ class ChangedTestItem extends ChangedItem { public function preSave() { parent::preSave(); - if ($this->value == REQUEST_TIME) { + if ($this->value == \Drupal::time()->getRequestTime()) { // During a test the request time is immutable. To allow tests of the // algorithm of // Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem::preSave() we need diff --git a/core/modules/system/tests/src/Kernel/System/CronQueueTest.php b/core/modules/system/tests/src/Kernel/System/CronQueueTest.php index e450e3a3837ef58630ae7f7c89d3b7e0a9134fbe..95567ee2c66eb179976644d3be8512b0e27d38ea 100644 --- a/core/modules/system/tests/src/Kernel/System/CronQueueTest.php +++ b/core/modules/system/tests/src/Kernel/System/CronQueueTest.php @@ -202,9 +202,10 @@ public function testUncaughtExceptions() { // The item should be left in the queue. $this->assertEquals(1, $queue->numberOfItems(), 'Failing item still in the queue after throwing an exception.'); - // Expire the queue item manually. system_cron() relies in REQUEST_TIME to - // find queue items whose expire field needs to be reset to 0. This is a - // Kernel test, so REQUEST_TIME won't change when cron runs. + // Expire the queue item manually. system_cron() relies in + // \Drupal::time()->getRequestTime() to find queue items whose expire field needs to be + // reset to 0. This is a Kernel test, so \Drupal::time()->getRequestTime() won't change + // when cron runs. // @see system_cron() // @see \Drupal\Core\Cron::processQueues() $this->connection->update('queue') diff --git a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php index 802190359b4c89b089f2702d5c9ce0109cc5403c..c17b5793b8a6eed1d5d504b16d003cd1b555a33f 100644 --- a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php +++ b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php @@ -156,7 +156,7 @@ public function testSystemSiteTokenReplacement() { */ public function testSystemDateTokenReplacement() { // Set time to one hour before request. - $date = REQUEST_TIME - 3600; + $date = \Drupal::time()->getRequestTime() - 3600; // Generate and test tokens. $tests = []; diff --git a/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php index 4b5118c8e9f55d47b4001c9c853965508734c736..16bf30be17680ebf0ee3bc90c8e6568ff163fe0b 100644 --- a/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php @@ -31,8 +31,8 @@ public function testUpdateDeleteFileIfStale() { // During testing, the file change and the stale checking occurs in the same // request, so the beginning of request will be before the file changes and - // REQUEST_TIME - $filectime is negative or zero. Set the maximum age to a - // number greater than that. + // \Drupal::time()->getRequestTime() - $filectime is negative or zero. + // Set the maximum age to a number even smaller than that. $this->config('system.file') ->set('temporary_maximum_age', 100000) ->save(); diff --git a/core/modules/user/tests/src/Kernel/Views/UserViewsFieldAccessTest.php b/core/modules/user/tests/src/Kernel/Views/UserViewsFieldAccessTest.php index 3e21632541a3a2c60df32f133197c9d398fae211..e42ce1faba9ed92c9f88bde363f298cb1802fd40 100644 --- a/core/modules/user/tests/src/Kernel/Views/UserViewsFieldAccessTest.php +++ b/core/modules/user/tests/src/Kernel/Views/UserViewsFieldAccessTest.php @@ -55,7 +55,7 @@ public function testUserFields() { $this->assertFieldAccess('user', 'timezone', 'ut1'); $this->assertFieldAccess('user', 'status', 'On'); // $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456)); - // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME)); + // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime())); } } diff --git a/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php b/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php index ec84fcfacfbf136d00a242fb421cfc198aa29a77..4582e3455d0be3d3a009d36aedf133598fcafd14 100644 --- a/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php +++ b/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php @@ -72,7 +72,6 @@ protected function setUp(): void { * Tests the Who's Online block. */ public function testWhoIsOnlineBlock() { - $request_time = \Drupal::time()->getRequestTime(); // Generate users. $user1 = User::create([ 'name' => 'user1', @@ -80,7 +79,8 @@ public function testWhoIsOnlineBlock() { ]); $user1->addRole('administrator'); $user1->activate(); - $user1->setLastAccessTime($request_time); + $requestTime = \Drupal::time()->getRequestTime(); + $user1->setLastAccessTime($requestTime); $user1->save(); $user2 = User::create([ @@ -88,7 +88,7 @@ public function testWhoIsOnlineBlock() { 'mail' => 'user2@example.com', ]); $user2->activate(); - $user2->setLastAccessTime($request_time + 1); + $user2->setLastAccessTime($requestTime + 1); $user2->save(); $user3 = User::create([ @@ -97,7 +97,7 @@ public function testWhoIsOnlineBlock() { ]); $user3->activate(); // Insert an inactive user who should not be seen in the block. - $inactive_time = $request_time - (60 * 60); + $inactive_time = $requestTime - (60 * 60); $user3->setLastAccessTime($inactive_time); $user3->save(); diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php index d3dafb9bd5766a4631dfd96165a32e8f0b5ad9c8..46c91f7720763985b8dffae68295502661b06414 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php @@ -87,26 +87,27 @@ protected function setUp($import_test_views = TRUE): void { $admin = $this->createUser(); // And three nodes. + $requestTime = \Drupal::time()->getRequestTime(); $this->node1 = $this->createNode([ 'type' => 'bar', 'title' => 'foo', 'status' => 1, 'uid' => $admin->id(), - 'created' => REQUEST_TIME - 10, + 'created' => $requestTime - 10, ]); $this->node2 = $this->createNode([ 'type' => 'foo', 'title' => 'foo', 'status' => 1, 'uid' => $admin->id(), - 'created' => REQUEST_TIME - 5, + 'created' => $requestTime - 5, ]); $this->node3 = $this->createNode([ 'type' => 'bar', 'title' => 'bars', 'status' => 1, 'uid' => $admin->id(), - 'created' => REQUEST_TIME, + 'created' => $requestTime, ]); // Now create a user with the ability to edit bar but not foo. diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php index 995b9af0b3d20468db82c5b93b8aa29490643c32..2d33f07cd1c70db4d4c00baabae1a4d0421878ba 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php @@ -89,7 +89,7 @@ protected function setUp($import_test_views = TRUE): void { $this->testUsers[$i] = User::create([ 'name' => 'test ' . $i, 'timezone' => User::getAllowedTimezones()[$i], - 'created' => REQUEST_TIME - rand(0, 3600), + 'created' => \Drupal::time()->getRequestTime() - rand(0, 3600), ]); $this->testUsers[$i]->save(); } diff --git a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php index fd0812c7bab0deb44dfab9a362b5072eec96bfaa..91a4f425024698d6642ff54d05b78e83483e42c4 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php @@ -43,7 +43,7 @@ protected function setUp($import_test_views = TRUE): void { $this->installEntitySchema('user'); // Setup the current time properly. - \Drupal::request()->server->set('REQUEST_TIME', time()); + \Drupal::request()->server->set('REQUEST_TIME', \Drupal::time()->getCurrentTime()); } /** diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index e727def905d1586b8f80c3f2134a3c6528bff851..31ae8c3284bf4b5703bedd6d30acc873afd89abb 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -993,16 +993,6 @@ parameters: count: 1 path: modules/block_content/tests/src/Functional/BlockContentSaveTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 2 - path: modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php - - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 3 - path: modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php - - message: "#^Variable \\$callable in empty\\(\\) always exists and is not falsy\\.$#" count: 1 @@ -1183,11 +1173,6 @@ parameters: count: 4 path: modules/datetime/tests/src/Functional/DateTimeFieldTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php - - message: "#^Method Drupal\\\\datetime_range\\\\Plugin\\\\Field\\\\FieldType\\\\DateRangeFieldItemList\\:\\:defaultValuesForm\\(\\) should return array but return statement is missing\\.$#" count: 1 @@ -1243,11 +1228,6 @@ parameters: count: 1 path: modules/field/tests/src/Kernel/FieldAttachStorageTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php - - message: "#^Variable \\$entity_display might not be defined\\.$#" count: 1 @@ -1338,21 +1318,11 @@ parameters: count: 1 path: modules/file/tests/src/Functional/FileUploadJsonCookieTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 2 - path: modules/file/tests/src/Kernel/DeleteTest.php - - message: "#^Variable \\$unexpected in empty\\(\\) always exists and is not falsy\\.$#" count: 1 path: modules/file/tests/src/Kernel/FileManagedUnitTestBase.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 2 - path: modules/file/tests/src/Kernel/UsageTest.php - - message: "#^Variable \\$rows might not be defined\\.$#" count: 1 @@ -1378,11 +1348,6 @@ parameters: count: 1 path: modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 2 - path: modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php - - message: "#^Variable \\$image_style in empty\\(\\) always exists and is not falsy\\.$#" count: 1 @@ -1601,11 +1566,6 @@ parameters: count: 1 path: modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 2 - path: modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php - - message: "#^Method Drupal\\\\menu_ui\\\\MenuForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#" count: 1 @@ -2096,11 +2056,6 @@ parameters: count: 1 path: modules/system/tests/modules/deprecation_test/src/DeprecatedController.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/ChangedTestItem.php - - message: "#^Variable \\$options might not be defined\\.$#" count: 1 @@ -2177,11 +2132,6 @@ parameters: count: 2 path: modules/system/tests/src/Functional/Theme/ThemeUiTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php - - message: "#^Variable \\$help_message might not be defined\\.$#" count: 1 @@ -2653,16 +2603,6 @@ parameters: count: 2 path: modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 3 - path: modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php - - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: modules/views/tests/src/Kernel/Handler/FieldFieldTest.php - - message: "#^Variable \\$rand1 might not be defined\\.$#" count: 2 @@ -2849,11 +2789,6 @@ parameters: count: 1 path: tests/Drupal/KernelTests/Core/Cache/ApcuBackendTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 12 - path: tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php - - message: """ #^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: @@ -2899,21 +2834,11 @@ parameters: count: 3 path: tests/Drupal/KernelTests/Core/Database/StatementTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 4 - path: tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php - - message: "#^Variable \\$title might not be defined\\.$#" count: 2 path: tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 9 - path: tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php - - message: "#^Variable \\$previous_untranslatable_field_value in isset\\(\\) always exists and is not nullable\\.$#" count: 2 @@ -2924,11 +2849,6 @@ parameters: count: 9 path: tests/Drupal/KernelTests/Core/Entity/EntitySchemaTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: tests/Drupal/KernelTests/Core/Entity/EntityTypeConstraintsTest.php - - message: "#^Variable \\$e might not be defined\\.$#" count: 1 @@ -2954,11 +2874,6 @@ parameters: count: 1 path: tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php - - message: """ #^Call to deprecated method expectErrorMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: @@ -2967,16 +2882,6 @@ parameters: count: 1 path: tests/Drupal/KernelTests/Core/Render/Element/MachineNameTest.php - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 1 - path: tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php - - - - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 5 - path: tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php - - message: "#^Variable \\$value in isset\\(\\) always exists and is not nullable\\.$#" count: 1 diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php index 0655ba469b7dd61dffd70c80a0a6f20ca82dccc5..e17476c02e015d1fd1c302406e33d57277591060 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php @@ -144,28 +144,28 @@ public function testSetGet() { $this->assertSame($with_backslash, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); // We need to round because microtime may be rounded up in the backend. - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached->created); $this->assertEquals(Cache::PERMANENT, $cached->expire, 'Expire time is correct.'); $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2."); - $backend->set('test2', ['value' => 3], REQUEST_TIME + 3); + $backend->set('test2', ['value' => 3], \Drupal::time()->getRequestTime() + 3); $cached = $backend->get('test2'); $this->assertIsObject($cached); $this->assertSame(['value' => 3], $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached->created); - $this->assertEquals(REQUEST_TIME + 3, $cached->expire, 'Expire time is correct.'); + $this->assertEquals(\Drupal::time()->getRequestTime() + 3, $cached->expire, 'Expire time is correct.'); - $backend->set('test3', 'foobar', REQUEST_TIME - 3); + $backend->set('test3', 'foobar', \Drupal::time()->getRequestTime() - 3); $this->assertFalse($backend->get('test3'), 'Invalid item not returned.'); $cached = $backend->get('test3', TRUE); $this->assertIsObject($cached); $this->assertFalse($cached->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached->created); - $this->assertEquals(REQUEST_TIME - 3, $cached->expire, 'Expire time is correct.'); + $this->assertEquals(\Drupal::time()->getRequestTime() - 3, $cached->expire, 'Expire time is correct.'); $this->assertFalse($backend->get('test4'), "Backend does not contain data for cache id test4."); $with_eof = ['foo' => "\nEOF\ndata"]; @@ -174,7 +174,7 @@ public function testSetGet() { $this->assertIsObject($cached); $this->assertSame($with_eof, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached->created); $this->assertEquals(Cache::PERMANENT, $cached->expire, 'Expire time is correct.'); @@ -185,7 +185,7 @@ public function testSetGet() { $this->assertIsObject($cached); $this->assertSame($with_eof_and_semicolon, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached->created); $this->assertEquals(Cache::PERMANENT, $cached->expire, 'Expire time is correct.'); @@ -328,7 +328,7 @@ public function testGetMultiple() { $this->assertArrayHasKey('test7', $ret, "Existing cache id test7 is set."); // Test return - ensure that objects has expected properties. $this->assertTrue($ret['test2']->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $ret['test2']->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $ret['test2']->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $ret['test2']->created); $this->assertEquals(Cache::PERMANENT, $ret['test2']->expire, 'Expire time is correct.'); // Test return - ensure it does not contain nonexistent cache ids. @@ -390,7 +390,7 @@ public function testGetMultiple() { public function testSetMultiple() { $backend = $this->getCacheBackend(); - $future_expiration = REQUEST_TIME + 100; + $future_expiration = \Drupal::time()->getRequestTime() + 100; // Set multiple testing keys. $backend->set('cid_1', 'Some other value'); @@ -407,7 +407,7 @@ public function testSetMultiple() { $this->assertEquals($items['cid_1']['data'], $cached['cid_1']->data, 'Over-written cache item set correctly.'); $this->assertTrue($cached['cid_1']->valid, 'Item is marked as valid.'); - $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached['cid_1']->created); + $this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $cached['cid_1']->created); $this->assertLessThanOrEqual(round(microtime(TRUE), 3), $cached['cid_1']->created); $this->assertEquals(CacheBackendInterface::CACHE_PERMANENT, $cached['cid_1']->expire, 'Cache expiration defaults to permanent.'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php index c60c16413c6177771afe02be895b046fd0d5c7e7..017fc90aea8237c0b0b8ce9160cc25639df35b28 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php @@ -75,10 +75,8 @@ public function testChanged() { ]); $entity->save(); - $this->assertTrue( - $entity->getChangedTime() >= REQUEST_TIME, - 'Changed time of original language is valid.' - ); + $requestTime = \Drupal::time()->getRequestTime(); + $this->assertGreaterThanOrEqual($requestTime, $entity->getChangedTime(), 'Changed time of original language is valid.'); // We can't assert equality here because the created time is set to the // request time, while instances of ChangedTestItem use the current @@ -86,7 +84,7 @@ public function testChanged() { // between the created time and now. $this->assertTrue( ($entity->getChangedTime() >= $entity->get('created')->value) && - (($entity->getChangedTime() - $entity->get('created')->value) <= time() - REQUEST_TIME), + (($entity->getChangedTime() - $entity->get('created')->value) <= time() - $requestTime), 'Changed and created time of original language can be assumed to be identical.' ); @@ -254,7 +252,7 @@ public function testRevisionChanged() { $entity->save(); $this->assertTrue( - $entity->getChangedTime() >= REQUEST_TIME, + $entity->getChangedTime() >= \Drupal::time()->getRequestTime(), 'Changed time of original language is valid.' ); @@ -263,7 +261,7 @@ public function testRevisionChanged() { // timestamp every time. $this->assertTrue( ($entity->getChangedTime() >= $entity->get('created')->value) && - (($entity->getChangedTime() - $entity->get('created')->value) <= time() - REQUEST_TIME), + (($entity->getChangedTime() - $entity->get('created')->value) <= time() - \Drupal::time()->getRequestTime()), 'Changed and created time of original language can be assumed to be identical.' ); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php index 414d11b4ef4df92bf4b859df169658a9a394e0bb..95e380d1b20912ecb96abce3c220d00423de1f77 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php @@ -168,8 +168,8 @@ public function testCommentHooks() { 'promote' => 0, 'sticky' => 0, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - 'created' => REQUEST_TIME, - 'changed' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), + 'changed' => \Drupal::time()->getRequestTime(), ]); $node->save(); $nid = $node->id(); @@ -183,8 +183,8 @@ public function testCommentHooks() { 'field_name' => 'comment', 'uid' => $account->id(), 'subject' => 'Test comment', - 'created' => REQUEST_TIME, - 'changed' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), + 'changed' => \Drupal::time()->getRequestTime(), 'status' => 1, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ]); @@ -250,8 +250,8 @@ public function testFileHooks() { 'filemime' => 'text/plain', 'filesize' => filesize($url), 'status' => 1, - 'created' => REQUEST_TIME, - 'changed' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), + 'changed' => \Drupal::time()->getRequestTime(), ]); $this->assertHookMessageOrder([ @@ -313,8 +313,8 @@ public function testNodeHooks() { 'promote' => 0, 'sticky' => 0, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - 'created' => REQUEST_TIME, - 'changed' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), + 'changed' => \Drupal::time()->getRequestTime(), ]); $this->assertHookMessageOrder([ @@ -498,7 +498,7 @@ public function testUserHooks() { $account = User::create([ 'name' => 'Test user', 'mail' => 'test@example.com', - 'created' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), 'status' => 1, 'language' => 'en', ]); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityTypeConstraintsTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypeConstraintsTest.php index 1d0aa063fae41864c4af1ff9cf25a59ac1dcba6c..529d0f623f7e7ea666c9d95aa98694b8f60900be 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityTypeConstraintsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypeConstraintsTest.php @@ -64,7 +64,7 @@ public function testConstraintValidation() { $violations = $entity->validate(); $this->assertEquals(0, $violations->count(), 'Validation passed.'); $entity->save(); - $entity->changed->value = REQUEST_TIME - 86400; + $entity->changed->value = \Drupal::time()->getRequestTime() - 86400; $violations = $entity->validate(); $this->assertEquals(1, $violations->count(), 'Validation failed.'); $this->assertEquals('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.', $violations[0]->getMessage()); diff --git a/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php b/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php index 669a835b086b0267d050991a96e5bff6eb143467..904eeab89e7df381923ad60e960bc0d3650061b3 100644 --- a/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php +++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php @@ -43,7 +43,7 @@ public function testGarbageCollection() { 'collection' => $collection, ]) ->fields([ - 'expire' => REQUEST_TIME - 1, + 'expire' => \Drupal::time()->getRequestTime() - 1, ]) ->execute(); } diff --git a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php index 20acd1083b6c90250ce7ff6996f090f9d8c88f04..6a0ccb57879efbaa7930963a9fc19ea3c1a2d979 100644 --- a/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php @@ -103,7 +103,7 @@ public function testSharedTempStore() { // Now manually expire the item (this is not exposed by the API) and then // assert it is no longer accessible. $database->update('key_value_expire') - ->fields(['expire' => REQUEST_TIME - 1]) + ->fields(['expire' => \Drupal::time()->getRequestTime() - 1]) ->condition('collection', "tempstore.shared.$collection") ->condition('name', $key) ->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php index 87d4b1a47493e90f84c5c18697fdf2eec696bc82..0d21bb88539318efafe517f4f87434cca9934809 100644 --- a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php +++ b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php @@ -226,12 +226,13 @@ public function testGetAndSet() { $this->assertNull($typed_data->getDateTime()); // Timestamp type. - $value = REQUEST_TIME; + $requestTime = \Drupal::time()->getRequestTime(); + $value = $requestTime; $typed_data = $this->createTypedData(['type' => 'timestamp'], $value); $this->assertInstanceOf(DateTimeInterface::class, $typed_data); $this->assertSame($typed_data->getValue(), $value, 'Timestamp value was fetched.'); $this->assertEquals(0, $typed_data->validate()->count()); - $new_value = REQUEST_TIME + 1; + $new_value = $requestTime + 1; $typed_data->setValue($new_value); $this->assertSame($typed_data->getValue(), $new_value, 'Timestamp value was changed and set.'); $this->assertEquals(0, $typed_data->validate()->count()); @@ -241,10 +242,10 @@ public function testGetAndSet() { $typed_data->setValue('invalid'); $this->assertEquals(1, $typed_data->validate()->count(), 'Validation detected invalid value.'); // Check implementation of DateTimeInterface. - $typed_data = $this->createTypedData(['type' => 'timestamp'], REQUEST_TIME); + $typed_data = $this->createTypedData(['type' => 'timestamp'], $requestTime); $this->assertInstanceOf(DrupalDateTime::class, $typed_data->getDateTime()); - $typed_data->setDateTime(DrupalDateTime::createFromTimestamp(REQUEST_TIME + 1)); - $this->assertEquals(REQUEST_TIME + 1, $typed_data->getValue()); + $typed_data->setDateTime(DrupalDateTime::createFromTimestamp($requestTime + 1)); + $this->assertEquals($requestTime + 1, $typed_data->getValue()); $typed_data->setValue(NULL); $this->assertNull($typed_data->getDateTime()); diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php index 59a66b53bd87f58ce84e3810d8b443a4634ee8dc..8e1b76cc878b0b47a1d7f08c39287873728cc817 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTestBase.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Render; use Drupal\Component\Datetime\Time; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\Context\ContextCacheKeys; @@ -25,6 +26,13 @@ */ abstract class RendererTestBase extends UnitTestCase { + /** + * System time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected TimeInterface $datetimeTime; + /** * The tested renderer. * @@ -184,11 +192,13 @@ protected function setUp(): void { $this->placeholderGenerator = new PlaceholderGenerator($this->cacheContextsManager, $this->rendererConfig); $this->renderCache = new PlaceholderingRenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager, $this->placeholderGenerator); $this->renderer = new Renderer($this->callableResolver, $this->themeManager, $this->elementInfo, $this->placeholderGenerator, $this->renderCache, $this->requestStack, $this->rendererConfig); + $this->datetimeTime = new Time($this->requestStack); $container = new ContainerBuilder(); $container->set('cache_contexts_manager', $this->cacheContextsManager); $container->set('render_cache', $this->renderCache); $container->set('renderer', $this->renderer); + $container->set('datetime.time', $this->datetimeTime); \Drupal::setContainer($container); }