From 4a65940e6206aef6b85a0aacfb5324ecabf76e12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Oct 2012 22:14:04 +0200 Subject: [feature/soft-delete] Add unit tests for get_forums_visibility_sql() PHPBB3-9657 --- .../fixtures/get_forums_visibility_sql.xml | 133 ++++++++++++++++++ .../get_forums_visibility_sql_test.php | 149 +++++++++++++++++++++ .../content_visibility/get_visibility_sql_test.php | 5 - 3 files changed, 282 insertions(+), 5 deletions(-) create mode 100644 tests/content_visibility/fixtures/get_forums_visibility_sql.xml create mode 100644 tests/content_visibility/get_forums_visibility_sql_test.php (limited to 'tests') diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml new file mode 100644 index 0000000000..658d34398f --- /dev/null +++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml @@ -0,0 +1,133 @@ + + + + topic_id + forum_id + topic_visibility + topic_title + + 1 + 1 + 0 + Unapproved + + + 2 + 1 + 1 + Approved + + + 3 + 1 + 2 + Softdeleted + + + 4 + 2 + 0 + Unapproved + + + 5 + 2 + 1 + Approved + + + 6 + 2 + 2 + Softdeleted + + + 7 + 3 + 0 + Unapproved + + + 8 + 3 + 1 + Approved + + + 9 + 3 + 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 + + + 4 + 4 + 2 + 0 + Unapproved + + + 5 + 5 + 2 + 1 + Approved + + + 6 + 6 + 2 + 2 + Softdeleted + + + 7 + 7 + 3 + 0 + Unapproved + + + 8 + 8 + 3 + 1 + Approved + + + 9 + 9 + 3 + 2 + Softdeleted + +
+
diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php new file mode 100644 index 0000000000..62e1c8187d --- /dev/null +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -0,0 +1,149 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml'); + } + + public function get_forums_visibility_sql_data() + { + return array( + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + array('m_restore', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + array('topic_id' => 7), + array('topic_id' => 8), + array('topic_id' => 9), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true)), + array('m_restore', true, array(1 => true, 2 => true)), + ), + array( + array('topic_id' => 1), + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 6), + ), + ), + array( + 'phpbb_topics', + 'topic', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + array('m_restore', true, array(1 => true)), + ), + array( + array('topic_id' => 2), + array('topic_id' => 3), + array('topic_id' => 4), + array('topic_id' => 5), + array('topic_id' => 8), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(1 => true, 2 => true, 3 => true)), + array('m_restore', true, array(1 => true, 2 => true, 3 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + array('post_id' => 7), + array('post_id' => 8), + array('post_id' => 9), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2), '', + array( + array('m_approve', true, array(1 => true, 2 => true)), + array('m_restore', true, array(1 => true, 2 => true)), + ), + array( + array('post_id' => 1), + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 6), + ), + ), + array( + 'phpbb_posts', + 'post', array(1, 2, 3), '', + array( + array('m_approve', true, array(2 => true)), + array('m_restore', true, array(1 => true)), + ), + array( + array('post_id' => 2), + array('post_id' => 3), + array('post_id' => 4), + array('post_id' => 5), + array('post_id' => 8), + ), + ), + ); + } + + /** + * @dataProvider get_forums_visibility_sql_data + */ + public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected) + { + global $db, $auth; + + $db = $this->new_dbal(); + + // Create auth mock + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_getf') + ->with($this->stringContains('_'), $this->anything()) + ->will($this->returnValueMap($permissions)); + + $result = $db->sql_query('SELECT ' . $mode . '_id + FROM ' . $table . ' + WHERE ' . phpbb_content_visibility::get_forums_visibility_sql($mode, $forum_ids, $table_alias) . ' + ORDER BY ' . $mode . '_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php index 415a33d17f..55396aaba5 100644 --- a/tests/content_visibility/get_visibility_sql_test.php +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -121,11 +121,6 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te // 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()) -- cgit v1.2.1