1<?php
2/**
3 * Prepare the test setup.
4 */
5require_once dirname(__FILE__) . '/Base.php';
6
7/**
8 * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
9 *
10 * @author     Jan Schneider <jan@horde.org>
11 * @category   Horde
12 * @package    Horde_SessionHandler
13 * @subpackage UnitTests
14 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
15 */
16class Horde_SessionHandler_Storage_ExternalTest extends Horde_SessionHandler_Storage_Base
17{
18    public function testWrite()
19    {
20        $this->_write();
21    }
22
23    /**
24     * @depends testWrite
25     */
26    public function testRead()
27    {
28        $this->_read();
29    }
30
31    /**
32     * @depends testWrite
33     */
34    public function testReopen()
35    {
36        $this->_reopen();
37    }
38
39    /**
40     * The external driver doesn't support listing, so test for existing
41     * sessions manually.
42     *
43     * @depends testWrite
44     */
45    public function testList()
46    {
47        self::$handler->close();
48        self::$handler->open(self::$dir, 'sessionname');
49        self::$handler->read('sessionid2');
50        self::$handler->write('sessionid2', 'sessiondata2');
51        /* List while session is active. */
52        $this->assertNotEmpty(self::$handler->read('sessionid'));
53        $this->assertNotEmpty(self::$handler->read('sessionid2'));
54        self::$handler->close();
55
56        /* List while session is inactive. */
57        self::$handler->open(self::$dir, 'sessionname');
58        $this->assertNotEmpty(self::$handler->read('sessionid'));
59        $this->assertNotEmpty(self::$handler->read('sessionid2'));
60        self::$handler->close();
61    }
62
63    /**
64     * @depends testList
65     */
66    public function testDestroy()
67    {
68        self::$handler->open(self::$dir, 'sessionname');
69        self::$handler->read('sessionid2');
70        self::$handler->destroy('sessionid2');
71        $this->assertSame('', self::$handler->read('sessionid2'));
72    }
73
74    /**
75     * @depends testDestroy
76     */
77    public function testGc()
78    {
79        self::$handler->open(self::$dir, 'sessionname');
80        self::$handler->gc(-1);
81        $this->assertSame('', self::$handler->read('sessionid'));
82    }
83
84    public static function setUpBeforeClass()
85    {
86        parent::setUpBeforeClass();
87        $external = new Horde_SessionHandler_Storage_File(array('path' => self::$dir));
88        self::$handler = new Horde_SessionHandler_Storage_External(
89            array('open' => array($external, 'open'),
90                  'close' => array($external, 'close'),
91                  'read' => array($external, 'read'),
92                  'write' => array($external, 'write'),
93                  'destroy' => array($external, 'destroy'),
94                  'gc' => array($external, 'gc')));
95    }
96}
97