aboutsummaryrefslogtreecommitdiffstats
path: root/tests/content_visibility/get_visibility_sql_test.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-10-01 17:13:15 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-10-01 17:13:15 +0200
commit280619eea9585924a44611f001f266d354036d0a (patch)
treeedbcc5686acb2372afd72ae3df901fa65640f909 /tests/content_visibility/get_visibility_sql_test.php
parent38d83da69e65f3dac635d203230d38089df314a5 (diff)
downloadforums-280619eea9585924a44611f001f266d354036d0a.tar
forums-280619eea9585924a44611f001f266d354036d0a.tar.gz
forums-280619eea9585924a44611f001f266d354036d0a.tar.bz2
forums-280619eea9585924a44611f001f266d354036d0a.tar.xz
forums-280619eea9585924a44611f001f266d354036d0a.zip
[feature/soft-delete] Add unit tests for get_visibility_sql()
PHPBB3-9657
Diffstat (limited to 'tests/content_visibility/get_visibility_sql_test.php')
-rw-r--r--tests/content_visibility/get_visibility_sql_test.php141
1 files changed, 141 insertions, 0 deletions
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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->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));
+ }
+}