From 4410e460cc3b08db7ceb81b2db01224262eb1176 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 20 Oct 2015 09:59:53 -0400 Subject: [PATCH] Improved config validation. --- .../Search/Primo/PrimoPermissionHandler.php | 6 ++-- .../Primo/PrimoPermissionHandlerTest.php | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php b/module/VuFind/src/VuFind/Search/Primo/PrimoPermissionHandler.php index 3c646921e74..a23e438fff3 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 49cf3d80c62..adb7bafb9f3 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) -- GitLab