Skip to content

Commit

Permalink
Add basic alias test.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Dec 20, 2023
1 parent 9a471c8 commit 6f81f77
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar = Domain Translation
2 changes: 2 additions & 0 deletions module/VuFind/tests/fixtures/language/aliases/aliases.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo = bar
baz = Domain::bar
1 change: 1 addition & 0 deletions module/VuFind/tests/fixtures/language/aliases/en.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar = Translation
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -74,7 +74,7 @@ public function testTranslations()
*
* @return void
*/
public function testFallback()
public function testFallback(): void
{
$pathStack = [
realpath($this->getFixtureDir() . 'language/base'),
Expand All @@ -98,7 +98,7 @@ public function testFallback()
*
* @return void
*/
public function testFallbackToSelf()
public function testFallbackToSelf(): void
{
$pathStack = [
realpath($this->getFixtureDir() . 'language/base'),
Expand All @@ -118,7 +118,7 @@ public function testFallbackToSelf()
*
* @return void
*/
public function testSelfAsParent()
public function testSelfAsParent(): void
{
$pathStack = [
realpath($this->getFixtureDir() . 'language/base'),
Expand All @@ -139,7 +139,7 @@ public function testSelfAsParent()
*
* @return void
*/
public function testParentChain()
public function testParentChain(): void
{
$pathStack = [
realpath($this->getFixtureDir() . 'language/base'),
Expand All @@ -162,12 +162,55 @@ 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');

$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
);
}
}

0 comments on commit 6f81f77

Please sign in to comment.