aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.md13
-rw-r--r--tests/auth/fixtures/oauth_tokens.xml6
-rw-r--r--tests/auth/phpbb_not_a_token.php23
-rw-r--r--tests/auth/provider_oauth_token_storage_test.php18
-rw-r--r--tests/avatar/manager_test.php18
-rw-r--r--tests/bootstrap.php1
-rw-r--r--tests/config_php_file_test.php30
-rw-r--r--tests/console/cron/cron_list_test.php4
-rw-r--r--tests/console/cron/run_test.php2
-rw-r--r--tests/content_visibility/delete_post_test.php4
-rw-r--r--tests/controller/helper_route_test.php1
-rw-r--r--tests/dbal/db_tools_test.php3
-rw-r--r--tests/dbal/fixtures/migrator_config_text.xml7
-rw-r--r--tests/dbal/migrator_tool_config_text_test.php75
-rw-r--r--tests/dbal/order_lower_test.php2
-rw-r--r--tests/dbal/select_test.php4
-rw-r--r--tests/dbal/sql_insert_buffer_test.php8
-rw-r--r--tests/di/create_container_test.php145
-rw-r--r--tests/di/fixtures/config/services.yml14
-rw-r--r--tests/di/fixtures/ext/vendor/available/config/services.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/disabled/config/services.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/enabled/config/services.yml2
-rw-r--r--tests/di/fixtures/other_config/services.yml14
-rw-r--r--tests/event/php_exporter_test.php2
-rw-r--r--tests/extension/ext/barfoo/composer.json8
-rw-r--r--tests/extension/ext/vendor/moo/composer.json8
-rw-r--r--tests/extension/ext/vendor2/bar/composer.json8
-rw-r--r--tests/extension/ext/vendor2/foo/composer.json8
-rw-r--r--tests/extension/ext/vendor3/foo/composer.json23
-rw-r--r--tests/extension/ext/vendor3/foo/ext.php20
-rw-r--r--tests/extension/manager_test.php63
-rw-r--r--tests/extension/metadata_manager_test.php325
-rw-r--r--tests/filesystem/clean_path_test.php2
-rw-r--r--tests/fixtures/config.php3
-rw-r--r--tests/fixtures/config_other.php3
-rw-r--r--tests/functional/download_test.php6
-rw-r--r--tests/functional/extension_acp_test.php6
-rw-r--r--tests/functional/feed_test.php6
-rw-r--r--tests/functional/fileupload_form_test.php6
-rw-r--r--tests/functional/fileupload_remote_test.php4
-rw-r--r--tests/functional/fixtures/ext/foo/bar/composer.json8
-rw-r--r--tests/functional/forgot_password_test.php2
-rw-r--r--tests/functional/jumpbox_test.php20
-rw-r--r--tests/functional/mcp_test.php22
-rw-r--r--tests/functional/plupload_test.php2
-rw-r--r--tests/functional/posting_test.php23
-rw-r--r--tests/functional/private_messages_test.php69
-rw-r--r--tests/functional/ucp_profile_test.php12
-rw-r--r--tests/functional/visibility_softdelete_test.php40
-rw-r--r--tests/functions/build_url_test.php3
-rw-r--r--tests/functions/convert_30_dbms_to_31_test.php4
-rw-r--r--tests/functions/obtain_online_test.php8
-rw-r--r--tests/functions_content/get_username_string_test.php14
-rw-r--r--tests/log/function_view_log_test.php26
-rw-r--r--tests/mock/controller_helper.php5
-rw-r--r--tests/mock/phpbb_di_container_builder.php20
-rw-r--r--tests/notification/user_list_trim_test.php10
-rw-r--r--tests/path_helper/path_helper_test.php95
-rw-r--r--tests/profile/custom_string_test.php120
-rw-r--r--tests/profile/custom_test.php75
-rw-r--r--tests/profile/fixtures/profile_fields.xml31
-rw-r--r--tests/profile/get_profile_value_test.php46
-rw-r--r--tests/profilefields/type_bool_test.php195
-rw-r--r--tests/profilefields/type_date_test.php228
-rw-r--r--tests/profilefields/type_dropdown_test.php235
-rw-r--r--tests/profilefields/type_googleplus_test.php62
-rw-r--r--tests/profilefields/type_int_test.php236
-rw-r--r--tests/profilefields/type_string_test.php292
-rw-r--r--tests/profilefields/type_url_test.php141
-rw-r--r--tests/security/redirect_test.php1
-rw-r--r--tests/template/template_events_test.php1
-rw-r--r--tests/template/template_test.php7
-rw-r--r--tests/template/template_test_case.php1
-rw-r--r--tests/template/template_test_case_with_tree.php1
-rw-r--r--tests/template/templates/if_nested_tags.html1
-rw-r--r--tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php2
-rw-r--r--tests/test_framework/phpbb_database_test_case.php31
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php50
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php293
-rw-r--r--tests/test_framework/phpbb_mink_test_case.php183
-rw-r--r--tests/test_framework/phpbb_session_test_case.php1
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php19
-rw-r--r--tests/upload/filespec_test.php39
-rw-r--r--tests/viewonline/helper_test.php46
84 files changed, 2693 insertions, 926 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md
index d638c86859..afd7caa709 100644
--- a/tests/RUNNING_TESTS.md
+++ b/tests/RUNNING_TESTS.md
@@ -32,7 +32,6 @@ will be skipped:
- apc (APC cache driver)
- bz2 (compress tests)
-- interbase, pdo_firebird (Firebird database driver)
- mysql, pdo_mysql (MySQL database driver)
- mysqli, pdo_mysql (MySQLi database driver)
- pcntl (flock class)
@@ -82,16 +81,10 @@ Special Database Cases
----------------------
In order to run tests on some of the databases that we support, it will be
necessary to provide a custom DSN string in test_config.php. This is only
-needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when
-PDO_Firebird does not work on your system
-(https://bugs.php.net/bug.php?id=61183). The variable must be named `$custom_dsn`.
+needed for MSSQL 2000+ (PHP module) and MSSQL via ODBC. The variable must be
+named `$custom_dsn`.
-Examples:
-Firebird using http://www.firebirdsql.org/en/odbc-driver/
-
- $custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname";
-
-MSSQL
+Example MSSQL:
$custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname";
diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml
index 9bfb5a4422..6c82e94e62 100644
--- a/tests/auth/fixtures/oauth_tokens.xml
+++ b/tests/auth/fixtures/oauth_tokens.xml
@@ -5,6 +5,12 @@
<column>session_id</column>
<column>provider</column>
<column>oauth_token</column>
+ <row>
+ <value>1</value>
+ <value>abcd</value>
+ <value>auth.provider.oauth.service.testing</value>
+ <value>{"token_class":"phpbb_not_a_token","accessToken":"error","refreshToken":0,"endOfLife":null,"extraParams":null}</value>
+ </row>
</table>
</dataset>
diff --git a/tests/auth/phpbb_not_a_token.php b/tests/auth/phpbb_not_a_token.php
new file mode 100644
index 0000000000..61cc14fa10
--- /dev/null
+++ b/tests/auth/phpbb_not_a_token.php
@@ -0,0 +1,23 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_not_a_token
+{
+ public function __construct($param1, $param2, $param3, $param4)
+ {
+ }
+
+ public function setEndOfLife()
+ {
+ }
+}
diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php
index ec28e546bd..45daa9816b 100644
--- a/tests/auth/provider_oauth_token_storage_test.php
+++ b/tests/auth/provider_oauth_token_storage_test.php
@@ -13,6 +13,8 @@
use OAuth\OAuth2\Token\StdOAuth2Token;
+require_once dirname(__FILE__) . '/phpbb_not_a_token.php';
+
class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_case
{
protected $db;
@@ -73,6 +75,22 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c
$this->assertEquals($token, $stored_token);
}
+ public function test_retrieveAccessToken_wrong_token()
+ {
+ $this->user->data['session_id'] = 'abcd';
+ try
+ {
+ $this->token_storage->retrieveAccessToken($this->service_name);
+ $this->fail('The token can not be deserialized and an exception should be thrown.');
+ }
+ catch (\OAuth\Common\Storage\Exception\TokenNotFoundException $e)
+ {
+ }
+
+ $row = $this->get_token_row_by_session_id('abcd');
+ $this->assertFalse($row);
+ }
+
public function test_retrieveAccessToken_from_db()
{
$expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES);
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index 246397ad6c..d8099b40d4 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -38,10 +38,19 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
+ $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,
+ );
+ $guesser = new \phpbb\mimetype\guesser($guessers);
+
// $this->avatar_foobar will be needed later on
$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
$this->avatar_foobar->expects($this->any())
@@ -56,7 +65,14 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
foreach ($this->avatar_drivers() as $driver)
{
- $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ if ($driver !== 'upload')
+ {
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ }
+ else
+ {
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache));
+ }
$cur_avatar->expects($this->any())
->method('get_name')
->will($this->returnValue('avatar.driver.' . $driver));
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index bb4a703cc3..2856ba02bb 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -31,4 +31,5 @@ require_once 'test_framework/phpbb_test_case_helpers.php';
require_once 'test_framework/phpbb_test_case.php';
require_once 'test_framework/phpbb_database_test_case.php';
require_once 'test_framework/phpbb_database_test_connection_manager.php';
+require_once 'test_framework/phpbb_mink_test_case.php';
require_once 'test_framework/phpbb_functional_test_case.php';
diff --git a/tests/config_php_file_test.php b/tests/config_php_file_test.php
new file mode 100644
index 0000000000..c2e4eb21c7
--- /dev/null
+++ b/tests/config_php_file_test.php
@@ -0,0 +1,30 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_config_php_file_test extends phpbb_test_case
+{
+ public function test_default()
+ {
+ $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php');
+ $this->assertSame('bar', $config_php->get('foo'));
+ $this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all());
+ }
+
+ public function test_set_config_file()
+ {
+ $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php');
+ $config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php');
+ $this->assertSame('foo', $config_php->get('bar'));
+ $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all());
+ }
+}
diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php
index 46705a585f..1059a3f221 100644
--- a/tests/console/cron/cron_list_test.php
+++ b/tests/console/cron/cron_list_test.php
@@ -75,7 +75,7 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
public function get_command_tester()
{
$application = new Application();
- $application->add(new cron_list($this->cron_manager, $this->user));
+ $application->add(new cron_list($this->user, $this->cron_manager));
$command = $application->find('cron:list');
$this->command_name = $command->getName();
@@ -98,6 +98,6 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
$this->get_cron_manager($tasks);
$this->command_tester = $this->get_command_tester();
- $this->command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true));
+ $this->command_tester->execute(array('command' => $this->command_name), array('decorated' => false));
}
}
diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php
index ff251cff3c..60bd74e1f0 100644
--- a/tests/console/cron/run_test.php
+++ b/tests/console/cron/run_test.php
@@ -148,7 +148,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
public function get_command_tester()
{
$application = new Application();
- $application->add(new run($this->cron_manager, $this->lock, $this->user));
+ $application->add(new run($this->user, $this->cron_manager, $this->lock));
$command = $application->find('cron:run');
$this->command_name = $command->getName();
diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php
index e2b1477e10..aa705c52a5 100644
--- a/tests/content_visibility/delete_post_test.php
+++ b/tests/content_visibility/delete_post_test.php
@@ -266,7 +266,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
*/
public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum)
{
- global $auth, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx;
+ global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
$config['search_type'] = 'phpbb_mock_search';
$cache = new phpbb_mock_cache;
@@ -284,6 +284,8 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
)));
$user = $this->getMock('\phpbb\user');
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $phpbb_config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php
index 621efaa830..206c3a4f0b 100644
--- a/tests/controller/helper_route_test.php
+++ b/tests/controller/helper_route_test.php
@@ -26,6 +26,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index f3c6888c8d..6cc2f8ec0f 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -46,6 +46,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
'c_bool' => array('BOOL', 1),
'c_vchar' => array('VCHAR', 'foo'),
'c_vchar_size' => array('VCHAR:4', 'foo'),
+ 'c_vchar_null' => array('VCHAR', null),
'c_char_size' => array('CHAR:4', 'foo'),
'c_xstext' => array('XSTEXT', 'foo'),
'c_stext' => array('STEXT', 'foo'),
@@ -111,6 +112,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
'c_bool' => 0,
'c_vchar' => '',
'c_vchar_size' => '',
+ 'c_vchar_null' => null,
'c_char_size' => 'abcd',
'c_xstext' => '',
'c_stext' => '',
@@ -144,6 +146,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
array('c_bool', 0),
array('c_vchar', str_repeat('a', 255)),
array('c_vchar_size', str_repeat('a', 4)),
+ array('c_vchar_null', str_repeat('a', 4)),
array('c_char_size', str_repeat('a', 4)),
array('c_xstext', str_repeat('a', 1000)),
array('c_stext', str_repeat('a', 3000)),
diff --git a/tests/dbal/fixtures/migrator_config_text.xml b/tests/dbal/fixtures/migrator_config_text.xml
new file mode 100644
index 0000000000..ba8e1fcfcc
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_config_text.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config_text">
+ <column>config_name</column>
+ <column>config_value</column>
+ </table>
+</dataset>
diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php
new file mode 100644
index 0000000000..b271c2d62e
--- /dev/null
+++ b/tests/dbal/migrator_tool_config_text_test.php
@@ -0,0 +1,75 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_config_text.xml');
+ }
+
+ public function setup()
+ {
+ parent::setup();
+
+ $this->db = $this->new_dbal();
+ $this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text');
+
+ $this->tool = new \phpbb\db\migration\tool\config_text($this->config_text);
+ }
+
+ public function test_add()
+ {
+ $this->tool->add('foo', 'bar');
+ $this->assertEquals('bar', $this->config_text->get('foo'));
+ }
+
+ public function test_add_twice()
+ {
+ $this->tool->add('foo', 'bar');
+ $this->assertEquals('bar', $this->config_text->get('foo'));
+
+ $this->tool->add('foo', 'bar2');
+ $this->assertEquals('bar', $this->config_text->get('foo'));
+ }
+
+ public function test_update()
+ {
+ $this->config_text->set('foo', 'bar');
+
+ $this->tool->update('foo', 'bar2');
+ $this->assertEquals('bar2', $this->config_text->get('foo'));
+ }
+
+ public function test_remove()
+ {
+ $this->config_text->set('foo', 'bar');
+
+ $this->tool->remove('foo');
+ $this->assertNull($this->config_text->get('foo'));
+ }
+
+ public function test_reverse_add()
+ {
+ $this->config_text->set('foo', 'bar');
+
+ $this->tool->reverse('add', 'foo');
+ $this->assertNull($this->config_text->get('foo'));
+ }
+
+ public function test_reverse_remove()
+ {
+ $this->tool->reverse('remove', 'foo');
+ $this->assertSame('', $this->config_text->get('foo'));
+ }
+}
diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php
index b7a69c7c5d..b101d28c7d 100644
--- a/tests/dbal/order_lower_test.php
+++ b/tests/dbal/order_lower_test.php
@@ -22,7 +22,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case
{
$db = $this->new_dbal();
- if (strpos($db->sql_layer, 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>='))
+ if (strpos($db->get_sql_layer(), 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>='))
{
$this->markTestSkipped('MySQL 5.6 fails to order things correctly. See also: http://tracker.phpbb.com/browse/PHPBB3-11571 http://bugs.mysql.com/bug.php?id=69005');
}
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index 7cac4d6a3b..e480716a49 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -219,8 +219,8 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
{
$db = $this->new_dbal();
- $like_expression = str_replace('*', $db->any_char, $like_expression);
- $like_expression = str_replace('#', $db->one_char, $like_expression);
+ $like_expression = str_replace('*', $db->get_any_char(), $like_expression);
+ $like_expression = str_replace('#', $db->get_one_char(), $like_expression);
$where = ($like_expression) ? 'username_clean ' . $db->sql_like_expression($like_expression) : '';
$result = $db->sql_query('SELECT username_clean
diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php
index 2f9ed0008f..eae0abceba 100644
--- a/tests/dbal/sql_insert_buffer_test.php
+++ b/tests/dbal/sql_insert_buffer_test.php
@@ -32,7 +32,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
public function test_multi_insert_disabled_insert_and_flush()
{
- $this->db->multi_insert = false;
+ $this->db->set_multi_insert(false);
$this->assertTrue($this->buffer->insert($this->get_row(1)));
$this->assert_config_count(3);
$this->assertFalse($this->buffer->flush());
@@ -50,7 +50,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
public function test_multi_insert_disabled_insert_with_flush()
{
- $this->db->multi_insert = false;
+ $this->db->set_multi_insert(false);
$this->assertTrue($this->buffer->insert($this->get_row(1)));
$this->assert_config_count(3);
$this->assertTrue($this->buffer->insert($this->get_row(2)));
@@ -68,7 +68,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
public function test_multi_insert_disabled_insert_all_and_flush()
{
- $this->db->multi_insert = false;
+ $this->db->set_multi_insert(false);
$this->assertTrue($this->buffer->insert_all($this->get_rows(3)));
$this->assert_config_count(5);
}
@@ -93,7 +93,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
protected function check_multi_insert_support()
{
- if (!$this->db->multi_insert)
+ if (!$this->db->get_multi_insert())
{
$this->markTestSkipped('Database does not support multi_insert');
}
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php
index 8bf9f636fa..559c0b122c 100644
--- a/tests/di/create_container_test.php
+++ b/tests/di/create_container_test.php
@@ -14,47 +14,135 @@
namespace
{
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
- class phpbb_di_container_test extends phpbb_test_case
+ class phpbb_di_container_test extends \phpbb_test_case
{
- public function test_phpbb_create_container()
+ protected $config_php;
+
+ /**
+ * @var \phpbb\di\container_builder
+ */
+ protected $builder;
+ protected $phpbb_root_path;
+ protected $filename;
+
+ public function setUp()
{
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
+ $this->phpbb_root_path = dirname(__FILE__) . '/';
+ $this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php');
+ $this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php');
+
+ $this->filename = $this->phpbb_root_path . '../tmp/container.php';
+ if (is_file($this->filename))
+ {
+ unlink($this->filename);
+ }
+
+ parent::setUp();
+ }
+ public function test_default_container()
+ {
+ $container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks the core services
+ $this->assertTrue($container->hasParameter('core'));
+
+ // Checks compile_container
+ $this->assertTrue($container->isFrozen());
+
+ // Checks inject_config
+ $this->assertTrue($container->hasParameter('dbal.dbhost'));
+
+ // Checks use_extensions
+ $this->assertTrue($container->hasParameter('enabled'));
+ $this->assertFalse($container->hasParameter('disabled'));
+ $this->assertFalse($container->hasParameter('available'));
+
+ // Checks set_custom_parameters
+ $this->assertTrue($container->hasParameter('core.root_path'));
+
+ // Checks dump_container
+ $this->assertTrue(is_file($this->filename));
+
+ // Checks the construction of a dumped container
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('phpbb_cache_container', $container);
+ $this->assertFalse($container->isFrozen());
+ $container->getParameterBag(); // needed, otherwise the container is not marked as frozen
+ $this->assertTrue($container->isFrozen());
}
- public function test_phpbb_create_install_container()
+ public function test_dump_container()
{
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_install_container($phpbb_root_path, 'php');
+ $this->builder->set_dump_container(false);
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ // Checks dump_container
+ $this->assertFalse(is_file($this->filename));
+
+ // Checks the construction of a dumped container
+ $container = $this->builder->get_container();
+ $this->assertNotInstanceOf('phpbb_cache_container', $container);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
$this->assertTrue($container->isFrozen());
}
- public function test_phpbb_create_compiled_container()
+ public function test_use_extensions()
{
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $config_file = __DIR__ . '/fixtures/config.php';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php');
+ $this->builder->set_use_extensions(false);
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks the core services
+ $this->assertTrue($container->hasParameter('core'));
+
+ // Checks use_extensions
+ $this->assertFalse($container->hasParameter('enabled'));
+ $this->assertFalse($container->hasParameter('disabled'));
+ $this->assertFalse($container->hasParameter('available'));
+ }
+ public function test_compile_container()
+ {
+ $this->builder->set_compile_container(false);
+ $container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
- $this->assertTrue($container->isFrozen());
+
+ // Checks compile_container
+ $this->assertFalse($container->isFrozen());
+ }
+
+ public function test_inject_config()
+ {
+ $this->builder->set_inject_config(false);
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks inject_config
+ $this->assertFalse($container->hasParameter('dbal.dbhost'));
+ }
+
+ public function test_set_config_path()
+ {
+ $this->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/');
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ $this->assertTrue($container->hasParameter('other_config'));
+ $this->assertFalse($container->hasParameter('core'));
+ }
+
+ public function test_set_custom_parameters()
+ {
+ $this->builder->set_custom_parameters(array('my_parameter' => true));
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ $this->assertTrue($container->hasParameter('my_parameter'));
+ $this->assertFalse($container->hasParameter('core.root_path'));
}
}
}
@@ -102,5 +190,12 @@ namespace phpbb\db\driver
function sql_like_expression($expression)
{
}
+
+ function sql_fetchrowset($query_id = false)
+ {
+ return array(
+ array('ext_name' => 'vendor/enabled'),
+ );
+ }
}
}
diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml
new file mode 100644
index 0000000000..f2a22ae109
--- /dev/null
+++ b/tests/di/fixtures/config/services.yml
@@ -0,0 +1,14 @@
+parameters:
+ core: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
diff --git a/tests/di/fixtures/ext/vendor/available/config/services.yml b/tests/di/fixtures/ext/vendor/available/config/services.yml
new file mode 100644
index 0000000000..2ced431f5a
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/available/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ available: true
diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/services.yml
new file mode 100644
index 0000000000..31ada384bf
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/disabled/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ disabled: true
diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/services.yml
new file mode 100644
index 0000000000..88a7919ed1
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ enabled: true
diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml
new file mode 100644
index 0000000000..c299bfc648
--- /dev/null
+++ b/tests/di/fixtures/other_config/services.yml
@@ -0,0 +1,14 @@
+parameters:
+ other_config: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php
index 823d90b63f..b52d68e305 100644
--- a/tests/event/php_exporter_test.php
+++ b/tests/event/php_exporter_test.php
@@ -118,6 +118,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
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'),
+ array('* @since 3.1.0-RC2', '3.1.0-RC2'),
);
}
@@ -137,6 +138,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
array('* @since 3.1.0-a1 bertie is cool'),
array('bertie* @since 3.1.0-a1'),
array('* @since 3.1-A2'),
+ array('* @since 3.1.0-rc1'),
);
}
diff --git a/tests/extension/ext/barfoo/composer.json b/tests/extension/ext/barfoo/composer.json
index d88fd413c9..05bb099707 100644
--- a/tests/extension/ext/barfoo/composer.json
+++ b/tests/extension/ext/barfoo/composer.json
@@ -13,10 +13,12 @@
"role": "N/A"
}],
"require": {
- "php": ">=5.3",
- "phpbb/phpbb": "3.1.*@dev"
+ "php": ">=5.3"
},
"extra": {
- "display-name": "phpBB BarFoo Extension"
+ "display-name": "phpBB BarFoo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
}
}
diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json
index b8fc544c01..d49aab47cd 100644
--- a/tests/extension/ext/vendor/moo/composer.json
+++ b/tests/extension/ext/vendor/moo/composer.json
@@ -13,10 +13,12 @@
"role": "N/A"
}],
"require": {
- "php": ">=5.3",
- "phpbb/phpbb": "3.1.*@dev"
+ "php": ">=5.3"
},
"extra": {
- "display-name": "phpBB Moo Extension"
+ "display-name": "phpBB Moo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
}
}
diff --git a/tests/extension/ext/vendor2/bar/composer.json b/tests/extension/ext/vendor2/bar/composer.json
index 215e7d59db..9d2ed86a0c 100644
--- a/tests/extension/ext/vendor2/bar/composer.json
+++ b/tests/extension/ext/vendor2/bar/composer.json
@@ -12,10 +12,12 @@
"role": "N/A"
}],
"require": {
- "php": ">=5.3",
- "phpbb/phpbb": "3.1.*@dev"
+ "php": ">=5.3"
},
"extra": {
- "display-name": "phpBB Bar Extension"
+ "display-name": "phpBB Bar Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
}
}
diff --git a/tests/extension/ext/vendor2/foo/composer.json b/tests/extension/ext/vendor2/foo/composer.json
index 7b2a80f5d3..efcdfc338f 100644
--- a/tests/extension/ext/vendor2/foo/composer.json
+++ b/tests/extension/ext/vendor2/foo/composer.json
@@ -12,10 +12,12 @@
"role": "N/A"
}],
"require": {
- "php": ">=5.3",
- "phpbb/phpbb": "3.1.*@dev"
+ "php": ">=5.3"
},
"extra": {
- "display-name": "phpBB Foo Extension"
+ "display-name": "phpBB Foo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
}
}
diff --git a/tests/extension/ext/vendor3/foo/composer.json b/tests/extension/ext/vendor3/foo/composer.json
new file mode 100644
index 0000000000..b4b3e6f32f
--- /dev/null
+++ b/tests/extension/ext/vendor3/foo/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "vendor3/foo",
+ "type": "phpbb-extension",
+ "description": "An example/sample extension to be used for testing purposes in phpBB Development.",
+ "version": "1.0.0",
+ "time": "2012-02-15 01:01:01",
+ "license": "GPL-2.0",
+ "authors": [{
+ "name": "John Smith",
+ "email": "email@phpbb.com",
+ "homepage": "http://phpbb.com",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "extra": {
+ "display-name": "phpBB Bar Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/extension/ext/vendor3/foo/ext.php b/tests/extension/ext/vendor3/foo/ext.php
new file mode 100644
index 0000000000..b52649d921
--- /dev/null
+++ b/tests/extension/ext/vendor3/foo/ext.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace vendor3\foo;
+
+class ext extends \phpbb\extension\base
+{
+ static public $enabled;
+
+ public function enable_step($old_state)
+ {
+ self::$enabled = true;
+
+ return self::$enabled;
+ }
+
+ public function is_enableable()
+ {
+ return false;
+ }
+}
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index d9f8fbd1a4..1e43c2a0a3 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/ext/vendor2/bar/ext.php';
require_once dirname(__FILE__) . '/ext/vendor2/foo/ext.php';
+require_once dirname(__FILE__) . '/ext/vendor3/foo/ext.php';
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php';
class phpbb_extension_manager_test extends phpbb_database_test_case
@@ -32,22 +33,62 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->extension_manager = $this->create_extension_manager();
}
- public function test_available()
+ public function test_all_available()
{
// barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure.
- $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_available()));
+ $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo'), array_keys($this->extension_manager->all_available()));
}
- public function test_enabled()
+ public function test_all_enabled()
{
$this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
}
- public function test_configured()
+ public function test_all_configured()
{
$this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
}
+ public function test_is_enabled()
+ {
+ $this->assertSame(true, $this->extension_manager->is_enabled('vendor2/foo'));
+ $this->assertSame(false, $this->extension_manager->is_enabled('vendor/moo'));
+ $this->assertSame(false, $this->extension_manager->is_enabled('vendor2/bar'));
+ $this->assertSame(false, $this->extension_manager->is_enabled('bertie/worlddominationplan'));
+ }
+
+ public function test_is_disabled()
+ {
+ $this->assertSame(false, $this->extension_manager->is_disabled('vendor2/foo'));
+ $this->assertSame(true, $this->extension_manager->is_disabled('vendor/moo'));
+ $this->assertSame(false, $this->extension_manager->is_disabled('vendor2/bar'));
+ $this->assertSame(false, $this->extension_manager->is_disabled('bertie/worlddominationplan'));
+ }
+
+ public function test_is_purged()
+ {
+ $this->assertSame(false, $this->extension_manager->is_purged('vendor2/foo'));
+ $this->assertSame(false, $this->extension_manager->is_purged('vendor/moo'));
+ $this->assertSame(true, $this->extension_manager->is_purged('vendor2/bar'));
+ $this->assertSame(false, $this->extension_manager->is_purged('bertie/worlddominationplan'));
+ }
+
+ public function test_is_configured()
+ {
+ $this->assertSame(true, $this->extension_manager->is_configured('vendor2/foo'));
+ $this->assertSame(true, $this->extension_manager->is_configured('vendor/moo'));
+ $this->assertSame(false, $this->extension_manager->is_configured('vendor2/bar'));
+ $this->assertSame(false, $this->extension_manager->is_configured('bertie/worlddominationplan'));
+ }
+
+ public function test_is_available()
+ {
+ $this->assertSame(true, $this->extension_manager->is_available('vendor2/foo'));
+ $this->assertSame(true, $this->extension_manager->is_available('vendor/moo'));
+ $this->assertSame(true, $this->extension_manager->is_available('vendor2/bar'));
+ $this->assertSame(false, $this->extension_manager->is_available('bertie/worlddominationplan'));
+ }
+
public function test_enable()
{
vendor2\bar\ext::$state = 0;
@@ -60,6 +101,18 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->assertEquals(4, vendor2\bar\ext::$state);
}
+ public function test_enable_not_enableable()
+ {
+ vendor3\foo\ext::$enabled = false;
+
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->extension_manager->enable('vendor3/foo');
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
+
+ $this->assertSame(false, vendor3\foo\ext::$enabled);
+ }
+
public function test_disable()
{
vendor2\foo\ext::$disabled = false;
@@ -95,7 +148,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
protected function create_extension_manager($with_cache = true)
{
- $config = new \phpbb\config\config(array());
+ $config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
$db = $this->new_dbal();
$db_tools = new \phpbb\db\tools($db);
$phpbb_root_path = __DIR__ . './../../phpBB/';
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index 3678ac0a3f..535e4fe0d5 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -19,8 +19,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
protected $cache;
protected $config;
protected $db;
+ protected $db_tools;
+ protected $table_prefix;
protected $phpbb_root_path;
protected $phpEx;
+ protected $migrator;
protected $template;
protected $user;
@@ -50,6 +53,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$this->phpbb_root_path,
$this->phpEx
),
@@ -70,7 +74,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
new \phpbb\db\migration\helper()
);
$container = new phpbb_mock_container_builder();
- $container->set('migrator', $migrator);
+ $container->set('migrator', $this->migrator);
$this->extension_manager = new \phpbb\extension\manager(
$container,
@@ -96,9 +100,10 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{
$manager->get_metadata();
}
- catch(\phpbb\extension\exception $e){}
-
- $this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'));
+ catch (\phpbb\extension\exception $e)
+ {
+ $this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'));
+ }
}
// Should be the same as a direct json_decode of the composer.json file
@@ -112,7 +117,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{
$metadata = $manager->get_metadata();
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
$this->fail($e);
}
@@ -122,64 +127,42 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$this->assertEquals($metadata, $json);
}
- public function test_validator_non_existant()
+ public function validator_non_existing_data()
{
- $ext_name = 'validator';
-
- $manager = $this->get_metadata_manager($ext_name);
-
- // Non-existant data
- try
- {
- $manager->validate('name');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'name'));
- }
-
- try
- {
- $manager->validate('type');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'type'));
- }
-
- try
- {
- $manager->validate('license');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'license'));
- }
+ return array(
+ array('name'),
+ array('type'),
+ array('license'),
+ array('version'),
+ );
+ }
+ /**
+ * @dataProvider validator_non_existing_data
+ */
+ public function test_validator_non_existing($field_name)
+ {
+ $manager = $this->get_metadata_manager('validator');
try
{
- $manager->validate('version');
-
+ $manager->validate($field_name);
$this->fail('Exception not triggered');
}
catch(\phpbb\extension\exception $e)
{
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'version'));
+ $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', $field_name));
}
+ }
+ public function test_validator_non_existing_authors()
+ {
+ $manager = $this->get_metadata_manager('validator');
try
{
$manager->validate_authors();
-
$this->fail('Exception not triggered');
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors'));
}
@@ -193,72 +176,44 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
try
{
$manager->validate_authors();
-
$this->fail('Exception not triggered');
}
- catch(\phpbb\extension\exception $e)
+ catch (\phpbb\extension\exception $e)
{
$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name'));
}
}
-
- public function test_validator_invalid()
+ public function validator_invalid_data()
{
- $ext_name = 'validator';
+ return array(
+ array('name', 'asdf'),
+ array('type', 'asdf'),
+ array('license', ''),
+ array('version', ''),
+ );
+ }
- $manager = $this->get_metadata_manager($ext_name);
+ /**
+ * @dataProvider validator_invalid_data
+ */
+ public function test_validator_invalid($field_name, $field_value)
+ {
+ $manager = $this->get_metadata_manager('validator');
// Invalid data
$manager->set_metadata(array(
- 'name' => 'asdf',
- 'type' => 'asdf',
- 'license' => '',
- 'version' => '',
+ $field_name => $field_value,
));
try
{
- $manager->validate('name');
-
+ $manager->validate($field_name);
$this->fail('Exception not triggered');
}
catch(\phpbb\extension\exception $e)
{
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'name'));
- }
-
- try
- {
- $manager->validate('type');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'type'));
- }
-
- try
- {
- $manager->validate('license');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'license'));
- }
-
- try
- {
- $manager->validate('version');
-
- $this->fail('Exception not triggered');
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'version'));
+ $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name));
}
}
@@ -286,143 +241,83 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
}
}
-
- public function test_validator_requirements()
+ public function validator_requirements_data()
{
- $ext_name = 'validator';
-
- $manager = $this->get_metadata_manager($ext_name);
- // Too high of requirements
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => '10.0.0',
- 'phpbb/phpbb' => '3.2.0', // config is set to 3.1.0
+ return array(
+ array(
+ '10.0.0',
+ '100.2.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
),
- ));
-
- try
- {
- //$this->assertEquals(false, $manager->validate_require_php());
- //$this->assertEquals(false, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
-
-
- // Too high of requirements
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => '5.3.0',
- 'phpbb/phpbb' => '3.1.0-beta', // config is set to 3.1.0
+ array(
+ '5.3.0',
+ '3.1.0-beta',
+ true,
+ true,
),
- ));
-
- try
- {
- $this->assertEquals(true, $manager->validate_require_php());
- $this->assertEquals(true, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
-
-
- // Too high of requirements
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => '>' . phpversion(),
- 'phpbb/phpbb' => '>3.1.0', // config is set to 3.1.0
+ array(
+ '>' . phpversion(),
+ '>3.1.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
),
- ));
-
- try
- {
- //$this->assertEquals(false, $manager->validate_require_php());
- //$this->assertEquals(false, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
-
-
- // Too high of current install
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => '<' . phpversion(),
- 'phpbb/phpbb' => '<3.1.0', // config is set to 3.1.0
+ array(
+ '<' . phpversion(),
+ '<3.1.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
),
- ));
-
- try
- {
- //$this->assertEquals(false, $manager->validate_require_php());
- //$this->assertEquals(false, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
-
-
- // Matching requirements
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => phpversion(),
- 'phpbb/phpbb' => '3.1.0', // config is set to 3.1.0
+ array(
+ phpversion(),
+ '3.1.0',
+ true,
+ true,
),
- ));
-
- try
- {
- $this->assertEquals(true, $manager->validate_require_php());
- $this->assertEquals(true, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
-
-
- // Matching requirements
- $manager->merge_metadata(array(
- 'require' => array(
- 'php' => '>=' . phpversion(),
- 'phpbb/phpbb' => '>=3.1.0', // config is set to 3.1.0
+ array(
+ '>=' . phpversion(),
+ '>=3.1.0',
+ true,
+ true,
),
- ));
+ array(
+ '<=' . phpversion(),
+ '<=3.1.0',
+ true,
+ true,
+ ),
+ );
+ }
- try
- {
- $this->assertEquals(true, $manager->validate_require_php());
- $this->assertEquals(true, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
+ /**
+ * @dataProvider validator_requirements_data
+ */
+ public function test_validator_requirements($php_version, $phpbb_version, $expected_php, $expected_phpbb, $incomplete_reason = '')
+ {
+ if ($incomplete_reason)
{
- $this->fail($e);
+ $this->markTestIncomplete($incomplete_reason);
}
-
- // Matching requirements
+ $ext_name = 'validator';
+ $manager = $this->get_metadata_manager($ext_name);
+ // Too high of requirements
$manager->merge_metadata(array(
'require' => array(
- 'php' => '<=' . phpversion(),
- 'phpbb/phpbb' => '<=3.1.0', // config is set to 3.1.0
+ 'php' => $php_version,
+ ),
+ 'extra' => array(
+ 'soft-require' => array(
+ 'phpbb/phpbb' => $phpbb_version, // config is set to 3.1.0
+ ),
),
));
- try
- {
- $this->assertEquals(true, $manager->validate_require_php());
- $this->assertEquals(true, $manager->validate_require_phpbb());
- }
- catch(\phpbb\extension\exception $e)
- {
- $this->fail($e);
- }
+ $this->assertEquals($expected_php, $manager->validate_require_php());
+ $this->assertEquals($expected_phpbb, $manager->validate_require_phpbb());
}
/**
diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php
index 1aef0d8a0c..c585b17155 100644
--- a/tests/filesystem/clean_path_test.php
+++ b/tests/filesystem/clean_path_test.php
@@ -32,6 +32,8 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case
array('foo/bar/.', 'foo/bar'),
array('./foo/bar', './foo/bar'),
array('../foo/bar', '../foo/bar'),
+ array('./../foo/bar', './../foo/bar'),
+ array('././../foo/bar', './../foo/bar'),
array('one/two/three', 'one/two/three'),
array('one/two/../three', 'one/three'),
array('one/../two/three', 'two/three'),
diff --git a/tests/fixtures/config.php b/tests/fixtures/config.php
new file mode 100644
index 0000000000..ae9e8c22de
--- /dev/null
+++ b/tests/fixtures/config.php
@@ -0,0 +1,3 @@
+<?php
+$foo = 'bar';
+$foo_foo = 'bar bar';
diff --git a/tests/fixtures/config_other.php b/tests/fixtures/config_other.php
new file mode 100644
index 0000000000..e0ecc17bb9
--- /dev/null
+++ b/tests/fixtures/config_other.php
@@ -0,0 +1,3 @@
+<?php
+$bar = 'foo';
+$bar_bar = 'foo foo';
diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php
index dbf197fcfa..6a6df14c81 100644
--- a/tests/functional/download_test.php
+++ b/tests/functional/download_test.php
@@ -205,12 +205,8 @@ class phpbb_functional_download_test extends phpbb_functional_test_case
),
));
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Download Topic #1']}&sid={$this->sid}");
-
$this->add_lang('posting');
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('delete_topic');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Download Topic #1'], 'DELETE_TOPIC');
$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
$this->add_lang('mcp');
diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php
index b6dd5db708..6490c1ead3 100644
--- a/tests/functional/extension_acp_test.php
+++ b/tests/functional/extension_acp_test.php
@@ -84,7 +84,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
$this->assertCount(1, $crawler->filter('.ext_enabled'));
- $this->assertCount(4, $crawler->filter('.ext_disabled'));
+ $this->assertCount(5, $crawler->filter('.ext_disabled'));
$this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text());
$this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text());
@@ -162,6 +162,10 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
$this->assertContains($this->lang('EXTENSION_ENABLE_CONFIRM', 'phpBB Moo Extension'), $crawler->filter('#main')->text());
+
+ // Correctly submit the enable form
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor3%2Ffoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NOT_ENABLEABLE', $crawler->filter('.errorbox')->text());
}
public function test_disable_pre()
diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php
index a474ecf27f..7aa2d0da7d 100644
--- a/tests/functional/feed_test.php
+++ b/tests/functional/feed_test.php
@@ -619,12 +619,8 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case
),
));
- $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);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC');
$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
$this->add_lang('mcp');
diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
index cf36a0523f..29036c821e 100644
--- a/tests/functional/fileupload_form_test.php
+++ b/tests/functional/fileupload_form_test.php
@@ -42,6 +42,8 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
unlink($fileinfo->getPathname());
}
+
+ parent::tearDown();
}
private function upload_file($filename, $mimetype)
@@ -107,9 +109,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
$crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
- // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the
+ // Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the
// DISALLOWED_CONTENT check
- $this->assertEquals($this->lang('UNABLE_GET_IMAGE_SIZE'), $crawler->filter('p.error')->text());
+ $this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text());
}
public function test_too_large()
diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php
index f904258a5c..ef39e1d71b 100644
--- a/tests/functional/fileupload_remote_test.php
+++ b/tests/functional/fileupload_remote_test.php
@@ -11,6 +11,8 @@
*
*/
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+
/**
* @group functional
*/
@@ -43,6 +45,8 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
global $config, $user;
$user = null;
$config = array();
+
+ parent::tearDown();
}
public function test_invalid_extension()
diff --git a/tests/functional/fixtures/ext/foo/bar/composer.json b/tests/functional/fixtures/ext/foo/bar/composer.json
index 2f91426d2a..f0c7f0e6c1 100644
--- a/tests/functional/fixtures/ext/foo/bar/composer.json
+++ b/tests/functional/fixtures/ext/foo/bar/composer.json
@@ -13,10 +13,12 @@
"role": "Developer"
}],
"require": {
- "php": ">=5.3",
- "phpbb/phpbb": "3.1.*@dev"
+ "php": ">=5.3"
},
"extra": {
- "display-name": "phpBB 3.1 Extension Testing"
+ "display-name": "phpBB 3.1 Extension Testing",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
}
}
diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php
index 64fa19557f..c95efc5b2e 100644
--- a/tests/functional/forgot_password_test.php
+++ b/tests/functional/forgot_password_test.php
@@ -57,5 +57,7 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case
'config[allow_password_reset]' => 1,
));
$crawler = self::submit($form);
+
+ parent::tearDown();
}
}
diff --git a/tests/functional/jumpbox_test.php b/tests/functional/jumpbox_test.php
index 9eddcb6bf6..f5a671b1b9 100644
--- a/tests/functional/jumpbox_test.php
+++ b/tests/functional/jumpbox_test.php
@@ -20,18 +20,16 @@ class phpbb_functional_jumpbox_test extends phpbb_functional_test_case
{
$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',
- ));
+ $this->crawler = $this->get_quickmod_page(1, 'MERGE_TOPIC');
+ $this->check_valid_jump('Your first forum');
- $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,
- ));
+ $link = $this->crawler->filter('#jumpbox')->selectLink('Your first category')->link()->getUri();
+ $this->crawler = self::request('GET', substr($link, strpos($link, 'mcp.')));
+ $this->check_valid_jump('Your first category');
+ }
- $crawler = self::submit($form);
- $this->assertContains($this->lang('FORUM') . ': Your first category', $crawler->filter('#cp-main h2')->text());
+ protected function check_valid_jump($forum)
+ {
+ $this->assertContains($this->lang('FORUM') . ": $forum", $this->crawler->filter('#cp-main h2')->text(), $this->crawler->text());
}
}
diff --git a/tests/functional/mcp_test.php b/tests/functional/mcp_test.php
index e4d950ef34..40615d66a5 100644
--- a/tests/functional/mcp_test.php
+++ b/tests/functional/mcp_test.php
@@ -35,11 +35,7 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
public function test_handle_quickmod($crawler)
{
// Test moving a post
- $form = $crawler->selectButton('Go')->eq(1)->form();
- $form['action']->select('merge');
- $crawler = self::submit($form);
-
- return $crawler;
+ return $this->get_quickmod_page(0, 'MERGE_POSTS', $crawler);
}
/**
@@ -68,4 +64,20 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case
$crawler = self::submit($form);
$this->assertContains($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text());
}
+
+ public function test_delete_logs()
+ {
+ $this->login();
+ $crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}");
+ $this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton($this->lang('DELETE_ALL'))->form();
+ $crawler = self::submit($form);
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+
+ $this->assertCount(0, $crawler->filter('input[type=checkbox]'));
+ }
}
diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php
index ee71597ffc..d9faec035c 100644
--- a/tests/functional/plupload_test.php
+++ b/tests/functional/plupload_test.php
@@ -57,6 +57,8 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case
unlink($fileinfo->getPathname());
}
+
+ parent::tearDown();
}
public function get_urls()
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
index 2611ef7bf1..fd802eed45 100644
--- a/tests/functional/posting_test.php
+++ b/tests/functional/posting_test.php
@@ -36,4 +36,27 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
$crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
}
+
+ public function test_unsupported_characters()
+ {
+ $this->login();
+
+ $this->add_lang('posting');
+
+ self::create_post(2,
+ 1,
+ 'Unsupported characters',
+ "This is a test with these weird characters: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6",
+ array(),
+ 'Your message contains the following unsupported characters'
+ );
+
+ self::create_post(2,
+ 1,
+ "Unsupported: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6",
+ 'This is a test with emoji characters in the topic title.',
+ array(),
+ 'Your subject contains the following unsupported characters'
+ );
+ }
}
diff --git a/tests/functional/private_messages_test.php b/tests/functional/private_messages_test.php
new file mode 100644
index 0000000000..1f6dc3a979
--- /dev/null
+++ b/tests/functional/private_messages_test.php
@@ -0,0 +1,69 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_private_messages_test extends phpbb_functional_test_case
+{
+ public function test_setup_config()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=board&mode=message");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ // Set the maximum number of private messages per folder to 1
+ $values['config[pm_max_msgs]'] = 1;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
+ }
+
+ public function test_inbox_full()
+ {
+ $this->login();
+ $message_id = $this->create_private_message('Test private message #1', 'This is a test private message sent by the testing framework.', array(2));
+
+ $crawler = self::request('GET', "ucp.php?i=pm&mode=view&sid{$this->sid}&p={$message_id}");
+ $this->assertContains($this->lang('UCP_PM_VIEW'), $crawler->filter('html')->text());
+
+ $message_id = $this->create_private_message('Test private message #2', 'This is a test private message sent by the testing framework.', array(2));
+
+ $crawler = self::request('GET', "ucp.php?i=pm&mode=view&sid{$this->sid}&p={$message_id}");
+ $this->assertContains($this->lang('NO_AUTH_READ_HOLD_MESSAGE'), $crawler->filter('html')->text());
+ }
+
+ public function test_restore_config()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=board&mode=message");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values['config[pm_max_msgs]'] = 50;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
+ }
+}
diff --git a/tests/functional/ucp_profile_test.php b/tests/functional/ucp_profile_test.php
index ea08eece78..e7abba9255 100644
--- a/tests/functional/ucp_profile_test.php
+++ b/tests/functional/ucp_profile_test.php
@@ -25,13 +25,25 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case
$this->assertContainsLang('UCP_PROFILE_PROFILE_INFO', $crawler->filter('#cp-main h2')->text());
$form = $crawler->selectButton('Submit')->form(array(
+ 'pf_phpbb_facebook' => 'phpbb',
+ 'pf_phpbb_googleplus' => 'phpbb',
'pf_phpbb_location' => 'Bertie´s Empire',
+ 'pf_phpbb_skype' => 'phpbb.skype.account',
+ 'pf_phpbb_twitter' => 'phpbb_twitter',
+ 'pf_phpbb_youtube' => 'phpbb.youtube',
));
+
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->filter('#message')->text());
$crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info');
$form = $crawler->selectButton('Submit')->form();
+
+ $this->assertEquals('phpbb', $form->get('pf_phpbb_facebook')->getValue());
+ $this->assertEquals('phpbb', $form->get('pf_phpbb_googleplus')->getValue());
$this->assertEquals('Bertie´s Empire', $form->get('pf_phpbb_location')->getValue());
+ $this->assertEquals('phpbb.skype.account', $form->get('pf_phpbb_skype')->getValue());
+ $this->assertEquals('phpbb_twitter', $form->get('pf_phpbb_twitter')->getValue());
+ $this->assertEquals('phpbb.youtube', $form->get('pf_phpbb_youtube')->getValue());
}
}
diff --git a/tests/functional/visibility_softdelete_test.php b/tests/functional/visibility_softdelete_test.php
index 5b5f09905c..794f0cde68 100644
--- a/tests/functional/visibility_softdelete_test.php
+++ b/tests/functional/visibility_softdelete_test.php
@@ -186,11 +186,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
'forum_last_post_id' => 0,
), 'before moving #2');
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
-
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('move');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'MOVE_TOPIC');
$this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text());
$this->add_lang('mcp');
@@ -261,12 +257,8 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
), 'before softdeleting #2');
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
-
$this->add_lang('posting');
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('delete_topic');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'DELETE_TOPIC');
$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
$this->add_lang('mcp');
@@ -336,11 +328,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
'forum_last_post_id' => 0,
), 'before moving #2');
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
-
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('move');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'MOVE_TOPIC');
$this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text());
$this->add_lang('mcp');
@@ -484,12 +472,9 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
'forum_last_post_id' => 0,
), 'before splitting #2');
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'SPLIT_TOPIC');
$this->add_lang('mcp');
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('split');
- $crawler = self::submit($form);
$this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text());
$form = $crawler->selectButton('Submit')->form(array(
@@ -546,12 +531,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
),
));
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}");
-
- $form = $crawler->selectButton('Go')->eq(1)->form();
- $form['action']->select('move');
- $crawler = self::submit($form);
-
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MOVE_TOPIC');
$form = $crawler->selectButton('Yes')->form();
$form['to_forum_id']->select($this->data['forums']['Soft Delete #1']);
$crawler = self::submit($form);
@@ -605,9 +585,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
$this->assertContainsLang('BOOKMARK_ADDED', $crawler_bookmark->text());
$this->add_lang('mcp');
- $form = $crawler->selectButton('Go')->eq(1)->form();
- $form['action']->select('merge_topic');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MERGE_TOPIC', $crawler);
$this->assertContainsLang('SELECT_MERGE', $crawler->text());
$crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}");
@@ -670,12 +648,8 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
'forum_last_post_id' => 0,
), 'before forking #2');
- $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
-
$this->add_lang('mcp');
- $form = $crawler->selectButton('Go')->eq(2)->form();
- $form['action']->select('fork');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'FORK_TOPIC');
$this->assertContainsLang('FORK_TOPIC', $crawler->text());
$form = $crawler->selectButton('Yes')->form();
diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php
index 7a70bddc71..06415a424e 100644
--- a/tests/functions/build_url_test.php
+++ b/tests/functions/build_url_test.php
@@ -30,10 +30,11 @@ class phpbb_build_url_test extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
'php'
);
- $phpbb_container->set('path_helper', $path_helper);
+ $phpbb_container->set('path_helper', $phpbb_path_helper);
}
public function build_url_test_data()
{
diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php
index 9647eb341c..729c0a82f0 100644
--- a/tests/functions/convert_30_dbms_to_31_test.php
+++ b/tests/functions/convert_30_dbms_to_31_test.php
@@ -18,7 +18,6 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
public function convert_30_dbms_to_31_data()
{
return array(
- array('firebird'),
array('mssql'),
array('mssql_odbc'),
array('mssqlnative'),
@@ -37,7 +36,8 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
{
$expected = "phpbb\\db\\driver\\$input";
- $output = phpbb_convert_30_dbms_to_31($input);
+ $config_php_file = new \phpbb\config_php_file('', '');
+ $output = $config_php_file->convert_30_dbms_to_31($input);
$this->assertEquals($expected, $output);
}
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php
index 830b52fb4c..e793a4eb82 100644
--- a/tests/functions/obtain_online_test.php
+++ b/tests/functions/obtain_online_test.php
@@ -128,19 +128,19 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
{
return array(
array(0, false, array(
- 'online_userlist' => 'REGISTERED_USERS 2, 3',
+ 'online_userlist' => 'REGISTERED_USERS <span class="username">2</span>, <span class="username">3</span>',
'l_online_users' => 'ONLINE_USERS_TOTAL 5 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3',
)),
array(0, true, array(
- 'online_userlist' => 'REGISTERED_USERS 2, 3',
+ 'online_userlist' => 'REGISTERED_USERS <span class="username">2</span>, <span class="username">3</span>',
'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 7 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3 GUEST_USERS_TOTAL 2',
)),
array(1, false, array(
- 'online_userlist' => 'BROWSING_FORUM 3',
+ 'online_userlist' => 'BROWSING_FORUM <span class="username">3</span>',
'l_online_users' => 'ONLINE_USERS_TOTAL 2 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1',
)),
array(1, true, array(
- 'online_userlist' => 'BROWSING_FORUM_GUESTS 1 3',
+ 'online_userlist' => 'BROWSING_FORUM_GUESTS 1 <span class="username">3</span>',
'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 3 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1 GUEST_USERS_TOTAL 1',
)),
array(2, false, array(
diff --git a/tests/functions_content/get_username_string_test.php b/tests/functions_content/get_username_string_test.php
index 502796d1df..01ec97f6a4 100644
--- a/tests/functions_content/get_username_string_test.php
+++ b/tests/functions_content/get_username_string_test.php
@@ -94,11 +94,11 @@ class phpbb_functions_content_get_username_string_test extends phpbb_test_case
global $phpbb_root_path, $phpEx;
return array(
- array(0, '', '', false, false, 'Guest'),
- array(ANONYMOUS, 'Anonymous', '', false, false, 'Anonymous'),
+ array(0, '', '', false, false, '<span class="username">Guest</span>'),
+ array(ANONYMOUS, 'Anonymous', '', false, false, '<span class="username">Anonymous</span>'),
array(2, 'Administrator', 'FF0000', false, false, '<a href="' . $phpbb_root_path . 'memberlist.' . $phpEx . '?mode=viewprofile&amp;u=2" style="color: #FF0000;" class="username-coloured">Administrator</a>'),
- array(5, 'User5', '', false, 'http://www.example.org/user.php?mode=show', '<a href="http://www.example.org/user.php?mode=show&amp;u=5">User5</a>'),
- array(8, 'Eight', '', false, false, '<a href="' . $phpbb_root_path . 'memberlist.php?mode=viewprofile&amp;u=8">Eight</a>'),
+ array(5, 'User5', '', false, 'http://www.example.org/user.php?mode=show', '<a href="http://www.example.org/user.php?mode=show&amp;u=5" class="username">User5</a>'),
+ array(8, 'Eight', '', false, false, '<a href="' . $phpbb_root_path . 'memberlist.php?mode=viewprofile&amp;u=8" class="username">Eight</a>'),
);
}
@@ -113,10 +113,10 @@ class phpbb_functions_content_get_username_string_test extends phpbb_test_case
public function get_username_string_no_profile_data()
{
return array(
- array(ANONYMOUS, 'Anonymous', '', false, false, 'Anonymous'),
- array(ANONYMOUS, 'Anonymous', '', '', false, 'Guest'),
+ array(ANONYMOUS, 'Anonymous', '', false, false, '<span class="username">Anonymous</span>'),
+ array(ANONYMOUS, 'Anonymous', '', '', false, '<span class="username">Guest</span>'),
array(2, 'Administrator', 'FF0000', false, false, '<span style="color: #FF0000;" class="username-coloured">Administrator</span>'),
- array(8, 'Eight', '', false, false, 'Eight'),
+ array(8, 'Eight', '', false, false, '<span class="username">Eight</span>'),
);
}
diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php
index b7e60c7393..02e0b3912f 100644
--- a/tests/log/function_view_log_test.php
+++ b/tests/log/function_view_log_test.php
@@ -40,7 +40,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -59,7 +59,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -78,7 +78,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -97,7 +97,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -118,7 +118,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -139,7 +139,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -160,7 +160,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -177,11 +177,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'reportee_id' => 2,
'reportee_username' => 'admin',
- 'reportee_username_full'=> 'admin',
+ 'reportee_username_full'=> '<span class="username">admin</span>',
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -196,11 +196,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'reportee_id' => 1,
'reportee_username' => 'Anonymous',
- 'reportee_username_full'=> 'Anonymous',
+ 'reportee_username_full'=> '<span class="username">Anonymous</span>',
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -219,7 +219,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
@@ -238,7 +238,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case
'user_id' => 1,
'username' => 'Anonymous',
- 'username_full' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
'ip' => '127.0.0.1',
'time' => 1,
diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php
index 9f70f8e96c..f9d231258e 100644
--- a/tests/mock/controller_helper.php
+++ b/tests/mock/controller_helper.php
@@ -23,4 +23,9 @@ class phpbb_mock_controller_helper extends \phpbb\controller\helper
$provider->find_routing_files($manager->get_finder());
$this->route_collection = $provider->find($phpbb_root_path_ext)->get_routes();
}
+
+ public function get_current_url()
+ {
+ return '';
+ }
}
diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php
new file mode 100644
index 0000000000..59cdf0bb2b
--- /dev/null
+++ b/tests/mock/phpbb_di_container_builder.php
@@ -0,0 +1,20 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder
+{
+ protected function get_container_filename()
+ {
+ return $this->phpbb_root_path . '../../tmp/container.' . $this->php_ext;
+ }
+}
diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php
index 7e0add2bb5..851c9ec221 100644
--- a/tests/notification/user_list_trim_test.php
+++ b/tests/notification/user_list_trim_test.php
@@ -75,7 +75,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
'post_username' => 'A',
'responders' => null,
),
- 'A replied to the topic “Test”.',
+ '<strong>Reply</strong> from A in topic:',
),
array(
array(
@@ -86,7 +86,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 3),
),
),
- 'A and B replied to the topic “Test”.',
+ '<strong>Reply</strong> from A and <span class="username">B</span> in topic:',
),
array(
array(
@@ -98,7 +98,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 4),
),
),
- 'A, B, and C replied to the topic “Test”.',
+ '<strong>Reply</strong> from A, <span class="username">B</span>, and <span class="username">C</span> in topic:',
),
array(
array(
@@ -111,7 +111,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 5),
),
),
- 'A, B, C, and D replied to the topic “Test”.',
+ '<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and <span class="username">D</span> in topic:',
),
array(
array(
@@ -125,7 +125,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 6),
),
),
- 'A, B, C, and 2 others replied to the topic “Test”.',
+ '<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and 2 others in topic:',
),
);
}
diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php
index a3ad901379..27e94d6a07 100644
--- a/tests/path_helper/path_helper_test.php
+++ b/tests/path_helper/path_helper_test.php
@@ -13,6 +13,7 @@
class phpbb_path_helper_test extends phpbb_test_case
{
+ /** @var \phpbb\path_helper */
protected $path_helper;
protected $phpbb_root_path = '';
@@ -20,13 +21,15 @@ class phpbb_path_helper_test extends phpbb_test_case
{
parent::setUp();
- $this->set_phpbb_root_path();
+ $filesystem = new \phpbb\filesystem();
+ $this->set_phpbb_root_path($filesystem);
$this->path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$this->phpbb_root_path,
'php'
);
@@ -40,9 +43,9 @@ class phpbb_path_helper_test extends phpbb_test_case
* any time we wish to use it in one of these functions (and
* also in general for everything else)
*/
- public function set_phpbb_root_path()
+ public function set_phpbb_root_path($filesystem)
{
- $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/';
+ $this->phpbb_root_path = $filesystem->clean_path(dirname(__FILE__) . '/../../phpBB/');
}
public function test_get_web_root_path()
@@ -53,7 +56,8 @@ class phpbb_path_helper_test extends phpbb_test_case
public function basic_update_web_root_path_data()
{
- $this->set_phpbb_root_path();
+ $filesystem = new \phpbb\filesystem();
+ $this->set_phpbb_root_path($filesystem);
return array(
array(
@@ -71,7 +75,7 @@ class phpbb_path_helper_test extends phpbb_test_case
),
array(
$this->phpbb_root_path . $this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . $this->phpbb_root_path . 'test.php',
+ $filesystem->clean_path($this->phpbb_root_path . $this->phpbb_root_path . 'test.php'),
),
);
}
@@ -81,51 +85,55 @@ class phpbb_path_helper_test extends phpbb_test_case
*/
public function test_basic_update_web_root_path($input, $expected)
{
- $this->assertEquals($expected, $this->path_helper->update_web_root_path($input, $symfony_request));
+ $this->assertEquals($expected, $this->path_helper->update_web_root_path($input));
}
public function update_web_root_path_data()
{
- $this->set_phpbb_root_path();
+ $this->set_phpbb_root_path(new \phpbb\filesystem());
return array(
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . 'test.php',
'/',
+ null,
+ null,
+ '',
),
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . '../test.php',
'//',
+ null,
+ null,
+ './../',
),
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . '../test.php',
'//',
'foo/bar.php',
'bar.php',
+ './../',
),
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . '../../test.php',
'/foo/template',
'/phpbb3-fork/phpBB/app.php/foo/template',
'/phpbb3-fork/phpBB/app.php',
+ './../../',
),
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . '../test.php',
'/foo/template',
'/phpbb3-fork/phpBB/foo/template',
'/phpbb3-fork/phpBB/app.php',
+ './../',
),
array(
$this->phpbb_root_path . 'test.php',
- $this->phpbb_root_path . '../test.php',
'/',
'/phpbb3-fork/phpBB/app.php/',
'/phpbb3-fork/phpBB/app.php',
+ './../',
),
);
}
@@ -133,9 +141,9 @@ class phpbb_path_helper_test extends phpbb_test_case
/**
* @dataProvider update_web_root_path_data
*/
- public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null)
+ public function test_update_web_root_path($input, $getPathInfo, $getRequestUri, $getScriptName, $correction)
{
- $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array(
+ $symfony_request = $this->getMock('\phpbb\symfony_request', array(), array(
new phpbb_mock_request(),
));
$symfony_request->expects($this->any())
@@ -151,11 +159,12 @@ class phpbb_path_helper_test extends phpbb_test_case
$path_helper = new \phpbb\path_helper(
$symfony_request,
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$this->phpbb_root_path,
'php'
);
- $this->assertEquals($expected, $path_helper->update_web_root_path($input, $symfony_request));
+ $this->assertEquals($correction . $input, $path_helper->update_web_root_path($input, $symfony_request));
}
public function clean_url_data()
@@ -331,4 +340,58 @@ class phpbb_path_helper_test extends phpbb_test_case
{
$this->assertEquals($expected, $this->path_helper->append_url_params($url, $params, $is_amp));
}
+
+ public function get_web_root_path_from_ajax_referer_data()
+ {
+ return array(
+ array(
+ 'http://www.phpbb.com/community/route1/route2/',
+ 'http://www.phpbb.com/community',
+ '../../',
+ ),
+ array(
+ 'http://www.phpbb.com/community/route1/route2',
+ 'http://www.phpbb.com/community',
+ '../',
+ ),
+ array(
+ 'http://www.phpbb.com/community/route1',
+ 'http://www.phpbb.com/community',
+ '',
+ ),
+ array(
+ 'http://www.phpbb.com/community/',
+ 'http://www.phpbb.com/community',
+ '',
+ ),
+ array(
+ 'http://www.phpbb.com/notcommunity/route1/route2/',
+ 'http://www.phpbb.com/community',
+ '../../../community/',
+ ),
+ array(
+ 'http://www.phpbb.com/notcommunity/route1/route2',
+ 'http://www.phpbb.com/community',
+ '../../community/',
+ ),
+ array(
+ 'http://www.phpbb.com/notcommunity/route1',
+ 'http://www.phpbb.com/community',
+ '../community/',
+ ),
+ array(
+ 'http://www.phpbb.com/notcommunity/',
+ 'http://www.phpbb.com/community',
+ '../community/',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_web_root_path_from_ajax_referer_data
+ */
+ public function test_get_web_root_path_from_ajax_referer($referer_url, $board_url, $expected)
+ {
+ $this->assertEquals($this->phpbb_root_path . $expected, $this->path_helper->get_web_root_path_from_ajax_referer($referer_url, $board_url));
+ }
}
diff --git a/tests/profile/custom_string_test.php b/tests/profile/custom_string_test.php
deleted file mode 100644
index 9e45d05ae3..0000000000
--- a/tests/profile/custom_string_test.php
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
-
-class phpbb_profile_custom_string_test extends phpbb_database_test_case
-{
- public function getDataSet()
- {
- return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/profile_fields.xml');
- }
-
- static public function string_fields()
- {
- return array(
- // note, there is an offset of 1 between option_id (0-indexed)
- // in the database and values (1-indexed) to avoid problems with
- // transmitting 0 in an HTML form
- // required, value, validation, expected, description
- array(
- 1,
- 'H3110',
- '[0-9]+',
- 'FIELD_INVALID_CHARS_NUMBERS_ONLY-field',
- 'Required field should reject characters in a numbers-only field',
- ),
- array(
- 1,
- 'This string is too long',
- '.*',
- 'FIELD_TOO_LONG-10-field',
- 'Required field should reject a field too long',
- ),
- array(
- 0,
- '&lt;&gt;&quot;&amp;%&amp;&gt;&lt;&gt;',
- '.*',
- false,
- 'Optional field should accept html entities',
- ),
- array(
- 1,
- 'ö ä ü ß',
- '.*',
- false,
- 'Required field should accept UTF-8 string',
- ),
- array(
- 1,
- 'This ö ä string has to b',
- '.*',
- 'FIELD_TOO_LONG-10-field',
- 'Required field should reject an UTF-8 string which is too long',
- ),
- array(
- 1,
- 'ö äö äö ä',
- '[\w]+',
- 'FIELD_INVALID_CHARS_ALPHA_ONLY-field',
- 'Required field should reject UTF-8 in alpha only field',
- ),
- array(
- 1,
- 'Hello',
- '[\w]+',
- false,
- 'Required field should accept a characters only field',
- ),
- );
- }
-
- /**
- * @dataProvider string_fields
- */
- public function test_string_validate($field_required, $field_value, $field_validation, $expected, $description)
- {
- $db = $this->new_dbal();
-
- $field_data = array(
- 'field_id' => 1,
- 'lang_id' => 1,
- 'lang_name' => 'field',
- 'field_novalue' => 1,
- 'field_required' => $field_required,
- 'field_maxlen' => 10,
- 'field_validation' => $field_validation,
- );
- $user = $this->getMock('\phpbb\user');
- $user->expects($this->any())
- ->method('lang')
- ->will($this->returnCallback(array($this, 'return_callback_implode')));
-
- $request = $this->getMock('\phpbb\request\request');
- $template = $this->getMock('\phpbb\template\template');
-
- $cp = new \phpbb\profilefields\type\type_string(
- $request,
- $template,
- $user
- );
- $result = $cp->validate_profile_field($field_value, $field_data);
-
- $this->assertEquals($expected, $result, $description);
- }
-
- public function return_callback_implode()
- {
- return implode('-', func_get_args());
- }
-}
diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php
deleted file mode 100644
index 8570e8e6ee..0000000000
--- a/tests/profile/custom_test.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-class phpbb_profile_custom_test extends phpbb_database_test_case
-{
- public function getDataSet()
- {
- return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/profile_fields.xml');
- }
-
- static public function dropdown_fields()
- {
- return array(
- // note, there is an offset of 1 between option_id (0-indexed)
- // in the database and values (1-indexed) to avoid problems with
- // transmitting 0 in an HTML form
- // required, value, expected
- array(1, '0', 'FIELD_INVALID_VALUE-field', 'Required field should throw error for out-of-range value'),
- array(1, '1', 'FIELD_REQUIRED-field', 'Required field should throw error for default value'),
- array(1, '2', false, 'Required field should accept non-default value'),
- array(0, '0', 'FIELD_INVALID_VALUE-field', 'Optional field should throw error for out-of-range value'),
- array(0, '1', false, 'Optional field should accept default value'),
- array(0, '2', false, 'Optional field should accept non-default value'),
- );
- }
-
- /**
- * @dataProvider dropdown_fields
- */
- public function test_dropdown_validate($field_required, $field_value, $expected, $description)
- {
- global $db, $table_prefix;
- $db = $this->new_dbal();
-
- $field_data = array(
- 'field_id' => 1,
- 'lang_id' => 1,
- 'lang_name' => 'field',
- 'field_novalue' => 1,
- 'field_required' => $field_required,
- );
- $user = $this->getMock('\phpbb\user');
- $user->expects($this->any())
- ->method('lang')
- ->will($this->returnCallback(array($this, 'return_callback_implode')));
-
- $request = $this->getMock('\phpbb\request\request');
- $template = $this->getMock('\phpbb\template\template');
-
- $cp = new \phpbb\profilefields\type\type_dropdown(
- new \phpbb\profilefields\lang_helper($db, $table_prefix . 'profile_fields_lang'),
- $request,
- $template,
- $user
- );
- $result = $cp->validate_profile_field($field_value, $field_data);
-
- $this->assertEquals($expected, $result, $description);
- }
-
- public function return_callback_implode()
- {
- return implode('-', func_get_args());
- }
-}
diff --git a/tests/profile/fixtures/profile_fields.xml b/tests/profile/fixtures/profile_fields.xml
deleted file mode 100644
index e0c260bbf5..0000000000
--- a/tests/profile/fixtures/profile_fields.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<dataset>
- <table name="phpbb_profile_fields_lang">
- <column>field_id</column>
- <column>lang_id</column>
- <column>option_id</column>
- <column>field_type</column>
- <column>lang_value</column>
- <row>
- <value>1</value>
- <value>1</value>
- <value>0</value>
- <value>profilefields.type.dropdown</value>
- <value>Default Option</value>
- </row>
- <row>
- <value>1</value>
- <value>1</value>
- <value>1</value>
- <value>profilefields.type.dropdown</value>
- <value>First Alternative</value>
- </row>
- <row>
- <value>1</value>
- <value>1</value>
- <value>2</value>
- <value>profilefields.type.dropdown</value>
- <value>Third Alternative</value>
- </row>
- </table>
-</dataset>
diff --git a/tests/profile/get_profile_value_test.php b/tests/profile/get_profile_value_test.php
deleted file mode 100644
index 7a4a4ab5c2..0000000000
--- a/tests/profile/get_profile_value_test.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-class phpbb_profile_get_profile_value_test extends phpbb_test_case
-{
- static public function get_profile_value_int_data()
- {
- return array(
- array('\phpbb\profilefields\type\type_int', '10', true, 10),
- array('\phpbb\profilefields\type\type_int', '0', true, 0),
- array('\phpbb\profilefields\type\type_int', '', true, 0),
- array('\phpbb\profilefields\type\type_int', null, true, 0),
- array('\phpbb\profilefields\type\type_int', '10', false, 10),
- array('\phpbb\profilefields\type\type_int', '0', false, 0),
- array('\phpbb\profilefields\type\type_int', '', false, null),
- array('\phpbb\profilefields\type\type_int', null, false, null),
- );
- }
-
- /**
- * @dataProvider get_profile_value_int_data
- */
- public function test_get_profile_value_int($type, $value, $show_novalue, $expected)
- {
- $cp = new $type(
- $this->getMock('\phpbb\request\request'),
- $this->getMock('\phpbb\template\template'),
- $this->getMock('\phpbb\user')
- );
-
- $this->assertSame($expected, $cp->get_profile_value($value, array(
- 'field_type' => $type,
- 'field_show_novalue' => $show_novalue,
- )));
- }
-}
diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php
new file mode 100644
index 0000000000..bdab179c8c
--- /dev/null
+++ b/tests/profilefields/type_bool_test.php
@@ -0,0 +1,195 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_profilefield_type_bool_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options = array();
+ protected $options = array();
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return void
+ */
+ public function setUp()
+ {
+ $user = $this->getMock('\phpbb\user');
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $lang = $this->getMock('\phpbb\profilefields\lang_helper', array(), array(null, null));
+
+ $lang->expects($this->any())
+ ->method('get_options_lang');
+
+ $lang->expects($this->any())
+ ->method('is_set')
+ ->will($this->returnCallback(array($this, 'is_set_callback')));
+
+ $lang->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'get')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_bool(
+ $lang,
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_bool',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ 'field_default_value' => 1,
+ 'field_length' => 1,
+ );
+
+ $this->options = array(
+ 0 => 'Yes',
+ 1 => 'No',
+ );
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ false,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should not accept empty values for required fields',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_data()
+ {
+ return array(
+ array(
+ false,
+ array('field_show_novalue' => true),
+ 'No',
+ 'Field should output the default value',
+ ),
+ array(
+ false,
+ array('field_show_novalue' => false, 'field_length' => 2),
+ null,
+ 'Field should not show anything for empty value',
+ ),
+ array(
+ 0,
+ array(),
+ 'Yes',
+ 'Field should show the set value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_data
+ */
+ public function test_get_profile_value($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ '4',
+ array('field_show_novalue' => true),
+ '4',
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should return correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ null,
+ 'Field should return correct raw value',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => false),
+ null,
+ 'Field should return correct raw value',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => true),
+ null,
+ 'Field should return correct raw value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function is_set_callback($field_id, $lang_id, $field_value)
+ {
+ return isset($this->options[$field_value]);
+ }
+
+ public function get($field_id, $lang_id, $field_value)
+ {
+ return $this->options[$field_value];
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}
diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php
new file mode 100644
index 0000000000..0ad2cde9fe
--- /dev/null
+++ b/tests/profilefields/type_date_test.php
@@ -0,0 +1,228 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_profilefield_type_date_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options;
+ protected $user;
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ $this->user = $this->getMock('\phpbb\user');
+ $this->user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $this->user->expects($this->any())
+ ->method('create_datetime')
+ ->will($this->returnCallback(array($this, 'create_datetime_callback')));
+
+ $this->user->timezone = new DateTimeZone('UTC');
+ $this->user->lang = array(
+ 'datetime' => array(),
+ 'DATE_FORMAT' => 'm/d/Y',
+ );
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_date(
+ $request,
+ $template,
+ $this->user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_date',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ );
+ }
+
+ public function profile_value_data()
+ {
+ return array(
+ array(
+ '01-01-2009',
+ array('field_show_novalue' => true),
+ '01/01/2009',
+ 'Field should output the correctly formatted date',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => false),
+ null,
+ 'Field should leave empty value as is',
+ ),
+ array(
+ 'None',
+ array('field_show_novalue' => true),
+ 'None',
+ 'Field should leave invalid value as is',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_data
+ */
+ public function test_get_profile_value($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ '',
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being empty',
+ ),
+ array(
+ '0125',
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ '01-01-2012',
+ array(),
+ false,
+ 'Field should accept a valid value',
+ ),
+ array(
+ '40-05-2009',
+ array(),
+ 'FIELD_INVALID_DATE-field',
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ '12-30-2012',
+ array(),
+ 'FIELD_INVALID_DATE-field',
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ 'string',
+ array(),
+ false,
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ 'string',
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ 100,
+ array(),
+ false,
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ 100,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being invalid',
+ ),
+ array(
+ null,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being empty',
+ ),
+ array(
+ true,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should reject value for being empty',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ '',
+ 'Field should return correct raw value',
+ ),
+ array(
+ '12/06/2014',
+ array('field_show_novalue' => true),
+ '12/06/2014',
+ 'Field should return correct raw value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+
+ public function create_datetime_callback($time = 'now', \DateTimeZone $timezone = null)
+ {
+ $timezone = $timezone ?: $this->user->timezone;
+ return new \phpbb\datetime($this->user, $time, $timezone);
+ }
+}
diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php
new file mode 100644
index 0000000000..ebecbf97f0
--- /dev/null
+++ b/tests/profilefields/type_dropdown_test.php
@@ -0,0 +1,235 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_profilefield_type_dropdown_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options = array();
+ protected $dropdown_options = array();
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ $user = $this->getMock('\phpbb\user');
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $lang = $this->getMock('\phpbb\profilefields\lang_helper', array(), array(null, null));
+
+ $lang->expects($this->any())
+ ->method('get_options_lang');
+
+ $lang->expects($this->any())
+ ->method('is_set')
+ ->will($this->returnCallback(array($this, 'is_set_callback')));
+
+ $lang->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'get')));
+
+ $this->cp = new \phpbb\profilefields\type\type_dropdown(
+ $lang,
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_dropdown',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ 'field_validation' => '.*',
+ 'field_novalue' => 0,
+ );
+
+ $this->dropdown_options = array(
+ 0 => '<No Value>',
+ 1 => 'Option 1',
+ 2 => 'Option 2',
+ 3 => 'Option 3',
+ 4 => 'Option 4',
+ );
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ 7,
+ array(),
+ 'FIELD_INVALID_VALUE-field',
+ 'Invalid value should throw error',
+ ),
+ array(
+ true,
+ array('field_required' => true),
+ false,
+ 'Boolean would evaluate to 1 and hence correct value',
+ ),
+ array(
+ 'string',
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'String should be rejected for value',
+ ),
+ array(
+ 2,
+ array(),
+ false,
+ 'Valid value should not throw error'
+ ),
+ array(
+ 0,
+ array(),
+ false,
+ 'Empty value should be acceptible',
+ ),
+ array(
+ 0,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Required field should not accept empty value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_data()
+ {
+ return array(
+ array(
+ 1,
+ array('field_show_novalue' => true),
+ 'Option 1',
+ 'Field should output the given value',
+ ),
+ array(
+ 4,
+ array('field_show_novalue' => false),
+ 'Option 4',
+ 'Field should output the given value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ '<No Value>',
+ 'Field should output nothing for empty value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should simply output null for empty value',
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider profile_value_data
+ */
+ public function test_get_profile_value($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ '4',
+ array('field_show_novalue' => true),
+ '4',
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should null for empty value without show_novalue',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should return 0 for empty value with show_novalue',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => false),
+ null,
+ 'Field should return correct raw value',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should return 0 for empty value with show_novalue',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function is_set_callback($field_id, $lang_id, $field_value)
+ {
+ return isset($this->dropdown_options[$field_value]);
+ }
+
+ public function get($field_id, $lang_id, $field_value)
+ {
+ return $this->dropdown_options[$field_value];
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}
diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php
new file mode 100644
index 0000000000..fdbdd86553
--- /dev/null
+++ b/tests/profilefields/type_googleplus_test.php
@@ -0,0 +1,62 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_profilefield_type_googleplus_test extends phpbb_test_case
+{
+ public function get_profile_contact_value_data()
+ {
+ return array(
+ array(
+ '112010191010100',
+ array(),
+ '112010191010100',
+ 'Field should return a numerical Google+ ID as is',
+ ),
+ array(
+ 'TestUsername',
+ array(),
+ '+TestUsername',
+ 'Field should return a string Google+ ID with a + prefixed',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_profile_contact_value_data
+ */
+ public function test_get_profile_contact_value($value, $field_options, $expected, $description)
+ {
+ $user = $this->getMock('\phpbb\user');
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $field = new \phpbb\profilefields\type\type_googleplus(
+ $request,
+ $template,
+ $user
+ );
+
+ $default_field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_googleplus',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ 'field_validation' => '[\w]+',
+ );
+ $field_options = array_merge($default_field_options, $field_options);
+
+ $this->assertSame($expected, $field->get_profile_contact_value($value, $field_options), $description);
+ }
+}
diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php
new file mode 100644
index 0000000000..ac48c10a84
--- /dev/null
+++ b/tests/profilefields/type_int_test.php
@@ -0,0 +1,236 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_profilefield_type_int_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options;
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ $user = $this->getMock('\phpbb\user');
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_int(
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_int',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ );
+ }
+
+ public function profile_value_data()
+ {
+ return array(
+ array(
+ '10',
+ array('field_show_novalue' => true),
+ 10,
+ 'Field should output integer value of given input',
+ ),
+ array(
+ '0',
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should output integer value of given input',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should translate empty value to 0 as integer',
+ false,
+ ),
+ array(
+ null,
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should translate null value to 0 as integer',
+ ),
+ array(
+ '10',
+ array('field_show_novalue' => false),
+ 10,
+ 'Field should output integer value of given input',
+ ),
+ array(
+ '0',
+ array('field_show_novalue' => false),
+ 0,
+ 'Field should output integer value of given input',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should leave empty value as is',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => false),
+ null,
+ 'Field should leave empty value as is',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_data
+ */
+ public function test_get_profile_value($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ '15',
+ array('field_minlen' => 10, 'field_maxlen' => 20, 'field_required' => true),
+ false,
+ 'Field should accept input of correct boundaries',
+ ),
+ array(
+ '556476',
+ array('field_maxlen' => 50000, 'field_required' => true),
+ 'FIELD_TOO_LARGE-50000-field',
+ 'Field should reject value of greater value than max',
+ ),
+ array(
+ '9',
+ array('field_minlen' => 10, 'field_required' => true),
+ 'FIELD_TOO_SMALL-10-field',
+ 'Field should reject value which is less than defined minimum',
+ ),
+ array(
+ true,
+ array('field_maxlen' => 20),
+ false,
+ 'Field should accept correct boolean value',
+ ),
+ array(
+ 'string',
+ array('field_maxlen' => 10, 'field_required' => true),
+ false,
+ 'Field should accept correct string value',
+ ),
+ array(
+ null,
+ array('field_minlen' => 1, 'field_maxlen' => 10, 'field_required' => true),
+ 'FIELD_TOO_SMALL-1-field',
+ 'Field should not accept an empty value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ '10',
+ array('field_show_novalue' => true),
+ 10,
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '0',
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should return correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should return correct raw value',
+ ),
+ array(
+ '10',
+ array('field_show_novalue' => false),
+ 10,
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '0',
+ array('field_show_novalue' => false),
+ 0,
+ 'Field should return correct raw value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should return correct raw value',
+ ),
+ array(
+ 'string',
+ array('field_show_novalue' => false),
+ 0,
+ 'Field should return int cast of passed string'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}
diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php
new file mode 100644
index 0000000000..2277526758
--- /dev/null
+++ b/tests/profilefields/type_string_test.php
@@ -0,0 +1,292 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_profilefield_type_string_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options;
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ global $request, $user, $cache;
+
+ $user = $this->getMock('\phpbb\user');
+ $cache = new phpbb_mock_cache;
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_string(
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_string',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ 'field_validation' => '.*',
+ );
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ '',
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should not accept empty values for required fields',
+ ),
+ array(
+ null,
+ array('field_required' => true),
+ 'FIELD_REQUIRED-field',
+ 'Field should not accept empty values for required field',
+ ),
+ array(
+ 0,
+ array('field_required' => true),
+ false,
+ 'Field should accept a non-empty input',
+ ),
+ array(
+ 'false',
+ array('field_required' => true),
+ false,
+ 'Field should accept a non-empty input',
+ ),
+ array(
+ 10,
+ array('field_required' => true),
+ false,
+ 'Field should accept a non-empty input',
+ ),
+ array(
+ 'tas',
+ array('field_minlen' => 2, 'field_maxlen' => 5),
+ false,
+ 'Field should accept value of correct length',
+ ),
+ array(
+ 't',
+ array('field_minlen' => 2, 'field_maxlen' => 5),
+ 'FIELD_TOO_SHORT-2-field',
+ 'Field should reject value of incorrect length',
+ ),
+ array(
+ 'this is a long string',
+ array('field_minlen' => 2, 'field_maxlen' => 5),
+ 'FIELD_TOO_LONG-5-field',
+ 'Field should reject value of incorrect length',
+ ),
+ array(
+ 'H3110',
+ array('field_validation' => '[0-9]+'),
+ 'FIELD_INVALID_CHARS_NUMBERS_ONLY-field',
+ 'Required field should reject characters in a numbers-only field',
+ ),
+ array(
+ '&lt;&gt;&quot;&amp;%&amp;&gt;&lt;&gt;',
+ array('field_maxlen' => 10, 'field_minlen' => 2),
+ false,
+ 'Optional field should accept html entities',
+ ),
+ array(
+ 'ö ä ü ß',
+ array(),
+ false,
+ 'Required field should accept UTF-8 string',
+ ),
+ array(
+ 'This ö ä string has to b',
+ array('field_maxlen' => 10),
+ 'FIELD_TOO_LONG-10-field',
+ 'Required field should reject an UTF-8 string which is too long',
+ ),
+ array(
+ 'ö äö äö ä',
+ array('field_validation' => '[\w]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_ONLY-field',
+ 'Required field should reject UTF-8 in alpha only field',
+ ),
+ array(
+ 'Hello',
+ array('field_validation' => '[\w]+'),
+ false,
+ 'Required field should accept a characters only field',
+ ),
+ array(
+ 'Valid.Username123',
+ array('field_validation' => '[\w.]+'),
+ false,
+ 'Required field should accept a alphanumeric field with dots',
+ ),
+ array(
+ 'Invalid.,username123',
+ array('field_validation' => '[\w.]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_DOTS-field',
+ 'Required field should reject field with comma',
+ ),
+ array(
+ 'skype.test.name,_this',
+ array('field_validation' => '[a-zA-Z][\w\.,\-_]+'),
+ false,
+ 'Required field should accept alphanumeric field with punctuations',
+ ),
+ array(
+ '1skype.this.should.faila',
+ array('field_validation' => '[a-zA-Z][\w\.,\-_]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_PUNCTUATION-field',
+ 'Required field should reject field having invalid input for the given validation',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_data()
+ {
+ return array(
+ array(
+ 'test',
+ array('field_show_novalue' => true),
+ 'test',
+ 'Field should output the given value',
+ ),
+ array(
+ 'test',
+ array('field_show_novalue' => false),
+ 'test',
+ 'Field should output the given value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => true),
+ '',
+ 'Field should output nothing for empty value',
+ ),
+ array(
+ '',
+ array('field_show_novalue' => false),
+ null,
+ 'Field should simply output null for empty vlaue',
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider profile_value_data
+ */
+ public function test_get_profile_value($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ '[b]bbcode test[/b]',
+ array('field_show_novalue' => true),
+ '[b]bbcode test[/b]',
+ 'Field should return the correct raw value',
+ ),
+ array(
+ '[b]bbcode test[/b]',
+ array('field_show_novalue' => false),
+ '[b]bbcode test[/b]',
+ 'Field should return correct raw value',
+ ),
+ array(
+ 125,
+ array('field_show_novalue' => false),
+ 125,
+ 'Field should return value of integer as is',
+ ),
+ array(
+ 0,
+ array('field_show_novalue' => false),
+ 0,
+ 'Field should return value of integer 0 without show_novalue',
+ ),
+ array(
+ '0',
+ array('field_show_novalue' => false),
+ '0',
+ 'Field should return string 0',
+ ),
+ array(
+ 0,
+ array('field_show_novalue' => true),
+ 0,
+ 'Field should return 0 for empty integer with show_novalue',
+ ),
+ array(
+ null,
+ array('field_show_novalue' => true),
+ null,
+ 'field should return null value as is',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}
diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php
new file mode 100644
index 0000000000..a45a28e7c7
--- /dev/null
+++ b/tests/profilefields/type_url_test.php
@@ -0,0 +1,141 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_profilefield_type_url_test extends phpbb_test_case
+{
+ protected $cp;
+ protected $field_options;
+
+ /**
+ * Sets up basic test objects
+ *
+ * @access public
+ * @return null
+ */
+ public function setUp()
+ {
+ $user = $this->getMock('\phpbb\user');
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->cp = new \phpbb\profilefields\type\type_url(
+ $request,
+ $template,
+ $user
+ );
+
+ $this->field_options = array(
+ 'field_type' => '\phpbb\profilefields\type\type_url',
+ 'field_name' => 'field',
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'lang_name' => 'field',
+ 'field_required' => false,
+ );
+ }
+
+ public function validate_profile_field_data()
+ {
+ return array(
+ array(
+ '',
+ array('field_required' => true),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject empty field that is required',
+ ),
+ array(
+ 'invalidURL',
+ array(),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject invalid input',
+ ),
+ array(
+ 'http://onetwothree.example.io',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html?param1=test&param2=awesome',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html/test/path?document=get',
+ array(),
+ false,
+ 'Field should accept valid URL',
+ ),
+ array(
+ 'http://example.com/index.html/test/path?document[]=DocType%20test&document[]=AnotherDoc',
+ array(),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject invalid URL having multi value parameters',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_profile_field_data
+ */
+ public function test_validate_profile_field($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->validate_profile_field($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function profile_value_raw_data()
+ {
+ return array(
+ array(
+ 'http://example.com',
+ array('field_show_novalue' => true),
+ 'http://example.com',
+ 'Field should return the correct raw value',
+ ),
+ array(
+ 'http://example.com',
+ array('field_show_novalue' => false),
+ 'http://example.com',
+ 'Field should return correct raw value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider profile_value_raw_data
+ */
+ public function test_get_profile_value_raw($value, $field_options, $expected, $description)
+ {
+ $field_options = array_merge($this->field_options, $field_options);
+
+ $result = $this->cp->get_profile_value_raw($value, $field_options);
+
+ $this->assertSame($expected, $result, $description);
+ }
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+}
diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php
index fb1011cde0..3961c2781e 100644
--- a/tests/security/redirect_test.php
+++ b/tests/security/redirect_test.php
@@ -63,6 +63,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$this->phpbb_root_path,
'php'
);
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index ce3c90b78a..c415c969fe 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -143,6 +143,7 @@ Zeta test event in all',
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 4f5b7629d5..0bbfe3848d 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -352,6 +352,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
"13FOOBAR|foobar",
),
+ array(
+ 'if_nested_tags.html',
+ array('S_VALUE' => true,),
+ array(),
+ array(),
+ 'inner_value',
+ ),
);
}
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 00b823b2c4..83446b5352 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -72,6 +72,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 4f778a9c1c..68ecc4b706 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -27,6 +27,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
new phpbb_mock_request()
),
new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
diff --git a/tests/template/templates/if_nested_tags.html b/tests/template/templates/if_nested_tags.html
new file mode 100644
index 0000000000..0348a31a8d
--- /dev/null
+++ b/tests/template/templates/if_nested_tags.html
@@ -0,0 +1 @@
+<!-- IF S_VALUE --><!-- DEFINE $INNER_VALUE = 'inner_value' --><!-- ENDIF -->{$INNER_VALUE}
diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
index 22d55b4ed5..db31edc984 100644
--- a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
+++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
@@ -25,7 +25,7 @@ if (!class_exists('PDO'))
*/
class phpbb_database_connection_odbc_pdo_wrapper extends PDO
{
- // Name of the driver being used (i.e. mssql, firebird)
+ // Name of the driver being used (i.e. mssql)
public $driver = '';
// Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index 1f3a564205..46276bcfcb 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -145,25 +145,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
public function createXMLDataSet($path)
{
- $db_config = $this->get_database_config();
-
- // Firebird requires table and column names to be uppercase
- if ($db_config['dbms'] == 'phpbb\db\driver\firebird')
- {
- $xml_data = file_get_contents($path);
- $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
- $xml_data = preg_replace_callback('/(?:(<column>))([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data);
-
- $new_fixture = tmpfile();
- fwrite($new_fixture, $xml_data);
- fseek($new_fixture, 0);
-
- $meta_data = stream_get_meta_data($new_fixture);
- $path = $meta_data['uri'];
- }
-
$this->fixture_xml_data = parent::createXMLDataSet($path);
-
return $this->fixture_xml_data;
}
@@ -244,19 +226,6 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
return new phpbb_database_test_connection_manager($config);
}
- /**
- * Converts a match in the middle of a string to uppercase.
- * This is necessary for transforming the fixture information for Firebird tests
- *
- * @param $matches The array of matches from a regular expression
- *
- * @return string The string with the specified match converted to uppercase
- */
- static public function to_upper($matches)
- {
- return $matches[1] . strtoupper($matches[2]) . $matches[3];
- }
-
public function assert_array_content_equals($one, $two)
{
// http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index b73b05025e..92e2080dba 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -116,7 +116,7 @@ class phpbb_database_test_connection_manager
// These require different connection strings on the phpBB side than they do in PDO
// so you must provide a DSN string for ODBC separately
- if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb\db\driver\mssql' || $this->config['dbms'] == 'phpbb\db\driver\firebird'))
+ if (!empty($this->config['custom_dsn']) && $this->config['dbms'] == 'phpbb\db\driver\mssql')
{
$dsn = 'odbc:' . $this->config['custom_dsn'];
}
@@ -130,14 +130,6 @@ class phpbb_database_test_connection_manager
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break;
- case 'phpbb\db\driver\firebird':
- if (!empty($this->config['custom_dsn']))
- {
- $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
- break;
- }
- // Fall through if they're using the firebird PDO driver and not the generic ODBC driver
-
default:
$this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break;
@@ -197,7 +189,6 @@ class phpbb_database_test_connection_manager
{
case 'phpbb\db\driver\sqlite':
case 'phpbb\db\driver\sqlite3':
- case 'phpbb\db\driver\firebird':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -298,13 +289,6 @@ class phpbb_database_test_connection_manager
FROM pg_stat_user_tables';
break;
- case 'phpbb\db\driver\firebird':
- $sql = 'SELECT rdb$relation_name
- FROM rdb$relations
- WHERE rdb$view_source is null
- AND rdb$system_flag = 0';
- break;
-
case 'phpbb\db\driver\oracle':
$sql = 'SELECT table_name
FROM USER_TABLES';
@@ -358,14 +342,17 @@ class phpbb_database_test_connection_manager
$filename = $directory . $schema . '_schema.sql';
- $queries = file_get_contents($filename);
- $sql = phpbb_remove_comments($queries);
+ if (file_exists($filename))
+ {
+ $queries = file_get_contents($filename);
+ $sql = phpbb_remove_comments($queries);
- $sql = split_sql_file($sql, $this->dbms['DELIM']);
+ $sql = split_sql_file($sql, $this->dbms['DELIM']);
- foreach ($sql as $query)
- {
- $this->pdo->exec($query);
+ foreach ($sql as $query)
+ {
+ $this->pdo->exec($query);
+ }
}
// Ok we have the db info go ahead and work on building the table
@@ -404,11 +391,6 @@ class phpbb_database_test_connection_manager
protected function get_dbms_data($dbms)
{
$available_dbms = array(
- 'phpbb\db\driver\firebird' => array(
- 'SCHEMA' => 'firebird',
- 'DELIM' => ';;',
- 'PDO' => 'firebird',
- ),
'phpbb\db\driver\mysqli' => array(
'SCHEMA' => 'mysql_41',
'DELIM' => ';',
@@ -478,18 +460,6 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
- case 'phpbb\db\driver\firebird':
- $sql = 'SELECT RDB$GENERATOR_NAME
- FROM RDB$GENERATORS
- WHERE RDB$SYSTEM_FLAG = 0';
- $result = $this->pdo->query($sql);
-
- while ($row = $result->fetch(PDO::FETCH_NUM))
- {
- $queries[] = 'DROP GENERATOR ' . current($row);
- }
- break;
-
case 'phpbb\db\driver\oracle':
$sql = 'SELECT sequence_name
FROM USER_SEQUENCES';
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index e4504a5f8d..9bb4d69bf4 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -11,14 +11,12 @@
*
*/
use Symfony\Component\BrowserKit\CookieJar;
+use Behat\Mink\Driver\Goutte\Client;
+use Behat\Mink\Driver\GoutteDriver;
-require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
-
-class phpbb_functional_test_case extends phpbb_test_case
+class phpbb_functional_test_case extends phpbb_mink_test_case
{
- static protected $client;
static protected $cookieJar;
- static protected $root_url;
protected $cache = null;
protected $db = null;
@@ -36,7 +34,6 @@ class phpbb_functional_test_case extends phpbb_test_case
*/
protected $lang = array();
- static protected $config = array();
static protected $already_installed = false;
static public function setUpBeforeClass()
@@ -46,6 +43,24 @@ class phpbb_functional_test_case extends phpbb_test_case
self::$config = phpbb_test_case_helpers::get_test_config();
self::$root_url = self::$config['phpbb_functional_url'];
+ self::$cookieJar = new CookieJar;
+ self::$client = new Client(array(), null, self::$cookieJar);
+
+ $client_options = array(
+ Guzzle\Http\Client::DISABLE_REDIRECTS => true,
+ 'curl.options' => array(
+ CURLOPT_TIMEOUT => 120,
+ ),
+ );
+
+ self::$client->setClient(new Guzzle\Http\Client('', $client_options));
+
+ // Reset the curl handle because it is 0 at this point and not a valid
+ // resource
+ self::$client->getClient()->getCurlMulti()->reset(true);
+
+ self::$driver = new GoutteDriver(self::$client);
+
// Important: this is used both for installation and by
// test cases for querying the tables.
// Therefore table prefix must be set before a board is
@@ -78,12 +93,6 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->bootstrap();
- self::$cookieJar = new CookieJar;
- self::$client = new Goutte\Client(array(), null, self::$cookieJar);
- // Reset the curl handle because it is 0 at this point and not a valid
- // resource
- self::$client->getClient()->getCurlMulti()->reset(true);
-
// Clear the language array so that things
// that were added in other tests are gone
$this->lang = array();
@@ -110,13 +119,14 @@ class phpbb_functional_test_case extends phpbb_test_case
protected function tearDown()
{
- parent::tearDown();
-
if ($this->db instanceof \phpbb\db\driver\driver_interface)
{
// Close the database connections again this test
$this->db->sql_close();
}
+
+ self::$cookieJar->clear();
+ parent::tearDown();
}
/**
@@ -256,144 +266,6 @@ class phpbb_functional_test_case extends phpbb_test_case
return $extension_manager;
}
- static protected function install_board()
- {
- global $phpbb_root_path, $phpEx;
-
- self::recreate_database(self::$config);
-
- $config_file = $phpbb_root_path . "config.$phpEx";
- $config_file_dev = $phpbb_root_path . "config_dev.$phpEx";
- $config_file_test = $phpbb_root_path . "config_test.$phpEx";
-
- if (file_exists($config_file))
- {
- if (!file_exists($config_file_dev))
- {
- rename($config_file, $config_file_dev);
- }
- else
- {
- unlink($config_file);
- }
- }
-
- self::$cookieJar = new CookieJar;
- self::$client = new Goutte\Client(array(), null, self::$cookieJar);
- // Set client manually so we can increase the cURL timeout
- self::$client->setClient(new Guzzle\Http\Client('', array(
- Guzzle\Http\Client::DISABLE_REDIRECTS => true,
- 'curl.options' => array(
- CURLOPT_TIMEOUT => 120,
- ),
- )));
-
- // Reset the curl handle because it is 0 at this point and not a valid
- // resource
- self::$client->getClient()->getCurlMulti()->reset(true);
-
- $parseURL = parse_url(self::$config['phpbb_functional_url']);
-
- $crawler = self::request('GET', 'install/index.php?mode=install');
- self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form();
-
- // install/index.php?mode=install&sub=requirements
- $crawler = self::submit($form);
- self::assertContains('Installation compatibility', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form();
-
- // install/index.php?mode=install&sub=database
- $crawler = self::submit($form);
- self::assertContains('Database configuration', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form(array(
- // Installer uses 3.0-style dbms name
- 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']),
- 'dbhost' => self::$config['dbhost'],
- 'dbport' => self::$config['dbport'],
- 'dbname' => self::$config['dbname'],
- 'dbuser' => self::$config['dbuser'],
- 'dbpasswd' => self::$config['dbpasswd'],
- 'table_prefix' => self::$config['table_prefix'],
- ));
-
- // install/index.php?mode=install&sub=database
- $crawler = self::submit($form);
- self::assertContains('Successful connection', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form();
-
- // install/index.php?mode=install&sub=administrator
- $crawler = self::submit($form);
- self::assertContains('Administrator configuration', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form(array(
- 'default_lang' => 'en',
- 'admin_name' => 'admin',
- 'admin_pass1' => 'adminadmin',
- 'admin_pass2' => 'adminadmin',
- 'board_email' => 'nobody@example.com',
- ));
-
- // install/index.php?mode=install&sub=administrator
- $crawler = self::submit($form);
- self::assertContains('Tests passed', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form();
-
- // We have to skip install/index.php?mode=install&sub=config_file
- // because that step will create a config.php file if phpBB has the
- // permission to do so. We have to create the config file on our own
- // in order to get the DEBUG constants defined.
- $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true);
- $config_created = file_put_contents($config_file, $config_php_data) !== false;
- if (!$config_created)
- {
- self::markTestSkipped("Could not write $config_file file.");
- }
-
- // We also have to create a install lock that is normally created by
- // the installer. The file will be removed by the final step of the
- // installer.
- $install_lock_file = $phpbb_root_path . 'cache/install_lock';
- $lock_created = file_put_contents($install_lock_file, '') !== false;
- if (!$lock_created)
- {
- self::markTestSkipped("Could not create $lock_created file.");
- }
- @chmod($install_lock_file, 0666);
-
- // install/index.php?mode=install&sub=advanced
- $form_data = $form->getValues();
- unset($form_data['submit']);
-
- $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data);
- self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form(array(
- 'email_enable' => true,
- 'smtp_delivery' => true,
- 'smtp_host' => 'nxdomain.phpbb.com',
- 'smtp_auth' => 'PLAIN',
- 'smtp_user' => 'nxuser',
- 'smtp_pass' => 'nxpass',
- 'cookie_secure' => false,
- 'force_server_vars' => false,
- 'server_protocol' => $parseURL['scheme'] . '://',
- 'server_name' => 'localhost',
- 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80,
- 'script_path' => $parseURL['path'],
- ));
-
- // install/index.php?mode=install&sub=create_table
- $crawler = self::submit($form);
- self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text());
- self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text());
- $form = $crawler->selectButton('submit')->form();
-
- // install/index.php?mode=install&sub=final
- $crawler = self::submit($form);
- self::assertContains('You have successfully installed', $crawler->text());
-
- copy($config_file, $config_file_test);
- }
-
public function install_ext($extension)
{
$this->login();
@@ -412,12 +284,6 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->logout();
}
- static private function recreate_database($config)
- {
- $db_conn_mgr = new phpbb_database_test_connection_manager($config);
- $db_conn_mgr->recreate_db();
- }
-
/**
* Creates a new style
*
@@ -1031,6 +897,76 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->add_lang('posting');
+ $crawler = $this->submit_message($posting_url, $posting_contains, $form_data);
+
+ if ($expected !== '')
+ {
+ if (isset($this->lang[$expected]))
+ {
+ $this->assertContainsLang($expected, $crawler->filter('html')->text());
+ }
+ else
+ {
+ $this->assertContains($expected, $crawler->filter('html')->text());
+ }
+ return null;
+ }
+
+ $url = $crawler->selectLink($form_data['subject'])->link()->getUri();
+
+ return array(
+ 'topic_id' => $this->get_parameter_from_link($url, 't'),
+ 'post_id' => $this->get_parameter_from_link($url, 'p'),
+ );
+ }
+
+ /**
+ * Creates a private message
+ *
+ * Be sure to login before creating
+ *
+ * @param string $subject
+ * @param string $message
+ * @param array $to
+ * @param array $additional_form_data Any additional form data to be sent in the request
+ * @return int private_message_id
+ */
+ public function create_private_message($subject, $message, $to, $additional_form_data = array())
+ {
+ $this->add_lang(array('ucp', 'posting'));
+
+ $posting_url = "ucp.php?i=pm&mode=compose&sid={$this->sid}";
+
+ $form_data = array_merge(array(
+ 'subject' => $subject,
+ 'message' => $message,
+ 'post' => true,
+ ), $additional_form_data);
+
+ foreach ($to as $user_id)
+ {
+ $form_data['address_list[u][' . $user_id . ']'] = 'to';
+ }
+
+ $crawler = self::submit_message($posting_url, 'POST_NEW_PM', $form_data);
+
+ $this->assertContains($this->lang('MESSAGE_STORED'), $crawler->filter('html')->text());
+ $url = $crawler->selectLink($this->lang('VIEW_PRIVATE_MESSAGE', '', ''))->link()->getUri();
+
+ return $this->get_parameter_from_link($url, 'p');
+ }
+
+ /**
+ * Helper for submitting a message (post or private message)
+ *
+ * @param string $posting_url
+ * @param string $posting_contains
+ * @param array $form_data
+ * @return \Symfony\Component\DomCrawler\Crawler the crawler object
+ */
+ protected function submit_message($posting_url, $posting_contains, $form_data)
+ {
+
$crawler = self::request('GET', $posting_url);
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
@@ -1072,19 +1008,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// I use a request because the form submission method does not allow you to send data that is not
// contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
// Instead, I send it as a request with the submit button "post" set to true.
- $crawler = self::request('POST', $posting_url, $form_data);
-
- if ($expected !== '')
- {
- $this->assertContainsLang($expected, $crawler->filter('html')->text());
- return null;
- }
- $url = $crawler->selectLink($form_data['subject'])->link()->getUri();
-
- return array(
- 'topic_id' => $this->get_parameter_from_link($url, 't'),
- 'post_id' => $this->get_parameter_from_link($url, 'p'),
- );
+ return self::request('POST', $posting_url, $form_data);
}
/**
@@ -1097,12 +1021,8 @@ class phpbb_functional_test_case extends phpbb_test_case
*/
public function delete_topic($topic_id)
{
- $crawler = self::request('GET', "viewtopic.php?t={$topic_id}&sid={$this->sid}");
-
$this->add_lang('posting');
- $form = $crawler->selectButton('Go')->eq(1)->form();
- $form['action']->select('delete_topic');
- $crawler = self::submit($form);
+ $crawler = $this->get_quickmod_page($topic_id, 'DELETE_TOPIC');
$this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
$this->add_lang('mcp');
@@ -1193,4 +1113,25 @@ class phpbb_functional_test_case extends phpbb_test_case
return $manager;
}
+
+ /**
+ * Get quickmod page
+ *
+ * @param int $topic_id
+ * @param string $action Language key for the quickmod action
+ * @param Symfony\Component\DomCrawler\Crawler Optional crawler object to use instead of creating new one.
+ * @return Symfony\Component\DomCrawler\Crawler
+ */
+ public function get_quickmod_page($topic_id, $action, $crawler = false)
+ {
+ $this->add_lang('viewtopic');
+
+ if ($crawler === false)
+ {
+ $crawler = self::request('GET', "viewtopic.php?t={$topic_id}&sid={$this->sid}");
+ }
+ $link = $crawler->filter('#quickmod')->selectLink($this->lang($action))->link()->getUri();
+
+ return self::request('GET', substr($link, strpos($link, 'mcp.')));
+ }
}
diff --git a/tests/test_framework/phpbb_mink_test_case.php b/tests/test_framework/phpbb_mink_test_case.php
new file mode 100644
index 0000000000..ba480e35fb
--- /dev/null
+++ b/tests/test_framework/phpbb_mink_test_case.php
@@ -0,0 +1,183 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+use \Behat\Mink\Session;
+
+require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
+
+abstract class phpbb_mink_test_case extends phpbb_test_case
+{
+ static protected $driver;
+ static protected $client;
+ static protected $session;
+ static protected $config = array();
+ static protected $root_url;
+
+ public function __construct($name = null, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_mink_test_case' => array('config', 'already_installed'),
+ );
+ }
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ if (!self::$driver)
+ {
+ self::markTestSkipped('Mink driver not initialized.');
+ }
+
+ if (!self::$session)
+ {
+ self::$session = new Session(self::$driver);
+ }
+ }
+
+ static protected function recreate_database($config)
+ {
+ $db_conn_mgr = new phpbb_database_test_connection_manager($config);
+ $db_conn_mgr->recreate_db();
+ }
+
+ protected function tearDown()
+ {
+ self::$session->reset();
+ parent::tearDown();
+ }
+
+ static protected function visit($path)
+ {
+ self::$session->visit(self::$root_url . $path);
+ return self::$session->getPage();
+ }
+
+ static protected function click_submit($submit_button_id = 'submit')
+ {
+ self::$session->getPage()->findById($submit_button_id)->click();
+ return self::$session->getPage();
+ }
+
+ static protected function install_board()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ self::recreate_database(self::$config);
+ self::$session = new Session(self::$driver);
+
+ $config_file = $phpbb_root_path . "config.$phpEx";
+ $config_file_dev = $phpbb_root_path . "config_dev.$phpEx";
+ $config_file_test = $phpbb_root_path . "config_test.$phpEx";
+
+ if (file_exists($config_file))
+ {
+ if (!file_exists($config_file_dev))
+ {
+ rename($config_file, $config_file_dev);
+ }
+ else
+ {
+ unlink($config_file);
+ }
+ }
+
+ $parseURL = parse_url(self::$config['phpbb_functional_url']);
+
+ $page = self::visit('install/index.php?mode=install');
+ self::assertContains('Welcome to Installation', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=requirements
+ $page = self::click_submit();
+ self::assertContains('Installation compatibility', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=database
+ $page = self::click_submit();
+ self::assertContains('Database configuration', $page->findById('main')->getText());
+
+ $page->findById('dbms')->setValue(str_replace('phpbb\db\driver\\', '', self::$config['dbms']));
+ $page->findById('dbhost')->setValue(self::$config['dbhost']);
+ $page->findById('dbport')->setValue(self::$config['dbport']);
+ $page->findById('dbname')->setValue(self::$config['dbname']);
+ $page->findById('dbuser')->setValue(self::$config['dbuser']);
+ $page->findById('dbpasswd')->setValue(self::$config['dbpasswd']);
+ $page->findById('table_prefix')->setValue(self::$config['table_prefix']);
+
+ // install/index.php?mode=install&sub=database
+ $page = self::click_submit();
+ self::assertContains('Successful connection', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=administrator
+ $page = self::click_submit();
+ self::assertContains('Administrator configuration', $page->findById('main')->getText());
+
+ $page->findById('admin_name')->setValue('admin');
+ $page->findById('admin_pass1')->setValue('adminadmin');
+ $page->findById('admin_pass2')->setValue('adminadmin');
+ $page->findById('board_email')->setValue('nobody@example.com');
+
+ // install/index.php?mode=install&sub=administrator
+ $page = self::click_submit();
+ self::assertContains('Tests passed', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=config_file
+ $page = self::click_submit();
+
+ // Installer has created a config.php file, we will overwrite it with a
+ // config file of our own in order to get the DEBUG constants defined
+ $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true);
+ $config_created = file_put_contents($config_file, $config_php_data) !== false;
+ if (!$config_created)
+ {
+ self::markTestSkipped("Could not write $config_file file.");
+ }
+
+ if (strpos($page->findById('main')->getText(), 'The configuration file has been written') === false)
+ {
+ $page = self::click_submit('dldone');
+ }
+ self::assertContains('The configuration file has been written', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=advanced
+ $page = self::click_submit();
+ self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $page->findById('main')->getText());
+
+ $page->findById('smtp_delivery')->setValue('1');
+ $page->findById('smtp_host')->setValue('nxdomain.phpbb.com');
+ $page->findById('smtp_user')->setValue('nxuser');
+ $page->findById('smtp_pass')->setValue('nxpass');
+ $page->findById('server_protocol')->setValue($parseURL['scheme'] . '://');
+ $page->findById('server_name')->setValue('localhost');
+ $page->findById('server_port')->setValue(isset($parseURL['port']) ? $parseURL['port'] : 80);
+ $page->findById('script_path')->setValue($parseURL['path']);
+
+ // install/index.php?mode=install&sub=create_table
+ $page = self::click_submit();
+ self::assertContains('The database tables used by phpBB', $page->findById('main')->getText());
+ self::assertContains('have been created and populated with some initial data.', $page->findById('main')->getText());
+
+ // install/index.php?mode=install&sub=final
+ $page = self::click_submit();
+ self::assertContains('You have successfully installed', $page->getText());
+
+ copy($config_file, $config_file_test);
+
+ self::$session->stop();
+ }
+}
diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php
index 8a5d582573..d4fc174a12 100644
--- a/tests/test_framework/phpbb_session_test_case.php
+++ b/tests/test_framework/phpbb_session_test_case.php
@@ -32,6 +32,7 @@ abstract class phpbb_session_test_case extends phpbb_database_test_case
$phpbb_path_helper = new \phpbb\path_helper(
$symfony_request,
$phpbb_filesystem,
+ $this->getMock('\phpbb\request\request'),
$phpbb_root_path,
$phpEx
);
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index a29b6e1955..dee70ad016 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -142,17 +142,15 @@ class phpbb_test_case_helpers
$test_config = dirname(__FILE__) . '/../test_config.php';
}
+ $config_php_file = new \phpbb\config_php_file('', '');
+
if (file_exists($test_config))
{
- include($test_config);
-
- if (!function_exists('phpbb_convert_30_dbms_to_31'))
- {
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- }
+ $config_php_file->set_config_file($test_config);
+ extract($config_php_file->get_all());
$config = array_merge($config, array(
- 'dbms' => phpbb_convert_30_dbms_to_31($dbms),
+ 'dbms' => $config_php_file->convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
@@ -183,13 +181,8 @@ class phpbb_test_case_helpers
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
- if (!function_exists('phpbb_convert_30_dbms_to_31'))
- {
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- }
-
$config = array_merge($config, array(
- 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
+ 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $config_php_file->convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php
index 5e333213f4..d8fa82e2b5 100644
--- a/tests/upload/filespec_test.php
+++ b/tests/upload/filespec_test.php
@@ -65,6 +65,16 @@ class phpbb_filespec_test extends phpbb_test_case
copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2');
}
}
+
+ $guessers = array(
+ new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
+ new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
+ new \phpbb\mimetype\content_guesser(),
+ new \phpbb\mimetype\extension_guesser(),
+ );
+ $guessers[2]->set_priority(-2);
+ $guessers[3]->set_priority(-2);
+ $this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
}
private function get_filespec($override = array())
@@ -78,7 +88,7 @@ class phpbb_filespec_test extends phpbb_test_case
'error' => '',
);
- return new filespec(array_merge($upload_ary, $override), null);
+ return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser);
}
protected function tearDown()
@@ -222,6 +232,9 @@ class phpbb_filespec_test extends phpbb_test_case
array('png', 'image/png', true),
array('tif', 'image/tif', true),
array('txt', 'text/plain', false),
+ array('jpg', 'application/octet-stream', false),
+ array('gif', 'application/octetstream', false),
+ array('png', 'application/mime', false),
);
}
@@ -234,6 +247,30 @@ class phpbb_filespec_test extends phpbb_test_case
$this->assertEquals($expected, $filespec->is_image());
}
+ public function is_image_get_mimetype()
+ {
+ return array(
+ array('gif', 'image/gif', true),
+ array('jpg', 'image/jpg', true),
+ array('png', 'image/png', true),
+ array('tif', 'image/tif', true),
+ array('txt', 'text/plain', false),
+ array('jpg', 'application/octet-stream', true),
+ array('gif', 'application/octetstream', true),
+ array('png', 'application/mime', true),
+ );
+ }
+
+ /**
+ * @dataProvider is_image_get_mimetype
+ */
+ public function test_is_image_get_mimetype($filename, $mimetype, $expected)
+ {
+ $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
+ $filespec->get_mimetype($this->path . $filename);
+ $this->assertEquals($expected, $filespec->is_image());
+ }
+
public function move_file_variables()
{
return array(
diff --git a/tests/viewonline/helper_test.php b/tests/viewonline/helper_test.php
new file mode 100644
index 0000000000..bbbed59de7
--- /dev/null
+++ b/tests/viewonline/helper_test.php
@@ -0,0 +1,46 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_viewonline_helper_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->viewonline_helper = new \phpbb\viewonline_helper(new \phpbb\filesystem());
+ }
+
+ public function session_pages_data()
+ {
+ return array(
+ array('index.php', 'index'),
+ array('foobar/test.php', 'foobar/test'),
+ array('', ''),
+ array('./../../index.php', '../../index'),
+ array('../subdir/index.php', '../subdir/index'),
+ array('../index.php', '../index'),
+ array('././index.php', 'index'),
+ array('./index.php', 'index'),
+ );
+ }
+
+ /**
+ * @dataProvider session_pages_data
+ */
+ public function test_get_user_page($session_page, $expected)
+ {
+ $on_page = $this->viewonline_helper->get_user_page($session_page);
+ $this->assertArrayHasKey(1, $on_page);
+ $this->assertSame($expected, $on_page[1]);
+ }
+}