Skip to content
Snippets Groups Projects
Commit 4410e460 authored by Demian Katz's avatar Demian Katz
Browse files

Improved config validation.

parent 1cb60c92
No related merge requests found
...@@ -67,8 +67,10 @@ class PrimoPermissionHandler ...@@ -67,8 +67,10 @@ class PrimoPermissionHandler
*/ */
public function __construct($primoPermConfig) public function __construct($primoPermConfig)
{ {
$this->primoConfig = is_array($primoPermConfig) if ($primoPermConfig instanceof \Zend\Config\Config) {
? $primoPermConfig : $primoPermConfig->toArray(); $primoPermConfig = $primoPermConfig->toArray();
}
$this->primoConfig = is_array($primoPermConfig) ? $primoPermConfig : [];
$this->checkLegacySettings(); $this->checkLegacySettings();
$this->checkConfig(); $this->checkConfig();
} }
......
...@@ -141,20 +141,13 @@ class PrimoPermissionHandlerTest extends TestCase ...@@ -141,20 +141,13 @@ class PrimoPermissionHandlerTest extends TestCase
* This should throw an Exception. * This should throw an Exception.
* *
* @return void * @return void
*
* @expectedException Exception
* @expectedExceptionMessage No institutionCode found.
*/ */
public function testWithoutConfig() public function testWithoutConfig()
{ {
// TODO: make this test work properly new PrimoPermissionHandler(null);
$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()
);
}
} }
/** /**
...@@ -169,6 +162,20 @@ class PrimoPermissionHandlerTest extends TestCase ...@@ -169,6 +162,20 @@ class PrimoPermissionHandlerTest extends TestCase
$this->assertEquals(false, $handler->hasPermission()); $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 * Test the handler code if permission matches
* This should return the actual institution code (depending on config) * This should return the actual institution code (depending on config)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment