diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php index 9651f09bc22effe4cb4f75a3c149bb85f4c1a443..a1f5d2f7b8727e147c949e9799d9098853faaecb 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/TranslateTest.php @@ -54,6 +54,48 @@ class TranslateTest extends \PHPUnit_Framework_TestCase ); } + /** + * Test invalid translation array + * + * @return void + * + * @expectedException Exception + * @expectedExceptionMessage Unexpected value sent to translator! + */ + public function testTranslateWithEmptyArray() + { + $translate = new Translate(); + $translate->__invoke([]); + } + + /** + * Test invalid translation array + * + * @return void + * + * @expectedException Exception + * @expectedExceptionMessage Unexpected value sent to translator! + */ + public function testTranslateWithOverfilledArray() + { + $translate = new Translate(); + $translate->__invoke([1, 2, 3]); + } + + /** + * Test invalid translation string + * + * @return void + * + * @expectedException Exception + * @expectedExceptionMessage Unexpected value sent to translator! + */ + public function testTranslateWithDoubleTextDomainArray() + { + $translate = new Translate(); + $translate->__invoke('a::b::c'); + } + /** * Test translation with a loaded translator * @@ -70,6 +112,20 @@ class TranslateTest extends \PHPUnit_Framework_TestCase $this->assertEquals('baz', $translate->__invoke( 'foo', ['%%token%%' => 'baz'], 'failure') ); + // Test namespace syntax: + $this->assertEquals('baz', $translate->__invoke( + 'default::foo', ['%%token%%' => 'baz'], 'failure') + ); + // Test array syntax: + $this->assertEquals('baz', $translate->__invoke( + ['foo'], ['%%token%%' => 'baz'], 'failure') + ); + $this->assertEquals('baz', $translate->__invoke( + [null, 'foo'], ['%%token%%' => 'baz'], 'failure') + ); + $this->assertEquals('baz', $translate->__invoke( + ['default', 'foo'], ['%%token%%' => 'baz'], 'failure') + ); } /**