aboutsummaryrefslogtreecommitdiff
blob: b3d19f1782b31bb72abf04a84d637c2d6990c9cc (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

require_once dirname(__FILE__) . '/cache_memory.php';

class phpbb_cache_memory_test extends phpbb_database_test_case
{
	protected $cache;
	protected $db;

	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/cache_memory.xml');
	}

	protected function setUp(): void
	{
		global $db;
		parent::setUp();

		$this->cache = new phpbb_cache_memory();
		$db = $this->new_dbal();
		$this->db = $db;
	}

	static public function cache_single_query_data()
	{
		return array(
			array(
				array(
					array(
						'SELECT * FROM ' . POSTS_TABLE,
						3,
					),
				),
				POSTS_TABLE,
			),
			array(
				array(
					array(
						'SELECT * FROM ' . POSTS_TABLE,
						3,
					),
					array(
						'SELECT * FROM ' . POSTS_TABLE . ' p
							LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
						3,
					),
				),
				POSTS_TABLE,
			),
			array(
				array(
					array(
						'SELECT * FROM ' . POSTS_TABLE,
						3,
					),
					array(
						'SELECT * FROM ' . POSTS_TABLE . ' p
							LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
						3,
					),
					array(
						'SELECT * FROM ' . POSTS_TABLE . ' p
							LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
							LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
						3,
					),
				),
				POSTS_TABLE,
			),
			array(
				array(
					array(
						'SELECT * FROM ' . POSTS_TABLE . ' p
							LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
						3,
					),
					array(
						'SELECT * FROM ' . POSTS_TABLE . ' p
							LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
							LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
						3,
					),
				),
				TOPICS_TABLE,
			),
		);
	}

	/**
	* @dataProvider cache_single_query_data
	*/
	public function test_cache_single_query($sql_queries, $table)
	{
		foreach ($sql_queries as $query)
		{
			$sql_request_res = $this->db->sql_query($query[0]);

			$this->cache->sql_save($this->db, $query[0], $sql_request_res, 1);

			$results = array();
			$query_id = $this->cache->sql_load($query[0]);
			while ($row = $this->cache->sql_fetchrow($query_id))
			{
				$results[] = $row;
			}
			$this->cache->sql_freeresult($query_id);
			$this->assertEquals($query[1], count($results));
		}

		$this->cache->destroy('sql', $table);

		foreach ($sql_queries as $query)
		{
			$this->assertNotEquals(false, $this->cache->sql_load($query[0]));
		}
	}
}