From 6195823aef54ca9b39421b0ec3481dd645e41a8e Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Mon, 23 Dec 2024 19:21:27 +0100 Subject: [PATCH] Fix whitespace in Tests output --- .github/workflows/php-test.yml | 2 +- .../humhub/components/i18n/Formatter.php | 36 +++++++++++++++++++ .../codeception/acceptance/ScheduledCest.php | 2 +- .../unit/widgets/TimeAgoWidgetTest.php | 8 ----- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 7bbf6cc268..dae3739b92 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -139,4 +139,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: codeception-output - path: tests/codeception/_output/* + path: protected/humhub/tests/codeception/_output/* diff --git a/protected/humhub/components/i18n/Formatter.php b/protected/humhub/components/i18n/Formatter.php index 93fc3a4448..a86a278fe2 100644 --- a/protected/humhub/components/i18n/Formatter.php +++ b/protected/humhub/components/i18n/Formatter.php @@ -103,4 +103,40 @@ class Formatter extends \yii\i18n\Formatter return Yii::t('base', '{nFormatted}B', $params, $this->language); // Billion } } + + /** + * Fix unicode chars + * + * @param string $value + * @return string + */ + private function fixUnicodeChars($value): string + { + // Replace newly introduced Unicode separator whitespace, which a standard one, to sway backward compatible. + return str_replace(' ', ' ', $value); + } + + /** + * @inheritdoc + */ + public function asDate($value, $format = null) + { + return $this->fixUnicodeChars(parent::asDate($value, $format)); + } + + /** + * @inheritdoc + */ + public function asTime($value, $format = null) + { + return $this->fixUnicodeChars(parent::asTime($value, $format)); + } + + /** + * @inheritdoc + */ + public function asDatetime($value, $format = null) + { + return $this->fixUnicodeChars(parent::asDatetime($value, $format)); + } } diff --git a/protected/humhub/modules/content/tests/codeception/acceptance/ScheduledCest.php b/protected/humhub/modules/content/tests/codeception/acceptance/ScheduledCest.php index d4f40eaf01..8fddb042f7 100644 --- a/protected/humhub/modules/content/tests/codeception/acceptance/ScheduledCest.php +++ b/protected/humhub/modules/content/tests/codeception/acceptance/ScheduledCest.php @@ -53,7 +53,7 @@ class ScheduledCest { return $datetime instanceof DateTime // Replace newly introduced Unicode separator whitespace, which a standard one, to sway backward compatible. - ? 'SCHEDULED FOR ' . str_replace(' ', ' ', Yii::$app->formatter->asDatetime($datetime, self::DATE_FORMAT)) + ? 'SCHEDULED FOR ' . Yii::$app->formatter->asDatetime($datetime, self::DATE_FORMAT) : 'DRAFT'; } diff --git a/protected/humhub/tests/codeception/unit/widgets/TimeAgoWidgetTest.php b/protected/humhub/tests/codeception/unit/widgets/TimeAgoWidgetTest.php index e303b74e27..340ed47abe 100644 --- a/protected/humhub/tests/codeception/unit/widgets/TimeAgoWidgetTest.php +++ b/protected/humhub/tests/codeception/unit/widgets/TimeAgoWidgetTest.php @@ -88,10 +88,6 @@ class TimeAgoWidgetTest extends HumHubDbTestCase // TS outside of default 172800 but default deactivated $ts = (new DateTime())->setTime(12, 00, 00)->getTimestamp(); $result = TimeAgo::widget(['timestamp' => $ts, 'timeAgoBefore' => 1]); - - // Replace newly introduced Unicode separator whitespace, which a standard one, to sway backward compatible. - $result = str_replace(' ', ' ', $result); - $this->assertStringContainsString('12:00 PM', $result); } @@ -100,10 +96,6 @@ class TimeAgoWidgetTest extends HumHubDbTestCase // TS outside of default 172800 but default deactivated $ts = DateTime::createFromFormat('Y-m-d H:i:s', '2018-10-12 12:00:00')->getTimestamp(); $result = TimeAgo::widget(['timestamp' => $ts, 'hideTimeAfter' => false]); - - // Replace newly introduced Unicode separator whitespace, which a standard one, to sway backward compatible. - $result = str_replace(' ', ' ', $result); - $this->assertStringContainsString('Oct 12, 2018 - 12:00 PM', $result); }