diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-10-01 15:00:01 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-10-03 23:50:24 +0200 |
commit | 8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a (patch) | |
tree | 7a92af7c477390b22f389163e73f542d2cd4fbfa /tests/cache/cache_memory_test.php | |
parent | 40cd7570e6f4da7cc60d83a3e99c72a2fb99e3f7 (diff) | |
download | forums-8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a.tar forums-8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a.tar.gz forums-8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a.tar.bz2 forums-8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a.tar.xz forums-8e638dbf6d53be3d8c5b1eda8ce44e7e4f60b75a.zip |
[ticket/11224] Revert Revert "Merge pull request #2460 from ticket/11224"
This reverts commit 40cd7570e6f4da7cc60d83a3e99c72a2fb99e3f7.
Diffstat (limited to 'tests/cache/cache_memory_test.php')
-rw-r--r-- | tests/cache/cache_memory_test.php | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php new file mode 100644 index 0000000000..7a529c1d04 --- /dev/null +++ b/tests/cache/cache_memory_test.php @@ -0,0 +1,125 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/cache_memory.php'; + +class phpbb_cache_memory_test extends phpbb_database_test_case +{ + protected $cache; + + 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(); + } + + 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) + { + global $db; + + foreach ($sql_queries as $query) + { + $sql_request_res = $db->sql_query($query[0]); + + $this->cache->sql_save($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])); + } + } +} |