From b7f54e42b269374f018fe67ece11e63cf86b0c12 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 15 May 2014 00:22:27 +0200 Subject: [ticket/11224] Add unit test PHPBB3-11224 --- tests/cache/cache_memory_test.php | 109 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/cache/cache_memory_test.php (limited to 'tests/cache/cache_memory_test.php') diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php new file mode 100644 index 0000000000..90c9f4413e --- /dev/null +++ b/tests/cache/cache_memory_test.php @@ -0,0 +1,109 @@ +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, + ), + ); + } + + /** + * @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->assertNotFalse($this->cache->sql_load($query[0])); + } + } +} -- cgit v1.2.1 From 292908ca4add9d6e31a35c7e620046b3f038e81d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 15 May 2014 01:49:07 +0200 Subject: [ticket/11224] Use assertNotEquals(false) instead of assertNotFalse() assertNotFalse() is unavailable with the version of phpunit used with php 5.2 PHPBB3-11224 --- tests/cache/cache_memory_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/cache/cache_memory_test.php') diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php index 90c9f4413e..5a9f61f36e 100644 --- a/tests/cache/cache_memory_test.php +++ b/tests/cache/cache_memory_test.php @@ -103,7 +103,7 @@ class phpbb_cache_memory_test extends phpbb_database_test_case foreach ($sql_queries as $query) { - $this->assertNotFalse($this->cache->sql_load($query[0])); + $this->assertNotEquals(false, $this->cache->sql_load($query[0])); } } } -- cgit v1.2.1 From 74a96bf7c2c6d4bb0c68cf74858260d0466ed3cc Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 24 Sep 2014 16:16:47 +0200 Subject: [ticket/11224] Adds a test case PHPBB3-11224 --- tests/cache/cache_memory_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/cache/cache_memory_test.php') diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php index 5a9f61f36e..7a529c1d04 100644 --- a/tests/cache/cache_memory_test.php +++ b/tests/cache/cache_memory_test.php @@ -73,6 +73,22 @@ class phpbb_cache_memory_test extends phpbb_database_test_case ), 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, + ), ); } -- cgit v1.2.1