/source/solar/tests/Test/Solar/Access/Adapter.php
PHP | 224 lines | 103 code | 32 blank | 89 comment | 3 complexity | 3456759f6df6ad7f261ac8e7a930aa91 MD5 | raw file
- <?php
- /**
- *
- * Abstract class test.
- *
- */
- abstract class Test_Solar_Access_Adapter extends Solar_Test {
-
- /**
- *
- * Configuration values.
- *
- * @var array
- *
- */
- protected $_Test_Solar_Access_Adapter = array(
- );
-
- protected $_access;
-
- // -----------------------------------------------------------------
- //
- // Support methods.
- //
- // -----------------------------------------------------------------
-
- /**
- *
- * Constructor.
- *
- * @param array $config User-defined configuration parameters.
- *
- */
- public function __construct($config = null)
- {
- parent::__construct($config);
- }
-
- /**
- *
- * Destructor; runs after all methods are complete.
- *
- * @param array $config User-defined configuration parameters.
- *
- */
- public function __destruct()
- {
- parent::__destruct();
- }
-
- /**
- *
- * Setup; runs before each test method.
- *
- */
- public function setup()
- {
- // remove "Test_" prefix
- $this->_class = substr(get_class($this), 5);
-
- $this->_access = Solar::factory($this->_class, $this->_config);
-
- parent::setup();
- }
-
- /**
- *
- * Setup; runs after each test method.
- *
- */
- public function teardown()
- {
- parent::teardown();
- }
-
- // -----------------------------------------------------------------
- //
- // Test methods.
- //
- // -----------------------------------------------------------------
-
- /**
- *
- * Test -- Constructor.
- *
- */
- public function test__construct()
- {
- $obj = Solar::factory($this->_class);
- $this->assertInstance($obj, $this->_class);
- }
-
- /**
- *
- * Test -- Fetch access privileges for a user handle and roles.
- *
- */
- public function testFetch()
- {
- // anonymous user
- $list = $this->_access->fetch(null, array());
- $this->assertTrue(count($list) == 1);
-
- $list = $this->_access->fetch('gir', array());
- $this->assertTrue(count($list) == 4);
-
- $list = $this->_access->fetch('gir', array('bar'));
- $this->assertTrue(count($list) == 5);
- }
-
- /**
- *
- * Test -- Tells whether or not to allow access to a class/action/process combination.
- *
- */
- public function testIsAllowed()
- {
- $this->_access->load('gir', array('bar'));
-
- // deny all override
- $this->assertFalse($this->_access->isAllowed(
- 'Vendor_App_Deny',
- '*'
- ));
-
- // allowed for role bar
- $this->assertTrue($this->_access->isAllowed(
- 'Vendor_App_Example',
- 'read'
- ));
-
- // test wildcard actions
- $this->assertTrue($this->_access->isAllowed(
- 'Vendor_App_Example2',
- 'read'
- ));
-
- // test specific action
- $this->assertFalse($this->_access->isAllowed(
- 'Vendor_App_Example3',
- 'edit'
- ));
-
- // allow access to all authenticated users ('+')
- $this->assertTrue($this->_access->isAllowed(
- 'Vendor_App_Example4',
- 'read'
- ));
-
- $this->_access->load('someone', array('foo'));
- // deny access for role 'foo'
- $this->assertFalse($this->_access->isAllowed(
- 'Vendor_App_Example',
- 'read'
- ));
-
- // non-autenticated user
- $this->_access->load(null, array());
-
- $this->assertFalse($this->_access->isAllowed(
- 'Vendor_App_Auth',
- 'read'
- ));
- }
-
- /**
- *
- * Test -- Checks to see if the current user is the owner of application-specific content.
- *
- */
- public function testIsOwner()
- {
- $this->skip('Not implemented by this adapter');
- }
-
- /**
- *
- * Test -- Fetches the access list from the adapter into $this->list.
- *
- */
- public function testLoad()
- {
- // load with literal handle and roles
- $this->_access->load('gir', array('bar'));
- $this->diag($this->_access->list);
-
- // simply test there's correct amount of acl rows
- $actual = count($this->_access->list);
- $expect = 5;
- $this->assertEquals($actual, $expect);
- }
-
-
- public function testLoad_object()
- {
- $auth = Solar::factory('Solar_Auth');
- $auth->handle = 'gir';
-
- $role = Solar::factory('Solar_Role');
- $role->setList(array('bar'));
-
- // load with auth and role object
- $this->_access->load($auth, $role);
- $this->diag($this->_access->list);
-
- // simply test there's correct amount of acl rows
- $actual = count($this->_access->list);
- $expect = 5;
- $this->assertEquals($actual, $expect);
- }
-
- /**
- *
- * Test -- Resets the current access controls to a blank array, along with the $_auth and $_role properties.
- *
- */
- public function testReset()
- {
- $this->_access->reset();
- $this->assertProperty($this->_access, '_auth', 'same', null);
- $this->assertProperty($this->_access, '_role', 'same', null);
- $this->assertSame($this->_access->list, array());
- }
- }