Location: PHPKode > scripts > Security_Token > security_token/Test/Validator/SessionToken.php
<?php
/**
 * $Id: ValidateCSS.class.php 310 2006-08-27 06:24:05Z matthieu $
 */
if (!class_exists('Test_Validator_SessionToken')) {
    if (!defined('__CLASS_PATH__')) {
        define('__CLASS_PATH__', realpath(dirname(__FILE__) . '/../../'));
    }
    if (!defined('__SIMPLETEST_PATH__')) {
        define('__SIMPLETEST_PATH__', realpath(__CLASS_PATH__ . '/simpletest/'));
    }
    require_once __CLASS_PATH__ . '/Autoload.php';
    require_once __SIMPLETEST_PATH__ . '/shell_tester.php';
    require_once __SIMPLETEST_PATH__ . '/reporter.php';
    /**
     * unit test case for ValidateSessionToken
     * @author matthieu <hide@address.com>
     * @package validation
     * @subpackage unit_test_case
     */
    class Test_Validator_SessionToken extends ShellTestCase
    {
        /**
         * default constructor
         * @access public
         * @return void
         */
        public function __construct()
        {
            parent :: __construct();
            session_start();
        }
        /**
         * destructor
         * @access public
         * @return void
         */
        public function __destruct()
        {
            session_write_close();
        }
        /**
         * test for an empty token
         * @access public
         * @return void
         */
        public function testEmptyToken()
        {
            $token = new Security_Token();
            $token->save($_SESSION);
            $validator = new Validator_SessionToken('');
            $this->assertFalse($validator->isValid(),
             'Unexpected validation for an empty token');
            unset ($token);
            unset ($validator);
        }
        /**
         * test a valid token
         * @access public
         * @return void
         */
        public function testValidToken()
        {
            $token = new Security_Token();
            $token->save($_SESSION);
            $validator = new Validator_SessionToken($token->getToken());
            $this->assertTrue($validator->isValid(),
             'Token is not validate : ' . $validator->getError());
            unset ($token);
            unset ($validator);
        }
        /**
         * test an unvalid token
         * @access public
         * @return void
         */
        public function testUnvalidToken()
        {
            $token = new Security_Token();
            $token->save($_SESSION);
            $new_token = 'zazazazazazazazazazaz';
            $validator = new Validator_SessionToken($new_token);
            $this->assertFalse($validator->isValid(),
             'Unexpected validation for an a new token (' . $new_token . '), expected (' . $token->getToken() . ')');
            unset ($token);
            unset ($validator);
        }
    }
}
Return current item: Security_Token