redis_session_test.php 3.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Tests redis session handler
 *
 * @package    core
 * @copyright  2016 Nicholas Hoobin (nicholashoobin@catalyst-au.net)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

/**
 * Tests redis session handler class
 *
 * @package    core
 * @copyright  2016 Nicholas Hoobin (nicholashoobin@catalyst-au.net)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class redis_session_testcase extends advanced_testcase {

    /**
     * Test test_redis_connection_parser()
     * @param string $constring The connection string, 'savepath'.
     * @param array $expected An array of expected results.
     * @param int $count Number of valid connections.
     * @dataProvider connectionprovider
     */
    public function test_redis_connection_parser($constring, $expected, $debug) {
        $handler = new \core\session\redis;

        $servers = $handler->connection_string_to_redis_servers($constring);

        if ($debug == true) {
            $this->assertDebuggingCalled();
        }

        $this->assertEquals($expected, $servers);
    }

    /**
     * Provides data for test_redis_connection_parser().
     * @return array array of connection results
     */
    public function connectionprovider() {
        return array(
            array(
                "tcp://127.0.0.1, unix:///var/run/redis/redis.sock",
                array(
                    array(
                        'database' => 0,
                        'timeout' => 86400,
                        'port' => 6379,
                        'scheme' => 'tcp',
                        'prefix' => 'PHPREDIS_SESSION:',
                        'host' => '127.0.0.1'
                    ),
                    array(
                        'database' => 0,
                        'timeout' => 86400,
                        'scheme' => 'unix',
                        'prefix' => 'PHPREDIS_SESSION:',
                        'path' => '/var/run/redis/redis.sock'
                    )
                ),
                false
            ),
            array(
                "tcp://127.0.0.1?database=2&timeout=2.5&port=54428",
                array(
                    array(
                        'database' => '2',
                        'timeout' => '2.5',
                        'port' => '54428',
                        'scheme' => 'tcp',
                        'prefix' => 'PHPREDIS_SESSION:',
                        'host' => '127.0.0.1',
                        'query' => 'database=2&timeout=2.5&port=54428'
                    ),
                ),
                false
            ),
            array(
                "127.0.0.1",
                array(),
                true
            ),
            array(
                "tcp:sdgf243@Q#t23",
                array(),
                true
            ),
            array(
                "/var/run/redis/redis.sock",
                array(),
                true
            )
        );
    }
}