diff --git a/module/VuFind/tests/fixtures/language/aliases/Domain/en.ini b/module/VuFind/tests/fixtures/language/aliases/Domain/en.ini new file mode 100644 index 00000000000..0dd3a4fadd2 --- /dev/null +++ b/module/VuFind/tests/fixtures/language/aliases/Domain/en.ini @@ -0,0 +1 @@ +bar = Domain Translation \ No newline at end of file diff --git a/module/VuFind/tests/fixtures/language/aliases/aliases.ini b/module/VuFind/tests/fixtures/language/aliases/aliases.ini new file mode 100644 index 00000000000..cb7ace2eb9b --- /dev/null +++ b/module/VuFind/tests/fixtures/language/aliases/aliases.ini @@ -0,0 +1,2 @@ +foo = bar +baz = Domain::bar \ No newline at end of file diff --git a/module/VuFind/tests/fixtures/language/aliases/en.ini b/module/VuFind/tests/fixtures/language/aliases/en.ini new file mode 100644 index 00000000000..8c761a7dbe2 --- /dev/null +++ b/module/VuFind/tests/fixtures/language/aliases/en.ini @@ -0,0 +1 @@ +bar = Translation \ No newline at end of file diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php index 7fd31e67731..ff2cae84634 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php @@ -50,7 +50,7 @@ class ExtendedIniTest extends \PHPUnit\Framework\TestCase * * @return void */ - public function testTranslations() + public function testTranslations(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/base'), @@ -74,7 +74,7 @@ public function testTranslations() * * @return void */ - public function testFallback() + public function testFallback(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/base'), @@ -98,7 +98,7 @@ public function testFallback() * * @return void */ - public function testFallbackToSelf() + public function testFallbackToSelf(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/base'), @@ -118,7 +118,7 @@ public function testFallbackToSelf() * * @return void */ - public function testSelfAsParent() + public function testSelfAsParent(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/base'), @@ -139,7 +139,7 @@ public function testSelfAsParent() * * @return void */ - public function testParentChain() + public function testParentChain(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/base'), @@ -162,7 +162,7 @@ public function testParentChain() * * @return void */ - public function testMissingPathStack() + public function testMissingPathStack(): void { $this->expectException(\Laminas\I18n\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Ini file \'en.ini\' not found'); @@ -170,4 +170,47 @@ public function testMissingPathStack() $loader = new ExtendedIni(); $loader->load('en', null); } + + /** + * Test alias behavior. + * + * @return void + */ + public function testAliasing(): void + { + $pathStack = [ + realpath($this->getFixtureDir() . 'language/aliases'), + ]; + $loader = new ExtendedIni($pathStack, 'en'); + $result = $loader->load('en', null); + $this->assertEquals( + [ + 'bar' => 'Translation', + 'baz' => 'Domain Translation', + 'foo' => 'Translation', + ], + (array)$result + ); + } + + /** + * Test that alias behavior can be disabled. + * + * @return void + */ + public function testDisabledAliasing(): void + { + $pathStack = [ + realpath($this->getFixtureDir() . 'language/aliases'), + ]; + $loader = new ExtendedIni($pathStack, 'en'); + $loader->disableAliases(); + $result = $loader->load('en', null); + $this->assertEquals( + [ + 'bar' => 'Translation', + ], + (array)$result + ); + } }