From 16b87f7f1aa0ed30b3a05ca74a771eec67da1e9f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 8 Sep 2015 10:27:56 -0400
Subject: [PATCH] Improved test coverage.

---
 .../View/Helper/Root/TranslateTest.php        | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)

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 9651f09bc22..a1f5d2f7b87 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')
+        );
     }
 
     /**
-- 
GitLab