| | 12 | private $acl_group; |
| | 13 | private $acl_user_alice; |
| | 14 | private $acl_user_bob; |
| | 15 | |
| | 16 | function setup() |
| | 17 | { |
| | 18 | // create test group and user |
| | 19 | $this->acl_group = UserGroup::create( array( 'name' => 'acltest-group' ) ); |
| | 20 | $this->acl_user_alice = User::create( array( 'username' => 'acl-alice' ) ); |
| | 21 | $this->acl_user_bob = User::create( array( 'username' => 'acl-bob' ) ); |
| | 22 | $this->acl_group->add( 'acl-alice' ); |
| | 23 | $this->acl_group->add( 'acl-bob' ); |
| | 24 | } |
| | 25 | |
| | 26 | function test_group_permissions() |
| | 27 | { |
| | 28 | ACL::create_permission( 'acltest', 'A test ACL permission' ); |
| | 29 | |
| | 30 | $this->assert_true( |
| | 31 | ACL::token_exists( 'acltest' ), |
| | 32 | 'Could not create acltest permission.' |
| | 33 | ); |
| | 34 | |
| | 35 | $token_id = ACL::token_id( 'acltest' ); |
| | 36 | |
| | 37 | ACL::grant_group( $this->acl_group->id, $token_id, 'full' ); |
| | 38 | $this->assert_true( |
| | 39 | $this->acl_group->can( 'acltest', 'full' ), |
| | 40 | 'Could not grant acltest permission to acltest-group.' |
| | 41 | ); |
| | 42 | |
| | 43 | ACL::revoke_group_permission( $this->acl_group->id, $token_id ); |
| | 44 | $this->assert_false( |
| | 45 | ACL::group_can( $this->acl_group->id, $token_id, 'full' ), |
| | 46 | 'Could not revoke acltest permission from acltest-group.' |
| | 47 | ); |
| | 48 | |
| | 49 | // check alternate means of granting a permission |
| | 50 | $this->acl_group->grant( 'acltest', 'full' ); |
| | 51 | $this->assert_true( |
| | 52 | $this->acl_group->can( 'acltest', 'full' ), |
| | 53 | 'Could not grant acltest permission to acltest-group through UserGroup call.' |
| | 54 | ); |
| | 55 | |
| | 56 | // full > read/write |
| | 57 | $this->assert_true( |
| | 58 | $this->acl_group->can( 'acltest', 'read' ), |
| | 59 | "Group with 'full' acltest permission cannot not 'read'." |
| | 60 | ); |
| | 61 | $this->assert_true( |
| | 62 | $this->acl_group->can( 'acltest', 'write' ), |
| | 63 | "Group with 'full' acltest permission cannot 'write'." |
| | 64 | ); |
| | 65 | } |
| | 66 | |
| | 67 | function test_user_permissions() |
| | 68 | { |
| | 69 | $this->acl_user_alice->grant( 'acltest', 'full' ); |
| | 70 | $this->assert_true( |
| | 71 | $this->acl_user_alice->can( 'acltest', 'full' ), |
| | 72 | 'Could not grant acltest permission to user.' |
| | 73 | ); |
| | 74 | |
| | 75 | $this->acl_user_alice->revoke( 'acltest' ); |
| | 76 | |
| | 77 | // check that members of a group inherit that group's permissions |
| | 78 | $this->acl_group->grant( 'acltest', 'full' ); |
| | 79 | $this->assert_true( |
| | 80 | $this->acl_user_alice->can( 'acltest', 'full' ), |
| | 81 | 'Users do not inherit group permissions.' |
| | 82 | ); |
| | 83 | } |
| | 84 | |
| | 85 | /** TODO write test_post_permissions() to verify that sensible default |
| | 86 | * permissions are attached to new posts |
| | 87 | */ |
| | 88 | function test_post_permissions() |
| | 89 | { |
| | 90 | |
| | 91 | } |