aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/avatar/manager_test.php20
-rw-r--r--tests/bbcode/parser_test.php2
-rw-r--r--tests/cache/null_driver_test.php6
-rw-r--r--tests/class_loader/class_loader_test.php2
-rw-r--r--tests/controller/controller_test.php7
-rw-r--r--tests/controller/ext/vendor2/foo/subfolder/config/routing.yml3
-rw-r--r--tests/controller/helper_route_test.php28
-rw-r--r--tests/cron/manager_test.php2
-rw-r--r--tests/dbal/migration/revert.php8
-rw-r--r--tests/dbal/migrator_test.php6
-rw-r--r--tests/event/export_php_test.php45
-rw-r--r--tests/event/fixtures/default.test9
-rw-r--r--tests/event/fixtures/duplicate_event.test19
-rw-r--r--tests/event/fixtures/extra_description.test11
-rw-r--r--tests/event/fixtures/missing_var.test17
-rw-r--r--tests/event/fixtures/none.test6
-rw-r--r--tests/event/fixtures/trigger.test15
-rw-r--r--tests/event/fixtures/trigger_many_vars.test65
-rw-r--r--tests/event/md_exporter_test.php67
-rw-r--r--tests/event/php_exporter_test.php722
-rw-r--r--tests/functional/feed_test.php1490
-rw-r--r--tests/functional/jumpbox_test.php33
-rw-r--r--tests/functional/ucp_allow_pm_test.php70
-rw-r--r--tests/functional/visibility_disapprove_test.php (renamed from tests/functional/disapprove_test.php)2
-rw-r--r--tests/functional/visibility_reapprove_test.php416
-rw-r--r--tests/functional/visibility_softdelete_test.php (renamed from tests/functional/softdelete_test.php)4
-rw-r--r--tests/functions/build_url_test.php82
-rw-r--r--tests/functions/fixtures/banned_users.xml38
-rw-r--r--tests/functions/phpbb_get_banned_user_ids.php58
-rw-r--r--tests/functions/validate_with_method_test.php39
-rw-r--r--tests/log/fixtures/full_log.xml12
-rw-r--r--tests/log/function_view_log_test.php27
-rw-r--r--tests/migrator/convert_timezones_test.php94
-rw-r--r--tests/migrator/fixtures/convert_timezones.xml66
-rw-r--r--tests/mimetype/guesser_test.php41
-rw-r--r--tests/mock/controller_helper.php22
-rw-r--r--tests/mock/session_testable.php2
-rw-r--r--tests/notification/submit_post_type_quote_test.php3
-rw-r--r--tests/pagination/pagination_test.php8
-rw-r--r--tests/passwords/drivers_test.php2
-rw-r--r--tests/passwords/manager_test.php6
-rw-r--r--tests/path_helper/path_helper_test.php (renamed from tests/path_helper/web_root_path_test.php)153
-rw-r--r--tests/session/fixtures/sessions_key.xml1
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html4
-rw-r--r--tests/template/template_events_test.php1
-rw-r--r--tests/template/template_test.php1
-rw-r--r--tests/template/templates/loop_nested_include1.html4
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php22
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php14
49 files changed, 3721 insertions, 54 deletions
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index 527bb223d5..69d4280b9a 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -9,29 +9,33 @@
require_once dirname(__FILE__) . '/driver/foobar.php';
-class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
+class phpbb_avatar_manager_test extends \phpbb_test_case
{
+ /** @var \phpbb\avatar\manager */
+ protected $manager;
+ protected $avatar_foobar;
+ protected $avatar_barfoo;
+
public function setUp()
{
global $phpbb_root_path, $phpEx;
// Mock phpbb_container
- $this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $this->phpbb_container->expects($this->any())
+ $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $phpbb_container->expects($this->any())
->method('get')
->will($this->returnArgument(0));
// Prepare dependencies for avatar manager and driver
$config = new \phpbb\config\config(array());
- $request = $this->getMock('\phpbb\request\request');
$cache = $this->getMock('\phpbb\cache\driver\driver_interface');
$path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
new phpbb_mock_request()
),
new \phpbb\filesystem(),
- $this->phpbb_root_path,
- $this->phpEx
+ $phpbb_root_path,
+ $phpEx
);
// $this->avatar_foobar will be needed later on
@@ -60,7 +64,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;
// Set up avatar manager
- $this->manager = new \phpbb\avatar\manager($config, $avatar_drivers, $this->phpbb_container);
+ $this->manager = new \phpbb\avatar\manager($config, $avatar_drivers, $phpbb_container);
}
protected function avatar_drivers()
@@ -222,8 +226,6 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
*/
public function test_clean_row(array $input, array $output, $prefix = '')
{
- $cleaned_row = array();
-
$cleaned_row = \phpbb\avatar\manager::clean_row($input, $prefix);
foreach ($output as $key => $value)
{
diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php
index d0dcce5bbf..4bf5037f45 100644
--- a/tests/bbcode/parser_test.php
+++ b/tests/bbcode/parser_test.php
@@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
-class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase
+class phpbb_bbcode_parser_test extends \phpbb_test_case
{
public function bbcode_firstpass_data()
{
diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php
index 58e57f2b3a..049d0412b6 100644
--- a/tests/cache/null_driver_test.php
+++ b/tests/cache/null_driver_test.php
@@ -35,14 +35,12 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case
public function test_purge()
{
- // does nothing
- $this->driver->purge();
+ $this->assertNull($this->driver->purge());
}
public function test_destroy()
{
- // does nothing
- $this->driver->destroy('foo');
+ $this->assertNull($this->driver->destroy('foo'));
}
public function test_cache_sql()
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
index 6e551f658a..d3c7bb0579 100644
--- a/tests/class_loader/class_loader_test.php
+++ b/tests/class_loader/class_loader_test.php
@@ -7,7 +7,7 @@
*
*/
-class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
+class phpbb_class_loader_test extends \phpbb_test_case
{
public function setUp()
{
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
index 550679ff07..7b8b78dd22 100644
--- a/tests/controller/controller_test.php
+++ b/tests/controller/controller_test.php
@@ -8,8 +8,6 @@
*/
use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\Route;
-use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -31,7 +29,8 @@ class phpbb_controller_controller_test extends phpbb_test_case
public function test_provider()
{
- $provider = new \phpbb\controller\provider($this->extension_manager->get_finder());
+ $provider = new \phpbb\controller\provider();
+ $provider->find_routing_files($this->extension_manager->get_finder());
$routes = $provider->find(__DIR__)->get_routes();
// This will need to be updated if any new routes are defined
@@ -43,6 +42,8 @@ class phpbb_controller_controller_test extends phpbb_test_case
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2'));
$this->assertEquals('/foo/bar', $routes->get('controller2')->getPath());
+
+ $this->assertNull($routes->get('controller_noroute'));
}
public function test_controller_resolver()
diff --git a/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml b/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml
new file mode 100644
index 0000000000..b4d8d19107
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml
@@ -0,0 +1,3 @@
+controller_noroute:
+ pattern: /donotfindthis
+ defaults: { _controller: foo.controller:handle }
diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php
index 5264c788c7..ae6f924a62 100644
--- a/tests/controller/helper_route_test.php
+++ b/tests/controller/helper_route_test.php
@@ -27,23 +27,25 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
);
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context());
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ )
+ );
$finder = new \phpbb\extension\finder(
- new phpbb_mock_extension_manager(
- dirname(__FILE__) . '/',
- array(
- 'vendor2/foo' => array(
- 'ext_name' => 'vendor2/foo',
- 'ext_active' => '1',
- 'ext_path' => 'ext/vendor2/foo/',
- ),
- )
- ),
+ $this->extension_manager,
new \phpbb\filesystem(),
dirname(__FILE__) . '/',
new phpbb_mock_cache()
);
- $this->provider = new \phpbb\controller\provider($finder);
+ $this->provider = new \phpbb\controller\provider();
+ $this->provider->find_routing_files($finder);
$this->provider->find(dirname(__FILE__) . '/');
}
@@ -82,7 +84,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
*/
public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
- $this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, $this->provider, '', 'php');
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, '', 'php', dirname(__FILE__) . '/');
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id));
}
@@ -122,7 +124,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
{
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, $this->provider, '', 'php');
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, '', 'php', dirname(__FILE__) . '/');
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id));
}
}
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 713f44c1e2..937add252f 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/tasks/simple_ready.php';
require_once dirname(__FILE__) . '/tasks/simple_not_runnable.php';
require_once dirname(__FILE__) . '/tasks/simple_should_not_run.php';
-class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
+class phpbb_cron_manager_test extends \phpbb_test_case
{
public function setUp()
{
diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php
index c2520f4d8a..1c98710ffb 100644
--- a/tests/dbal/migration/revert.php
+++ b/tests/dbal/migration/revert.php
@@ -35,6 +35,14 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration
{
return array(
array('config.add', array('foobartest', 0)),
+ array('custom', array(array(&$this, 'my_custom_function'))),
);
}
+
+ function my_custom_function()
+ {
+ global $migrator_test_revert_counter;
+
+ $migrator_test_revert_counter += 1;
+ }
}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index c18c49b2a0..cc3e92071f 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -174,10 +174,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
public function test_revert()
{
+ global $migrator_test_revert_counter;
+
// Make sure there are no other migrations in the db, this could cause issues
$this->db->sql_query("DELETE FROM phpbb_migrations");
$this->migrator->load_migration_state();
+ $migrator_test_revert_counter = 0;
+
$this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency'));
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
@@ -219,6 +223,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
$this->fail('Revert did not remove test_column.');
}
+
+ $this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again');
}
public function test_fail()
diff --git a/tests/event/export_php_test.php b/tests/event/export_php_test.php
new file mode 100644
index 0000000000..f38b524ffe
--- /dev/null
+++ b/tests/event/export_php_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
+*
+*/
+
+class phpbb_event_export_php_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path;
+ $this->exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ }
+
+ static public function crawl_php_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ $files = $exporter->get_recursive_file_list($phpbb_root_path);
+
+ $data_provider = array();
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($file);
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file)
+ {
+ $this->assertGreaterThanOrEqual(0, $this->exporter->crawl_php_file($file));
+ }
+}
diff --git a/tests/event/fixtures/default.test b/tests/event/fixtures/default.test
new file mode 100644
index 0000000000..edfe4823dc
--- /dev/null
+++ b/tests/event/fixtures/default.test
@@ -0,0 +1,9 @@
+<?php
+
+/**
+* Description
+*
+* @event default.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('default.dispatch');
diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test
new file mode 100644
index 0000000000..b042ca0377
--- /dev/null
+++ b/tests/event/fixtures/duplicate_event.test
@@ -0,0 +1,19 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @var int start Start item of this page
+ * @since 3.1.0-a3
+ */
+ $vars = array('start');
+ extract($phpbb_dispatcher->trigger_event('duplicate.trigger', compact($vars)));
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @since 3.1.0-b1
+ */
+ $phpbb_dispatcher->dispatch('duplicate.trigger');
diff --git a/tests/event/fixtures/extra_description.test b/tests/event/fixtures/extra_description.test
new file mode 100644
index 0000000000..ce8f97ce89
--- /dev/null
+++ b/tests/event/fixtures/extra_description.test
@@ -0,0 +1,11 @@
+<?php
+
+/**
+* Description
+*
+* NOTE: This will not be exported
+*
+* @event extra_description.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('extra_description.dispatch');
diff --git a/tests/event/fixtures/missing_var.test b/tests/event/fixtures/missing_var.test
new file mode 100644
index 0000000000..7ced5e93dc
--- /dev/null
+++ b/tests/event/fixtures/missing_var.test
@@ -0,0 +1,17 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @var array attachments List of attachments
+ * @var array user_poster_data Poster's data from user cache
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/none.test b/tests/event/fixtures/none.test
new file mode 100644
index 0000000000..6e2267024b
--- /dev/null
+++ b/tests/event/fixtures/none.test
@@ -0,0 +1,6 @@
+<?php
+
+/**
+* Hi there :)
+*/
+echo 1 + 2;
diff --git a/tests/event/fixtures/trigger.test b/tests/event/fixtures/trigger.test
new file mode 100644
index 0000000000..7cd6a7b956
--- /dev/null
+++ b/tests/event/fixtures/trigger.test
@@ -0,0 +1,15 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test
new file mode 100644
index 0000000000..a624138588
--- /dev/null
+++ b/tests/event/fixtures/trigger_many_vars.test
@@ -0,0 +1,65 @@
+<?php
+
+ /**
+ * This event allows you to modify template variables for the posting screen
+ *
+ * @event core.posting_modify_template_vars
+ * @var array post_data Array with post data
+ * @var array moderators Array with forum moderators
+ * @var string mode What action to take if the form is submitted
+ * post|reply|quote|edit|delete|bump|smilies|popup
+ * @var string page_title Title of the mode page
+ * @var bool s_topic_icons Whether or not to show the topic icons
+ * @var string form_enctype If attachments are allowed for this form
+ * "multipart/form-data" or empty string
+ * @var string s_action The URL to submit the POST data to
+ * @var string s_hidden_fields Concatenated hidden input tags of posting form
+ * @var int post_id ID of the post
+ * @var int topic_id ID of the topic
+ * @var int forum_id ID of the forum
+ * @var bool submit Whether or not the form has been submitted
+ * @var bool preview Whether or not the post is being previewed
+ * @var bool save Whether or not a draft is being saved
+ * @var bool load Whether or not a draft is being loaded
+ * @var bool delete Whether or not the post is being deleted
+ * @var bool cancel Whether or not to cancel the form (returns to
+ * viewtopic or viewforum depending on if the user
+ * is posting a new topic or editing a post)
+ * @var array error Any error strings; a non-empty array aborts
+ * form submission.
+ * NOTE: Should be actual language strings, NOT
+ * language keys.
+ * @var bool refresh Whether or not to retain previously submitted data
+ * @var array page_data Posting page data that should be passed to the
+ * posting page via $template->assign_vars()
+ * @var object message_parser The message parser object
+ * @since 3.1.0-a1
+ * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title,
+ * s_topic_icons, form_enctype, s_action, s_hidden_fields,
+ * post_id, topic_id, forum_id, submit, preview, save, load,
+ * delete, cancel, refresh, error, page_data, message_parser
+ */
+ $vars = array(
+ 'post_data',
+ 'moderators',
+ 'mode',
+ 'page_title',
+ 's_topic_icons',
+ 'form_enctype',
+ 's_action',
+ 's_hidden_fields',
+ 'post_id',
+ 'topic_id',
+ 'forum_id',
+ 'submit',
+ 'preview',
+ 'save',
+ 'load',
+ 'delete',
+ 'cancel',
+ 'refresh',
+ 'error',
+ 'page_data',
+ 'message_parser',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php
new file mode 100644
index 0000000000..b62b55accd
--- /dev/null
+++ b/tests/event/md_exporter_test.php
@@ -0,0 +1,67 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_event_md_exporter_test extends phpbb_test_case
+{
+
+ static public function crawl_eventsmd_data()
+ {
+ return array(
+ array('styles'),
+ array('adm'),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_eventsmd_data
+ */
+ public function test_crawl_eventsmd($filter)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter));
+ }
+
+ static public function crawl_template_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $data_provider = array();
+
+ $styles = array(
+ 'adm/style/' => 'adm',
+ 'styles/prosilver/template/' => 'styles',
+ 'styles/subsilver2/template/' => 'styles',
+ );
+ foreach ($styles as $path => $filter)
+ {
+ $files = $exporter->get_recursive_file_list($phpbb_root_path . $path, $path);
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($filter, $path . $file);
+ }
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_template_file_data
+ */
+ public function test_crawl_template_file($filter, $file)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $exporter->crawl_eventsmd('docs/events.md', $filter);
+ $events = $exporter->crawl_file_for_events($file);
+
+ $this->assertGreaterThanOrEqual(0, sizeof($events));
+ $this->assertTrue($exporter->validate_events_from_file($file, $events));
+ }
+}
diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php
new file mode 100644
index 0000000000..9917f8309b
--- /dev/null
+++ b/tests/event/php_exporter_test.php
@@ -0,0 +1,722 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_event_php_exporter_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/');
+ }
+
+ static public function crawl_php_file_data()
+ {
+ return array(
+ array(
+ 'default.test',
+ array(
+ 'default.dispatch' => array(
+ 'event' => 'default.dispatch',
+ 'file' => 'default.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'extra_description.test',
+ array(
+ 'extra_description.dispatch' => array(
+ 'event' => 'extra_description.dispatch',
+ 'file' => 'extra_description.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'trigger.test',
+ array(
+ 'core.trigger' => array(
+ 'event' => 'core.trigger',
+ 'file' => 'trigger.test',
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
+ 'since' => '3.1.0-a3',
+ 'description' => 'Event after the post data has been assigned to the template',
+ ),
+ ),
+ ),
+ array(
+ 'trigger_many_vars.test',
+ array(
+ 'core.posting_modify_template_vars' => array(
+ 'event' => 'core.posting_modify_template_vars',
+ 'file' => 'trigger_many_vars.test',
+ 'arguments' => array(
+ 'cancel', 'delete', 'error', 'form_enctype', 'forum_id',
+ 'load', 'message_parser', 'mode', 'moderators', 'page_data',
+ 'page_title', 'post_data', 'post_id', 'preview', 'refresh',
+ 's_action', 's_hidden_fields', 's_topic_icons', 'save',
+ 'submit', 'topic_id',
+ ),
+ 'since' => '3.1.0-a1',
+ 'description' => 'This event allows you to modify template variables for the posting screen',
+ ),
+ ),
+ ),
+ array(
+ 'none.test',
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file, $expected)
+ {
+ $this->exporter->crawl_php_file($file);
+ $this->assertEquals($expected, $this->exporter->get_events());
+ }
+
+ static public function crawl_php_file_throws_data()
+ {
+ return array(
+ array('missing_var.test', null),
+ array('duplicate_event.test', 10),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_throws_data
+ */
+ public function test_crawl_php_file_throws($file, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->crawl_php_file($file);
+ }
+
+ static public function validate_since_data()
+ {
+ return array(
+ array('* @since 3.1.0-a1', '3.1.0-a1'),
+ array('* @since 3.1.0-b3', '3.1.0-b3'),
+ array(' * @since 3.1.0-b3', '3.1.0-b3'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_data
+ */
+ public function test_validate_since($since, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_since($since));
+ }
+
+ static public function validate_since_throws_data()
+ {
+ return array(
+ array(' * @since 3.1.0-a1'),
+ array('* @since 3.1.0-a1 '),
+ array('* @since 3.1.0-a1 bertie is cool'),
+ array('bertie* @since 3.1.0-a1'),
+ array('* @since 3.1-A2'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_since_throws($since)
+ {
+ $this->exporter->validate_since($since);
+ }
+
+ static public function validate_event_data()
+ {
+ return array(
+ array('test.event', '* @event test.event', 'test.event'),
+ array('test.event2', ' * @event test.event2', 'test.event2'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_data
+ */
+ public function test_validate_event($event_name, $event, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_event($event_name, $event));
+ }
+
+ static public function validate_event_throws_data()
+ {
+ return array(
+ array('test.event', ' * @event test.event', 1),
+ array('test.event', '* @event test.event bertie is cool', 2),
+ array('test.event', 'bertie* @event test.event', 2),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_event_throws($event_name, $event, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->validate_event($event_name, $event);
+ }
+
+ static public function validate_vars_docblock_array_data()
+ {
+ return array(
+ array(array('abc', 'def'), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_data
+ */
+ public function test_validate_vars_docblock_array($vars_array, $vars_docblock)
+ {
+ $this->assertNull($this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock));
+ }
+
+ static public function validate_vars_docblock_array_throws_data()
+ {
+ return array(
+ array(array('abc', 'def'), array()),
+ array(array('abc', 'def'), array('abc')),
+ array(array('abc', 'defg'), array('abc', 'def')),
+ array(array('abc'), array('abc', 'def')),
+ array(array(), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock)
+ {
+ $this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock);
+ }
+
+ static public function get_dispatch_name_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'),
+ array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_data
+ */
+ public function test_get_dispatch_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, true));
+ }
+
+ static public function get_dispatch_name_throws_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch();"),
+ array("\$phpbb_dispatcher->dispatch('');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch.2one');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch');"),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_dispatch_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, true);
+ }
+
+ static public function get_trigger_event_name_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'),
+ array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_data
+ */
+ public function test_get_trigger_event_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, false));
+ }
+
+ static public function get_trigger_event_name_throws_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event());"),
+ array("extract(\$phpbb_dispatcher->trigger_event(''));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.2one'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"),
+ array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_trigger_event_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, false);
+ }
+
+ static public function get_vars_from_array_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\');',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ array('bertie'),
+ ),
+ array(
+ array(
+ "\t/**",
+ "\t*/",
+ "\t\$vars = array('_Strange123', 'phpBB3_Test');",
+ "\t\$this->dispatcher->dispatch('test');",
+ ),
+ 3,
+ array('_Strange123', 'phpBB3_Test'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_data
+ */
+ public function test_get_vars_from_array($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_array());
+ }
+
+ static public function get_vars_from_array_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 2,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = $bertie;',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'$bertie\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array();',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'t1\', \'t2\', \'t3\', \'t4\', \'t5\', \'t6\', \'t7\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'test2\', \'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\',\'basically_valid\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_array_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_array();
+ }
+
+ static public function get_vars_from_docblock_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ array('name1', 'name2'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_data
+ */
+ public function test_get_vars_from_docblock($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_docblock());
+ }
+
+ static public function get_vars_from_docblock_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 2,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array $name2 Description',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 4,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_docblock();
+ }
+
+ static public function find_since_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '* @since 3.1.0-a1',
+ '/**',
+ '* @since 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_data
+ */
+ public function test_find_since($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_since());
+ }
+
+ static public function find_since_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @var',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_since_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_since();
+ }
+
+ static public function find_description_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* Hello Bertie!',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ ' /**',
+ ' * Hello Bertie!',
+ ' *',
+ ' * @since 3.1.0-a1',
+ ' * @changed 3.1.0-a2',
+ ' */',
+ ' $phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 6,
+ 1,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_data
+ */
+ public function test_find_description($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_description());
+ }
+
+ static public function find_description_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*',
+ '* @since 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* ',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_description_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_description();
+ }
+}
diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php
new file mode 100644
index 0000000000..86d3930a7b
--- /dev/null
+++ b/tests/functional/feed_test.php
@@ -0,0 +1,1490 @@
+<?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_feed_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ static public $init_values = array();
+
+ public function __construct($name = null, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_feed_test' => array('init_values'),
+ );
+ }
+
+ public function test_setup_config_before_state()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ self::$init_values['post_base_items'] = (int) $values['config[feed_limit_post]'];
+ self::$init_values['topic_base_items'] = (int) $values['config[feed_limit_topic]'];
+
+ // Enable all feeds
+ $values['config[feed_enable]'] = true;
+ $values['config[feed_forum]'] = true;
+ $values['config[feed_item_statistics]'] = true;
+ $values['config[feed_overall]'] = true;
+ $values['config[feed_overall_forums]'] = true;
+ $values['config[feed_topic]'] = true;
+ $values['config[feed_topics_active]'] = true;
+ $values['config[feed_topics_new]'] = true;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+
+ // Special config (Guest can't see attachments)
+ $this->add_lang('acp/permissions');
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1");
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ $form['setting[1][0][u_download]']->select(-1);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_dump_board_state()
+ {
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+ $this->login();
+
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+
+ }
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->create_user('disapprove_user');
+ $this->add_user_group('NEWLY_REGISTERED', array('disapprove_user'));
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // 'Feeds #1.1' is a sub-forum of 'Feeds #1'
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$this->data['forums']['Feeds #1']}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1.1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #news' will be used for feed.php?mode=news
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #news',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #exclude' will not be displayed on feed.php?mode=forums
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #exclude',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function test_setup_config_after_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+
+ // News/Exclude's forums config
+ $form['feed_news_id']->select(array($this->data['forums']['Feeds #news']));
+ $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude']));
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_feeds_empty()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ // Excluded forums (and topics under them) shouldn't be displayed in feeds
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'nb_entries' => 0,
+ ),
+ array(
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'nb_entries' => 0,
+ ),
+ ),
+ 'forums' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/category[@label="Feeds #exclude"]' => 0,
+ ),
+ ),
+ ),
+ 'news' => array(
+ array(
+ 'nb_entries' => 0,
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_exclude_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #exclude'], 'Feeds #exclude - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #exclude - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_exclude()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ 'topics' => array(
+ 'Feeds #exclude - Topic #1',
+ ),
+ ));
+
+ // Assert that feeds aren't available for excluded forums
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #exclude'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #exclude - Topic #1'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_news_topics()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id'];
+ $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Feeds #news'], $post['topic_id'], 'Re: Feeds #news - Topic #2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_news_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ 'topics' => array(
+ 'Feeds #news - Topic #1',
+ 'Feeds #news - Topic #2',
+ ),
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that the first post of the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ // News should also be displayed in other feeds
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #news'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #news - Topic #1'],
+ ),
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #news - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 3,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_news_guest()
+ {
+ $this->load_ids(array(
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that first post of the the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_sub_forum_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_sub_forum()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // The topics of the sub-forum shouldn't be displayed
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ 'posts' => array(
+ 'Re: Feeds #1 - Topic #2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Feeds #1']}&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_feeds_softdeleted_post_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_post_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ));
+ }
+
+ public function test_softdelete_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+
+ $this->add_lang('posting');
+ $form = $crawler->selectButton('Go')->eq(2)->form();
+ $form['action']->select('delete_topic');
+ $crawler = self::submit($form);
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text());
+ }
+
+ public function test_feeds_softdeleted_topic_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_topic_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_unapproved_post()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $this->login('admin');
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #2', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1.1 - Topic #2'] = (int) $post['topic_id'];
+ $this->logout();
+
+ // Test creating a reply
+ $this->login('disapprove_user');
+ $post2 = $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text());
+ }
+
+ public function test_feeds_unapproved_post_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved post is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 9,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_post_disapprove_user()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved isn't displayed for regular users
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_unapproved_topic()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+
+ // We have to wait because of the flood interval.
+ sleep(15);
+
+ $this->login('disapprove_user');
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text());
+ }
+
+ public function test_feeds_unapproved_topic_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ // Assert that the unapproved topic is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 4,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 10,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_topic_disapprove_user()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_attachment_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // Test creating a topic with 1 attachment
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #3', 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]', array('upload_files' => 1));
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_attachment_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 4,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 11,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_attachment_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_missing_attachment_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ // Test creating a reply with 1 missing attachment
+ $post2 = $this->create_post($this->data['forums']['Feeds #1'], $this->data['topics']['Feeds #1 - Topic #3'], 'Re: Feeds #1 - Topic #3-1', 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_missing_attachment_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ $this->add_lang('viewtopic');
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 5,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 12,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 8,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ protected function assert_feeds($data, $username = false)
+ {
+ if ($username)
+ {
+ $this->login($username);
+ $init_values = self::$init_values[$username];
+ }
+ else
+ {
+ $init_values = self::$init_values['disapprove_user'];
+ }
+
+ foreach ($data as $mode => $feeds)
+ {
+ foreach ($feeds as $feed_data)
+ {
+ if ($mode === 'f' || $mode === 't')
+ {
+ $params = "?{$mode}={$feed_data['id']}";
+ $this->assert_feed($params, $feed_data);
+ }
+ else
+ {
+ switch ($mode) {
+ case 'forums':
+ $feed_data['nb_entries'] = ((int)$feed_data['nb_entries'] + $init_values['forums_value']);
+ break;
+ case 'overall':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['overall_value'], self::$init_values['post_base_items']);
+ break;
+ case 'topics':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_new':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_new_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_active':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_active_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'news':
+ break;
+ default:
+ $this->fail('Unsupported feed mode: ' . $mode);
+ }
+
+ $params = "?mode={$mode}";
+ $this->assert_feed($params, $feed_data);
+ }
+ }
+ }
+ }
+
+ protected function assert_feed($params, $data)
+ {
+ $crawler = self::request('GET', 'feed.php' . $params, array(), false);
+
+ if (empty($data['invalid']))
+ {
+ self::assert_response_xml();
+ $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'");
+
+ if (!empty($data['xpath']))
+ {
+
+ foreach($data['xpath'] as $xpath => $count_expected)
+ {
+ $this->assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'feed.php{$params}', Search for {$xpath}");
+ }
+ }
+
+ if (!empty($data['contents']))
+ {
+ foreach($data['contents'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['attachments']))
+ {
+ foreach($data['attachments'] as $entry_id => $attachments)
+ {
+ foreach ($attachments as $i => $attachment)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $url = "./download/file.php?id={$attachment['id']}";
+ $string = "Attachment #{$i}";
+
+ if ($attachment['displayed'])
+ {
+ $this->assertContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ $this->assertNotContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ else
+ {
+ $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ $this->assertNotContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ self::assert_response_html();
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $string)
+ {
+ $content = $crawler->filter('html')->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ $post_ids = array();
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ $post_ids[] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ if (isset($data['attachments']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_attachments
+ WHERE in_message = 0 AND ' . $this->db->sql_in_set('post_msg_id', $post_ids);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->data['attachments'][(int) $row['post_msg_id']][] = (int) $row['attach_id'];
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+ }
+}
diff --git a/tests/functional/jumpbox_test.php b/tests/functional/jumpbox_test.php
new file mode 100644
index 0000000000..b987d2b99b
--- /dev/null
+++ b/tests/functional/jumpbox_test.php
@@ -0,0 +1,33 @@
+<?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_jumpbox_test extends phpbb_functional_test_case
+{
+ public function test_jumpbox()
+ {
+ $this->login();
+
+ $crawler = self::request('GET', "viewtopic.php?t=1&sid={$this->sid}");
+ $form = $crawler->filter('#quickmodform')->selectButton($this->lang('GO'))->form(array(
+ 'action' => 'merge_topic',
+ ));
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('FORUM') . ': Your first forum', $crawler->filter('#cp-main h2')->text());
+ $form = $crawler->filter('#jumpbox')->selectButton($this->lang('GO'))->form(array(
+ 'f' => 1,
+ ));
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('FORUM') . ': Your first category', $crawler->filter('#cp-main h2')->text());
+ }
+}
diff --git a/tests/functional/ucp_allow_pm_test.php b/tests/functional/ucp_allow_pm_test.php
new file mode 100644
index 0000000000..b433ec8e75
--- /dev/null
+++ b/tests/functional/ucp_allow_pm_test.php
@@ -0,0 +1,70 @@
+<?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_ucp_allow_pm_test extends phpbb_functional_test_case
+{
+ static protected $data = array();
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_ucp_allow_pm_test' => array('data'),
+ );
+ }
+
+ // user A sends a PM to user B where B accepts PM
+ public function test_enabled_pm_user_to_user()
+ {
+ // setup
+ $this->create_user('test_ucp_allow_pm_sender');
+ $this->login('test_ucp_allow_pm_sender');
+ self::$data['recipient_id'] = $this->create_user('test_ucp_allow_pm_recipient');
+ self::$data['pm_url'] = "ucp.php?i=pm&mode=compose&u=" . (int) self::$data['recipient_id'] . "&sid={$this->sid}";
+
+ // the actual test
+ $this->set_user_allow_pm(self::$data['recipient_id'], 1);
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
+ }
+
+ // user A sends a PM to user B where B does not accept PM
+ public function test_disabled_pm_user_to_user()
+ {
+ $this->login('test_ucp_allow_pm_sender');
+ $this->set_user_allow_pm(self::$data['recipient_id'], 0);
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('.error')->text());
+ }
+
+
+ // An admin sends a PM to user B where B does not accept PM, but cannot
+ // ignore a PM from an admin
+ public function test_disabled_pm_admin_to_user()
+ {
+ $this->login();
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
+ }
+
+ // enable or disable PM for a user, like from ucp
+ protected function set_user_allow_pm($user_id, $allow)
+ {
+ $db = $this->get_db();
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_allow_pm = " . $allow . "
+ WHERE user_id = " . $user_id;
+ $result = $db->sql_query($sql);
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/functional/disapprove_test.php b/tests/functional/visibility_disapprove_test.php
index ea594b1062..ca6f6f5f37 100644
--- a/tests/functional/disapprove_test.php
+++ b/tests/functional/visibility_disapprove_test.php
@@ -10,7 +10,7 @@
/**
* @group functional
*/
-class phpbb_functional_disapprove_test extends phpbb_functional_test_case
+class phpbb_functional_visibility_disapprove_test extends phpbb_functional_test_case
{
protected $data = array();
diff --git a/tests/functional/visibility_reapprove_test.php b/tests/functional/visibility_reapprove_test.php
new file mode 100644
index 0000000000..70134ef724
--- /dev/null
+++ b/tests/functional/visibility_reapprove_test.php
@@ -0,0 +1,416 @@
+<?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_visibility_reapprove_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Reapprove Test #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // Set flood interval to 0
+ $this->set_flood_interval(0);
+ }
+
+ public function test_create_posts()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ // Test creating topic #1
+ $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #1', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->data['topics']['Reapprove Test Topic #1'] = (int) $post['topic_id'];
+ $this->data['posts']['Reapprove Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after creating topic #1');
+
+ $this->logout();
+ $this->create_user('reapprove_testuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser'));
+ $this->login('reapprove_testuser');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Reapprove Test #1'], $post['topic_id'], 'Re: Reapprove Test Topic #1-#2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after replying');
+
+ // Test creating topic #2
+ $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Reapprove Test #1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('html')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after creating topic #2');
+
+ $this->logout();
+ }
+
+ public function test_approve_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'before approving post');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+
+ $form = $crawler->selectButton($this->lang('APPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_APPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'],
+ ), 'after approving post');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Reapprove Test #1'] . '&t=' . $this->data['topics']['Reapprove Test Topic #1'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ }
+
+ public function test_approve_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'],
+ ), 'before approving topic');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text());
+
+ $form = $crawler->selectButton($this->lang('APPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ //@todo $this->assertContainsLang('TOPIC_APPROVED_SUCCESS', $crawler->text());
+ $this->assertContainsLang('POST_APPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'after approving topic');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewtopic.php?f=' . $this->data['topic']['Reapprove Test Topic #2'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text());
+ }
+
+ public function test_edit_posts()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'before editing post');
+
+ $this->login('reapprove_testuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser'));
+
+ // Test editing a post
+ $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Re: Reapprove Test Topic #1-#2']}&sid={$this->sid}";
+ $form_data = array(
+ 'message' => 'Post edited by testing framework',
+ 'subject' => 'Re: Reapprove Test Topic #1-#2',
+ 'post' => true,
+ );
+ $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'after editing post');
+
+ // Test editing a topic
+ $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Reapprove Test Topic #2']}&sid={$this->sid}";
+ $form_data = array(
+ 'message' => 'Post edited by testing framework',
+ 'subject' => 'Reapprove Test Topic #2',
+ 'post' => true,
+ );
+ $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}", array(), false);
+ self::assert_response_html(404);
+ $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('#page-body')->text());
+ $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after editing topic');
+
+ $this->logout();
+ $this->login();
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ $this->assertContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+ }
+
+ public function test_approve_post_again()
+ {
+ $this->test_approve_post();
+ }
+
+ public function test_approve_topic_again()
+ {
+ $this->test_approve_topic();
+ }
+
+ public function test_reset_flood_interval()
+ {
+ $this->login();
+ $this->admin_login();
+
+ // Set flood interval back to 15
+ $this->set_flood_interval(15);
+ }
+
+ protected function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ protected function set_flood_interval($flood_interval)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[flood_interval]"] = $flood_interval;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functional/softdelete_test.php b/tests/functional/visibility_softdelete_test.php
index 1c86d00b9b..3d44476ff0 100644
--- a/tests/functional/softdelete_test.php
+++ b/tests/functional/visibility_softdelete_test.php
@@ -10,7 +10,7 @@
/**
* @group functional
*/
-class phpbb_functional_softdelete_test extends phpbb_functional_test_case
+class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_case
{
protected $data = array();
@@ -608,7 +608,7 @@ class phpbb_functional_softdelete_test extends phpbb_functional_test_case
$crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
$this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
- $this->assertContainsLang('POST_DELETED', $crawler->filter('body')->text());
+ $this->assertContainsLang('POST_DELETED_ACTION', $crawler->filter('body')->text());
$this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
'forum_posts_approved' => 1,
diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php
new file mode 100644
index 0000000000..ad36f29b8c
--- /dev/null
+++ b/tests/functions/build_url_test.php
@@ -0,0 +1,82 @@
+<?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_build_url_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ global $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpbb_path_helper;
+
+ parent::setUp();
+
+ $phpbb_container = new phpbb_mock_container_builder();
+ $user = new phpbb_mock_user();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $phpbb_path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $phpbb_root_path,
+ 'php'
+ );
+ $phpbb_container->set('path_helper', $path_helper);
+ }
+ public function build_url_test_data()
+ {
+ return array(
+ array(
+ 'index.php',
+ false,
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'index.php',
+ 't',
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=4',
+ false,
+ 'phpBB/viewtopic.php?t=5&amp;f=4',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ 'f',
+ 'phpBB/viewtopic.php?style=1&amp;t=6',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'phpBB/viewtopic.php?',
+ ),
+ array(
+ 'http://test.phpbb.com/viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'http://test.phpbb.com/viewtopic.php?',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_url_test_data
+ */
+ public function test_build_url($page, $strip_vars, $expected)
+ {
+ global $user, $phpbb_root_path;
+
+ $user->page['page'] = $page;
+ $output = build_url($strip_vars);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/functions/fixtures/banned_users.xml b/tests/functions/fixtures/banned_users.xml
new file mode 100644
index 0000000000..cec3f4e51f
--- /dev/null
+++ b/tests/functions/fixtures/banned_users.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_banlist">
+ <column>ban_userid</column>
+ <column>ban_exclude</column>
+ <column>ban_end</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>0</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>0</value>
+ <value>999999999999999999999</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>0</value>
+ <value>3</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functions/phpbb_get_banned_user_ids.php b/tests/functions/phpbb_get_banned_user_ids.php
new file mode 100644
index 0000000000..96de5c5767
--- /dev/null
+++ b/tests/functions/phpbb_get_banned_user_ids.php
@@ -0,0 +1,58 @@
+<?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_user.php';
+
+class phpbb_get_banned_user_ids_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/banned_users.xml');
+ }
+
+ public function phpbb_get_banned_user_ids_data()
+ {
+ return array(
+ // Input to phpbb_get_banned_user_ids (user_id list, ban_end)
+ // Expected output
+ array(
+ // True to get users currently banned
+ array(array(1, 2, 4, 5, 6), true),
+ array(2 => 2, 5 => 5),
+ ),
+ array(
+ // False to only get permanently banned users
+ array(array(1, 2, 4, 5, 6), false),
+ array(2 => 2),
+ ),
+ array(
+ // Unix timestamp to get users banned until that time
+ array(array(1, 2, 4, 5, 6), 2),
+ array(2 => 2, 5 => 5, 6 => 6),
+ ),
+ );
+ }
+
+ public function setUp()
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+
+ return parent::setUp();
+ }
+
+ /**
+ * @dataProvider phpbb_get_banned_user_ids_data
+ */
+ public function test_phpbb_get_banned_user_ids($input, $expected)
+ {
+ $this->assertEquals($expected, call_user_func_array('phpbb_get_banned_user_ids', $input));
+ }
+}
diff --git a/tests/functions/validate_with_method_test.php b/tests/functions/validate_with_method_test.php
new file mode 100644
index 0000000000..86d7b9571c
--- /dev/null
+++ b/tests/functions/validate_with_method_test.php
@@ -0,0 +1,39 @@
+<?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_user.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
+
+class phpbb_functions_validate_with_method_test extends phpbb_test_case
+{
+ protected $helper;
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->helper = new phpbb_functions_validate_data_helper($this);
+ }
+
+ public function test_validate_date()
+ {
+ $this->helper->assert_valid_data(array(
+ 'method_call' => array(
+ array(),
+ true,
+ array(array(array($this, 'with_method'), false)),
+ ),
+ ));
+ }
+
+ public function validate_with_method($bool, $optional = false)
+ {
+ return ! $bool;
+ }
+}
diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml
index 4e5538d5a9..ef35884444 100644
--- a/tests/log/fixtures/full_log.xml
+++ b/tests/log/fixtures/full_log.xml
@@ -131,6 +131,18 @@
<value>LOG_SINGULAR_PLURAL</value>
<value>a:1:{i:0;i:2;}</value>
</row>
+ <row>
+ <value>11</value>
+ <value>1</value>
+ <value>1</value>
+ <value>15</value>
+ <value>3</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD3</value>
+ <value>a:1:{i:0;s:5:"guest";}</value>
+ </row>
</table>
<table name="phpbb_users">
<column>user_id</column>
diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php
index 2f64459062..542d0adf9d 100644
--- a/tests/log/function_view_log_test.php
+++ b/tests/log/function_view_log_test.php
@@ -225,6 +225,27 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'viewforum' => '',
'action' => 'LOG_SINGULAR_PLURAL 2',
),
+ 11 => array(
+ 'id' => 11,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => 'Anonymous',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 15,
+ 'topic_id' => 3,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_MOD3 guest ',
+ 'viewtopic' => '',
+ 'viewlogs' => '',
+ ),
);
$test_cases = array(
@@ -310,6 +331,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'expected_returned' => 0,
'user', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'plural',
),
+ array(
+ 'expected' => array(11),
+ 'expected_returned' => 0,
+ 'mod', 0, 5, 0, 15, 3,
+ ),
);
foreach ($test_cases as $case => $case_data)
@@ -362,6 +388,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'LOG_INSTALL_INSTALLED' => 'installed: %s',
'LOG_USER' => 'User<br /> %s',
'LOG_MOD2' => 'Mod2',
+ 'LOG_MOD3' => 'Mod3: %1$s, %2$s',
'LOG_SINGULAR_PLURAL' => array(
1 => 'singular',
2 => 'plural (%d)',
diff --git a/tests/migrator/convert_timezones_test.php b/tests/migrator/convert_timezones_test.php
new file mode 100644
index 0000000000..a1eed1dbdf
--- /dev/null
+++ b/tests/migrator/convert_timezones_test.php
@@ -0,0 +1,94 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ $this->db = $this->new_dbal();
+ $db_tools = new \phpbb\db\tools($this->db);
+
+ // user_dst doesn't exist anymore, must re-add it to test this
+ $db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1));
+
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert_timezones.xml');
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'users' => array(
+ 'user_dst',
+ ),
+ ),
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'users' => array(
+ 'user_dst' => array('BOOL', 0),
+ ),
+ ),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+
+ $this->migration = new \phpbb\db\migration\data\v310\timezone(
+ new \phpbb\config\config(array()),
+ $this->db,
+ new \phpbb\db\tools($this->db),
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_'
+ );
+ }
+
+ protected $expected_results = array(
+ //user_id => user_timezone
+ 1 => 'Etc/GMT+12',
+ 2 => 'Etc/GMT+11',
+ 3 => 'Etc/GMT-3',
+ 4 => 'Etc/GMT-4',
+ 5 => 'America/St_Johns',
+ 6 => 'Australia/Eucla',
+ );
+
+ public function test_convert()
+ {
+ $this->migration->update_timezones(0);
+
+ $sql = 'SELECT user_id, user_timezone
+ FROM phpbb_users
+ ORDER BY user_id ASC';
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']);
+ }
+ $this->db->sql_freeresult($result);
+
+ $db_tools = new \phpbb\db\tools($this->db);
+
+ // Remove the user_dst field again
+ $db_tools->sql_column_remove('phpbb_users', 'user_dst');
+ }
+}
diff --git a/tests/migrator/fixtures/convert_timezones.xml b/tests/migrator/fixtures/convert_timezones.xml
new file mode 100644
index 0000000000..b02cf8393c
--- /dev/null
+++ b/tests/migrator/fixtures/convert_timezones.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_timezone</column>
+ <column>user_dst</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value>-12</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ <value>-12</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>4</value>
+ <value></value>
+ <value></value>
+ <value>3</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>5</value>
+ <value></value>
+ <value></value>
+ <value>-3.5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>6</value>
+ <value></value>
+ <value></value>
+ <value>8.75</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php
index 9f0371262b..7c58340a7a 100644
--- a/tests/mimetype/guesser_test.php
+++ b/tests/mimetype/guesser_test.php
@@ -19,7 +19,9 @@ function function_exists($name)
class guesser_test extends \phpbb_test_case
{
- public static $function_exists = true;
+ public static $function_exists = false;
+
+ protected $fileinfo_supported = false;
public function setUp()
{
@@ -28,7 +30,16 @@ class guesser_test extends \phpbb_test_case
$guessers = array(
new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
+ new \phpbb\mimetype\extension_guesser,
+ new \phpbb\mimetype\content_guesser,
);
+
+ // Check if any guesser except the extension_guesser is available
+ $this->fileinfo_supported = $guessers[0]->isSupported() | $guessers[1]->isSupported() | $guessers[3]->is_supported();
+
+ // Also create a guesser that emulates not having fileinfo available
+ $this->guesser_no_fileinfo = new \phpbb\mimetype\guesser(array($guessers[2]));
+
$this->guesser = new \phpbb\mimetype\guesser($guessers);
$this->path = dirname(__FILE__);
$this->jpg_file = $this->path . '/fixtures/jpg';
@@ -52,9 +63,32 @@ class guesser_test extends \phpbb_test_case
*/
public function test_guess_files($expected, $file)
{
+ // We will always get application/octet-stream as mimetype if only the
+ // extension guesser is supported
+ if (!$this->fileinfo_supported)
+ {
+ $this->markTestSkipped('Unable to run tests depending on fileinfo if it is not available');
+ }
$this->assertEquals($expected, $this->guesser->guess($this->path . '/../upload/fixture/' . $file));
}
+ public function data_guess_files_no_fileinfo()
+ {
+ return array(
+ array('application/octet-stream', 'gif'),
+ array('application/octet-stream', 'txt'),
+ array(false, 'foobar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_guess_files_no_fileinfo
+ */
+ public function test_guess_files_no_fileinfo($expected, $file)
+ {
+ $this->assertEquals($expected, $this->guesser_no_fileinfo->guess($this->path . '/../upload/fixture/' . $file));
+ }
+
public function test_file_not_readable()
{
@chmod($this->jpg_file, 0000);
@@ -130,6 +164,11 @@ class guesser_test extends \phpbb_test_case
$supported = false;
self::$function_exists = !$overload;
+ if (!\function_exists('mime_content_type'))
+ {
+ $this->markTestSkipped('Emulating supported mime_content_type() when it is not supported will cause a fatal error');
+ }
+
// Cover possible LogicExceptions
foreach ($guessers as $cur_guesser)
{
diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php
new file mode 100644
index 0000000000..01ac6494d0
--- /dev/null
+++ b/tests/mock/controller_helper.php
@@ -0,0 +1,22 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_mock_controller_helper extends \phpbb\controller\helper
+{
+ public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, $phpbb_root_path, $php_ext, $phpbb_root_path_ext)
+ {
+ $this->template = $template;
+ $this->user = $user;
+ $this->config = $config;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+ $provider->find_routing_files($manager->get_finder());
+ $this->route_collection = $provider->find($phpbb_root_path_ext)->get_routes();
+ }
+}
diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php
index d81ae3163e..a2a403727b 100644
--- a/tests/mock/session_testable.php
+++ b/tests/mock/session_testable.php
@@ -20,7 +20,7 @@ class phpbb_mock_session_testable extends \phpbb\session
{
private $_cookies = array();
- public function set_cookie($name, $data, $time)
+ public function set_cookie($name, $data, $time, $httponly = true)
{
$this->_cookies[$name] = array($data, $time);
}
diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php
index a849cb7b1b..9956f3b58e 100644
--- a/tests/notification/submit_post_type_quote_test.php
+++ b/tests/notification/submit_post_type_quote_test.php
@@ -55,7 +55,7 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
* 2 => Poster, should NOT receive a notification
* 3 => Quoted, should receive a notification
* 4 => Quoted, but unauthed to read, should NOT receive a notification
- * 5 => Quoted, but already notified, should NOT receive a new notification
+ * 5 => Quoted, but already notified, should STILL receive a new notification
* 6 => Quoted, but option disabled, should NOT receive a notification
* 7 => Quoted, option set to default, should receive a notification
*/
@@ -78,6 +78,7 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
array(
array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 5, 'item_id' => 2, 'item_parent_id' => 1),
array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
),
),
diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php
index 71206dff58..f7a02dc419 100644
--- a/tests/pagination/pagination_test.php
+++ b/tests/pagination/pagination_test.php
@@ -30,17 +30,19 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
->method('lang')
->will($this->returnCallback(array($this, 'return_callback_implode')));
+ $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array());
$this->finder = new \phpbb\extension\finder(
- new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()),
+ $manager,
new \phpbb\filesystem(),
dirname(__FILE__) . '/',
new phpbb_mock_cache()
);
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
- $provider = new \phpbb\controller\provider($this->finder);
+ $provider = new \phpbb\controller\provider();
+ $provider->find_routing_files($this->finder);
$provider->find(dirname(__FILE__) . '/');
- $this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, $provider, '', 'php');
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, '', 'php', dirname(__FILE__) . '/');
$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper);
}
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php
index 40bb110185..df1474419b 100644
--- a/tests/passwords/drivers_test.php
+++ b/tests/passwords/drivers_test.php
@@ -7,7 +7,7 @@
*
*/
-class phpbb_passwords_helper_test extends PHPUnit_Framework_TestCase
+class phpbb_passwords_helper_test extends \phpbb_test_case
{
public function setUp()
{
diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php
index 008f222696..561c4d1189 100644
--- a/tests/passwords/manager_test.php
+++ b/tests/passwords/manager_test.php
@@ -7,7 +7,7 @@
*
*/
-class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
+class phpbb_passwords_manager_test extends \phpbb_test_case
{
protected $passwords_drivers;
@@ -176,7 +176,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
}
}
- public function test_combined_hash_data()
+ public function combined_hash_data()
{
if (version_compare(PHP_VERSION, '5.3.7', '<'))
{
@@ -242,7 +242,7 @@ class phpbb_passwords_manager_test extends PHPUnit_Framework_TestCase
}
/**
- * @dataProvider test_combined_hash_data
+ * @dataProvider combined_hash_data
*/
public function test_combined_hash_password($first_type, $second_type, $expected = true)
{
diff --git a/tests/path_helper/web_root_path_test.php b/tests/path_helper/path_helper_test.php
index ec04135997..724f26956c 100644
--- a/tests/path_helper/web_root_path_test.php
+++ b/tests/path_helper/path_helper_test.php
@@ -7,7 +7,7 @@
*
*/
-class phpbb_path_helper_web_root_path_test extends phpbb_test_case
+class phpbb_path_helper_test extends phpbb_test_case
{
protected $path_helper;
protected $phpbb_root_path = '';
@@ -176,4 +176,155 @@ class phpbb_path_helper_web_root_path_test extends phpbb_test_case
{
$this->assertEquals($expected, $this->path_helper->clean_url($input));
}
+
+ public function glue_url_params_data()
+ {
+ return array(
+ array(
+ array(),
+ '',
+ ),
+ array(
+ array('test' => 'xyz'),
+ 'test=xyz',
+ ),
+ array(
+ array('test' => 'xyz', 'var' => 'value'),
+ 'test=xyz&amp;var=value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider glue_url_params_data
+ */
+ public function test_glue_url_params($params, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->glue_url_params($params));
+ }
+
+ public function get_url_parts_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ true,
+ array('base' => 'viewtopic.php', 'params' => array()),
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => './viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6',
+ false,
+ array('base' => 'viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => 'https://phpbb.com/community/viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'test.php?topic=post=5&amp;f=3',
+ true,
+ array('base' => 'test.php', 'params' => array('topic' => 'post=5', 'f' => '3')),
+ ),
+ array(
+ 'mcp.php?&amp;t=4&amp;f=3',
+ true,
+ array('base' => 'mcp.php', 'params' => array('t' => '4', 'f' => '3')),
+ ),
+ array(
+ 'mcp.php?=4&amp;f=3',
+ true,
+ array('base' => 'mcp.php', 'params' => array('f' => '3')),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_url_parts_data
+ */
+ public function test_get_url_parts($url, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->get_url_parts($url, $is_amp));
+ }
+
+ public function strip_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ 'sid',
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ 'f',
+ true,
+ './viewtopic.php?t=5',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('t'),
+ false,
+ 'viewtopic.php?f=6&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ array('t', 'f'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider strip_url_params_data
+ */
+ public function test_strip_url_params($url, $strip, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->strip_url_params($url, $strip, $is_amp));
+ }
+
+ public function append_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ array(),
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ array('t' => '7'),
+ true,
+ './viewtopic.php?t=7&amp;f=6',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('p' => '5'),
+ false,
+ 'viewtopic.php?t=5&amp;f=6&amp;p=5&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php',
+ array('t' => '7', 'f' => '8'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php?t=7&amp;f=8',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider append_url_params_data
+ */
+ public function test_append_url_params($url, $params, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->append_url_params($url, $params, $is_amp));
+ }
}
diff --git a/tests/session/fixtures/sessions_key.xml b/tests/session/fixtures/sessions_key.xml
index 4f349cd282..245f89a604 100644
--- a/tests/session/fixtures/sessions_key.xml
+++ b/tests/session/fixtures/sessions_key.xml
@@ -22,7 +22,6 @@
<value>4</value>
<value>127.0.0.1</value>
<value>user agent</value>
- <value>1</value>
</row>
</table>
<table name="phpbb_users">
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
index 4fdba859f3..98fa1770ba 100644
--- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
@@ -1,2 +1,2 @@
-[{event_loop.S_ROW_COUNT}<!-- BEGIN subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
-<!-- END subloop -->]
+[{event_loop.S_ROW_COUNT}<!-- BEGIN event_loop.subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
+<!-- END event_loop.subloop -->]
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index d09f22944f..866d42d831 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -102,7 +102,6 @@ Zeta test event in all',
),
array(),
'event_loop[0[subloop:0]]',
- 'Event files are missing opened parent loops: PHPBB3-12382',
),
);
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 49804c26c5..0d19e7afd1 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -330,7 +330,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
"[bar|[bar|]][bar1|[bar1|[bar1|works]]]",
array(),
- 'Included files are missing opened parent loops: PHPBB3-12382',
),
/* Does not pass with the current implementation.
array(
diff --git a/tests/template/templates/loop_nested_include1.html b/tests/template/templates/loop_nested_include1.html
index 0f1a180b4d..88efffc99c 100644
--- a/tests/template/templates/loop_nested_include1.html
+++ b/tests/template/templates/loop_nested_include1.html
@@ -1,5 +1,5 @@
[{test_loop.foo}|
-<!-- BEGIN inner -->
+<!-- BEGIN test_loop.inner -->
[{test_loop.foo}|
{test_loop.inner.myinner}]
-<!-- END inner -->]
+<!-- END test_loop.inner -->]
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index 887dad5b50..796a6e57cf 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -53,6 +53,7 @@ class phpbb_database_test_connection_manager
switch ($this->dbms['PDO'])
{
case 'sqlite2':
+ case 'sqlite': // SQLite3 driver
$dsn .= $this->config['dbhost'];
break;
@@ -191,6 +192,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'phpbb\db\driver\sqlite':
+ case 'phpbb\db\driver\sqlite3':
case 'phpbb\db\driver\firebird':
$this->connect();
// Drop all of the tables
@@ -272,6 +274,13 @@ class phpbb_database_test_connection_manager
WHERE type = "table"';
break;
+ case 'phpbb\db\driver\sqlite3':
+ $sql = 'SELECT name
+ FROM sqlite_master
+ WHERE type = "table"
+ AND name <> "sqlite_sequence"';
+ break;
+
case 'phpbb\db\driver\mssql':
case 'phpbb\db\driver\mssql_odbc':
case 'phpbb\db\driver\mssqlnative':
@@ -436,6 +445,11 @@ class phpbb_database_test_connection_manager
'DELIM' => ';',
'PDO' => 'sqlite2',
),
+ 'phpbb\db\driver\sqlite3' => array(
+ 'SCHEMA' => 'sqlite',
+ 'DELIM' => ';',
+ 'PDO' => 'sqlite',
+ ),
);
if (isset($available_dbms[$dbms]))
@@ -623,6 +637,14 @@ class phpbb_database_test_connection_manager
$queries[] = 'SELECT ' . implode(', ', $setval_queries);
}
break;
+
+ case 'phpbb\db\driver\sqlite3':
+ /**
+ * Just delete all of the sequences. When an insertion occurs, the sequence will be automatically
+ * re-created from the key with the AUTOINCREMENT attribute
+ */
+ $queries[] = 'DELETE FROM sqlite_sequence';
+ break;
}
foreach ($queries as $query)
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 2f225fe7af..aba63a0498 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -104,7 +104,19 @@ class phpbb_test_case_helpers
{
$config = array();
- if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
+
+ if (extension_loaded('sqlite3'))
+ {
+ $config = array_merge($config, array(
+ 'dbms' => 'phpbb\db\driver\sqlite3',
+ 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite3', // filename
+ 'dbport' => '',
+ 'dbname' => '',
+ 'dbuser' => '',
+ 'dbpasswd' => '',
+ ));
+ }
+ else if (extension_loaded('sqlite'))
{
$config = array_merge($config, array(
'dbms' => 'phpbb\db\driver\sqlite',