PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/source/solar/tests/Test/Solar/Access/Adapter.php

https://github.com/btweedy/foresmo
PHP | 224 lines | 103 code | 32 blank | 89 comment | 3 complexity | 3456759f6df6ad7f261ac8e7a930aa91 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Abstract class test.
  5. *
  6. */
  7. abstract class Test_Solar_Access_Adapter extends Solar_Test {
  8. /**
  9. *
  10. * Configuration values.
  11. *
  12. * @var array
  13. *
  14. */
  15. protected $_Test_Solar_Access_Adapter = array(
  16. );
  17. protected $_access;
  18. // -----------------------------------------------------------------
  19. //
  20. // Support methods.
  21. //
  22. // -----------------------------------------------------------------
  23. /**
  24. *
  25. * Constructor.
  26. *
  27. * @param array $config User-defined configuration parameters.
  28. *
  29. */
  30. public function __construct($config = null)
  31. {
  32. parent::__construct($config);
  33. }
  34. /**
  35. *
  36. * Destructor; runs after all methods are complete.
  37. *
  38. * @param array $config User-defined configuration parameters.
  39. *
  40. */
  41. public function __destruct()
  42. {
  43. parent::__destruct();
  44. }
  45. /**
  46. *
  47. * Setup; runs before each test method.
  48. *
  49. */
  50. public function setup()
  51. {
  52. // remove "Test_" prefix
  53. $this->_class = substr(get_class($this), 5);
  54. $this->_access = Solar::factory($this->_class, $this->_config);
  55. parent::setup();
  56. }
  57. /**
  58. *
  59. * Setup; runs after each test method.
  60. *
  61. */
  62. public function teardown()
  63. {
  64. parent::teardown();
  65. }
  66. // -----------------------------------------------------------------
  67. //
  68. // Test methods.
  69. //
  70. // -----------------------------------------------------------------
  71. /**
  72. *
  73. * Test -- Constructor.
  74. *
  75. */
  76. public function test__construct()
  77. {
  78. $obj = Solar::factory($this->_class);
  79. $this->assertInstance($obj, $this->_class);
  80. }
  81. /**
  82. *
  83. * Test -- Fetch access privileges for a user handle and roles.
  84. *
  85. */
  86. public function testFetch()
  87. {
  88. // anonymous user
  89. $list = $this->_access->fetch(null, array());
  90. $this->assertTrue(count($list) == 1);
  91. $list = $this->_access->fetch('gir', array());
  92. $this->assertTrue(count($list) == 4);
  93. $list = $this->_access->fetch('gir', array('bar'));
  94. $this->assertTrue(count($list) == 5);
  95. }
  96. /**
  97. *
  98. * Test -- Tells whether or not to allow access to a class/action/process combination.
  99. *
  100. */
  101. public function testIsAllowed()
  102. {
  103. $this->_access->load('gir', array('bar'));
  104. // deny all override
  105. $this->assertFalse($this->_access->isAllowed(
  106. 'Vendor_App_Deny',
  107. '*'
  108. ));
  109. // allowed for role bar
  110. $this->assertTrue($this->_access->isAllowed(
  111. 'Vendor_App_Example',
  112. 'read'
  113. ));
  114. // test wildcard actions
  115. $this->assertTrue($this->_access->isAllowed(
  116. 'Vendor_App_Example2',
  117. 'read'
  118. ));
  119. // test specific action
  120. $this->assertFalse($this->_access->isAllowed(
  121. 'Vendor_App_Example3',
  122. 'edit'
  123. ));
  124. // allow access to all authenticated users ('+')
  125. $this->assertTrue($this->_access->isAllowed(
  126. 'Vendor_App_Example4',
  127. 'read'
  128. ));
  129. $this->_access->load('someone', array('foo'));
  130. // deny access for role 'foo'
  131. $this->assertFalse($this->_access->isAllowed(
  132. 'Vendor_App_Example',
  133. 'read'
  134. ));
  135. // non-autenticated user
  136. $this->_access->load(null, array());
  137. $this->assertFalse($this->_access->isAllowed(
  138. 'Vendor_App_Auth',
  139. 'read'
  140. ));
  141. }
  142. /**
  143. *
  144. * Test -- Checks to see if the current user is the owner of application-specific content.
  145. *
  146. */
  147. public function testIsOwner()
  148. {
  149. $this->skip('Not implemented by this adapter');
  150. }
  151. /**
  152. *
  153. * Test -- Fetches the access list from the adapter into $this->list.
  154. *
  155. */
  156. public function testLoad()
  157. {
  158. // load with literal handle and roles
  159. $this->_access->load('gir', array('bar'));
  160. $this->diag($this->_access->list);
  161. // simply test there's correct amount of acl rows
  162. $actual = count($this->_access->list);
  163. $expect = 5;
  164. $this->assertEquals($actual, $expect);
  165. }
  166. public function testLoad_object()
  167. {
  168. $auth = Solar::factory('Solar_Auth');
  169. $auth->handle = 'gir';
  170. $role = Solar::factory('Solar_Role');
  171. $role->setList(array('bar'));
  172. // load with auth and role object
  173. $this->_access->load($auth, $role);
  174. $this->diag($this->_access->list);
  175. // simply test there's correct amount of acl rows
  176. $actual = count($this->_access->list);
  177. $expect = 5;
  178. $this->assertEquals($actual, $expect);
  179. }
  180. /**
  181. *
  182. * Test -- Resets the current access controls to a blank array, along with the $_auth and $_role properties.
  183. *
  184. */
  185. public function testReset()
  186. {
  187. $this->_access->reset();
  188. $this->assertProperty($this->_access, '_auth', 'same', null);
  189. $this->assertProperty($this->_access, '_role', 'same', null);
  190. $this->assertSame($this->_access->list, array());
  191. }
  192. }