abstract public function purge();
/**
+ * Return a "number used once" (a concatenation of a timestamp and a random
+ * numer).
+ *
+ * @return string A string of 6 bytes.
+ */
+ public function getNonce()
+ {
+ return pack('N', time()) . pack('n', mt_rand());
+ }
+
+ /**
* Encodes the remote address.
*
* @return string Encoded address.
--- /dev/null
+<?php
+/**
+ * All tests for the Horde_Token:: package.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Token
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Token
+ */
+
+/**
+ * Define the main method
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Horde_Token_AllTests::main');
+}
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Horde/Test/AllTests.php';
+
+/**
+ * Combine the tests for this package.
+ *
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Token
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Token
+ */
+class Horde_Token_AllTests extends Horde_Test_AllTests
+{
+}
+
+Horde_Token_AllTests::init('Horde_Token', __FILE__);
+
+if (PHPUnit_MAIN_METHOD == 'Horde_Token_AllTests::main') {
+ Horde_Token_AllTests::main();
+}
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * PHP version 5
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Token
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Token
+ */
+
+require_once 'Horde/Test/Autoload.php';
+
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
--- /dev/null
+<?php
+/**
+ * Test the file based token backend.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Token
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Token
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Base for session testing.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Token
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Token
+ */
+class Horde_Token_Unit_Storage_FileTest extends PHPUnit_Framework_TestCase
+{
+ public function tearDown()
+ {
+ if (!empty($this->_temp_dir)) {
+ $this->_rrmdir($this->_temp_dir);
+ }
+ }
+
+ public function testNonces()
+ {
+ $t = new Horde_Token_File();
+ $this->assertEquals(6, strlen($t->getNonce()));
+ }
+
+ private function _getTemporaryDirectory()
+ {
+ $this->_temp_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR
+ . 'Horde_Token_' . mt_rand();
+ mkdir($this->_temp_dir);
+ return $this->_temp_dir;
+ }
+
+ private function _rrmdir($dir)
+ {
+ if (is_dir($dir)) {
+ $objects = scandir($dir);
+ foreach ($objects as $object) {
+ if ($object != '.' && $object != '..') {
+ if (filetype($dir . DIRECTORY_SEPARATOR . $object) == 'dir') {
+ $this->_rrmdir($dir . DIRECTORY_SEPARATOR . $object);
+ } else {
+ unlink($dir . DIRECTORY_SEPARATOR . $object);
+ }
+ }
+ }
+ reset($objects);
+ rmdir($dir);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit>
+ <filter>
+ <whitelist>
+ <directory suffix=".php">../../../lib</directory>
+ </whitelist>
+ </filter>
+</phpunit>