aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.md14
-rw-r--r--tests/cache/cache_memory.php62
-rw-r--r--tests/cache/cache_memory_test.php125
-rw-r--r--tests/cache/fixtures/cache_memory.xml85
-rw-r--r--tests/functional/acp_attachments_test.php78
-rw-r--r--tests/functional/acp_users_test.php45
-rw-r--r--tests/functional/private_messages_test.php65
-rw-r--r--tests/functions/obtain_online_test.php3
-rw-r--r--tests/functions/parse_cfg_file_test.php103
-rw-r--r--tests/functions_content/get_username_string_test.php125
-rw-r--r--tests/functions_content/phpbb_clean_search_string_test.php38
-rw-r--r--tests/functions_user/delete_user_test.php436
-rw-r--r--tests/functions_user/fixtures/delete_user.xml531
-rw-r--r--tests/lint_test.php28
-rw-r--r--tests/profile/get_profile_value_test.php42
-rw-r--r--tests/security/redirect_test.php9
-rw-r--r--tests/security/trailing_path_test.php60
-rw-r--r--tests/session/fixtures/sessions_empty.xml7
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php81
-rw-r--r--tests/text_processing/generate_text_for_display_test.php38
20 files changed, 1951 insertions, 24 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md
index 23c74f4411..d9306d78d7 100644
--- a/tests/RUNNING_TESTS.md
+++ b/tests/RUNNING_TESTS.md
@@ -110,12 +110,16 @@ Slow tests
--------------
Certain tests, such as the UTF-8 normalizer or the DNS tests tend to be slow.
-Thus these tests are in the `slow` group, which is excluded by default. You can
-enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you
+Thus these tests are in the `slow` group, which is excluded by default. If you
only want the slow tests, run:
$ phpBB/vendor/bin/phpunit --group slow
+If you want all tests, run:
+
+ $ phpBB/vendor/bin/phpunit --group __nogroup__,functional,slow
+
+
Functional tests
-----------------
@@ -136,10 +140,10 @@ on which to run tests.
$phpbb_functional_url = 'http://localhost/phpBB3/';
-To then run the tests, you run PHPUnit, but use the phpunit.xml.functional
-config file instead of the default one. Specify this through the "-c" option:
+Functional tests are automatically run, if '$phpbb_functional_url' is configured.
+If you only want the functional tests, run:
- $ phpBB/vendor/bin/phpunit -c phpunit.xml.functional
+ $ phpBB/vendor/bin/phpunit --group functional
This will change your board's config.php file, but it makes a backup at
config_dev.php, so you can restore it after the test run is complete.
diff --git a/tests/cache/cache_memory.php b/tests/cache/cache_memory.php
new file mode 100644
index 0000000000..c468cb4658
--- /dev/null
+++ b/tests/cache/cache_memory.php
@@ -0,0 +1,62 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/acm/acm_memory.php';
+
+class phpbb_cache_memory extends acm_memory
+{
+ protected $data = array();
+
+ /**
+ * Set cache path
+ */
+ function phpbb_cache_memory()
+ {
+ }
+
+ /**
+ * Fetch an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return mixed Cached data
+ */
+ function _read($var)
+ {
+ return $this->data[$var];
+ }
+
+ /**
+ * Store data in the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @param mixed $data Data to store
+ * @param int $ttl Time-to-live of cached data
+ * @return bool True if the operation succeeded
+ */
+ function _write($var, $data, $ttl = 2592000)
+ {
+ $this->data[$var] = $data;
+ return true;
+ }
+
+ /**
+ * Remove an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return bool True if the operation succeeded
+ */
+ function _delete($var)
+ {
+ unset($this->data[$var]);
+ return true;
+ }
+}
diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php
new file mode 100644
index 0000000000..7a529c1d04
--- /dev/null
+++ b/tests/cache/cache_memory_test.php
@@ -0,0 +1,125 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/cache_memory.php';
+
+class phpbb_cache_memory_test extends phpbb_database_test_case
+{
+ protected $cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/cache_memory.xml');
+ }
+
+ protected function setUp()
+ {
+ global $db;
+ parent::setUp();
+
+ $this->cache = new phpbb_cache_memory();
+ $db = $this->new_dbal();
+ }
+
+ static public function cache_single_query_data()
+ {
+ return array(
+ array(
+ array(
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE,
+ 3,
+ ),
+ ),
+ POSTS_TABLE,
+ ),
+ array(
+ array(
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE,
+ 3,
+ ),
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE . ' p
+ LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
+ 3,
+ ),
+ ),
+ POSTS_TABLE,
+ ),
+ array(
+ array(
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE,
+ 3,
+ ),
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE . ' p
+ LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
+ 3,
+ ),
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE . ' p
+ LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
+ LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
+ 3,
+ ),
+ ),
+ POSTS_TABLE,
+ ),
+ array(
+ array(
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE . ' p
+ LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
+ 3,
+ ),
+ array(
+ 'SELECT * FROM ' . POSTS_TABLE . ' p
+ LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
+ LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
+ 3,
+ ),
+ ),
+ TOPICS_TABLE,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider cache_single_query_data
+ */
+ public function test_cache_single_query($sql_queries, $table)
+ {
+ global $db;
+
+ foreach ($sql_queries as $query)
+ {
+ $sql_request_res = $db->sql_query($query[0]);
+
+ $this->cache->sql_save($query[0], $sql_request_res, 1);
+
+ $results = array();
+ $query_id = $this->cache->sql_load($query[0]);
+ while ($row = $this->cache->sql_fetchrow($query_id))
+ {
+ $results[] = $row;
+ }
+ $this->cache->sql_freeresult($query_id);
+ $this->assertEquals($query[1], sizeof($results));
+ }
+
+ $this->cache->destroy('sql', $table);
+
+ foreach ($sql_queries as $query)
+ {
+ $this->assertNotEquals(false, $this->cache->sql_load($query[0]));
+ }
+ }
+}
diff --git a/tests/cache/fixtures/cache_memory.xml b/tests/cache/fixtures/cache_memory.xml
new file mode 100644
index 0000000000..6954c7b76b
--- /dev/null
+++ b/tests/cache/fixtures/cache_memory.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_title</column>
+ <column>topic_first_post_id</column>
+ <column>topic_last_post_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>Topic</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 2</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post 3</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_posts</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>user 1</value>
+ <value>user 1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>user 2</value>
+ <value>user 2</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>user 3</value>
+ <value>user 3</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functional/acp_attachments_test.php b/tests/functional/acp_attachments_test.php
new file mode 100644
index 0000000000..8e810a508a
--- /dev/null
+++ b/tests/functional/acp_attachments_test.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+/**
+ * @group functional
+ */
+class phpbb_functional_acp_attachments_test extends phpbb_functional_test_case
+{
+ public function data_imagick_path_linux()
+ {
+ return array(
+ array('/usr/bin', 'Configuration updated successfully'),
+ array('/usr/foobar', 'The entered path “/usr/foobar” does not exist.'),
+ array('/usr/bin/which', 'The entered path “/usr/bin/which” is not a directory.'),
+ );
+ }
+
+ /**
+ * @dataProvider data_imagick_path_linux
+ */
+ public function test_imagick_path_linux($imagick_path, $expected)
+ {
+ if (strtolower(substr(PHP_OS, 0, 5)) !== 'linux')
+ {
+ $this->markTestSkipped('Unable to test linux specific paths on other OS.');
+ }
+
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?i=attachments&mode=attach&sid=' . $this->sid);
+
+ $form = $crawler->selectButton('Submit')->form(array('config[img_imagick]' => $imagick_path));
+
+ $crawler = self::submit($form);
+ $this->assertContains($expected, $crawler->filter('#main')->text());
+ }
+
+ public function data_imagick_path_windows()
+ {
+ return array(
+ array('C:\Windows', 'Configuration updated successfully'),
+ array('C:\Windows\foobar1', 'The entered path “C:\Windows\foobar1” does not exist.'),
+ array('C:\Windows\explorer.exe', 'The entered path “C:\Windows\explorer.exe” is not a directory.'),
+ );
+ }
+
+ /**
+ * @dataProvider data_imagick_path_windows
+ */
+ public function test_imagick_path_windows($imagick_path, $expected)
+ {
+ if (strtolower(substr(PHP_OS, 0, 3)) !== 'win')
+ {
+ $this->markTestSkipped('Unable to test windows specific paths on other OS.');
+ }
+
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?i=attachments&mode=attach&sid=' . $this->sid);
+
+ $form = $crawler->selectButton('Submit')->form(array('config[img_imagick]' => $imagick_path));
+
+ $crawler = self::submit($form);
+ $this->assertContains($expected, $crawler->filter('#main')->text());
+ }
+}
diff --git a/tests/functional/acp_users_test.php b/tests/functional/acp_users_test.php
new file mode 100644
index 0000000000..50d9a67dc1
--- /dev/null
+++ b/tests/functional/acp_users_test.php
@@ -0,0 +1,45 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_acp_users_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/users');
+ }
+
+ public function test_founder_deletion()
+ {
+ $username = 'founder-account';
+ $user_id = $this->create_user($username);
+ $this->make_founder($user_id);
+
+ $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u=$user_id&sid={$this->sid}");
+ $form = $crawler->filter('#user_delete')->selectButton($this->lang('SUBMIT'))->form();
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('CANNOT_REMOVE_FOUNDER'), $this->get_content());
+ }
+
+ protected function make_founder($user_id)
+ {
+ $crawler = self::request('GET', "adm/index.php?i=users&mode=overview&u=$user_id&sid={$this->sid}");
+ $form = $crawler->filter('#user_overview')->selectButton($this->lang('SUBMIT'))->form();
+ $data = array('user_founder' => '1');
+ $form->setValues($data);
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('USER_OVERVIEW_UPDATED'), $this->get_content());
+ }
+}
diff --git a/tests/functional/private_messages_test.php b/tests/functional/private_messages_test.php
new file mode 100644
index 0000000000..15aa2b681a
--- /dev/null
+++ b/tests/functional/private_messages_test.php
@@ -0,0 +1,65 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_private_messages_test extends phpbb_functional_test_case
+{
+ public function test_setup_config()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=board&mode=message");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ // Set the maximum number of private messages per folder to 1
+ $values['config[pm_max_msgs]'] = 1;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
+ }
+
+ public function test_inbox_full()
+ {
+ $this->login();
+ $message_id = $this->create_private_message('Test private message #1', 'This is a test private message sent by the testing framework.', array(2));
+
+ $crawler = self::request('GET', "ucp.php?i=pm&mode=view&sid{$this->sid}&p={$message_id}");
+ $this->assertContains($this->lang('UCP_PM_VIEW'), $crawler->filter('html')->text());
+
+ $message_id = $this->create_private_message('Test private message #2', 'This is a test private message sent by the testing framework.', array(2));
+
+ $crawler = self::request('GET', "ucp.php?i=pm&mode=view&sid{$this->sid}&p={$message_id}");
+ $this->assertContains($this->lang('NO_AUTH_READ_HOLD_MESSAGE'), $crawler->filter('html')->text());
+ }
+
+ public function test_restore_config()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=board&mode=message");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values['config[pm_max_msgs]'] = 50;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
+ }
+}
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php
index b3beb55a96..de6451a0db 100644
--- a/tests/functions/obtain_online_test.php
+++ b/tests/functions/obtain_online_test.php
@@ -22,8 +22,9 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
{
parent::setUp();
- global $config, $db;
+ global $config, $db, $user;
+ $user = new StdClass;
$db = $this->db = $this->new_dbal();
$config = array(
'load_online_time' => 5,
diff --git a/tests/functions/parse_cfg_file_test.php b/tests/functions/parse_cfg_file_test.php
new file mode 100644
index 0000000000..69000ddf72
--- /dev/null
+++ b/tests/functions/parse_cfg_file_test.php
@@ -0,0 +1,103 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_functions_parse_cfg_file extends phpbb_test_case
+{
+ public function parse_cfg_file_data()
+ {
+ return array(
+ array(
+ array(
+ '#',
+ '# phpBB Style Configuration File',
+ '#',
+ '# @package phpBB3',
+ '# @copyright (c) 2005 phpBB Group',
+ '# @license http://opensource.org/licenses/gpl-license.php GNU Public License',
+ '#',
+ '#',
+ '# At the left is the name, please do not change this',
+ '# At the right the value is entered',
+ '# For on/off options the valid values are on, off, 1, 0, true and false',
+ '#',
+ '# Values get trimmed, if you want to add a space in front or at the end of',
+ '# the value, then enclose the value with single or double quotes.',
+ '# Single and double quotes do not need to be escaped.',
+ '#',
+ '',
+ '# General Information about this style',
+ 'name = prosilver',
+ 'copyright = © phpBB Group, 2007',
+ 'version = 3.0.12',
+ ),
+ array(
+ 'name' => 'prosilver',
+ 'copyright' => '© phpBB Group, 2007',
+ 'version' => '3.0.12',
+ ),
+ ),
+ array(
+ array(
+ 'name = subsilver2',
+ 'copyright = © 2005 phpBB Group',
+ 'version = 3.0.12',
+ ),
+ array(
+ 'name' => 'subsilver2',
+ 'copyright' => '© 2005 phpBB Group',
+ 'version' => '3.0.12',
+ ),
+ ),
+ array(
+ array(
+ 'foo = on',
+ 'foo1 = true',
+ 'foo2 = 1',
+ 'bar = off',
+ 'bar1 = false',
+ 'bar2 = 0',
+ 'foobar =',
+ 'foobar1 = "asdf"',
+ 'foobar2 = \'qwer\'',
+ ),
+ array(
+ 'foo' => true,
+ 'foo1' => true,
+ 'foo2' => true,
+ 'bar' => false,
+ 'bar1' => false,
+ 'bar2' => false,
+ 'foobar' => '',
+ 'foobar1' => 'asdf',
+ 'foobar2' => 'qwer',
+ ),
+ ),
+ array(
+ array(
+ 'foo = &amp; bar',
+ 'bar = <a href="test">Test</a>',
+ ),
+ array(
+ 'foo' => '&amp;amp; bar',
+ 'bar' => '&lt;a href=&quot;test&quot;&gt;Test&lt;/a&gt;',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider parse_cfg_file_data
+ */
+ public function test_parse_cfg_file($file_contents, $expected)
+ {
+ $this->assertEquals($expected, parse_cfg_file(false, $file_contents));
+ }
+}
diff --git a/tests/functions_content/get_username_string_test.php b/tests/functions_content/get_username_string_test.php
new file mode 100644
index 0000000000..48e8936cc1
--- /dev/null
+++ b/tests/functions_content/get_username_string_test.php
@@ -0,0 +1,125 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 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/functions_content.php';
+
+class phpbb_functions_content_get_username_string_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth, $user;
+ $auth = $this->getMock('auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'), $this->anything())
+ ->will($this->returnValueMap(array(
+ array('u_viewprofile', true),
+ )));
+ $user->data['user_id'] = ANONYMOUS;
+ $user->lang['GUEST'] = 'Guest';
+ }
+
+ public function get_username_string_profile_data()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return array(
+ array(ANONYMOUS, 'Anonymous', '', false, false, ''),
+ array(2, 'Administrator', 'FF0000', false, false, "{$phpbb_root_path}memberlist.$phpEx?mode=viewprofile&amp;u=2"),
+ array(42, 'User42', '', false, 'http://www.example.org/user.php?mode=show', 'http://www.example.org/user.php?mode=show&amp;u=42'),
+ );
+ }
+
+ /**
+ * @dataProvider get_username_string_profile_data
+ */
+ public function test_get_username_string_profile($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected)
+ {
+ $this->assertEquals($expected, get_username_string('profile', $user_id, $username, $user_colour, $guest_username, $custom_profile_url));
+ }
+
+ public function get_username_string_username_data()
+ {
+ return array(
+ array(ANONYMOUS, '', '', false, false, 'Guest'),
+ array(ANONYMOUS, '', '', 'CustomName', false, 'CustomName'),
+ array(2, 'User2', '', false, false, 'User2'),
+ array(5, 'User5', '', 'Anonymous', false, 'User5'),
+ array(128, 'User128', '', false, false, 'User128'),
+ );
+ }
+
+ /**
+ * @dataProvider get_username_string_username_data
+ */
+ public function test_get_username_string_username($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected)
+ {
+ $this->assertEquals($expected, get_username_string('username', $user_id, $username, $user_colour, $guest_username, $custom_profile_url));
+ }
+
+ public function get_username_string_colour_data()
+ {
+ return array(
+ array(0, '', '', false, false, ''),
+ array(0, '', 'F0F0F0', false, false, '#F0F0F0'),
+ array(ANONYMOUS, 'Anonymous', '000000', false, false, '#000000'),
+ array(2, 'Administrator', '', false, false, ''),
+ );
+ }
+
+ /**
+ * @dataProvider get_username_string_colour_data
+ */
+ public function test_get_username_string_colour($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected)
+ {
+ $this->assertEquals($expected, get_username_string('colour', $user_id, $username, $user_colour, $guest_username, $custom_profile_url));
+ }
+
+ public function get_username_string_full_data()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return array(
+ array(0, '', '', false, false, 'Guest'),
+ array(ANONYMOUS, 'Anonymous', '', false, false, 'Anonymous'),
+ array(2, 'Administrator', 'FF0000', false, false, '<a href="' . $phpbb_root_path . 'memberlist.' . $phpEx . '?mode=viewprofile&amp;u=2" style="color: #FF0000;" class="username-coloured">Administrator</a>'),
+ array(5, 'User5', '', false, 'http://www.example.org/user.php?mode=show', '<a href="http://www.example.org/user.php?mode=show&amp;u=5">User5</a>'),
+ array(8, 'Eight', '', false, false, '<a href="' . $phpbb_root_path . 'memberlist.php?mode=viewprofile&amp;u=8">Eight</a>'),
+ );
+ }
+
+ /**
+ * @dataProvider get_username_string_full_data
+ */
+ public function test_get_username_string_full($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected)
+ {
+ $this->assertEquals($expected, get_username_string('full', $user_id, $username, $user_colour, $guest_username, $custom_profile_url));
+ }
+
+ public function get_username_string_no_profile_data()
+ {
+ return array(
+ array(ANONYMOUS, 'Anonymous', '', false, false, 'Anonymous'),
+ array(ANONYMOUS, 'Anonymous', '', '', false, 'Guest'),
+ array(2, 'Administrator', 'FF0000', false, false, '<span style="color: #FF0000;" class="username-coloured">Administrator</span>'),
+ array(8, 'Eight', '', false, false, 'Eight'),
+ );
+ }
+
+ /**
+ * @dataProvider get_username_string_no_profile_data
+ */
+ public function test_get_username_string_no_profile($user_id, $username, $user_colour, $guest_username, $custom_profile_url, $expected)
+ {
+ $this->assertEquals($expected, get_username_string('no_profile', $user_id, $username, $user_colour, $guest_username, $custom_profile_url));
+ }
+}
diff --git a/tests/functions_content/phpbb_clean_search_string_test.php b/tests/functions_content/phpbb_clean_search_string_test.php
new file mode 100644
index 0000000000..de642c9040
--- /dev/null
+++ b/tests/functions_content/phpbb_clean_search_string_test.php
@@ -0,0 +1,38 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_functions_content_phpbb_clean_search_string_test extends phpbb_test_case
+{
+ public function phpbb_clean_search_string_data()
+ {
+ return array(
+ array('*', ''),
+ array('* *', ''),
+ array('test', 'test'),
+ array(' test ', 'test'),
+ array(' test * ', 'test'),
+ array('test* *', 'test*'),
+ array('* *test*', '*test*'),
+ array('test test * test', 'test test test'),
+ array(' some wild*cards * between wo*rds ', 'some wild*cards between wo*rds'),
+ array(' we * now have*** multiple wild***cards * ', 'we now have* multiple wild*cards'),
+ array('pi is *** . * **** * *****', 'pi is .'),
+ );
+ }
+
+ /**
+ * @dataProvider phpbb_clean_search_string_data
+ */
+ public function test_phpbb_clean_search_string($search_string, $expected)
+ {
+ $this->assertEquals($expected, phpbb_clean_search_string($search_string));
+ }
+}
diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php
new file mode 100644
index 0000000000..9a7805a819
--- /dev/null
+++ b/tests/functions_user/delete_user_test.php
@@ -0,0 +1,436 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 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/functions_user.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+require_once dirname(__FILE__) . '/../mock/null_cache.php';
+
+class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
+{
+ /** @var \dbal */
+ protected $db;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $cache, $config, $db;
+
+ $db = $this->db = $this->new_dbal();
+ $config = array(
+ 'load_online_time' => 5,
+ 'search_type' => 'fulltext_mysql',
+ );
+ $cache = new phpbb_mock_null_cache();
+ }
+
+ public function first_last_post_data()
+ {
+ return array(
+ array(
+ 'retain', false,
+ array(
+ array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => ''),
+ array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => ''),
+ array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ ),
+ array(
+ array(
+ 'topic_id' => 1,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 2,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 3,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 4,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ ),
+ array(
+ array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ ),
+ ),
+ array(
+ 'remove', false,
+ array(
+ array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ ),
+ array(
+ array(
+ 'topic_id' => 2,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 4,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ ),
+ array(
+ array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ ),
+ ),
+ array(
+ 'retain', 'Bertie',
+ array(
+ array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'),
+ array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'),
+ array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ ),
+ array(
+ array(
+ 'topic_id' => 1,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 2,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 3,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 4,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ ),
+ array(
+ array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Bertie', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Bertie', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ ),
+ ),
+ array(
+ 'remove', 'Bertie',
+ array(
+ array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
+ ),
+ array(
+ array(
+ 'topic_id' => 2,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ array(
+ 'topic_id' => 4,
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
+ ),
+ ),
+ array(
+ array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider first_last_post_data
+ */
+ public function test_first_last_post_info($mode, $post_username, $expected_posts, $expected_topics, $expected_forums)
+ {
+ $this->assertFalse(user_delete($mode, 2, $post_username));
+
+ $sql = 'SELECT post_id, poster_id, post_username
+ FROM ' . POSTS_TABLE . '
+ ORDER BY post_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post table poster info is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT topic_id, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour
+ FROM ' . TOPICS_TABLE . '
+ ORDER BY topic_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic table first/last poster info is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT forum_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour
+ FROM ' . FORUMS_TABLE . '
+ ORDER BY forum_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_forums, $this->db->sql_fetchrowset($result), 'Forum table last poster info is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+ }
+
+ public function report_attachment_data()
+ {
+ return array(
+ array(
+ 'retain',
+ array(
+ array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1),
+ array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1),
+ array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1),
+ array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1),
+ ),
+ array(
+ array('report_id' => 1, 'post_id' => 1, 'user_id' => 1),
+ array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
+ ),
+ array(
+ array('topic_id' => 1, 'topic_reported' => 1),
+ array('topic_id' => 2, 'topic_reported' => 1),
+ array('topic_id' => 3, 'topic_reported' => 0),
+ array('topic_id' => 4, 'topic_reported' => 0),
+ ),
+ array(
+ array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1),
+ array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1),
+ array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 1), // TODO should be deleted: PHPBB3-13089
+ ),
+ ),
+ array(
+ 'remove',
+ array(
+ array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1),
+ array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1),
+ ),
+ array(
+ array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
+ ),
+ array(
+ array('topic_id' => 2, 'topic_reported' => 1),
+ array('topic_id' => 4, 'topic_reported' => 0),
+ ),
+ array(
+ array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1),
+ array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider report_attachment_data
+ */
+ public function test_report_attachment_info($mode, $expected_posts, $expected_reports, $expected_topics, $expected_attach)
+ {
+ $this->assertFalse(user_delete($mode, 2));
+
+ $sql = 'SELECT post_id, post_reported, post_edit_user
+ FROM ' . POSTS_TABLE . '
+ ORDER BY post_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post report status content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT report_id, post_id, user_id
+ FROM ' . REPORTS_TABLE . '
+ ORDER BY report_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_reports, $this->db->sql_fetchrowset($result), 'Report table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT topic_id, topic_reported
+ FROM ' . TOPICS_TABLE . '
+ ORDER BY topic_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic report status is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT attach_id, post_msg_id, poster_id
+ FROM ' . ATTACHMENTS_TABLE . '
+ ORDER BY attach_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_attach, $this->db->sql_fetchrowset($result), 'Attachment table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+ }
+
+ public function delete_data()
+ {
+ return array(
+ array(
+ 'retain',
+ array(array('user_id' => 1, 'user_posts' => 4)),
+ array(array('user_id' => 1, 'zebra_id' => 3)),
+ array(array('ban_id' => 2), array('ban_id' => 3)),
+ array(array('session_id' => '12345678901234567890123456789013')),
+ array(
+ array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1),
+ array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1),
+ ),
+ array(
+ array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3),
+ array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1),
+ ),
+ ),
+ array(
+ 'remove',
+ array(array('user_id' => 1, 'user_posts' => 2)),
+ array(array('user_id' => 1, 'zebra_id' => 3)),
+ array(array('ban_id' => 2), array('ban_id' => 3)),
+ array(array('session_id' => '12345678901234567890123456789013')),
+ array(
+ array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1),
+ array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1),
+ ),
+ array(
+ array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3),
+ array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_data
+ */
+ public function test_delete_data($mode, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms)
+ {
+ $this->assertFalse(user_delete($mode, 2));
+
+ $sql = 'SELECT user_id, user_posts
+ FROM ' . USERS_TABLE . '
+ ORDER BY user_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_users, $this->db->sql_fetchrowset($result), 'User table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT user_id, zebra_id
+ FROM ' . ZEBRA_TABLE . '
+ ORDER BY user_id ASC, zebra_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_zebra, $this->db->sql_fetchrowset($result), 'Zebra table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT ban_id
+ FROM ' . BANLIST_TABLE . '
+ ORDER BY ban_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_ban, $this->db->sql_fetchrowset($result), 'Ban table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT session_id
+ FROM ' . SESSIONS_TABLE . '
+ ORDER BY session_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_sessions, $this->db->sql_fetchrowset($result), 'Session table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT log_id, user_id, reportee_id
+ FROM ' . LOG_TABLE . '
+ ORDER BY log_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_logs, $this->db->sql_fetchrowset($result), 'Log table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT msg_id, author_id, message_edit_user
+ FROM ' . PRIVMSGS_TABLE . '
+ ORDER BY msg_id ASC';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_pms, $this->db->sql_fetchrowset($result), 'Private messages table content is mismatching after deleting a user.');
+ $this->db->sql_freeresult($result);
+ }
+
+ public function delete_user_id_data()
+ {
+ return array(
+ array(
+ 'retain',
+ array(
+ USER_GROUP_TABLE,
+ TOPICS_WATCH_TABLE,
+ FORUMS_WATCH_TABLE,
+ ACL_USERS_TABLE,
+ TOPICS_TRACK_TABLE,
+ TOPICS_POSTED_TABLE,
+ FORUMS_TRACK_TABLE,
+ PROFILE_FIELDS_DATA_TABLE,
+ MODERATOR_CACHE_TABLE,
+ DRAFTS_TABLE,
+ BOOKMARKS_TABLE,
+ SESSIONS_KEYS_TABLE,
+ PRIVMSGS_FOLDER_TABLE,
+ PRIVMSGS_RULES_TABLE,
+ ),
+ ),
+ array(
+ 'remove',
+ array(
+ USER_GROUP_TABLE,
+ TOPICS_WATCH_TABLE,
+ FORUMS_WATCH_TABLE,
+ ACL_USERS_TABLE,
+ TOPICS_TRACK_TABLE,
+ TOPICS_POSTED_TABLE,
+ FORUMS_TRACK_TABLE,
+ PROFILE_FIELDS_DATA_TABLE,
+ MODERATOR_CACHE_TABLE,
+ DRAFTS_TABLE,
+ BOOKMARKS_TABLE,
+ SESSIONS_KEYS_TABLE,
+ PRIVMSGS_FOLDER_TABLE,
+ PRIVMSGS_RULES_TABLE,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_user_id_data
+ */
+ public function test_delete_user_id_data($mode, $cleaned_tables)
+ {
+ $this->assertFalse(user_delete($mode, 2));
+
+ foreach ($cleaned_tables as $table)
+ {
+ $sql = 'SELECT user_id
+ FROM ' . $table . '
+ WHERE user_id = 2';
+ $result = $this->db->sql_query($sql);
+ $this->assertFalse($this->db->sql_fetchfield('user_id'), 'Found data for deleted user in table: ' . $table);
+ $this->db->sql_freeresult($result);
+
+ $sql = 'SELECT user_id
+ FROM ' . $table . '
+ WHERE user_id = 3';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals(3, $this->db->sql_fetchfield('user_id'), 'Missing data for user in table: ' . $table);
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml
new file mode 100644
index 0000000000..07591389d2
--- /dev/null
+++ b/tests/functions_user/fixtures/delete_user.xml
@@ -0,0 +1,531 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_attachments">
+ <column>attach_id</column>
+ <column>post_msg_id</column>
+ <column>topic_id</column>
+ <column>in_message</column>
+ <column>poster_id</column>
+ <column>is_orphan</column>
+ <column>attach_comment</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>2</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_banlist">
+ <column>ban_id</column>
+ <column>ban_userid</column>
+ <column>ban_email</column>
+ <column>ban_reason</column>
+ <column>ban_give_reason</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_forums">
+ <column>forum_id</column>
+ <column>forum_last_poster_id</column>
+ <column>forum_last_poster_name</column>
+ <column>forum_last_poster_colour</column>
+ <column>forum_parents</column>
+ <column>forum_desc</column>
+ <column>forum_rules</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_log">
+ <column>log_id</column>
+ <column>user_id</column>
+ <column>reportee_id</column>
+ <column>log_operation</column>
+ <column>log_data</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>post_edit_user</column>
+ <column>post_username</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_approved</column>
+ <column>post_time</column>
+ <column>post_text</column>
+ <column>post_reported</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs">
+ <column>msg_id</column>
+ <column>author_id</column>
+ <column>message_edit_user</column>
+ <column>message_text</column>
+ <column>to_address</column>
+ <column>bcc_address</column>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs_to">
+ <column>msg_id</column>
+ <column>user_id</column>
+ <column>author_id</column>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>3</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>3</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>3</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_reports">
+ <column>report_id</column>
+ <column>post_id</column>
+ <column>user_id</column>
+ <column>report_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Post Removed?</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>3</value>
+ <value>2</value>
+ <value>Post Removed?</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>1</value>
+ <value>Keep</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>2</value>
+ <value>Remove Report</value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_page</column>
+ <row>
+ <value>12345678901234567890123456789012</value>
+ <value>2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>12345678901234567890123456789013</value>
+ <value>3</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_reported</column>
+ <column>topic_poster</column>
+ <column>topic_first_poster_name</column>
+ <column>topic_first_poster_colour</column>
+ <column>topic_last_poster_id</column>
+ <column>topic_last_poster_name</column>
+ <column>topic_last_poster_colour</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ <value>2</value>
+ <value></value>
+ <value>00AA00</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ <value>1</value>
+ <value>Other</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <column>user_posts</column>
+ <row>
+ <value>1</value>
+ <value>Anonymous</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>Foobar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_zebra">
+ <column>user_id</column>
+ <column>zebra_id</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_user_group">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_topics_watch">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_forums_watch">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_acl_users">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_topics_track">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_forums_track">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_topics_posted">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_profile_fields_data">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_moderator_cache">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_bookmarks">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_sessions_keys">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs_folder">
+ <column>user_id</column>
+ <row>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs_rules">
+ <column>user_id</column>
+ <column>rule_string</column>
+ <row>
+ <value>2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_drafts">
+ <column>user_id</column>
+ <column>draft_message</column>
+ <row>
+ <value>2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/lint_test.php b/tests/lint_test.php
index 905067072d..b0149063bd 100644
--- a/tests/lint_test.php
+++ b/tests/lint_test.php
@@ -9,20 +9,37 @@
class phpbb_lint_test extends phpbb_test_case
{
+ static protected $php_binary;
static protected $exclude;
static public function setUpBeforeClass()
{
+ // Try to use PHP_BINARY constant if available so lint tests are run
+ // using the same php binary as phpunit. If not available (pre PHP
+ // 5.4), assume binary is called 'php' and is in PATH.
+ self::$php_binary = defined('PHP_BINARY') ? escapeshellcmd(PHP_BINARY) : 'php';
+
$output = array();
$status = 1;
- exec('(php -v) 2>&1', $output, $status);
+ exec(sprintf('(%s --version) 2>&1', self::$php_binary), $output, $status);
if ($status)
{
$output = implode("\n", $output);
- self::markTestSkipped("php is not in PATH or broken: $output");
+ if (self::$php_binary === 'php')
+ {
+ self::markTestSkipped(sprintf('php is not in PATH or broken. Output: %s', $output));
+ }
+ else
+ {
+ self::markTestSkipped(sprintf('Could not run PHP_BINARY %s. Output: %s', self::$php_binary, $output));
+ }
}
self::$exclude = array(
+ dirname(__FILE__) . '/../.git',
+ dirname(__FILE__) . '/../build/new_version',
+ dirname(__FILE__) . '/../build/old_versions',
+ dirname(__FILE__) . '/../phpBB/cache',
// PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20
// https://gist.github.com/e003913ffd493da63cbc
dirname(__FILE__) . '/../phpBB/vendor',
@@ -45,7 +62,7 @@ class phpbb_lint_test extends phpbb_test_case
$dh = opendir($root);
while (($filename = readdir($dh)) !== false)
{
- if ($filename == '.' || $filename == '..' || $filename == 'git')
+ if ($filename == '.' || $filename == '..')
{
continue;
}
@@ -61,13 +78,12 @@ class phpbb_lint_test extends phpbb_test_case
}
else if (substr($filename, strlen($filename)-4) == '.php')
{
- // assume php binary is called php and it is in PATH
- $cmd = '(php -l ' . escapeshellarg($path) . ') 2>&1';
+ $cmd = sprintf('(%s -l %s) 2>&1', self::$php_binary, escapeshellarg($path));
$output = array();
$status = 1;
exec($cmd, $output, $status);
$output = implode("\n", $output);
- $this->assertEquals(0, $status, "php -l failed for $path:\n$output");
+ $this->assertEquals(0, $status, "PHP lint failed for $path:\n$output");
}
}
}
diff --git a/tests/profile/get_profile_value_test.php b/tests/profile/get_profile_value_test.php
new file mode 100644
index 0000000000..a5f37a85ce
--- /dev/null
+++ b/tests/profile/get_profile_value_test.php
@@ -0,0 +1,42 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_profile_fields.php';
+
+class phpbb_profile_get_profile_value_test extends phpbb_test_case
+{
+ static public function get_profile_value_int_data()
+ {
+ return array(
+ array(FIELD_INT, '10', true, 10),
+ array(FIELD_INT, '0', true, 0),
+ array(FIELD_INT, '', true, 0),
+ array(FIELD_INT, null, true, 0),
+ array(FIELD_INT, '10', false, 10),
+ array(FIELD_INT, '0', false, 0),
+ array(FIELD_INT, '', false, null),
+ array(FIELD_INT, null, false, null),
+ );
+ }
+
+ /**
+ * @dataProvider get_profile_value_int_data
+ */
+ public function test_get_profile_value_int($type, $value, $show_novalue, $expected)
+ {
+ $cp = new custom_profile;
+ $this->assertSame($expected, $cp->get_profile_value(array(
+ 'value' => $value,
+ 'data' => array(
+ 'field_type' => $type,
+ 'field_show_novalue' => $show_novalue,
+ ),
+ )));
+ }
+}
diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php
index 872a331dc7..9a24ba5d65 100644
--- a/tests/security/redirect_test.php
+++ b/tests/security/redirect_test.php
@@ -18,12 +18,17 @@ class phpbb_security_redirect_test extends phpbb_security_test_base
{
// array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
return array(
- array('data://x', false, 'http://localhost/phpBB'),
+ array('data://x', 'Tried to redirect to potentially insecure url.', false),
array('bad://localhost/phpBB/index.php', 'Tried to redirect to potentially insecure url.', false),
- array('http://www.otherdomain.com/somescript.php', false, 'http://localhost/phpBB'),
+ array('http://www.otherdomain.com/somescript.php', 'Tried to redirect to potentially insecure url.', false),
array("http://localhost/phpBB/memberlist.php\n\rConnection: close", 'Tried to redirect to potentially insecure url.', false),
array('javascript:test', false, 'http://localhost/phpBB/../javascript:test'),
array('http://localhost/phpBB/index.php;url=', 'Tried to redirect to potentially insecure url.', false),
+ array('https://foobar.com\@http://localhost/phpBB', 'Tried to redirect to potentially insecure url.', false),
+ array('https://foobar.com\@localhost/troll/http://localhost/', 'Tried to redirect to potentially insecure url.', false),
+ array('http://localhost.foobar.com\@localhost/troll/http://localhost/', 'Tried to redirect to potentially insecure url.', false),
+ array('http://localhost/phpBB', false, 'http://localhost/phpBB'),
+ array('http://localhost/phpBB/', false, 'http://localhost/phpBB/'),
);
}
diff --git a/tests/security/trailing_path_test.php b/tests/security/trailing_path_test.php
new file mode 100644
index 0000000000..9d586e74ef
--- /dev/null
+++ b/tests/security/trailing_path_test.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2011 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/startup.php';
+
+class phpbb_security_trailing_path_test extends phpbb_test_case
+{
+ public function data_has_trailing_path()
+ {
+ return array(
+ array(false, '', '', ''),
+ array(true, '/', '', ''),
+ array(true, '/foo', '', ''),
+ array(true, '', '/foo', ''),
+ array(true, '/foo', '/foo', ''),
+ array(false, '', '', '/'),
+ array(false, '', '', '/?/x.php/'),
+ array(false, '', '', '/index.php'),
+ array(false, '', '', '/dir.phpisfunny/foo.php'),
+ array(true, '', '', '/index.php/foo.php'),
+ array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5'),
+ array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5/'),
+ array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5/foo'),
+ array(true, '/foo', '/foo', '/phpBB/viewtopic.php?f=3&amp;t=5/foo'),
+ array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5/'),
+ array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5'),
+ array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5/foo.php/'),
+ array(false, '', '', '/projects/php.bb/phpBB/index.php'),
+ array(true, '', '', '/projects/php.bb/phpBB/index.php/'),
+ array(true, '', '', '/phpBB/index.php/?foo/a'),
+ array(true, '', '', '/projects/php.bb/phpBB/index.php/?a=5'),
+ array(false, '', '', '/projects/php.bb/phpBB/index.php?/a=5'),
+ array(false, '', '/phpBB/index.php', '/phpBB/index.php', '/phpBB/index.php'),
+ array(true, '', '/phpBB/index.php', '/phpBB/index.php'),
+ array(true, '', '/phpBB/index.php/', '/phpBB/index.php/', '/phpBB/index.php'),
+ array(true, '', '/phpBB/index.php/', '/phpBB/index.php/'),
+ );
+ }
+
+ /**
+ * @dataProvider data_has_trailing_path
+ */
+ public function test_has_trailing_path($expected, $path_info, $orig_path_info, $request_uri, $script_name = '')
+ {
+ global $phpEx;
+
+ $_SERVER['PATH_INFO'] = $path_info;
+ $_SERVER['ORIG_PATH_INFO'] = $orig_path_info;
+ $_SERVER['REQUEST_URI'] = $request_uri;
+ $_SERVER['SCRIPT_NAME'] = $script_name;
+
+ $this->assertSame($expected, phpbb_has_trailing_path($phpEx));
+ }
+}
diff --git a/tests/session/fixtures/sessions_empty.xml b/tests/session/fixtures/sessions_empty.xml
index 0e6ddccd88..c592e0a6c8 100644
--- a/tests/session/fixtures/sessions_empty.xml
+++ b/tests/session/fixtures/sessions_empty.xml
@@ -38,4 +38,11 @@
<column>session_ip</column>
<column>session_browser</column>
</table>
+ <table name="phpbb_banlist">
+ <column>ban_id</column>
+ <column>ban_userid</column>
+ <column>ban_email</column>
+ <column>ban_reason</column>
+ <column>ban_give_reason</column>
+ </table>
</dataset>
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 7d8b4a3144..9b64600c7d 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -423,6 +423,15 @@ class phpbb_functional_test_case extends phpbb_test_case
$config = array();
}
+ /*
+ * Add required config entries to the config array to prevent
+ * set_config() sending an INSERT query for already existing entries,
+ * resulting in a SQL error.
+ * This is because set_config() first sends an UPDATE query, then checks
+ * sql_affectedrows() which can be 0 (e.g. on MySQL) when the new
+ * data is already there.
+ */
+ $config['newest_user_colour'] = '';
$config['rand_seed'] = '';
$config['rand_seed_last_update'] = time() + 600;
@@ -577,6 +586,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// Any output before the doc type means there was an error
$content = self::$client->getResponse()->getContent();
+ self::assertNotContains('[phpBB Debug]', $content);
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
}
@@ -591,7 +601,7 @@ class phpbb_functional_test_case extends phpbb_test_case
*/
static public function assert_response_status_code($status_code = 200)
{
- self::assertEquals($status_code, self::$client->getResponse()->getStatus());
+ self::assertEquals($status_code, self::$client->getResponse()->getStatus(), 'HTTP status code does not match');
}
/**
@@ -655,12 +665,70 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->add_lang('posting');
+ $crawler = $this->submit_message($posting_url, $posting_contains, $form_data);
+
+ $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+ $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
+
+ return array(
+ 'topic_id' => $this->get_parameter_from_link($url, 't'),
+ 'post_id' => $this->get_parameter_from_link($url, 'p'),
+ );
+ }
+
+ /**
+ * Creates a private message
+ *
+ * Be sure to login before creating
+ *
+ * @param string $subject
+ * @param string $message
+ * @param array $to
+ * @param array $additional_form_data Any additional form data to be sent in the request
+ * @return int private_message_id
+ */
+ public function create_private_message($subject, $message, $to, $additional_form_data = array())
+ {
+ $this->add_lang(array('ucp', 'posting'));
+
+ $posting_url = "ucp.php?i=pm&mode=compose&sid={$this->sid}";
+
+ $form_data = array_merge(array(
+ 'subject' => $subject,
+ 'message' => $message,
+ 'post' => true,
+ ), $additional_form_data);
+
+ foreach ($to as $user_id)
+ {
+ $form_data['address_list[u][' . $user_id . ']'] = 'to';
+ }
+
+ $crawler = self::submit_message($posting_url, 'POST_NEW_PM', $form_data);
+
+ $this->assertContains($this->lang('MESSAGE_STORED'), $crawler->filter('html')->text());
+ $url = $crawler->selectLink($this->lang('VIEW_PRIVATE_MESSAGE', '', ''))->link()->getUri();
+
+ return $this->get_parameter_from_link($url, 'p');
+ }
+
+ /**
+ * Helper for submitting a message (post or private message)
+ *
+ * @param string $posting_url
+ * @param string $posting_contains
+ * @param array $form_data
+ * @return \Symfony\Component\DomCrawler\Crawler the crawler object
+ */
+ protected function submit_message($posting_url, $posting_contains, $form_data)
+ {
+
$crawler = self::request('GET', $posting_url);
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
$hidden_fields = array(
$crawler->filter('[type="hidden"]')->each(function ($node, $i) {
- return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ return array('name' => $node->attr('name'), 'value' => $node->attr('value'));
}),
);
@@ -679,14 +747,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// I use a request because the form submission method does not allow you to send data that is not
// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
// Instead, I send it as a request with the submit button "post" set to true.
- $crawler = self::request('POST', $posting_url, $form_data);
- $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
- $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
-
- return array(
- 'topic_id' => $this->get_parameter_from_link($url, 't'),
- 'post_id' => $this->get_parameter_from_link($url, 'p'),
- );
+ return self::request('POST', $posting_url, $form_data);
}
/**
diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php
new file mode 100644
index 0000000000..a157fe7d9a
--- /dev/null
+++ b/tests/text_processing/generate_text_for_display_test.php
@@ -0,0 +1,38 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 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/functions_content.php';
+require_once dirname(__FILE__) . '/../mock/user.php';
+require_once dirname(__FILE__) . '/../mock/cache.php';
+
+class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ global $cache, $user;
+
+ parent::setUp();
+
+ $cache = new phpbb_mock_cache;
+
+ $user = new phpbb_mock_user;
+ $user->optionset('viewcensors', false);
+ }
+
+ public function test_empty_string()
+ {
+ $this->assertSame('', generate_text_for_display('', '', '', 0));
+ }
+
+ public function test_zero_string()
+ {
+ $this->assertSame('0', generate_text_for_display('0', '', '', 0));
+ }
+}