AuthTest.php 1.4 KB

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