From 1706f29ace42b04df70045065b86dd01bc838bd7 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Tue, 24 Oct 2023 18:26:09 -0700 Subject: [PATCH] Use drupal time --- .../codeception/acceptance/Content/EventsCest.php | 15 +++++++++++---- tests/codeception/acceptance/SystemCest.php | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/codeception/acceptance/Content/EventsCest.php b/tests/codeception/acceptance/Content/EventsCest.php index 66c26956c..a4fcdeddf 100644 --- a/tests/codeception/acceptance/Content/EventsCest.php +++ b/tests/codeception/acceptance/Content/EventsCest.php @@ -359,19 +359,26 @@ public function testEventCard(AcceptanceTester $I) { $month = $xpath->query('//span[@class="su-event-start-month"]'); $I->assertNotEmpty($month); - $I->assertEquals(date('M', time()), $month->item(0)->nodeValue, 'Start Month does not match'); + $I->assertEquals(self::getDateTimeString('M', time()), preg_replace('/(\r\n|\n|\r)/', '', $month->item(0)->nodeValue), 'Start Month does not match'); $day = $xpath->query('//span[@class="su-event-start-date"]'); $I->assertNotEmpty($day); - $I->assertEquals(date('j', time()), $day->item(0)->nodeValue, 'Start Date does not match'); + $I->assertEquals(self::getDateTimeString('j', time()), preg_replace('/(\r\n|\n|\r)/', '', $day->item(0)->nodeValue), 'Start Date does not match'); $month = $xpath->query('//span[@class="su-event-end-month"]'); $I->assertNotEmpty($month); - $I->assertEquals(date('M', time() + (60 * 60 * 24)), $month->item(0)->nodeValue, 'End Month does not match'); + $I->assertEquals(self::getDateTimeString('M', time() + (60 * 60 * 24)), preg_replace('/(\r\n|\n|\r)/', '', $month->item(0)->nodeValue), 'End Month does not match'); $day = $xpath->query('//span[@class="su-event-end-date"]'); $I->assertNotEmpty($day); - $I->assertEquals(date('j', time() + (60 * 60 * 24)), $day->item(0)->nodeValue, 'End Date does not match'); + $I->assertEquals(self::getDateTimeString('j', time() + (60 * 60 * 24)), preg_replace('/(\r\n|\n|\r)/', '', $day->item(0)->nodeValue), 'End Date does not match'); + } + + protected static function getDateTimeString($format, $time) { + $timezone = \Drupal::config('system.date') + ->get('timezone.default') ?: @date_default_timezone_get(); + return \Drupal::service('date.formatter') + ->format($time, 'custom', $format, $timezone); } /** diff --git a/tests/codeception/acceptance/SystemCest.php b/tests/codeception/acceptance/SystemCest.php index aa6872bb0..cff232a45 100644 --- a/tests/codeception/acceptance/SystemCest.php +++ b/tests/codeception/acceptance/SystemCest.php @@ -11,6 +11,7 @@ class SystemCest { * Test the site status report. */ protected function footestSiteStatus(AcceptanceTester $I) { + $I->runDrush('xmlsitemap:rebuild'); $I->logInWithRole('administrator'); $I->amOnPage('/admin/reports/status'); $I->canSee('10.1', '.system-status-general-info');