Skip to content

Commit

Permalink
EWPP-2099: Fix tests by applying timezone for InfoDisclosureExtraFiel…
Browse files Browse the repository at this point in the history
…dBase::isCurrentDay() method.
  • Loading branch information
sergepavle committed Mar 28, 2022
1 parent 79b2f34 commit 9a8350e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ public static function create(ContainerInterface $container, array $configuratio
*
* @param int $timestamp
* The timestamp of start date.
* @param string|null $timezone
* The timezone id.
*
* @return bool
* True if timestamp is within current day.
*/
protected function isCurrentDay(int $timestamp): bool {
$current_date = $this->dateFormatter->format($this->requestDateTime->getTimestamp(), 'custom', 'Ymd');
$start_day = $this->dateFormatter->format($timestamp, 'custom', 'Ymd');
protected function isCurrentDay(int $timestamp, string $timezone = NULL): bool {
$current_date = $this->dateFormatter->format($this->requestDateTime->getTimestamp(), 'custom', 'Ymd', $timezone);
$start_day = $this->dateFormatter->format($timestamp, 'custom', 'Ymd', $timezone);
return $current_date === $start_day;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function viewElements(ContentEntityInterface $entity) {
// render the date only.
if ($event->isOnlinePeriodYetToCome($this->requestDateTime)) {
$this->applyHourTag($build, $event->getOnlineStartDate());
if ($this->isCurrentDay($event->getOnlineStartDate()->getTimestamp())) {
if ($this->isCurrentDay($event->getOnlineStartDate()->getTimestamp(), $event->getOnlineTimezone())) {
$build += $link;
$build['#hide_link'] = TRUE;
$this->attachDisclosureScript($build, $event->getOnlineStartDate()->getTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function viewElements(ContentEntityInterface $entity) {
$this->applyHourTag($build, $event->getOnlineStartDate());
// Do not send field value to browser if it is not yet day online
// livestreaming should be started.
if (!$this->isCurrentDay($event->getOnlineStartDate()->getTimestamp())) {
if (!$this->isCurrentDay($event->getOnlineStartDate()->getTimestamp(), $event->getOnlineTimezone())) {
$this->isEmpty = TRUE;
return $build;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function viewElements(ContentEntityInterface $entity) {

// If the request time is on the same day as the start day we need to
// show different message.
if ($this->isCurrentDay($datetime_start->getTimestamp())) {
if ($this->isCurrentDay($datetime_start->getTimestamp(), $event->getRegistrationTimezone())) {
$build['#registration_day_description'] = $this->t('Registration will open today, @start_date.', [
'@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
Expand Down Expand Up @@ -103,7 +103,7 @@ public function viewElements(ContentEntityInterface $entity) {
if ($event->hasRegistrationDates()) {
// If the request time is on the same day as the end day we need to
// show different message.
if ($this->isCurrentDay($datetime_end->getTimestamp())) {
if ($this->isCurrentDay($datetime_end->getTimestamp(), $event->getRegistrationTimezone())) {
$build['#description'] = $this->t('Book your seat, the registration will end today, @end_date', [
'@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ public function testTimeSensitiveFieldsDisplay(): void {
$node->set('oe_event_online_dates', [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->set('oe_event_registration_dates', [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->save();
$this->drupalGet($node->toUrl());
Expand Down Expand Up @@ -159,10 +161,12 @@ public function testTimeSensitiveFieldsDisplay(): void {
$node->set('oe_event_online_dates', [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->set('oe_event_registration_dates', [
'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->save();
$this->drupalGet($node->toUrl());
Expand Down Expand Up @@ -203,10 +207,12 @@ public function testTimeSensitiveFieldsDisplay(): void {
$node->set('oe_event_online_dates', [
'value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $static_time)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->set('oe_event_registration_dates', [
'value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $static_time)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->save();
$this->drupalGet($node->toUrl());
Expand All @@ -230,10 +236,12 @@ public function testTimeSensitiveFieldsDisplay(): void {
$node->set('oe_event_online_dates', [
'value' => (clone $static_time)->modify('-4 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->set('oe_event_registration_dates', [
'value' => (clone $static_time)->modify('-4 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'timezone' => 'Europe/Brussels',
]);
$node->save();
$this->drupalGet($node->toUrl());
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function testEventRendering(): void {
$this->drupalGet($node->toUrl());

$this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation');
$this->assertEquals('Book your seat, 2 hours left to register, registration will end on 21 February 2020, 15:00 CET', $registration_info_content->getText());
$this->assertEquals('Book your seat, the registration will end today, 21 February 2020, 15:00 CET', $registration_info_content->getText());

// Assert "Registration date" field in the past.
$static_time = new DrupalDateTime('2020-02-24 13:00:00', 'Europe/Brussels');
Expand Down

0 comments on commit 9a8350e

Please sign in to comment.