diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-10-01 17:13:15 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-10-01 17:13:15 +0200 |
commit | 280619eea9585924a44611f001f266d354036d0a (patch) | |
tree | edbcc5686acb2372afd72ae3df901fa65640f909 /tests | |
parent | 38d83da69e65f3dac635d203230d38089df314a5 (diff) | |
download | forums-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')
-rw-r--r-- | tests/content_visibility/fixtures/get_visibility_sql.xml | 55 | ||||
-rw-r--r-- | tests/content_visibility/get_visibility_sql_test.php | 141 |
2 files changed, 196 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <column>topic_visibility</column> + <column>topic_title</column> + <row> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_visibility</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>Unapproved</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>Approved</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + <value>2</value> + <value>Softdeleted</value> + </row> + </table> +</dataset> 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)); + } +} |