Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AuthorizationPolicyTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.security.authorization.AuthorizationPolicy');
19 
24  public function testAuthorizationPolicy() {
25  $policy = new AuthorizationPolicy('some message');
26 
27  // Test advice.
28  self::assertTrue($policy->hasAdvice(AUTHORIZATION_ADVICE_DENY_MESSAGE));
29  self::assertFalse($policy->hasAdvice(AUTHORIZATION_ADVICE_CALL_ON_DENY));
30  self::assertEquals('some message', $policy->getAdvice(AUTHORIZATION_ADVICE_DENY_MESSAGE));
31  self::assertNull($policy->getAdvice(AUTHORIZATION_ADVICE_CALL_ON_DENY));
32 
33  // Test authorized context objects.
34  self::assertFalse($policy->hasAuthorizedContextObject(ASSOC_TYPE_USER_GROUP));
35  $someContextObject = new DataObject();
36  $someContextObject->setData('test1', 'test1');
37  $policy->addAuthorizedContextObject(ASSOC_TYPE_USER_GROUP, $someContextObject);
38  self::assertTrue($policy->hasAuthorizedContextObject(ASSOC_TYPE_USER_GROUP));
39  self::assertEquals($someContextObject, $policy->getAuthorizedContextObject(ASSOC_TYPE_USER_GROUP));
40  self::assertEquals(array(ASSOC_TYPE_USER_GROUP => $someContextObject), $policy->getAuthorizedContext());
41 
42  // Test authorized context.
43  $someOtherContextObject = new DataObject();
44  $someOtherContextObject->setData('test2', 'test2');
45  $authorizedContext = array(ASSOC_TYPE_USER_GROUP => $someOtherContextObject);
46  $policy->setAuthorizedContext($authorizedContext);
47  self::assertEquals($authorizedContext, $policy->getAuthorizedContext());
48 
49  // Test default policies.
50  self::assertTrue($policy->applies());
51  self::assertEquals(AUTHORIZATION_DENY, $policy->effect());
52  }
53 }
54 ?>
Any class with an associated DAO should extend this class.
Test class for AuthorizationPolicy.
Class that implements functionality common to all PKP unit test cases.
Class to represent an authorization policy.