Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_cache_common_test_case
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 test_get_put_exists
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_purge
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 test_destroy
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 test_cache_sql
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14abstract class phpbb_cache_common_test_case extends phpbb_database_test_case
15{
16    /** @var \phpbb\cache\driver\driver_interface */
17    protected $driver;
18
19    public function test_get_put_exists()
20    {
21        $this->assertFalse($this->driver->_exists('test_key'));
22        $this->assertSame(false, $this->driver->get('test_key'));
23
24        $this->driver->put('test_key', 'test_value');
25
26        $this->assertTrue($this->driver->_exists('test_key'));
27        $this->assertEquals(
28            'test_value',
29            $this->driver->get('test_key'),
30            'File ACM put and get'
31        );
32    }
33
34    public function test_purge()
35    {
36        $this->driver->put('test_key', 'test_value');
37
38        $this->assertEquals(
39            'test_value',
40            $this->driver->get('test_key'),
41            'File ACM put and get'
42        );
43
44        $this->driver->purge();
45
46        $this->assertSame(false, $this->driver->get('test_key'));
47    }
48
49    public function test_destroy()
50    {
51        $this->driver->put('first_key', 'first_value');
52        $this->driver->put('second_key', 'second_value');
53
54        $this->assertEquals(
55            'first_value',
56            $this->driver->get('first_key')
57        );
58        $this->assertEquals(
59            'second_value',
60            $this->driver->get('second_key')
61        );
62
63        $this->driver->destroy('first_key');
64
65        $this->assertFalse($this->driver->_exists('first_key'));
66        $this->assertEquals(
67            'second_value',
68            $this->driver->get('second_key')
69        );
70    }
71
72    public function test_cache_sql()
73    {
74        global $db, $cache, $phpbb_root_path, $phpEx;
75        $config = new phpbb\config\config(array());
76        $db = $this->new_dbal();
77        $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
78        $cache = new \phpbb\cache\service($this->driver, $config, $db, $phpbb_dispatcher, $phpbb_root_path, $phpEx);
79
80        $sql = "SELECT * FROM phpbb_config
81            WHERE config_name = 'foo'";
82
83        $result = $db->sql_query($sql, 300);
84        $first_result = $db->sql_fetchrow($result);
85        $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0);
86        $this->assertEquals($expected, $first_result);
87
88        $sql = 'DELETE FROM phpbb_config';
89        $db->sql_query($sql);
90
91        $sql = "SELECT * FROM phpbb_config
92            WHERE config_name = 'foo'";
93        $result = $db->sql_query($sql, 300);
94
95        $this->assertEquals($expected, $db->sql_fetchrow($result));
96
97        $sql = "SELECT * FROM phpbb_config
98            WHERE config_name = 'foo'";
99        $result = $db->sql_query($sql);
100
101        $no_cache_result = $db->sql_fetchrow($result);
102        $this->assertSame(false, $no_cache_result);
103
104        $db->sql_close();
105    }
106}