Skip to content

Commit

Permalink
Use drupal time
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Oct 25, 2023
1 parent ec09b48 commit 1706f29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/codeception/acceptance/Content/EventsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/codeception/acceptance/SystemCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 1706f29

Please sign in to comment.