aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/class_visibility/all_tests.php40
-rw-r--r--tests/class_visibility/auth_mock.php290
-rw-r--r--tests/class_visibility/class_visibility_test.php199
-rw-r--r--tests/class_visibility/user_mock.php17
4 files changed, 0 insertions, 546 deletions
diff --git a/tests/class_visibility/all_tests.php b/tests/class_visibility/all_tests.php
deleted file mode 100644
index 1e5f5b8fd9..0000000000
--- a/tests/class_visibility/all_tests.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_visibility_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'class_visibility_test.php';
-
-class phpbb_visibility_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Visibility class');
-
- $suite->addTestSuite('phpbb_class_visibility_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_visibility_all_tests::main')
-{
- phpbb_visibility_all_tests::main();
-}
diff --git a/tests/class_visibility/auth_mock.php b/tests/class_visibility/auth_mock.php
deleted file mode 100644
index d829da4541..0000000000
--- a/tests/class_visibility/auth_mock.php
+++ /dev/null
@@ -1,290 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @version $Id$
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/*
-* phpbb_acl_mock_none
-* mock a user with no permissions
-*/
-class phpbb_acl_mock_none
-{
- public function acl_get($opt, $f)
- {
- if ($opt[0] == '!')
- {
- return true;
- }
-
- return false;
- }
-
- public function acl_gets($opt, $f)
- {
- if ($opt[0] == '!')
- {
- return true;
- }
-
- return false;
- }
-
- public function acl_getf_global($opt)
- {
- if ($opt[0] == '!')
- {
- return true;
- }
-
- return false;
- }
-
- public function acl_getf($opt, $clean = false)
- {
- $invert = false;
- if ($opt[0] == '!')
- {
- $invert = true;
- }
-
- $array = array();
- if ($clean && !$invert)
- {
- return $array; // return empty
- }
-
- for ($i = 1; $i < 15; $i++)
- {
- $array[$i] = !$invert;
- }
- return $array;
- }
-}
-
-class phpbb_acl_mock_founder
-{
- public function acl_get($opt, $f)
- {
- if ($opt[0] == '!')
- {
- return false;
- }
-
- return true;
- }
-
- public function acl_gets($opt, $f)
- {
- if ($opt[0] == '!')
- {
- return false;
- }
-
- return true;
- }
-
- public function acl_getf_global($opt)
- {
- if ($opt[0] == '!')
- {
- return false;
- }
-
- return true;
- }
-
- public function acl_getf($opt, $clean = false)
- {
- $invert = false;
- if ($opt[0] == '!')
- {
- $invert = true;
- }
-
- $array = array();
- if ($clean && $invert)
- {
- return $array; // return empty
- }
-
- for ($i = 1; $i < 15; $i++)
- {
- $array[$i] = !$invert;
- }
- return $array;
- }
-}
-
-class phpbb_acl_mock_moderator
-{
- public function acl_get($opt, $f = 0)
- {
- // just don't ask. Well, ok, I'll explain anyway
- // If we're negating an admin permission, we have it.
- if ($opt[0] == '!' && substr($opt, 0, 3) == '!a_')
- {
- return true;
- }
- // if we're negating something which is not an admin permission, we don't have it
- else if ($opt[0] == '!' && substr($opt, 0, 3) != '!a_')
- {
- return false;
- }
- // if we're not negating something that is an admin permission, we
- else if (substr($opt, 0, 2) == 'a_')
- {
- return false;
- }
-
- return true;
- }
-
- public function acl_gets()
- {
- $limit = func_num_args();
- for ($i = 0; $i < $limit; $i++)
- {
- $opt = func_get_arg($i);
-
- if ($opt[0] == '!' && substr($opt, 0, 3) == '!a_')
- {
- return true;
- }
- else if ($opt[0] != '!' && substr($opt, 0, 2) != 'a_')
- {
- return true;
- }
- }
-
- return false;
- }
-
- public function acl_getf_global($opt)
- {
- // this should only be called to check m_ permissions generally. Our ideal
- // moderator has all m_permissions.
- if ($opt[0] == '!')
- {
- return false;
- }
-
- return true;
- }
-
- public function acl_getf($opt, $clean = false)
- {
- // again, acl_getf should not be called for admin permissions (which are global...)
- $invert = false;
- if ($opt[0] == '!')
- {
- $invert = true;
- }
-
- if ($clean && $invert)
- {
- return $array; // return empty
- }
-
- $array = array();
- for ($i = 1; $i < 15; $i++)
- {
- $array[$i] = !$invert;
- }
- return $array;
- }
-}
-
-class phpbb_acl_mock_user
-{
- public function acl_get($opt, $f = 0)
- {
- // just don't ask. Well, ok, I'll explain anyway
- // If we're negating an admin or moderator permission (which our "user" does not have), we now have it.
- if ($opt[0] == '!' && in_array(substr($opt, 0, 3), array('!a_', '!m_')))
- {
- return true;
- }
- // if we're negating something which is not an admin permission, we don't have it
- else if ($opt[0] == '!' && !in_array(substr($opt, 0, 3), array('!a_', '!m_')))
- {
- return false;
- }
- // if we're not negating something that is an admin permission, we don't have it
- else if (in_array(substr($opt, 0, 2), array('f_', 'u_')))
- {
- return true;
- }
-
- // for anything else (this leaves u_ and f_ perms), we have it.
- return false;
- }
-
- public function acl_gets()
- {
-// NOT IMPLEMENTED YET for the USER class
- $limit = func_num_args();
- for ($i = 0; $i < $limit; $i++)
- {
- $opt = func_get_arg($i);
-
- if ($opt[0] == '!' && substr($opt, 0, 3) == '!a_')
- {
- return true;
- }
- else if ($opt[0] != '!' && substr($opt, 0, 2) != 'a_')
- {
- return true;
- }
- }
-
- return false;
- }
-
- public function acl_getf_global($opt)
- {
- // this should only be called to check m_ permissions generally. Our user
- // has no m_ permissions.
- if ($opt[0] == '!')
- {
- return true;
- }
-
- return false;
- }
-
- public function acl_getf($opt, $clean = false)
- {
- // again, acl_getf should not be called for admin permissions (which are global...)
- $invert = false;
- if ($opt[0] == '!')
- {
- $invert = true;
- $opt = substr($opt, 0, 1);
- }
-
- $has_it = ($opt[0] == 'f');
- if ($invert)
- {
- $has_it = !$has_it;
- }
-
- $array = array();
- if (!$has_it && $clean)
- {
- return $array; // return empty
- }
-
-
- for ($i = 1; $i < 15; $i++)
- {
- $array[$i] = $has_it;
- }
-
- return $array;
- }
-} \ No newline at end of file
diff --git a/tests/class_visibility/class_visibility_test.php b/tests/class_visibility/class_visibility_test.php
deleted file mode 100644
index 20aa207f46..0000000000
--- a/tests/class_visibility/class_visibility_test.php
+++ /dev/null
@@ -1,199 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @version $Id$
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-require_once 'test_framework/framework.php';
-require_once 'class_visibility/auth_mock.php';
-require_once 'class_visibility/user_mock.php';
-
-require_once '../phpBB/includes/class_content_visibility.php';
-require_once '../phpBB/includes/db/mysqli.php';
-require_once '../phpBB/includes/functions.php';
-require_once '../phpBB/includes/constants.php';
-
-$GLOBALS['db'] = new dbal_mysqli();
-
-class phpbb_class_visibility_test extends PHPUnit_Framework_TestCase
-{
- public function test_get_visibility_sql()
- {
- $GLOBALS['auth'] = new phpbb_acl_mock_none;
-
- $sql1 = phpbb_content_visibility::get_visibility_sql('topic', 1, '');
- $this->assertEquals('topic_visibility = 1', $sql1);
-
- $sql2 = phpbb_content_visibility::get_visibility_sql('post', 1, '');
- $this->assertEquals('post_visibility = 1', $sql2);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
-
- $sql3 = phpbb_content_visibility::get_visibility_sql('topic', 1, '');
- $this->assertEquals('topic_visibility IN (1, 0, 2)', $sql3);
-
- $sql4 = phpbb_content_visibility::get_visibility_sql('post', 1, '');
- $this->assertEquals('post_visibility IN (1, 0, 2)', $sql4);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_user;
- $GLOBALS['user'] = new phpbb_user_mock;
- $GLOBALS['user']->data['user_id'] = 2;
-
- $sql1 = phpbb_content_visibility::get_visibility_sql('topic', 1, '');
- $this->assertEquals('(topic_visibility = 1
- OR (topic_visibility = 2
- AND topic_poster = 2))', $sql1);
-
- $sql2 = phpbb_content_visibility::get_visibility_sql('post', 1, '');
- $this->assertEquals('(post_visibility = 1
- OR (post_visibility = 2
- AND poster_id = 2))', $sql2);
- }
-
- public function test_get_visibility_sql_global()
- {
- $GLOBALS['auth'] = new phpbb_acl_mock_none;
-
- $sql1 = phpbb_content_visibility::get_visibility_sql_global('topic', array(), '');
- $this->assertEquals('(topic_visibility = 1)', $sql1);
-
- $sql2 = phpbb_content_visibility::get_visibility_sql_global('post', array(), '');
- $this->assertEquals('(post_visibility = 1)', $sql2);
-
- $sql3 = phpbb_content_visibility::get_visibility_sql_global('post', range(2, 15), '');
- $this->assertEquals('(post_visibility = 1)', $sql3);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
-
- $sql1 = phpbb_content_visibility::get_visibility_sql_global('topic', array(), '');
- $this->assertEquals('(topic_visibility = 1 OR (topic_visibility = 0
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)) OR (topic_visibility = 2
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))', $sql1);
-
- $sql2 = phpbb_content_visibility::get_visibility_sql_global('post', array(), '');
- $this->assertEquals('(post_visibility = 1 OR (post_visibility = 0
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)) OR (post_visibility = 2
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))', $sql2);
-
- $sql3 = phpbb_content_visibility::get_visibility_sql_global('post', range(2, 14), '');
- $this->assertEquals('(post_visibility = 1 OR (post_visibility = 0
- AND forum_id = 1) OR (post_visibility = 2
- AND forum_id = 1))', $sql3);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_user;
- $GLOBALS['user'] = new phpbb_user_mock;
- $GLOBALS['user']->data['user_id'] = 2;
-
- $sql1 = phpbb_content_visibility::get_visibility_sql_global('topic', array(), '');
- $this->assertEquals('(topic_visibility = 1 OR (topic_poster = 2
- AND topic_visibility = 2
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))', $sql1);
-
- $sql2 = phpbb_content_visibility::get_visibility_sql_global('post', array(), '');
- $this->assertEquals('(post_visibility = 1 OR (poster_id = 2
- AND post_visibility = 2
- AND forum_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))', $sql2);
-
- $sql3 = phpbb_content_visibility::get_visibility_sql_global('post', range(2, 14), '');
- $this->assertEquals('(post_visibility = 1 OR (poster_id = 2
- AND post_visibility = 2
- AND forum_id = 1))', $sql3);
- }
-
- public function test_can_soft_delete()
- {
- $GLOBALS['user'] = new phpbb_user_mock;
- $GLOBALS['user']->data['user_id'] = 2;
-
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
- $result = phpbb_content_visibility::can_soft_delete(1, 4, true);
- $this->assertEquals(true, $result);
-
- $result = phpbb_content_visibility::can_soft_delete(1, 2, false);
- $this->assertEquals(true, $result);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_none;
- $result = phpbb_content_visibility::can_soft_delete(1, 4, true);
- $this->assertEquals(false, $result);
-
- $result = phpbb_content_visibility::can_soft_delete(1, 2, false);
- $this->assertEquals(false, $result);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_user;
- $result = phpbb_content_visibility::can_soft_delete(1, 4, true);
- $this->assertEquals(false, $result);
-
- $result = phpbb_content_visibility::can_soft_delete(1, 2, false);
- $this->assertEquals(true, $result);
-
- $result = phpbb_content_visibility::can_soft_delete(1, 2, true);
- $this->assertEquals(false, $result);
- }
-
- public function test_can_restore()
- {
- $GLOBALS['user'] = new phpbb_user_mock;
- $GLOBALS['user']->data['user_id'] = 2;
-
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
- $result = phpbb_content_visibility::can_restore(1, 4, true);
- $this->assertEquals(true, $result);
-
- $result = phpbb_content_visibility::can_restore(1, 2, false);
- $this->assertEquals(true, $result);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_none;
- $result = phpbb_content_visibility::can_restore(1, 4, true);
- $this->assertEquals(false, $result);
-
- $result = phpbb_content_visibility::can_restore(1, 2, false);
- $this->assertEquals(false, $result);
-
- $GLOBALS['auth'] = new phpbb_acl_mock_user;
- $result = phpbb_content_visibility::can_restore(1, 4, true);
- $this->assertEquals(false, $result);
-
- $result = phpbb_content_visibility::can_restore(1, 2, false);
- $this->assertEquals(true, $result);
-
- $result = phpbb_content_visibility::can_restore(1, 2, true);
- $this->assertEquals(false, $result);
- }
-
- public function test_hide_topic()
- {
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
-
- $topic_row = array('topic_replies' => 3);
- $sql_data = array();
- phpbb_content_visibility::hide_topic(4, 2, $topic_row, $sql_data);
- $this->assertEquals(
- array(FORUMS_TABLE => 'forum_topics = forum_topics - 1, forum_posts = forum_posts - 4', USERS_TABLE => 'user_posts = user_posts - 1'),
- $sql_data);
- }
-
- public function test_hide_post()
- {
- $GLOBALS['auth'] = new phpbb_acl_mock_founder;
-
- $sql_data = array();
- phpbb_content_visibility::hide_post(4, 111122211, array('topic_replies' => 1), $sql_data);
- $this->assertEquals(
- array(FORUMS_TABLE => 'forum_posts = forum_posts - 1',
- TOPICS_TABLE => 'topic_replies = topic_replies - 1, topic_last_view_time = 111122211',
- USERS_TABLE => 'user_posts = user_posts - 1'),
- $sql_data);
-
- $sql_data = array();
- phpbb_content_visibility::hide_post(4, 111122211, array('topic_replies' => 0), $sql_data);
- $this->assertEquals(
- array(FORUMS_TABLE => 'forum_posts = forum_posts - 1',
- TOPICS_TABLE => 'topic_last_view_time = 111122211',
- USERS_TABLE => 'user_posts = user_posts - 1'),
- $sql_data);
- }
-}
diff --git a/tests/class_visibility/user_mock.php b/tests/class_visibility/user_mock.php
deleted file mode 100644
index cbeec23875..0000000000
--- a/tests/class_visibility/user_mock.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @version $Id$
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/*
-* Mock a very basic user object, only having data array.
-*/
-class phpbb_user_mock
-{
- public $data;
-} \ No newline at end of file