AuthTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. App::uses('Auth', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. /**
  5. * 2010-06-29 ms
  6. */
  7. class AuthTest extends MyCakeTestCase {
  8. public $fixtures = array('core.session');
  9. public function startTest() {
  10. ClassRegistry::init('Session');
  11. }
  12. public function endTest() {
  13. ClassRegistry::flush();
  14. }
  15. public function testHasRole() {
  16. $res = Auth::hasRole(1, array(2, 3, 6));
  17. $this->assertFalse($res);
  18. $res = Auth::hasRole(3, array(2, 3, 6));
  19. $this->assertTrue($res);
  20. $res = Auth::hasRole(3, 1);
  21. $this->assertFalse($res);
  22. $res = Auth::hasRole(3, '3');
  23. $this->assertTrue($res);
  24. $res = Auth::hasRole(3, '');
  25. $this->assertFalse($res);
  26. }
  27. public function testHasRoles() {
  28. $res = Auth::hasRoles(array(1, 3), true, array(2, 3, 6));
  29. $this->assertTrue($res);
  30. $res = Auth::hasRoles(array(3), true, array(2, 3, 6));
  31. $this->assertTrue($res);
  32. $res = Auth::hasRoles(array(), true, array(2, 3, 6));
  33. $this->assertFalse($res);
  34. $res = Auth::hasRoles(null, true, array(2, 3, 6));
  35. $this->assertFalse($res);
  36. $res = Auth::hasRoles(array(2, 7), false, array(2, 3, 6));
  37. $this->assertFalse($res);
  38. $res = Auth::hasRoles(array(2, 6), false, array(2, 3, 6));
  39. $this->assertTrue($res);
  40. $res = Auth::hasRoles(array(2, 6), true, array(2, 3, 6));
  41. $this->assertTrue($res);
  42. $res = Auth::hasRoles(array(9, 11), true, array());
  43. $this->assertFalse($res);
  44. $res = Auth::hasRoles(array(9, 11), true, '');
  45. $this->assertFalse($res);
  46. $res = Auth::hasRoles(array(2, 7), false, array());
  47. $this->assertFalse($res);
  48. $res = Auth::hasRoles(array(2, 7), false);
  49. $this->assertFalse($res);
  50. }
  51. }