From 280619eea9585924a44611f001f266d354036d0a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 17:13:15 +0200 Subject: [PATCH] [feature/soft-delete] Add unit tests for get_visibility_sql() PHPBB3-9657 --- .../fixtures/get_visibility_sql.xml | 55 +++++++ .../get_visibility_sql_test.php | 141 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 tests/content_visibility/fixtures/get_visibility_sql.xml create mode 100644 tests/content_visibility/get_visibility_sql_test.php diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml new file mode 100644 index 0000000000..146244263e --- /dev/null +++ b/tests/content_visibility/fixtures/get_visibility_sql.xml @@ -0,0 +1,55 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + + 1 + 1 + 0 + Unapproved + + + 2 + 1 + 1 + Approved + + + 3 + 1 + 2 + Softdeleted + +
+ + post_id + topic_id + forum_id + post_visibility + post_text + + 1 + 1 + 1 + 0 + Unapproved + + + 2 + 2 + 1 + 1 + Approved + + + 3 + 3 + 1 + 2 + Softdeleted + +
+
diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php new file mode 100644 index 0000000000..415a33d17f --- /dev/null +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -0,0 +1,141 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml'); + } + + public function get_visibility_sql_data() + { + return array( + array( + 'phpbb_posts', + 'post', 1, '', + array( + array('m_approve', 1, true), + array('m_restore', 1, true), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + ), + ), + array( + 'phpbb_posts', + 'post', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + ), + ), + array( + 'phpbb_posts', + 'post', 1, '', + array( + array('m_restore', 1, true), + ), + array( + array('post_id' => 2), + array('post_id' => 3), + ), + ), + array( + 'phpbb_posts', + 'post', 1, '', + array( + ), + array( + array('post_id' => 2), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array( + array('m_approve', 1, true), + array('m_restore', 1, true), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array( + array('m_approve', 1, true), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array( + array('m_restore', 1, true), + ), + array( + array('topic_id' => 2), + array('topic_id' => 3), + ), + ), + array( + 'phpbb_topics', + 'topic', 1, '', + array(), + array( + array('topic_id' => 2), + ), + ), + ); + } + + /** + * @dataProvider get_visibility_sql_data + */ + public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected) + { + global $db, $auth; + + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $acl_get_map = array( + array('f_read', 23, true), + array('m_', 23, true), + ); + + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . phpbb_content_visibility::get_visibility_sql($mode, $forum_id, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +}