aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-10-06 23:21:13 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-10-06 23:21:13 +0200
commitf3eaf6fe04dc9edf43dc0298d97d6242d1472f00 (patch)
tree59722eb2bfe11abdd1e18ea586d13fc02af0f919 /tests
parent7479c61d0596e9730a73ebb71eccc9ddbded8542 (diff)
parent5354c46e01a1efd65d4b53af12173ef4947eec9c (diff)
downloadforums-f3eaf6fe04dc9edf43dc0298d97d6242d1472f00.tar
forums-f3eaf6fe04dc9edf43dc0298d97d6242d1472f00.tar.gz
forums-f3eaf6fe04dc9edf43dc0298d97d6242d1472f00.tar.bz2
forums-f3eaf6fe04dc9edf43dc0298d97d6242d1472f00.tar.xz
forums-f3eaf6fe04dc9edf43dc0298d97d6242d1472f00.zip
Merge pull request #3016 from Nicofuma/ticket/11224-ascraeus
[ticket/11224][ascraeus] SQL cache destroy does not destroy queries to tables joined
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/cache_memory.php64
-rw-r--r--tests/cache/cache_memory_test.php129
-rw-r--r--tests/cache/fixtures/cache_memory.xml77
3 files changed, 270 insertions, 0 deletions
diff --git a/tests/cache/cache_memory.php b/tests/cache/cache_memory.php
new file mode 100644
index 0000000000..806edb963a
--- /dev/null
+++ b/tests/cache/cache_memory.php
@@ -0,0 +1,64 @@
+<?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.
+ *
+ */
+
+class phpbb_cache_memory extends \phpbb\cache\driver\memory
+{
+ protected $data = array();
+
+ /**
+ * Set cache path
+ */
+ function phpbb_cache_memory()
+ {
+ }
+
+ /**
+ * Fetch an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return mixed Cached data
+ */
+ function _read($var)
+ {
+ return $this->data[$var];
+ }
+
+ /**
+ * Store data in the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @param mixed $data Data to store
+ * @param int $ttl Time-to-live of cached data
+ * @return bool True if the operation succeeded
+ */
+ function _write($var, $data, $ttl = 2592000)
+ {
+ $this->data[$var] = $data;
+ return true;
+ }
+
+ /**
+ * Remove an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return bool True if the operation succeeded
+ */
+ function _delete($var)
+ {
+ unset($this->data[$var]);
+ return true;
+ }
+}
diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php
new file mode 100644
index 0000000000..9f92e8d8dc
--- /dev/null
+++ b/tests/cache/cache_memory_test.php
@@ -0,0 +1,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()
+ {
+ 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], sizeof($results));
+ }
+
+ $this->cache->destroy('sql', $table);
+
+ foreach ($sql_queries as $query)
+ {
+ $this->assertNotEquals(false, $this->cache->sql_load($query[0]));
+ }
+ }
+}
diff --git a/tests/cache/fixtures/cache_memory.xml b/tests/cache/fixtures/cache_memory.xml
new file mode 100644
index 0000000000..9c19ebb7ba
--- /dev/null
+++ b/tests/cache/fixtures/cache_memory.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_title</column>
+ <column>topic_first_post_id</column>
+ <column>topic_last_post_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>Topic</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 2</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 3</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_posts</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>user 1</value>
+ <value>user 1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>user 2</value>
+ <value>user 2</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>user 3</value>
+ <value>user 3</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>