From 595fe442a7937ec3476553aa87945fc6d98a47f5 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 29 Oct 2024 08:30:33 +0000 Subject: [PATCH] provide tests for Request::i18n(), re #4774 Merge request studip/studip!3568 --- .../lib/classes/RequestParametersTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/lib/classes/RequestParametersTest.php b/tests/unit/lib/classes/RequestParametersTest.php index 85ef33cffd2..49f8098e8cb 100644 --- a/tests/unit/lib/classes/RequestParametersTest.php +++ b/tests/unit/lib/classes/RequestParametersTest.php @@ -38,6 +38,9 @@ class RequestParametersTest extends Codeception\Test\Unit $_GET['datetime'] = '2025-03-25 17:39:04'; $_GET['invalid_date'] = 'foobar'; + $_POST['localized'] = 'abc'; + $_POST['localized_i18n']['en_GB'] = 'def'; + $testconfig = new Config([ 'USERNAME_REGULAR_EXPRESSION' => '/^([a-zA-Z0-9_@.-]{4,})$/', ]); @@ -284,6 +287,29 @@ class RequestParametersTest extends Codeception\Test\Unit $this->assertFalse($invalid_date); } + /** + * @covers Request::i18n + */ + public function testRequestI18n() + { + $i18n = Request::i18n('localized'); + $this->assertEquals('abc', $i18n->original()); + $this->assertEquals('def', $i18n->localized('en_GB')); + $this->assertNull($i18n->localized('no_LANG')); + } + + /** + * @covers Request::i18n + */ + public function testRequestI18nWithDefault() + { + $default = new I18NString('foo', ['en_GB' => 'bar']); + + $i18n = Request::i18n('unknown', $default); + $this->assertEquals('foo', $i18n->original()); + $this->assertEquals('bar', $i18n->localized('en_GB')); + } + public function tearDown(): void { Config::set(null); -- GitLab