diff --git a/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php b/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php index 3c646921e74357e774258c9936753112c2f9ff35..a23e438fff3b31c0520582fea8b7d31e55b667e2 100644 --- a/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php +++ b/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php @@ -67,8 +67,10 @@ class PrimoPermissionHandler */ public function __construct($primoPermConfig) { - $this->primoConfig = is_array($primoPermConfig) - ? $primoPermConfig : $primoPermConfig->toArray(); + if ($primoPermConfig instanceof \Zend\Config\Config) { + $primoPermConfig = $primoPermConfig->toArray(); + } + $this->primoConfig = is_array($primoPermConfig) ? $primoPermConfig : []; $this->checkLegacySettings(); $this->checkConfig(); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Primo/PrimoPermissionHandlerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Primo/PrimoPermissionHandlerTest.php index 49cf3d80c62f383a4d1fb5dce37c3885004ca525..adb7bafb9f3046f49cb5245ef8917f54a9c2548f 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Primo/PrimoPermissionHandlerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Primo/PrimoPermissionHandlerTest.php @@ -141,20 +141,13 @@ class PrimoPermissionHandlerTest extends TestCase * This should throw an Exception. * * @return void + * + * @expectedException Exception + * @expectedExceptionMessage No institutionCode found. */ public function testWithoutConfig() { - // TODO: make this test work properly - $this->markTestSkipped(); - try { - $handler = new PrimoPermissionHandler(null); - } catch(Exception $e){ - $this->assertEquals( - "The Primo Permission System has not been configured. - Please configure section [Institutions] in Primo.ini.", - $e->getMessage() - ); - } + new PrimoPermissionHandler(null); } /** @@ -169,6 +162,20 @@ class PrimoPermissionHandlerTest extends TestCase $this->assertEquals(false, $handler->hasPermission()); } + /** + * Test the handler without setting an authorization service. + * This should always return false. + * + * @return void + */ + public function testWithoutAuthorizationServiceWithZendConfigObject() + { + $handler = new PrimoPermissionHandler( + new \Zend\Config\Config($this->primoConfig) + ); + $this->assertEquals(false, $handler->hasPermission()); + } + /** * Test the handler code if permission matches * This should return the actual institution code (depending on config)