1<?php 2 3$base_dir = dirname(__FILE__); 4ini_set( 'include_path', ini_get('include_path').":$base_dir/../lib"); 5require_once 'GangliaAcl.php'; 6 7/** 8 * Test class for GangliaAcl. 9 * Generated by PHPUnit on 2011-04-20 at 20:35:07. 10 */ 11class GangliaAclTest extends PHPUnit_Framework_TestCase { 12 13 protected function setUp() { 14 $this->object = new GangliaAcl; 15 } 16 17 // This is the normal way to access the ACL. 18 public function testGetInstance() { 19 $obj1 = GangliaAcl::getInstance(); 20 $obj2 = GangliaAcl::getInstance(); 21 22 $this->assertEquals( $obj1, $obj2 ); 23 } 24 25 public function testGuestCanViewNormalClusters() { 26 $this->assertTrue( $this->object->isAllowed( GangliaAcl::GUEST, GangliaAcl::ALL_CLUSTERS, GangliaAcl::VIEW ) ); 27 } 28 29 public function testAdminCanViewNormalClusters() { 30 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, GangliaAcl::ALL_CLUSTERS, GangliaAcl::VIEW ) ); 31 } 32 33 public function testGuestCannotEdit() { 34 $this->assertFalse( $this->object->isAllowed( GangliaAcl::GUEST, GangliaAcl::ALL_CLUSTERS, GangliaAcl::EDIT ) ); 35 } 36 37 public function testAdminCanEdit() { 38 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, GangliaAcl::ALL_CLUSTERS, GangliaAcl::EDIT ) ); 39 } 40 41 public function testAdminCanAccessPrivateCluster() { 42 $this->object->addPrivateCluster( 'clustername' ); 43 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, 'clustername', GangliaAcl::VIEW ) ); 44 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, 'clustername', GangliaAcl::EDIT ) ); 45 } 46 47 public function testGuestCannotAccessPrivateCluster() { 48 $this->object->addPrivateCluster( 'clustername' ); 49 $this->assertFalse( $this->object->isAllowed( GangliaAcl::GUEST, 'clustername', GangliaAcl::VIEW ) ); 50 $this->assertFalse( $this->object->isAllowed( GangliaAcl::GUEST, 'clustername', GangliaAcl::EDIT ) ); 51 } 52 53 public function testGuestCanViewNormalCluster() { 54 $this->object->add( new Zend_Acl_Resource('clustername'), GangliaAcl::ALL_CLUSTERS ); 55 $this->object->addRole( 'username', GangliaAcl::GUEST ); 56 $this->object->allow( 'username', 'clustername', array(GangliaAcl::EDIT, GangliaAcl::VIEW) ); 57 58 $this->assertTrue( $this->object->isAllowed( GangliaAcl::GUEST, 'clustername', GangliaAcl::VIEW ) ); 59 } 60 61 public function testUserMayBeGrantedViewAccessToPrivateCluster() { 62 $this->object->addPrivateCluster( 'clustername' ); 63 $this->object->addRole( 'newuser', GangliaAcl::GUEST ); 64 $this->object->allow( 'newuser', 'clustername', GangliaAcl::VIEW ); 65 66 $this->assertTrue( $this->object->isAllowed( 'newuser', 'clustername', GangliaAcl::VIEW ) ); 67 $this->assertFalse( $this->object->isAllowed( 'newuser', 'clustername', GangliaAcl::EDIT ) ); 68 } 69 70 public function testUserMayBeGrantedEditAccessToPrivateCluster() { 71 $this->object->addPrivateCluster( 'clustername' ); 72 $this->object->addRole( 'newuser', GangliaAcl::GUEST ); 73 $this->object->allow( 'newuser', 'clustername', array( GangliaAcl::VIEW, GangliaAcl::EDIT ) ); 74 75 $this->assertTrue( $this->object->isAllowed( 'newuser', 'clustername', GangliaAcl::VIEW ) ); 76 $this->assertTrue( $this->object->isAllowed( 'newuser', 'clustername', GangliaAcl::EDIT ) ); 77 } 78 79 public function testGuestCanViewViews() { 80 $this->assertTrue( $this->object->isAllowed( GangliaAcl::GUEST, GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW ) ); 81 } 82 83 public function testAdminCanViewViews() { 84 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW ) ); 85 } 86 87 public function testGuestCannotEditViews() { 88 $this->assertFalse( $this->object->isAllowed( GangliaAcl::GUEST, GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT ) ); 89 } 90 91 public function testAdminCanEditViews() { 92 $this->assertTrue( $this->object->isAllowed( GangliaAcl::ADMIN, GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT ) ); 93 } 94 95 public function testUserCanViewViews() { 96 $this->object->addRole( 'newuser', GangliaAcl::GUEST ); 97 $this->assertTrue( $this->object->isAllowed( 'newuser', GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW ) ); 98 } 99 100 public function testUserCannotEditViews() { 101 $this->object->addRole( 'newuser', GangliaAcl::GUEST ); 102 $this->assertFalse( $this->object->isAllowed( 'newuser', GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT ) ); 103 } 104 105} 106?> 107