* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} namespace Tests\Icinga\Authentication; // @codingStandardsIgnoreStart require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php'); // @codingStandardsIgnoreEnd use Icinga\Test\BaseTestCase; // @codingStandardsIgnoreStart require_once BaseTestCase::$libDir . '/Authentication/Session.php'; require_once BaseTestCase::$libDir . '/Authentication/PhpSession.php'; require_once BaseTestCase::$libDir . '/Application/Logger.php'; require_once BaseTestCase::$libDir . '/Exception/ConfigurationError.php'; require_once 'Zend/Log.php'; // @codingStandardsIgnoreEnd use Icinga\Authentication\PhpSession; class PhpSessionTest extends BaseTestCase { private function getSession() { if (!is_writable('/tmp')) { $this->markTestSkipped('Could not write to session directory'); } return new PhpSession( array( 'use_cookies' => false, 'save_path' => '/tmp' ) ); } /** * Test the creation of a PhpSession object * * @runInSeparateProcess **/ public function testSessionCreation() { $this->getSession(); } /** * Test PhpSession::open() * * @runInSeparateProcess */ public function testOpenSession() { $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet '); $session = $this->getSession(); $session->open(); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()'); } /** * Test a session being closed by PhpSession::close() * * @runInSeparateProcess **/ public function testCloseSession() { $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet '); $session = $this->getSession(); $session->open(); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()'); $session->close(); } /** * Test if a session is correctly purged when calling PhpSession::purge() * * @runInSeparateProcess */ public function testPurgeSession() { $this->assertEquals(session_id(), '', 'Asserting test precondition: session not being setup yet '); $session = $this->getSession(); $session->open(); $this->assertNotEquals(session_id(), '', 'Asserting a Session ID being available after PhpSession::open()'); $session->purge(); $this->assertEquals(session_id(), '', 'Asserting no Session ID being available after PhpSession::purge()'); } }