| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- App::uses('Auth', 'Tools.Lib');
- App::uses('MyCakeTestCase', 'Tools.TestSuite');
- /**
- * 2010-06-29 ms
- */
- class AuthTest extends MyCakeTestCase {
- public $fixtures = array('core.session');
- public function setUp() {
- parent::setUp();
- ClassRegistry::init('Session');
- $this->skipIf(php_sapi_name() === 'cli', 'Cannot test session in CLI');
- }
- public function tearDown() {
- parent::tearDown();
- ClassRegistry::flush();
- CakeSession::delete('Auth');
- }
- public function testId() {
- $id = Auth::id();
- $this->assertNull($id);
- CakeSession::write('Auth.User.id', 1);
- $id = Auth::id();
- $this->assertEquals(1, $id);
- }
- public function testHasRole() {
- $res = Auth::hasRole(1, array(2, 3, 6));
- $this->assertFalse($res);
- $res = Auth::hasRole(3, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRole(3, 1);
- $this->assertFalse($res);
- $res = Auth::hasRole(3, '3');
- $this->assertTrue($res);
- $res = Auth::hasRole(3, '');
- $this->assertFalse($res);
- }
- public function testHasRoles() {
- $res = Auth::hasRoles(array(1, 3), true, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRoles(array(3), true, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRoles(3, true, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRoles(array(), true, array(2, 3, 6));
- $this->assertFalse($res);
- $res = Auth::hasRoles(null, true, array(2, 3, 6));
- $this->assertFalse($res);
- $res = Auth::hasRoles(array(2, 7), false, array(2, 3, 6));
- $this->assertFalse($res);
- $res = Auth::hasRoles(array(2, 6), false, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRoles(array(2, 6), true, array(2, 3, 6));
- $this->assertTrue($res);
- $res = Auth::hasRoles(array(9, 11), true, array());
- $this->assertFalse($res);
- $res = Auth::hasRoles(array(9, 11), true, '');
- $this->assertFalse($res);
- $res = Auth::hasRoles(array(2, 7), false, array());
- $this->assertFalse($res);
- $res = Auth::hasRoles(array(2, 7), false);
- $this->assertFalse($res);
- }
- }
|