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); } }