From 7c5b900bd83b6b9bdb5656eb169381ff46f8106a Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 20 Jun 2014 15:41:05 -0300 Subject: First API implementation --- tests/units/AclTest.php | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tests/units/AclTest.php (limited to 'tests/units/AclTest.php') diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php new file mode 100644 index 00000000..a2c1c111 --- /dev/null +++ b/tests/units/AclTest.php @@ -0,0 +1,112 @@ + array('action1', 'action3'), + ); + + $acl = new Acl($this->db, $this->event); + $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1')); + $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action2')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action3')); + } + + public function testIsAdmin() + { + $acl = new Acl($this->db, $this->event); + + $_SESSION = array(); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array()); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => '1')); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => '2')); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertTrue($acl->isAdminUser()); + } + + public function testIsUser() + { + $acl = new Acl($this->db, $this->event); + + $_SESSION = array(); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array()); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => '2')); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertTrue($acl->isRegularUser()); + } + + public function testIsPageAllowed() + { + $acl = new Acl($this->db, $this->event); + + // Public access + $_SESSION = array(); + $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertFalse($acl->isPageAccessAllowed('app', 'index')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + + // Regular user + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + + // Admin user + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertTrue($acl->isPageAccessAllowed('user', 'create')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'save')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'remove')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + } +} -- cgit v1.2.3