aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.md33
-rw-r--r--tests/acp_board/auth_provider/invalid.php19
-rw-r--r--tests/acp_board/auth_provider/valid.php22
-rw-r--r--tests/acp_board/select_auth_method_test.php52
-rw-r--r--tests/auth/fixtures/oauth_tokens.xml16
-rw-r--r--tests/auth/fixtures/user.xml39
-rw-r--r--tests/auth/fixtures/user_533.xml39
-rw-r--r--tests/auth/phpbb_not_a_token.php23
-rw-r--r--tests/auth/provider_apache_test.php229
-rw-r--r--tests/auth/provider_db_test.php95
-rw-r--r--tests/auth/provider_oauth_token_storage_test.php229
-rw-r--r--tests/avatar/driver/barfoo.php26
-rw-r--r--tests/avatar/driver/foobar.php26
-rw-r--r--tests/avatar/fixtures/users.xml61
-rw-r--r--tests/avatar/manager_test.php430
-rw-r--r--tests/bbcode/parser_test.php269
-rw-r--r--tests/bbcode/url_bbcode_test.php14
-rw-r--r--tests/bootstrap.php40
-rw-r--r--tests/cache/apc_driver_test.php57
-rw-r--r--tests/cache/cache_memory.php20
-rw-r--r--tests/cache/cache_memory_test.php24
-rw-r--r--tests/cache/common_test_case.php102
-rw-r--r--tests/cache/file_driver_test.php73
-rw-r--r--tests/cache/fixtures/cache_memory.xml8
-rw-r--r--tests/cache/fixtures/config.xml18
-rw-r--r--tests/cache/null_driver_test.php77
-rw-r--r--tests/cache/redis_driver_test.php53
-rw-r--r--tests/captcha/qa_test.php94
-rw-r--r--tests/class_loader/class_loader_test.php101
-rw-r--r--tests/class_loader/phpbb/class_name.php8
-rw-r--r--tests/class_loader/phpbb/dir/class_name.php8
-rw-r--r--tests/class_loader/phpbb/dir/subdir/class_name.php8
-rw-r--r--tests/class_loader/phpbb/dir2/dir2.php8
-rw-r--r--tests/composer.json5
-rw-r--r--tests/composer.lock63
-rw-r--r--tests/compress/compress_test.php31
-rw-r--r--tests/config/config_test.php124
-rw-r--r--tests/config/db_test.php168
-rw-r--r--tests/config/db_text_test.php127
-rw-r--r--tests/config/fixtures/config.xml18
-rw-r--r--tests/config/fixtures/config_text.xml19
-rw-r--r--tests/config_php_file_test.php40
-rw-r--r--tests/console/cache/purge_test.php95
-rw-r--r--tests/console/config/config_test.php251
-rw-r--r--tests/console/cron/cron_list_test.php103
-rw-r--r--tests/console/cron/fixtures/config.xml8
-rw-r--r--tests/console/cron/run_test.php158
-rw-r--r--tests/console/cron/tasks/simple.php27
-rw-r--r--tests/console/cron/tasks/simple_not_ready.php13
-rw-r--r--tests/console/cron/tasks/simple_ready.php8
-rw-r--r--tests/content_visibility/delete_post_test.php350
-rw-r--r--tests/content_visibility/fixtures/delete_post.xml163
-rw-r--r--tests/content_visibility/fixtures/get_forums_visibility_sql.xml133
-rw-r--r--tests/content_visibility/fixtures/get_visibility_sql.xml55
-rw-r--r--tests/content_visibility/fixtures/set_post_visibility.xml238
-rw-r--r--tests/content_visibility/fixtures/set_topic_visibility.xml132
-rw-r--r--tests/content_visibility/get_forums_visibility_sql_test.php149
-rw-r--r--tests/content_visibility/get_global_visibility_sql_test.php149
-rw-r--r--tests/content_visibility/get_visibility_sql_test.php96
-rw-r--r--tests/content_visibility/set_post_visibility_test.php192
-rw-r--r--tests/content_visibility/set_topic_visibility_test.php113
-rw-r--r--tests/controller/common_helper_route.php467
-rw-r--r--tests/controller/config/routing.yml3
-rw-r--r--tests/controller/config/services.yml3
-rw-r--r--tests/controller/controller_test.php88
-rw-r--r--tests/controller/ext/vendor2/foo/config/routing.yml7
-rw-r--r--tests/controller/ext/vendor2/foo/config/routing_2.yml6
-rw-r--r--tests/controller/ext/vendor2/foo/config/services.yml3
-rw-r--r--tests/controller/ext/vendor2/foo/controller.php18
-rw-r--r--tests/controller/ext/vendor2/foo/subfolder/config/routing.yml3
-rw-r--r--tests/controller/helper_route_adm_subdir_test.php33
-rw-r--r--tests/controller/helper_route_adm_test.php33
-rw-r--r--tests/controller/helper_route_other_app.php37
-rw-r--r--tests/controller/helper_route_root_test.php33
-rw-r--r--tests/controller/helper_route_slash_test.php43
-rw-r--r--tests/controller/helper_route_unclean_path_test.php33
-rw-r--r--tests/controller/phpbb/controller/foo.php18
-rw-r--r--tests/cron/ext/testext/cron/dummy_task.php32
-rw-r--r--tests/cron/includes/cron/task/core/dummy_task.php32
-rw-r--r--tests/cron/includes/cron/task/core/second_dummy_task.php32
-rw-r--r--tests/cron/manager_test.php80
-rw-r--r--tests/cron/tasks/simple_not_runnable.php18
-rw-r--r--tests/cron/tasks/simple_ready.php13
-rw-r--r--tests/cron/tasks/simple_should_not_run.php18
-rw-r--r--tests/datetime/from_format_test.php126
-rw-r--r--tests/dbal/auto_increment_test.php13
-rw-r--r--tests/dbal/case_test.php73
-rw-r--r--tests/dbal/concatenate_test.php68
-rw-r--r--tests/dbal/connect_test.php14
-rw-r--r--tests/dbal/cross_join_test.php10
-rw-r--r--tests/dbal/db_tools_test.php110
-rw-r--r--tests/dbal/fixtures/massmail_crossjoin.xml8
-rw-r--r--tests/dbal/fixtures/migrator.xml29
-rw-r--r--tests/dbal/fixtures/migrator_config_text.xml7
-rw-r--r--tests/dbal/fixtures/migrator_module.xml133
-rw-r--r--tests/dbal/fixtures/migrator_permission.xml165
-rw-r--r--tests/dbal/fixtures/styles.xml34
-rw-r--r--tests/dbal/fixtures/three_users.xml8
-rw-r--r--tests/dbal/migration/dummy.php31
-rw-r--r--tests/dbal/migration/dummy_order.php30
-rw-r--r--tests/dbal/migration/dummy_order_0.php26
-rw-r--r--tests/dbal/migration/dummy_order_1.php26
-rw-r--r--tests/dbal/migration/dummy_order_2.php26
-rw-r--r--tests/dbal/migration/dummy_order_3.php26
-rw-r--r--tests/dbal/migration/dummy_order_4.php26
-rw-r--r--tests/dbal/migration/dummy_order_5.php27
-rw-r--r--tests/dbal/migration/fail.php45
-rw-r--r--tests/dbal/migration/if.php48
-rw-r--r--tests/dbal/migration/installed.php34
-rw-r--r--tests/dbal/migration/recall.php42
-rw-r--r--tests/dbal/migration/revert.php52
-rw-r--r--tests/dbal/migration/revert_with_dependency.php20
-rw-r--r--tests/dbal/migration/schema.php48
-rw-r--r--tests/dbal/migration/unfulfillable.php30
-rw-r--r--tests/dbal/migrator_test.php315
-rw-r--r--tests/dbal/migrator_tool_config_test.php90
-rw-r--r--tests/dbal/migrator_tool_config_text_test.php75
-rw-r--r--tests/dbal/migrator_tool_module_test.php305
-rw-r--r--tests/dbal/migrator_tool_permission_test.php223
-rw-r--r--tests/dbal/order_lower_test.php39
-rw-r--r--tests/dbal/schema_test.php42
-rw-r--r--tests/dbal/select_test.php86
-rw-r--r--tests/dbal/sql_affected_rows_test.php68
-rw-r--r--tests/dbal/sql_insert_buffer_test.php120
-rw-r--r--tests/dbal/write_sequence_test.php16
-rw-r--r--tests/dbal/write_test.php16
-rw-r--r--tests/di/create_container_test.php205
-rw-r--r--tests/di/fixtures/config.php11
-rw-r--r--tests/di/fixtures/config/services.yml17
-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.yml17
-rw-r--r--tests/download/http_byte_range_test.php68
-rw-r--r--tests/download/http_user_agent_test.php134
-rw-r--r--tests/error_collector_test.php41
-rw-r--r--tests/event/dispatcher_test.php33
-rw-r--r--tests/event/exception_listener_test.php100
-rw-r--r--tests/event/export_php_test.php49
-rw-r--r--tests/event/fixtures/adm/style/acp_bbcodes.html0
-rw-r--r--tests/event/fixtures/default.test9
-rw-r--r--tests/event/fixtures/duplicate_event.test19
-rw-r--r--tests/event/fixtures/extra_description.test11
-rw-r--r--tests/event/fixtures/missing_var.test17
-rw-r--r--tests/event/fixtures/none.test6
-rw-r--r--tests/event/fixtures/normal_events.md.test20
-rw-r--r--tests/event/fixtures/trigger.test15
-rw-r--r--tests/event/fixtures/trigger_many_vars.test65
-rw-r--r--tests/event/fixtures/trigger_wspace.test15
-rw-r--r--tests/event/md_exporter_test.php160
-rw-r--r--tests/event/php_exporter_test.php740
-rw-r--r--tests/extension/ext/barfoo/composer.json24
-rw-r--r--tests/extension/ext/barfoo/ext.php7
-rw-r--r--tests/extension/ext/vendor/moo/composer.json24
-rw-r--r--tests/extension/ext/vendor/moo/ext.php15
-rw-r--r--tests/extension/ext/vendor/moo/feature_class.php7
-rw-r--r--tests/extension/ext/vendor2/bar/acp/a_info.php18
-rw-r--r--tests/extension/ext/vendor2/bar/acp/a_module.php7
-rw-r--r--tests/extension/ext/vendor2/bar/composer.json23
-rw-r--r--tests/extension/ext/vendor2/bar/ext.php26
-rw-r--r--tests/extension/ext/vendor2/bar/migrations/migration.php18
-rw-r--r--tests/extension/ext/vendor2/foo/a_class.php7
-rw-r--r--tests/extension/ext/vendor2/foo/acp/a_info.php18
-rw-r--r--tests/extension/ext/vendor2/foo/acp/a_module.php7
-rw-r--r--tests/extension/ext/vendor2/foo/acp/fail_info.php22
-rw-r--r--tests/extension/ext/vendor2/foo/acp/fail_module.php11
-rw-r--r--tests/extension/ext/vendor2/foo/b_class.php7
-rw-r--r--tests/extension/ext/vendor2/foo/composer.json23
-rw-r--r--tests/extension/ext/vendor2/foo/ext.php15
-rw-r--r--tests/extension/ext/vendor2/foo/mcp/a_info.php18
-rw-r--r--tests/extension/ext/vendor2/foo/mcp/a_module.php7
-rw-r--r--tests/extension/ext/vendor2/foo/sub/type/alternative.php7
-rw-r--r--tests/extension/ext/vendor2/foo/type/alternative.php7
-rw-r--r--tests/extension/ext/vendor2/foo/type/dummy/empty.txt0
-rw-r--r--tests/extension/ext/vendor2/foo/typewrong/error.php7
-rw-r--r--tests/extension/ext/vendor3/bar/ext.php26
-rw-r--r--tests/extension/ext/vendor3/bar/my/hidden_class.php7
-rw-r--r--tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html1
-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/ext/vendor4/bar/composer.json23
-rw-r--r--tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html1
-rw-r--r--tests/extension/extension_base_test.php79
-rw-r--r--tests/extension/finder_test.php309
-rw-r--r--tests/extension/fixtures/extensions.xml18
-rw-r--r--tests/extension/includes/acp/acp_foobar.php29
-rw-r--r--tests/extension/includes/acp/info/acp_foobar.php27
-rw-r--r--tests/extension/manager_test.php187
-rw-r--r--tests/extension/metadata_manager_test.php343
-rw-r--r--tests/extension/modules_test.php238
-rw-r--r--tests/extension/phpbb/default/implementation.php5
-rw-r--r--tests/feed/attachments_base_test.php94
-rw-r--r--tests/feed/attachments_mock_feed.php31
-rw-r--r--tests/filesystem/clean_path_test.php (renamed from tests/functions/clean_path_test.php)32
-rw-r--r--tests/fixtures/config.php3
-rw-r--r--tests/fixtures/config_other.php3
-rw-r--r--tests/functional/acp_groups_test.php113
-rw-r--r--tests/functional/acp_permissions_test.php127
-rw-r--r--tests/functional/acp_profile_field_test.php71
-rw-r--r--tests/functional/acp_registration_test.php55
-rw-r--r--tests/functional/acp_users_test.php10
-rw-r--r--tests/functional/auth_test.php44
-rw-r--r--tests/functional/avatar_acp_groups_test.php85
-rw-r--r--tests/functional/avatar_acp_users_test.php65
-rw-r--r--tests/functional/avatar_ucp_groups_test.php74
-rw-r--r--tests/functional/avatar_ucp_users_test.php73
-rw-r--r--tests/functional/browse_test.php17
-rw-r--r--tests/functional/common_avatar_test_case.php97
-rw-r--r--tests/functional/common_groups_test_case.php (renamed from tests/functional/common_groups_test.php)58
-rw-r--r--tests/functional/download_test.php296
-rw-r--r--tests/functional/extension_acp_test.php237
-rw-r--r--tests/functional/extension_controller_test.php181
-rw-r--r--tests/functional/extension_global_lang_test.php75
-rw-r--r--tests/functional/extension_module_test.php136
-rw-r--r--tests/functional/extension_permission_lang_test.php86
-rw-r--r--tests/functional/feed_test.php1503
-rw-r--r--tests/functional/fileupload_form_test.php145
-rw-r--r--tests/functional/fileupload_remote_test.php79
-rw-r--r--tests/functional/fixtures/ext/foo/bar/acp/main_info.php37
-rw-r--r--tests/functional/fixtures/ext/foo/bar/acp/main_module.php33
-rw-r--r--tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html3
-rw-r--r--tests/functional/fixtures/ext/foo/bar/composer.json24
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/routing.yml35
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/services.yml20
-rw-r--r--tests/functional/fixtures/ext/foo/bar/controller/controller.php109
-rw-r--r--tests/functional/fixtures/ext/foo/bar/event/permission.php36
-rw-r--r--tests/functional/fixtures/ext/foo/bar/event/user_setup.php39
-rw-r--r--tests/functional/fixtures/ext/foo/bar/ext.php8
-rw-r--r--tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php5
-rw-r--r--tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php5
-rw-r--r--tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html3
-rw-r--r--tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html3
-rw-r--r--tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html8
-rw-r--r--tests/functional/fixtures/ext/foo/bar/ucp/main_info.php29
-rw-r--r--tests/functional/fixtures/ext/foo/bar/ucp/main_module.php25
-rw-r--r--tests/functional/fixtures/ext/foo/foo/composer.json24
-rw-r--r--tests/functional/fixtures/ext/foo/foo/config/resource.yml3
-rw-r--r--tests/functional/fixtures/ext/foo/foo/config/routing.yml3
-rw-r--r--tests/functional/fixtures/ext/foo/foo/config/services.yml3
-rw-r--r--tests/functional/fixtures/ext/foo/foo/controller/controller.php13
-rw-r--r--tests/functional/fixtures/ext/foo/foo/ext.php8
-rw-r--r--tests/functional/fixtures/files/disallowed.jpgbin0 -> 559 bytes
-rw-r--r--tests/functional/fixtures/files/empty.png0
-rw-r--r--tests/functional/fixtures/files/illegal-extension.bifbin0 -> 519 bytes
-rw-r--r--tests/functional/fixtures/files/too-large.pngbin0 -> 284717 bytes
-rw-r--r--tests/functional/fixtures/files/valid.jpgbin0 -> 554 bytes
-rw-r--r--tests/functional/forgot_password_test.php61
-rw-r--r--tests/functional/forum_password_test.php59
-rw-r--r--tests/functional/forum_style_test.php10
-rw-r--r--tests/functional/group_create_test.php35
-rw-r--r--tests/functional/jumpbox_test.php35
-rw-r--r--tests/functional/lang_test.php10
-rw-r--r--tests/functional/mcp_test.php32
-rw-r--r--tests/functional/memberlist_test.php137
-rw-r--r--tests/functional/metadata_manager_test.php94
-rw-r--r--tests/functional/notification_test.php88
-rw-r--r--tests/functional/paging_test.php43
-rw-r--r--tests/functional/plupload_test.php154
-rw-r--r--tests/functional/posting_test.php134
-rw-r--r--tests/functional/private_messages_test.php10
-rw-r--r--tests/functional/prune_shadow_topic_test.php211
-rw-r--r--tests/functional/registration_test.php67
-rw-r--r--tests/functional/report_post_captcha_test.php16
-rw-r--r--tests/functional/search/base.php108
-rw-r--r--tests/functional/search/mysql_test.php23
-rw-r--r--tests/functional/search/native_test.php22
-rw-r--r--tests/functional/search/postgres_test.php23
-rw-r--r--tests/functional/search/sphinx_test.php27
-rw-r--r--tests/functional/ucp_allow_pm_test.php74
-rw-r--r--tests/functional/ucp_groups_test.php46
-rw-r--r--tests/functional/ucp_pm_test.php52
-rw-r--r--tests/functional/ucp_preferences_test.php85
-rw-r--r--tests/functional/ucp_profile_test.php49
-rw-r--r--tests/functional/user_password_reset_test.php169
-rw-r--r--tests/functional/viewforum_paging_test.php256
-rw-r--r--tests/functional/visibility_disapprove_test.php323
-rw-r--r--tests/functional/visibility_reapprove_test.php419
-rw-r--r--tests/functional/visibility_softdelete_test.php841
-rw-r--r--tests/functions/build_hidden_fields_for_query_params_test.php75
-rw-r--r--tests/functions/build_url_test.php92
-rw-r--r--tests/functions/convert_30_dbms_to_31_test.php44
-rw-r--r--tests/functions/fixtures/banned_users.xml38
-rw-r--r--tests/functions/fixtures/obtain_online.xml22
-rw-r--r--tests/functions/fixtures/style_select.xml4
-rw-r--r--tests/functions/fixtures/user_delete.xml46
-rw-r--r--tests/functions/fixtures/validate_email.xml4
-rw-r--r--tests/functions/fixtures/validate_username.xml6
-rw-r--r--tests/functions/generate_string_list.php64
-rw-r--r--tests/functions/get_formatted_filesize_test.php10
-rw-r--r--tests/functions/get_preg_expression_test.php40
-rw-r--r--tests/functions/get_remote_file_test.php14
-rw-r--r--tests/functions/is_absolute_test.php12
-rw-r--r--tests/functions/language_select_test.php10
-rw-r--r--tests/functions/make_clickable_email_test.php222
-rw-r--r--tests/functions/make_clickable_test.php180
-rw-r--r--tests/functions/obtain_online_test.php55
-rw-r--r--tests/functions/parse_cfg_file_test.php27
-rw-r--r--tests/functions/phpbb_get_banned_user_ids.php62
-rw-r--r--tests/functions/quoteattr_test.php48
-rw-r--r--tests/functions/style_select_test.php10
-rw-r--r--tests/functions/user_delete_test.php113
-rw-r--r--tests/functions/validate_data_helper.php10
-rw-r--r--tests/functions/validate_date_test.php10
-rw-r--r--tests/functions/validate_email_test.php72
-rw-r--r--tests/functions/validate_hex_colour_test.php10
-rw-r--r--tests/functions/validate_jabber_test.php10
-rw-r--r--tests/functions/validate_lang_iso_test.php10
-rw-r--r--tests/functions/validate_match_test.php10
-rw-r--r--tests/functions/validate_num_test.php10
-rw-r--r--tests/functions/validate_password_test.php11
-rw-r--r--tests/functions/validate_string_test.php10
-rw-r--r--tests/functions/validate_user_email_test.php106
-rw-r--r--tests/functions/validate_username_test.php11
-rw-r--r--tests/functions/validate_with_method_test.php43
-rw-r--r--tests/functions_acp/build_cfg_template_test.php291
-rw-r--r--tests/functions_acp/build_select_test.php65
-rw-r--r--tests/functions_acp/h_radio_test.php130
-rw-r--r--tests/functions_acp/insert_config_array_test.php144
-rw-r--r--tests/functions_acp/validate_config_vars_test.php261
-rw-r--r--tests/functions_acp/validate_range_test.php168
-rw-r--r--tests/functions_content/get_username_string_test.php29
-rw-r--r--tests/functions_content/phpbb_clean_search_string_test.php10
-rw-r--r--tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php10
-rw-r--r--tests/functions_database_helper/update_rows_avoiding_duplicates_test.php10
-rw-r--r--tests/functions_install/ignore_new_file_on_update_test.php45
-rw-r--r--tests/functions_user/delete_user_test.php80
-rw-r--r--tests/functions_user/fixtures/delete_user.xml32
-rw-r--r--tests/functions_user/fixtures/group_user_attributes.xml113
-rw-r--r--tests/functions_user/group_user_attributes_test.php162
-rw-r--r--tests/groupposition/fixtures/legend.xml23
-rw-r--r--tests/groupposition/fixtures/teampage.xml102
-rw-r--r--tests/groupposition/legend_test.php407
-rw-r--r--tests/groupposition/teampage_test.php645
-rw-r--r--tests/lint_test.php61
-rw-r--r--tests/lock/db_test.php101
-rw-r--r--tests/lock/fixtures/config.xml13
-rw-r--r--tests/lock/flock_test.php124
-rw-r--r--tests/log/add_test.php101
-rw-r--r--tests/log/delete_test.php157
-rw-r--r--tests/log/fixtures/delete_log.xml232
-rw-r--r--tests/log/fixtures/empty_log.xml15
-rw-r--r--tests/log/fixtures/full_log.xml184
-rw-r--r--tests/log/function_add_log_test.php197
-rw-r--r--tests/log/function_view_log_test.php409
-rw-r--r--tests/mcp/fixtures/post_ip.xml73
-rw-r--r--tests/mcp/post_ip_test.php67
-rw-r--r--tests/migrator/convert_timezones_test.php98
-rw-r--r--tests/migrator/fixtures/convert_timezones.xml66
-rw-r--r--tests/migrator/get_schema_steps_test.php204
-rw-r--r--tests/migrator/reverse_update_data_test.php56
-rw-r--r--tests/migrator/schema_generator_test.php138
-rw-r--r--tests/mimetype/fixtures/jpgbin0 -> 519 bytes
-rw-r--r--tests/mimetype/guesser_test.php230
-rw-r--r--tests/mimetype/incorrect_guesser.php22
-rw-r--r--tests/mimetype/null_guesser.php34
-rw-r--r--tests/mock/auth_provider.php27
-rw-r--r--tests/mock/cache.php113
-rw-r--r--tests/mock/container_builder.php183
-rw-r--r--tests/mock/controller_helper.php34
-rw-r--r--tests/mock/event_dispatcher.php29
-rw-r--r--tests/mock/extension_manager.php26
-rw-r--r--tests/mock/file_downloader.php27
-rw-r--r--tests/mock/filespec.php36
-rw-r--r--tests/mock/filesystem_extension_manager.php36
-rw-r--r--tests/mock/fileupload.php27
-rw-r--r--tests/mock/lang.php42
-rw-r--r--tests/mock/metadata_manager.php27
-rw-r--r--tests/mock/migrator.php55
-rw-r--r--tests/mock/notification_manager.php97
-rw-r--r--tests/mock/notification_type_post.php40
-rw-r--r--tests/mock/notifications_auth.php44
-rw-r--r--tests/mock/null_cache.php15
-rw-r--r--tests/mock/phpbb_di_container_builder.php20
-rw-r--r--tests/mock/request.php138
-rw-r--r--tests/mock/search.php27
-rw-r--r--tests/mock/session_testable.php19
-rw-r--r--tests/mock/sql_insert_buffer.php25
-rw-r--r--tests/mock/user.php15
-rw-r--r--tests/network/checkdnsrr_test.php10
-rw-r--r--tests/network/ftp_fsock_pasv_epsv_test.php10
-rw-r--r--tests/network/inet_ntop_pton_test.php58
-rw-r--r--tests/network/ip_normalise_test.php68
-rw-r--r--tests/notification/base.php140
-rw-r--r--tests/notification/convert_test.php112
-rw-r--r--tests/notification/ext/test/notification/type/test.php91
-rw-r--r--tests/notification/fixtures/convert.xml66
-rw-r--r--tests/notification/fixtures/group_request.xml24
-rw-r--r--tests/notification/fixtures/notification.xml13
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.bookmark.xml161
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.post.xml205
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml159
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.quote.xml133
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.topic.xml134
-rw-r--r--tests/notification/fixtures/user_list_trim.xml51
-rw-r--r--tests/notification/group_request_test.php114
-rw-r--r--tests/notification/manager_helper.php71
-rw-r--r--tests/notification/notification_test.php330
-rw-r--r--tests/notification/submit_post_base.php154
-rw-r--r--tests/notification/submit_post_type_bookmark_test.php94
-rw-r--r--tests/notification/submit_post_type_post_in_queue_test.php111
-rw-r--r--tests/notification/submit_post_type_post_test.php100
-rw-r--r--tests/notification/submit_post_type_quote_test.php118
-rw-r--r--tests/notification/submit_post_type_topic_test.php153
-rw-r--r--tests/notification/user_list_trim_test.php143
-rw-r--r--tests/pagination/config/routing.yml6
-rw-r--r--tests/pagination/pagination_test.php331
-rw-r--r--tests/pagination/templates/pagination.html15
-rw-r--r--tests/pagination/templates/pagination_double_nested.html19
-rw-r--r--tests/pagination/templates/pagination_sub.html17
-rw-r--r--tests/passwords/drivers_test.php416
-rw-r--r--tests/passwords/manager_test.php347
-rw-r--r--tests/path_helper/path_helper_test.php464
-rw-r--r--tests/plupload/plupload_test.php53
-rw-r--r--tests/privmsgs/delete_user_pms_test.php15
-rw-r--r--tests/privmsgs/fixtures/delete_user_pms.xml10
-rw-r--r--tests/profile/custom_test.php55
-rw-r--r--tests/profile/fixtures/profile_fields.xml31
-rw-r--r--tests/profile/get_profile_value_test.php42
-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.php94
-rw-r--r--tests/profilefields/type_int_test.php236
-rw-r--r--tests/profilefields/type_string_test.php353
-rw-r--r--tests/profilefields/type_url_test.php181
-rw-r--r--tests/random/gen_rand_string_test.php10
-rw-r--r--tests/regex/censor_test.php10
-rw-r--r--tests/regex/email_test.php10
-rw-r--r--tests/regex/ipv4_test.php10
-rw-r--r--tests/regex/ipv6_test.php10
-rw-r--r--tests/regex/password_complexity_test.php11
-rw-r--r--tests/regex/table_prefix_test.php10
-rw-r--r--tests/regex/url_test.php12
-rw-r--r--tests/request/deactivated_super_global_test.php25
-rw-r--r--tests/request/request_test.php271
-rw-r--r--tests/request/request_var_test.php108
-rw-r--r--tests/request/type_cast_helper_test.php74
-rw-r--r--tests/search/common_test_case.php208
-rw-r--r--tests/search/fixtures/posts.xml53
-rw-r--r--tests/search/mysql_test.php45
-rw-r--r--tests/search/native_test.php262
-rw-r--r--tests/search/postgres_test.php45
-rw-r--r--tests/security/base.php54
-rw-r--r--tests/security/extract_current_page_test.php44
-rw-r--r--tests/security/hash_test.php37
-rw-r--r--tests/security/redirect_test.php105
-rw-r--r--tests/security/trailing_path_test.php60
-rw-r--r--tests/session/append_sid_test.php14
-rw-r--r--tests/session/check_ban_test.php82
-rw-r--r--tests/session/check_isvalid_test.php65
-rw-r--r--tests/session/continue_test.php121
-rw-r--r--tests/session/create_test.php47
-rw-r--r--tests/session/creation_test.php57
-rw-r--r--tests/session/extract_hostname_test.php55
-rw-r--r--tests/session/extract_page_test.php172
-rw-r--r--tests/session/fixtures/sessions_banlist.xml62
-rw-r--r--tests/session/fixtures/sessions_empty.xml8
-rw-r--r--tests/session/fixtures/sessions_full.xml11
-rw-r--r--tests/session/fixtures/sessions_garbage.xml54
-rw-r--r--tests/session/fixtures/sessions_key.xml39
-rw-r--r--tests/session/garbage_collection_test.php71
-rw-r--r--tests/session/session_key_test.php62
-rw-r--r--tests/session/testable_facade.php130
-rw-r--r--tests/session/testable_factory.php72
-rw-r--r--tests/session/unset_admin_test.php52
-rw-r--r--tests/session/validate_referrer_test.php74
-rw-r--r--tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/omega/styles/all/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/two.html1
-rw-r--r--tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/event/test.html1
-rw-r--r--tests/template/datasets/event_inheritance/styles/silver/template/event_test.html1
-rw-r--r--tests/template/datasets/event_inheritance/styles/silver/template/event_two.html1
-rw-r--r--tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html1
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/event_variable_spacing.html6
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_loop.html1
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html2
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/universal.html1
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/event/simple.html1
-rw-r--r--tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html3
-rw-r--r--tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html1
-rw-r--r--tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html3
-rw-r--r--tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html1
-rw-r--r--tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html1
-rw-r--r--tests/template/ext/include/css/styles/all/theme/child_only.css0
-rw-r--r--tests/template/ext/include/css/styles/all/theme/test.css0
-rw-r--r--tests/template/includephp_test.php60
-rw-r--r--tests/template/parent_templates/parent_and_child.html1
-rw-r--r--tests/template/parent_templates/parent_and_child.js1
-rw-r--r--tests/template/parent_templates/parent_only.css0
-rw-r--r--tests/template/parent_templates/parent_only.html1
-rw-r--r--tests/template/parent_templates/parent_only.js1
-rw-r--r--tests/template/subdir/includephp_from_subdir_test.php31
-rw-r--r--tests/template/template_allfolder_test.php59
-rw-r--r--tests/template/template_events_test.php153
-rw-r--r--tests/template/template_includecss_test.php97
-rw-r--r--tests/template/template_includejs_test.php109
-rw-r--r--tests/template/template_inheritance_test.php59
-rw-r--r--tests/template/template_parser_test.php33
-rw-r--r--tests/template/template_test.php707
-rw-r--r--tests/template/template_test_case.php132
-rw-r--r--tests/template/template_test_case_with_tree.php40
-rw-r--r--tests/template/templates/basic.html3
-rw-r--r--tests/template/templates/child_only.css0
-rw-r--r--tests/template/templates/child_only.html1
-rw-r--r--tests/template/templates/child_only.js1
-rw-r--r--tests/template/templates/define.html33
-rw-r--r--tests/template/templates/define_advanced.html12
-rw-r--r--tests/template/templates/define_error.html2
-rw-r--r--tests/template/templates/define_include.html3
-rw-r--r--tests/template/templates/define_include2.html11
-rw-r--r--tests/template/templates/events.html4
-rw-r--r--tests/template/templates/expressions.html29
-rw-r--r--tests/template/templates/if.html20
-rw-r--r--tests/template/templates/if_nested_tags.html1
-rw-r--r--tests/template/templates/include_define_variable.html6
-rw-r--r--tests/template/templates/include_loop.html4
-rw-r--r--tests/template/templates/include_loop1.html1
-rw-r--r--tests/template/templates/include_loop2.html1
-rw-r--r--tests/template/templates/include_loop3.html1
-rw-r--r--tests/template/templates/include_loop_define.html6
-rw-r--r--tests/template/templates/include_variable.html1
-rw-r--r--tests/template/templates/include_variables.html1
-rw-r--r--tests/template/templates/includecss.html10
-rw-r--r--tests/template/templates/includejs.html36
-rw-r--r--tests/template/templates/includephp_relative.html (renamed from tests/template/templates/includephp.html)1
-rw-r--r--tests/template/templates/includephp_variables.html2
-rw-r--r--tests/template/templates/invalid/endif_without_if.html1
-rw-r--r--tests/template/templates/invalid/output/endif_without_if.html1
-rw-r--r--tests/template/templates/invalid/output/include_nonexistent_file.html1
-rw-r--r--tests/template/templates/invalid/output/unknown_tag.html1
-rw-r--r--tests/template/templates/lang.html2
-rw-r--r--tests/template/templates/loop.html14
-rw-r--r--tests/template/templates/loop_advanced.html20
-rw-r--r--tests/template/templates/loop_expressions.html11
-rw-r--r--tests/template/templates/loop_include.html4
-rw-r--r--tests/template/templates/loop_include1.html1
-rw-r--r--tests/template/templates/loop_nested.html10
-rw-r--r--tests/template/templates/loop_nested2.html6
-rw-r--r--tests/template/templates/loop_nested_deep_multilevel_ref.html13
-rw-r--r--tests/template/templates/loop_nested_include.html4
-rw-r--r--tests/template/templates/loop_nested_include1.html5
-rw-r--r--tests/template/templates/loop_nested_multilevel_ref.html10
-rw-r--r--tests/template/templates/loop_reuse.html6
-rw-r--r--tests/template/templates/loop_size.html39
-rw-r--r--tests/template/templates/loop_underscore.html21
-rw-r--r--tests/template/templates/loop_vars.html26
-rw-r--r--tests/template/templates/parent_and_child.html1
-rw-r--r--tests/template/templates/parent_and_child.js1
-rw-r--r--tests/template/templates/subdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/subsubdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/variable.html1
-rw-r--r--tests/template/templates/trivial.html1
-rw-r--r--tests/template/templates/twig.html6
-rw-r--r--tests/template/templates/twig_parent.html7
-rw-r--r--tests/template/templates/variable_spacing.html6
-rw-r--r--tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php12
-rw-r--r--tests/test_framework/phpbb_database_test_case.php117
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php213
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php697
-rw-r--r--tests/test_framework/phpbb_search_test_case.php33
-rw-r--r--tests/test_framework/phpbb_session_test_case.php60
-rw-r--r--tests/test_framework/phpbb_test_case.php12
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php204
-rw-r--r--tests/test_framework/phpbb_ui_test_case.php571
-rw-r--r--tests/text_processing/censor_text_test.php16
-rw-r--r--tests/text_processing/generate_text_for_display_test.php14
-rw-r--r--tests/text_processing/make_clickable_test.php57
-rw-r--r--tests/tree/fixtures/phpbb_forums.xml13
-rw-r--r--tests/tree/nestedset_forum_base.php121
-rw-r--r--tests/tree/nestedset_forum_get_data_test.php139
-rw-r--r--tests/tree/nestedset_forum_insert_delete_test.php124
-rw-r--r--tests/tree/nestedset_forum_move_test.php573
-rw-r--r--tests/tree/nestedset_forum_regenerate_test.php76
-rw-r--r--tests/tree/nestedset_forum_test.php120
-rw-r--r--tests/ui/quick_links_test.php27
-rw-r--r--tests/upload/filespec_test.php338
-rw-r--r--tests/upload/fileupload_test.php149
-rw-r--r--tests/upload/fixture/copies/.gitkeep0
-rw-r--r--tests/upload/fixture/gifbin0 -> 35 bytes
-rw-r--r--tests/upload/fixture/jpgbin0 -> 519 bytes
-rw-r--r--tests/upload/fixture/pngbin0 -> 69 bytes
-rw-r--r--tests/upload/fixture/tifbin0 -> 256 bytes
-rw-r--r--tests/upload/fixture/txt2
-rw-r--r--tests/user/fixtures/user_loader.xml31
-rw-r--r--tests/user/lang_test.php73
-rw-r--r--tests/user/user_loader_test.php67
-rw-r--r--tests/utf/normalizer_test.php10
-rw-r--r--tests/utf/utf8_clean_string_test.php12
-rw-r--r--tests/utf/utf8_wordwrap_test.php10
-rw-r--r--tests/version/version_fetch_test.php63
-rw-r--r--tests/version/version_helper_remote_test.php216
-rw-r--r--tests/version/version_test.php827
-rw-r--r--tests/viewonline/helper_test.php46
-rw-r--r--tests/wrapper/gmgetdate_test.php60
-rw-r--r--tests/wrapper/mt_rand_test.php10
-rw-r--r--tests/wrapper/phpbb_php_ini_fake.php20
-rw-r--r--tests/wrapper/phpbb_php_ini_test.php90
-rw-r--r--tests/wrapper/version_compare_test.php10
601 files changed, 42871 insertions, 1635 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md
index d9306d78d7..afd7caa709 100644
--- a/tests/RUNNING_TESTS.md
+++ b/tests/RUNNING_TESTS.md
@@ -24,6 +24,7 @@ the following PHP extensions must be installed and enabled to run unit tests:
- ctype (also a PHPUnit dependency)
- dom (PHPUnit dependency)
+- json (also a phpBB dependency)
Some of the functionality in phpBB and/or the test suite uses additional
PHP extensions. If these extensions are not loaded, respective tests
@@ -31,11 +32,12 @@ 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)
- pdo (any database tests)
- pgsql, pdo_pgsql (PostgreSQL database driver)
+- redis (https://github.com/nicolasff/phpredis, Redis cache driver)
- simplexml (any database tests)
- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support
in pdo_sqlite)
@@ -54,7 +56,7 @@ found below. More information on configuration options can be found on the
wiki (see below).
<?php
- $dbms = 'mysqli';
+ $dbms = 'phpbb\db\driver\mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'database';
@@ -79,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";
@@ -98,6 +94,21 @@ to connect to that database in phpBB.
Additionally, you will need to be running the DbUnit fork from
https://github.com/phpbb/dbunit/tree/phpbb.
+Redis
+-----
+
+In order to run tests for the Redis cache driver, at least one of Redis host
+or port must be specified in test configuration. This can be done via
+test_config.php as follows:
+
+ <?php
+ $phpbb_redis_host = 'localhost';
+ $phpbb_redis_port = 6379;
+
+Or via environment variables as follows:
+
+ $ PHPBB_TEST_REDIS_HOST=localhost PHPBB_TEST_REDIS_PORT=6379 phpunit
+
Running
=======
diff --git a/tests/acp_board/auth_provider/invalid.php b/tests/acp_board/auth_provider/invalid.php
new file mode 100644
index 0000000000..dbd1d159a4
--- /dev/null
+++ b/tests/acp_board/auth_provider/invalid.php
@@ -0,0 +1,19 @@
+<?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.
+*
+*/
+
+namespace phpbb\auth\provider\acp;
+
+class board_invalid
+{
+
+}
diff --git a/tests/acp_board/auth_provider/valid.php b/tests/acp_board/auth_provider/valid.php
new file mode 100644
index 0000000000..6477bf4b53
--- /dev/null
+++ b/tests/acp_board/auth_provider/valid.php
@@ -0,0 +1,22 @@
+<?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.
+*
+*/
+
+namespace phpbb\auth\provider\acp;
+
+class board_valid extends \phpbb\auth\provider\base
+{
+ public function login($username, $password)
+ {
+ return;
+ }
+}
diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php
new file mode 100644
index 0000000000..16e5954c64
--- /dev/null
+++ b/tests/acp_board/select_auth_method_test.php
@@ -0,0 +1,52 @@
+<?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/acp/acp_board.php';
+require_once dirname(__FILE__) . '/auth_provider/invalid.php';
+require_once dirname(__FILE__) . '/auth_provider/valid.php';
+
+class phpbb_acp_board_select_auth_method_test extends phpbb_test_case
+{
+ protected $acp_board;
+
+ public static function select_auth_method_data()
+ {
+ return array(
+ array('acp_board_valid', '<option value="acp_board_valid" selected="selected" data-toggle-setting="#auth_acp_board_valid_settings">Acp_board_valid</option>'),
+ array('acp_board_invalid', '<option value="acp_board_valid" data-toggle-setting="#auth_acp_board_valid_settings">Acp_board_valid</option>'),
+ );
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_container;
+ $phpbb_container = new phpbb_mock_container_builder();
+
+ $phpbb_container->set('auth.provider_collection', array(
+ 'auth.provider.acp_board_valid' => new phpbb\auth\provider\acp\board_valid,
+ 'auth.provider.acp_board_invalid' => new phpbb\auth\provider\acp\board_invalid,
+ ));
+
+ $this->acp_board = new acp_board();
+ }
+
+ /**
+ * @dataProvider select_auth_method_data
+ */
+ public function test_select_auth_method($selected, $expected)
+ {
+ $this->assertEquals($expected, $this->acp_board->select_auth_method($selected));
+ }
+}
diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml
new file mode 100644
index 0000000000..6c82e94e62
--- /dev/null
+++ b/tests/auth/fixtures/oauth_tokens.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_oauth_tokens">
+ <column>user_id</column>
+ <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/fixtures/user.xml b/tests/auth/fixtures/user.xml
new file mode 100644
index 0000000000..1e0eb6ee49
--- /dev/null
+++ b/tests/auth/fixtures/user.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_password</column>
+ <column>user_passchg</column>
+ <column>user_email</column>
+ <column>user_type</column>
+ <column>user_login_attempts</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>foobar</value>
+ <value>foobar</value>
+ <value>$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i</value>
+ <value>0</value>
+ <value>example@example.com</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>foobar2</value>
+ <value>foobar2</value>
+ <value>$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/</value>
+ <value>0</value>
+ <value>example@example.com</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/auth/fixtures/user_533.xml b/tests/auth/fixtures/user_533.xml
new file mode 100644
index 0000000000..9731e4db4a
--- /dev/null
+++ b/tests/auth/fixtures/user_533.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_password</column>
+ <column>user_passchg</column>
+ <column>user_email</column>
+ <column>user_type</column>
+ <column>user_login_attempts</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>foobar</value>
+ <value>foobar</value>
+ <value>$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi</value>
+ <value>0</value>
+ <value>example@example.com</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>foobar2</value>
+ <value>foobar2</value>
+ <value>$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/</value>
+ <value>0</value>
+ <value>example@example.com</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></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_apache_test.php b/tests/auth/provider_apache_test.php
new file mode 100644
index 0000000000..68ad7b2c19
--- /dev/null
+++ b/tests/auth/provider_apache_test.php
@@ -0,0 +1,229 @@
+<?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/utf/utf_tools.php';
+
+class phpbb_auth_provider_apache_test extends phpbb_database_test_case
+{
+ protected $provider;
+ protected $user;
+ protected $request;
+
+ protected function setup()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $db = $this->new_dbal();
+ $config = new \phpbb\config\config(array());
+ $this->request = $this->getMock('\phpbb\request\request');
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ $driver_helper = new \phpbb\passwords\driver\helper($config);
+ $passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
+ );
+
+ $passwords_helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
+
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ $this->password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi';
+ }
+ else
+ {
+ $this->password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i';
+ }
+
+ $this->provider = new \phpbb\auth\provider\apache($db, $config, $passwords_manager, $this->request, $this->user, $phpbb_root_path, $phpEx);
+ }
+
+ public function getDataSet()
+ {
+ if ((version_compare(PHP_VERSION, '5.3.7', '<')))
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml');
+ }
+ else
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml');
+ }
+ }
+
+ /**
+ * Test to see if a user is identified to Apache. Expects false if they are.
+ */
+ public function test_init()
+ {
+ $this->user->data['username'] = 'foobar';
+ $this->request->expects($this->once())
+ ->method('is_set')
+ ->with('PHP_AUTH_USER',
+ \phpbb\request\request_interface::SERVER)
+ ->will($this->returnValue(true));
+ $this->request->expects($this->once())
+ ->method('server')
+ ->with('PHP_AUTH_USER')
+ ->will($this->returnValue('foobar'));
+
+ $this->assertFalse($this->provider->init());
+ }
+
+ public function test_login()
+ {
+ $username = 'foobar';
+ $password = 'example';
+
+ $this->request->expects($this->once())
+ ->method('is_set')
+ ->with('PHP_AUTH_USER',
+ \phpbb\request\request_interface::SERVER)
+ ->will($this->returnValue(true));
+ $this->request->expects($this->at(1))
+ ->method('server')
+ ->with('PHP_AUTH_USER')
+ ->will($this->returnValue('foobar'));
+ $this->request->expects($this->at(2))
+ ->method('server')
+ ->with('PHP_AUTH_PW')
+ ->will($this->returnValue('example'));
+
+ $expected = array(
+ 'status' => LOGIN_SUCCESS,
+ 'error_msg' => false,
+ 'user_row' => array(
+ 'user_id' => '1',
+ 'username' => 'foobar',
+ 'user_password' => $this->password_hash,
+ 'user_passchg' => '0',
+ 'user_email' => 'example@example.com',
+ 'user_type' => '0',
+ ),
+ );
+
+ $this->assertEquals($expected, $this->provider->login($username, $password));
+ }
+
+ public function test_autologin()
+ {
+ $this->request->expects($this->once())
+ ->method('is_set')
+ ->with('PHP_AUTH_USER',
+ \phpbb\request\request_interface::SERVER)
+ ->will($this->returnValue(true));
+ $this->request->expects($this->at(1))
+ ->method('server')
+ ->with('PHP_AUTH_USER')
+ ->will($this->returnValue('foobar'));
+ $this->request->expects($this->at(2))
+ ->method('server')
+ ->with('PHP_AUTH_PW')
+ ->will($this->returnValue('example'));
+
+ $expected = array(
+ 'user_id' => '1',
+ 'user_type' => '0',
+ 'group_id' => '3',
+ 'user_permissions' => '',
+ 'user_perm_from' => '0',
+ 'user_ip' => '',
+ 'user_regdate' => '0',
+ 'username' => 'foobar',
+ 'username_clean' => 'foobar',
+ 'user_password' => $this->password_hash,
+ 'user_passchg' => '0',
+ 'user_email' => 'example@example.com',
+ 'user_email_hash' => '0',
+ 'user_birthday' => '',
+ 'user_lastvisit' => '0',
+ 'user_lastmark' => '0',
+ 'user_lastpost_time' => '0',
+ 'user_lastpage' => '',
+ 'user_last_confirm_key' => '',
+ 'user_last_search' => '0',
+ 'user_warnings' => '0',
+ 'user_last_warning' => '0',
+ 'user_login_attempts' => '0',
+ 'user_inactive_reason' => '0',
+ 'user_inactive_time' => '0',
+ 'user_posts' => '0',
+ 'user_lang' => '',
+ 'user_timezone' => '',
+ 'user_dateformat' => 'd M Y H:i',
+ 'user_style' => '0',
+ 'user_rank' => '0',
+ 'user_colour' => '',
+ 'user_new_privmsg' => '0',
+ 'user_unread_privmsg' => '0',
+ 'user_last_privmsg' => '0',
+ 'user_message_rules' => '0',
+ 'user_full_folder' => '-3',
+ 'user_emailtime' => '0',
+ 'user_topic_show_days' => '0',
+ 'user_topic_sortby_type' => 't',
+ 'user_topic_sortby_dir' => 'd',
+ 'user_post_show_days' => '0',
+ 'user_post_sortby_type' => 't',
+ 'user_post_sortby_dir' => 'a',
+ 'user_notify' => '0',
+ 'user_notify_pm' => '1',
+ 'user_notify_type' => '0',
+ 'user_allow_pm' => '1',
+ 'user_allow_viewonline' => '1',
+ 'user_allow_viewemail' => '1',
+ 'user_allow_massemail' => '1',
+ 'user_options' => '230271',
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => '0',
+ 'user_avatar_height' => '0',
+ 'user_sig' => '',
+ 'user_sig_bbcode_uid' => '',
+ 'user_sig_bbcode_bitfield' => '',
+ 'user_jabber' => '',
+ 'user_actkey' => '',
+ 'user_newpasswd' => '',
+ 'user_form_salt' => '',
+ 'user_new' => '1',
+ 'user_reminded' => '0',
+ 'user_reminded_time' => '0',
+ );
+
+ $this->assertEquals($expected, $this->provider->autologin());
+ }
+
+ public function test_validate_session()
+ {
+ $user = array(
+ 'username' => 'foobar',
+ 'user_type'
+ );
+ $this->request->expects($this->once())
+ ->method('is_set')
+ ->with('PHP_AUTH_USER',
+ \phpbb\request\request_interface::SERVER)
+ ->will($this->returnValue(true));
+ $this->request->expects($this->once())
+ ->method('server')
+ ->with('PHP_AUTH_USER')
+ ->will($this->returnValue('foobar'));
+
+ $this->assertTrue($this->provider->validate_session($user));
+ }
+}
diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php
new file mode 100644
index 0000000000..09ca0816bf
--- /dev/null
+++ b/tests/auth/provider_db_test.php
@@ -0,0 +1,95 @@
+<?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/utf/utf_tools.php';
+
+class phpbb_auth_provider_db_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ if ((version_compare(PHP_VERSION, '5.3.7', '<')))
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml');
+ }
+ else
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml');
+ }
+ }
+
+ public function test_login()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $db = $this->new_dbal();
+ $config = new \phpbb\config\config(array(
+ 'ip_login_limit_max' => 0,
+ 'ip_login_limit_use_forwarded' => 0,
+ 'max_login_attempts' => 0,
+ ));
+ $request = $this->getMock('\phpbb\request\request');
+ $user = new \phpbb\user('\phpbb\datetime');
+ $driver_helper = new \phpbb\passwords\driver\helper($config);
+ $passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
+ );
+
+ $passwords_helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
+
+ $phpbb_container = new phpbb_mock_container_builder();
+
+ $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_container, $phpbb_root_path, $phpEx);
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ $password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi';
+ }
+ else
+ {
+ $password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i';
+ }
+
+ $expected = array(
+ 'status' => LOGIN_SUCCESS,
+ 'error_msg' => false,
+ 'user_row' => array(
+ 'user_id' => '1',
+ 'username' => 'foobar',
+ 'user_password' => $password_hash,
+ 'user_passchg' => '0',
+ 'user_email' => 'example@example.com',
+ 'user_type' => '0',
+ 'user_login_attempts' => '0',
+ ),
+ );
+
+ $login_return = $provider->login('foobar', 'example');
+ $this->assertEquals($expected['status'], $login_return['status']);
+ $this->assertEquals($expected['error_msg'], $login_return['error_msg']);
+
+ foreach ($expected['user_row'] as $key => $value)
+ {
+ $this->assertEquals($value, $login_return['user_row'][$key]);
+ }
+
+ // Check if convert works
+ $login_return = $provider->login('foobar2', 'example');
+ $password_start = (version_compare(PHP_VERSION, '5.3.7', '<')) ? '$2a$10$' : '$2y$10$';
+ $this->assertStringStartsWith($password_start, $login_return['user_row']['user_password']);
+ }
+}
diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php
new file mode 100644
index 0000000000..71b49ff439
--- /dev/null
+++ b/tests/auth/provider_oauth_token_storage_test.php
@@ -0,0 +1,229 @@
+<?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 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;
+ protected $service_name;
+ protected $session_id;
+ protected $token_storage;
+ protected $token_storage_table;
+ protected $user;
+
+ protected function setup()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ $this->service_name = 'auth.provider.oauth.service.testing';
+ $this->token_storage_table = 'phpbb_oauth_tokens';
+
+ // Give the user a session_id that we will remember
+ $this->session_id = '12345';
+ $this->user->data['session_id'] = $this->session_id;
+
+ // Set the user id to anonymous
+ $this->user->data['user_id'] = ANONYMOUS;
+
+ $this->token_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table);
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/oauth_tokens.xml');
+ }
+
+ public static function retrieveAccessToken_data()
+ {
+ return array(
+ array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')), null),
+ array(null, 'OAuth\Common\Storage\Exception\TokenNotFoundException'),
+ );
+ }
+
+ /**
+ * @dataProvider retrieveAccessToken_data
+ */
+ public function test_retrieveAccessToken($cache_token, $exception)
+ {
+ if ($cache_token)
+ {
+ $this->token_storage->storeAccessToken($this->service_name, $cache_token);
+ $token = $cache_token;
+ }
+
+ $this->setExpectedException($exception);
+
+ $stored_token = $this->token_storage->retrieveAccessToken($this->service_name);
+ $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);
+
+ // Store a token in the database
+ $temp_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table);
+ $temp_storage->storeAccessToken($this->service_name, $expected_token);
+ unset($temp_storage);
+
+ // Test to see if the token can be retrieved
+ $stored_token = $this->token_storage->retrieveAccessToken($this->service_name);
+ $this->assertEquals($expected_token, $stored_token);
+ }
+
+ /**
+ * @dataProvider retrieveAccessToken_data
+ */
+ public function test_retrieve_access_token_by_session($cache_token, $exception)
+ {
+ if ($cache_token)
+ {
+ $this->token_storage->storeAccessToken($this->service_name, $cache_token);
+ $token = $cache_token;
+ }
+
+ $this->setExpectedException($exception);
+
+ $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name);
+ $this->assertEquals($token, $stored_token);
+ }
+
+ public function test_retrieve_access_token_by_session_from_db()
+ {
+ $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES);
+
+ // Store a token in the database
+ $temp_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table);
+ $temp_storage->storeAccessToken($this->service_name, $expected_token);
+ unset($temp_storage);
+
+ // Test to see if the token can be retrieved
+ $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name);
+ $this->assertEquals($expected_token, $stored_token);
+ }
+
+ public function test_storeAccessToken()
+ {
+ $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') );
+ $this->token_storage->storeAccessToken($this->service_name, $token);
+
+ // Confirm that the token is cached
+ $extraParams = $this->token_storage->retrieveAccessToken($this->service_name)->getExtraParams();
+ $this->assertEquals( 'param', $extraParams['extra'] );
+ $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken($this->service_name)->getAccessToken() );
+
+ $row = $this->get_token_row_by_session_id($this->session_id);
+
+ // The token is serialized before stored in the database
+ $this->assertEquals($this->token_storage->json_encode_token($token), $row['oauth_token']);
+ }
+
+ public static function hasAccessToken_data()
+ {
+ return array(
+ array(null, false),
+ array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ), true),
+ );
+ }
+
+ /**
+ * @dataProvider hasAccessToken_data
+ */
+ public function test_hasAccessToken($token, $expected)
+ {
+ if ($token)
+ {
+ $this->token_storage->storeAccessToken($this->service_name, $token);
+ }
+
+ $has_access_token = $this->token_storage->hasAccessToken($this->service_name);
+ $this->assertEquals($expected, $has_access_token);
+ }
+
+ /**
+ * @dataProvider hasAccessToken_data
+ */
+ public function test_has_access_token_by_session($token, $expected)
+ {
+ if ($token)
+ {
+ $this->token_storage->storeAccessToken($this->service_name, $token);
+ }
+
+ $has_access_token = $this->token_storage->has_access_token_by_session($this->service_name);
+ $this->assertEquals($expected, $has_access_token);
+ }
+
+ public function test_clearToken()
+ {
+ $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') );
+ $this->token_storage->storeAccessToken($this->service_name, $token);
+
+ $this->token_storage->clearToken($this->service_name);
+
+ // Check that the database has been cleared
+ $row = $this->get_token_row_by_session_id($this->session_id);
+ $this->assertFalse($row);
+
+ // Check that the token is no longer in memory
+ $this->assertFalse($this->token_storage->hasAccessToken($this->service_name));
+ }
+
+ public function test_set_user_id()
+ {
+ $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') );
+ $this->token_storage->storeAccessToken($this->service_name, $token);
+
+ $new_user_id = ANONYMOUS + 1;
+ $this->token_storage->set_user_id($new_user_id);
+
+ $row = $this->get_token_row_by_session_id($this->session_id);
+ $this->assertEquals($new_user_id, $row['user_id']);
+ }
+
+ protected function get_token_row_by_session_id($session_id)
+ {
+ // Test that the token is stored in the database
+ $sql = 'SELECT * FROM phpbb_oauth_tokens
+ WHERE session_id = \'' . $this->db->sql_escape($session_id) . '\'';
+ $result = $this->db->sql_query($sql);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ return $row;
+ }
+}
diff --git a/tests/avatar/driver/barfoo.php b/tests/avatar/driver/barfoo.php
new file mode 100644
index 0000000000..0bf30b8a91
--- /dev/null
+++ b/tests/avatar/driver/barfoo.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace phpbb\avatar\driver;
+
+class barfoo extends \phpbb\avatar\driver\driver
+{
+ public function get_data($row)
+ {
+ return array();
+ }
+
+ public function prepare_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function process_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function get_template_name()
+ {
+ return 'barfoo.html';
+ }
+}
diff --git a/tests/avatar/driver/foobar.php b/tests/avatar/driver/foobar.php
new file mode 100644
index 0000000000..aabdaf5ac4
--- /dev/null
+++ b/tests/avatar/driver/foobar.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace phpbb\avatar\driver;
+
+class foobar extends \phpbb\avatar\driver\driver
+{
+ public function get_data($row)
+ {
+ return array();
+ }
+
+ public function prepare_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function process_form($request, $template, $user, $row, &$error)
+ {
+ return false;
+ }
+
+ public function get_template_name()
+ {
+ return 'foobar.html';
+ }
+}
diff --git a/tests/avatar/fixtures/users.xml b/tests/avatar/fixtures/users.xml
new file mode 100644
index 0000000000..1773d438c2
--- /dev/null
+++ b/tests/avatar/fixtures/users.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_avatar</column>
+ <column>user_avatar_type</column>
+ <column>user_avatar_width</column>
+ <column>user_avatar_height</column>
+ <row>
+ <value>1</value>
+ <value>barfoo</value>
+ <value></value>
+ <value></value>
+ <value>foobar@example.com</value>
+ <value>avatar.driver.gravatar</value>
+ <value>80</value>
+ <value>80</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>foobar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>foo</value>
+ <value></value>
+ <value></value>
+ <value>g5_1414350991.jpg</value>
+ <value>avatar.driver.upload</value>
+ <value>80</value>
+ <value>80</value>
+ </row>
+ </table>
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_type</column>
+ <column>group_name</column>
+ <column>group_avatar</column>
+ <column>group_avatar_type</column>
+ <column>group_avatar_width</column>
+ <column>group_avatar_height</column>
+ <row>
+ <value>5</value>
+ <value>3</value>
+ <value>ADMINISTRATORS</value>
+ <value>g5_1414350991.jpg</value>
+ <value>avatar.driver.upload</value>
+ <value>80</value>
+ <value>80</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
new file mode 100644
index 0000000000..802e71939d
--- /dev/null
+++ b/tests/avatar/manager_test.php
@@ -0,0 +1,430 @@
+<?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__) . '/driver/foobar.php';
+
+class phpbb_avatar_manager_test extends \phpbb_database_test_case
+{
+ /** @var \phpbb\avatar\manager */
+ protected $manager;
+ protected $avatar_foobar;
+ protected $avatar_barfoo;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/users.xml');
+ }
+
+ public function setUp()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ // Mock phpbb_container
+ $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $phpbb_container->expects($this->any())
+ ->method('get')
+ ->will($this->returnArgument(0));
+
+ // Prepare dependencies for avatar manager and driver
+ $this->config = new \phpbb\config\config(array());
+ $cache = $this->getMock('\phpbb\cache\driver\driver_interface');
+ $path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->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);
+
+ $dispatcher = new phpbb_mock_event_dispatcher();
+
+ // $this->avatar_foobar will be needed later on
+ $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ $this->avatar_foobar->expects($this->any())
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.foobar'));
+ // barfoo driver can't be mocked with constructor arguments
+ $this->avatar_barfoo = $this->getMock('\phpbb\avatar\driver\barfoo', array('get_name', 'get_config_name'));
+ $this->avatar_barfoo->expects($this->any())
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.barfoo'));
+ $this->avatar_barfoo->expects($this->any())
+ ->method('get_config_name')
+ ->will($this->returnValue('barfoo'));
+ $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo);
+
+ foreach ($this->avatar_drivers() as $driver)
+ {
+ if ($driver !== 'upload')
+ {
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ }
+ else
+ {
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $dispatcher, $cache));
+ }
+ $cur_avatar->expects($this->any())
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.' . $driver));
+ $this->config['allow_avatar_' . get_class($cur_avatar)] = $driver == 'gravatar';
+ $avatar_drivers[] = $cur_avatar;
+ }
+
+ $this->config['allow_avatar_' . get_class($this->avatar_foobar)] = true;
+ $this->config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;
+
+ // Set up avatar manager
+ $this->manager = new \phpbb\avatar\manager($this->config, $avatar_drivers, $phpbb_container);
+ $this->db = $this->new_dbal();
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ }
+
+ protected function avatar_drivers()
+ {
+ return array(
+ 'local',
+ 'upload',
+ 'remote',
+ 'gravatar',
+ );
+ }
+
+ public function test_get_all_drivers()
+ {
+ $drivers = $this->manager->get_all_drivers();
+ $this->assertEquals(array(
+ 'avatar.driver.barfoo' => 'avatar.driver.barfoo',
+ 'avatar.driver.foobar' => 'avatar.driver.foobar',
+ 'avatar.driver.local' => 'avatar.driver.local',
+ 'avatar.driver.remote' => 'avatar.driver.remote',
+ 'avatar.driver.upload' => 'avatar.driver.upload',
+ 'avatar.driver.gravatar' => 'avatar.driver.gravatar',
+ ), $drivers);
+ }
+
+ public function test_get_enabled_drivers()
+ {
+ $drivers = $this->manager->get_enabled_drivers();
+ $this->assertArrayHasKey('avatar.driver.foobar', $drivers);
+ $this->assertArrayNotHasKey('avatar.driver.barfoo', $drivers);
+ $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);
+ }
+
+ public function get_driver_data_enabled()
+ {
+ return array(
+ array('avatar.driver.foobar', 'avatar.driver.foobar'),
+ array('avatar.driver.gravatar', 'avatar.driver.gravatar'),
+ array('avatar.driver.foo_wrong', null),
+ array('avatar.driver.local', null),
+ array(AVATAR_GALLERY, null),
+ array(AVATAR_UPLOAD, null),
+ array(AVATAR_REMOTE, null),
+ );
+ }
+
+ /**
+ * @dataProvider get_driver_data_enabled
+ */
+ public function test_get_driver_enabled($driver_name, $expected)
+ {
+ $driver = $this->manager->get_driver($driver_name);
+ $this->assertEquals($expected, ($driver === null) ? null : $driver->get_name());
+ }
+
+ public function get_driver_data_all()
+ {
+ return array(
+ array('avatar.driver.foobar', 'avatar.driver.foobar'),
+ array('avatar.driver.foo_wrong', null),
+ array('avatar.driver.local', 'avatar.driver.local'),
+ array(AVATAR_GALLERY, 'avatar.driver.local'),
+ array(AVATAR_UPLOAD, 'avatar.driver.upload'),
+ array(AVATAR_REMOTE, 'avatar.driver.remote'),
+ );
+ }
+
+ /**
+ * @dataProvider get_driver_data_all
+ */
+ public function test_get_driver_all($driver_name, $expected)
+ {
+ $driver = $this->manager->get_driver($driver_name, false);
+ $this->assertEquals($expected, ($driver === null) ? $driver : $driver->get_name());
+ }
+
+ public function test_get_avatar_settings()
+ {
+ $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar);
+
+ $expected_settings = array(
+ 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
+ );
+
+ $this->assertEquals($expected_settings, $avatar_settings);
+ }
+
+ public function database_row_data()
+ {
+ return array(
+ array(
+ array(
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => '',
+ 'user_avatar_height' => '',
+ 'group_avatar' => '',
+ ),
+ array(
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => '',
+ 'user_avatar_height' => '',
+ 'group_avatar' => '',
+ ),
+ 'foobar',
+ ),
+ array(
+ array(),
+ array(
+ 'avatar' => '',
+ 'avatar_type' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
+ ),
+ ),
+ array(
+ array(
+ 'user_avatar' => '',
+ 'user_id' => 5,
+ 'group_id' => 4,
+ ),
+ array(
+ 'user_avatar' => '',
+ 'user_id' => 5,
+ 'group_id' => 4,
+ ),
+ ),
+ array(
+ array(
+ 'user_avatar' => '',
+ 'user_id' => 5,
+ 'group_id' => 4,
+ ),
+ array(
+ 'avatar' => '',
+ 'id' => 5,
+ 'group_id' => 4,
+ ),
+ 'user',
+ ),
+ array(
+ array(
+ 'group_avatar' => '',
+ 'user_id' => 5,
+ 'group_id' => 4,
+ ),
+ array(
+ 'avatar' => '',
+ 'id' => 'g4',
+ 'user_id' => 5,
+ ),
+ 'group',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider database_row_data
+ */
+ public function test_clean_row(array $input, array $output, $prefix = '')
+ {
+ $cleaned_row = \phpbb\avatar\manager::clean_row($input, $prefix);
+ foreach ($output as $key => $value)
+ {
+ $this->assertArrayHasKey($key, $cleaned_row);
+ $this->assertEquals($cleaned_row[$key], $value);
+ }
+ }
+
+ public function test_clean_driver_name()
+ {
+ $this->assertEquals('avatar.driver.local', $this->manager->clean_driver_name('avatar_driver_local'));
+ }
+
+ public function test_prepare_driver_name()
+ {
+ $this->assertEquals('avatar_driver_local', $this->manager->prepare_driver_name('avatar.driver.local'));
+ }
+
+ public function test_localize_errors()
+ {
+ $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $lang_array = array(
+ array('FOOBAR_OFF', 'foobar_off'),
+ array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'),
+ );
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnValueMap($lang_array));
+
+ // Pass error as string
+ $this->assertEquals(array('foobar_off'), $this->manager->localize_errors($user, array('FOOBAR_OFF')));
+
+ // Pass error as array for vsprintf()
+ $this->assertEquals(array('FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(array('FOOBAR_EXPLAIN', 'foo'))));
+
+ // Pass both types
+ $this->assertEquals(array('foobar_off', 'FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(
+ 'FOOBAR_OFF',
+ array('FOOBAR_EXPLAIN', 'foo'),
+ )));
+ }
+
+ public function data_handle_avatar_delete()
+ {
+ return array(
+ array(
+ array(
+ 'avatar' => '',
+ 'avatar_type' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
+ ), 1, array(
+ 'avatar' => 'foobar@example.com',
+ 'avatar_type' => 'avatar.driver.gravatar',
+ 'avatar_width' => '16',
+ 'avatar_height' => '16',
+ ), USERS_TABLE, 'user_',
+ ),
+ array(
+ array(
+ 'avatar' => '',
+ 'avatar_type' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
+ ), 5, array(
+ 'avatar' => 'g5_1414350991.jpg',
+ 'avatar_type' => 'avatar.driver.upload',
+ 'avatar_width' => '80',
+ 'avatar_height' => '80'
+ ), GROUPS_TABLE, 'group_',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_handle_avatar_delete
+ */
+ public function test_handle_avatar_delete($expected, $id, $avatar_data, $table, $prefix)
+ {
+ $this->config['allow_avatar_gravatar'] = true;
+ $this->assertNull($this->manager->handle_avatar_delete($this->db, $this->user, $avatar_data, $table, $prefix));
+
+ $sql = 'SELECT * FROM ' . $table . '
+ WHERE ' . $prefix . 'id = ' . $id;
+ $result = $this->db->sql_query_limit($sql, 1);
+
+ $row = $this->manager->clean_row($this->db->sql_fetchrow($result), substr($prefix, 0, -1));
+ $this->db->sql_freeresult($result);
+
+ foreach ($expected as $key => $value)
+ {
+ $this->assertEquals($value, $row[$key]);
+ }
+ }
+
+ /**
+ * @dependsOn test_handle_avatar_delete
+ */
+ public function test_user_group_avatar_deleted()
+ {
+ $sql = 'SELECT * FROM ' . USERS_TABLE . '
+ WHERE user_id = 3';
+ $result = $this->db->sql_query_limit($sql, 1);
+ $row = $this->manager->clean_row($this->db->sql_fetchrow($result), 'user');
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals(array(
+ 'avatar' => '',
+ 'avatar_type' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
+ ), $row);
+ }
+
+ public function data_remote_avatar_url()
+ {
+ return array(
+ array('127.0.0.1:91?foo.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array(gethostbyname('secure.gravatar.com') . '/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80),
+ array(gethostbyname('secure.gravatar.com') . ':120/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com:80?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), // should be a 404
+ array('2001:db8:0:0:0:0:2:1/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/2001:db8:0:0:0:0:2:1/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ array('secure.gravatar.com/127.0.0.1:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
+ );
+ }
+
+ /**
+ * @dataProvider data_remote_avatar_url
+ */
+ public function test_remote_avatar_url($url, $width, $height, $expected_error = array())
+ {
+ global $phpbb_root_path, $phpEx;
+
+ if (!function_exists('get_preg_expression'))
+ {
+ require($phpbb_root_path . 'includes/functions.' . $phpEx);
+ }
+
+ $this->config['server_name'] = 'foobar.com';
+
+ /** @var \phpbb\avatar\driver\remote $remote_avatar */
+ $remote_avatar = $this->manager->get_driver('avatar.driver.remote', false);
+
+ $request = new phpbb_mock_request(array(), array(
+ 'avatar_remote_url' => $url,
+ 'avatar_remote_width' => $width,
+ 'avatar_remote_height' => $height,
+ ));
+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $row = array();
+ $error = array();
+
+ $return = $remote_avatar->process_form($request, null, $user, $row, $error);
+ if (count($expected_error) > 0)
+ {
+ $this->assertFalse($return);
+ }
+ else
+ {
+ $this->assertNotEquals(false, $return);
+ }
+ $this->assertSame($expected_error, $error);
+ }
+}
diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php
new file mode 100644
index 0000000000..14736627f3
--- /dev/null
+++ b/tests/bbcode/parser_test.php
@@ -0,0 +1,269 @@
+<?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/bbcode.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
+
+class phpbb_bbcode_parser_test extends \phpbb_test_case
+{
+ public function bbcode_firstpass_data()
+ {
+ return array(
+ // Default bbcodes from in their simplest way
+ array(
+ 'Test default bbcodes: simple bold',
+ '[b]bold[/b]',
+ '[b:]bold[/b:]',
+ ),
+ array(
+ 'Test default bbcodes: simple underlined',
+ '[u]underlined[/u]',
+ '[u:]underlined[/u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple italic',
+ '[i]italic[/i]',
+ '[i:]italic[/i:]',
+ ),
+ array(
+ 'Test default bbcodes: simple color rgb',
+ '[color=#FF0000]colored[/color]',
+ '[color=#FF0000:]colored[/color:]',
+ ),
+ array(
+ 'Test default bbcodes: simple color name',
+ '[color=red]colored[/color]',
+ '[color=red:]colored[/color:]',
+ ),
+ array(
+ 'Test default bbcodes: simple size',
+ '[size=75]smaller[/size]',
+ '[size=75:]smaller[/size:]',
+ ),
+ array(
+ 'Test default bbcodes: simple quote',
+ '[quote]quoted[/quote]',
+ '[quote:]quoted[/quote:]',
+ ),
+ array(
+ 'Test default bbcodes: simple quote with username',
+ '[quote=&quot;username&quot;]quoted[/quote]',
+ '[quote=&quot;username&quot;:]quoted[/quote:]',
+ ),
+ array(
+ 'Test default bbcodes: simple code',
+ '[code]unparsed code[/code]',
+ '[code:]unparsed code[/code:]',
+ ),
+ array(
+ 'Test default bbcodes: simple php code',
+ '[code=php]unparsed code[/code]',
+ '[code=php:]<span class="syntaxdefault">unparsed&nbsp;code</span>[/code:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list',
+ '[list]no item[/list]',
+ '[list:]no item[/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item only',
+ '[*]unparsed',
+ '[*]unparsed',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item',
+ '[list][*]item[/list]',
+ '[list:][*:]item[/*:m:][/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item closed',
+ '[list][*]item[/*][/list]',
+ '[list:][*:]item[/*:][/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item numbered',
+ '[list=1][*]item[/list]',
+ '[list=1:][*:]item[/*:m:][/list:o:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item alpha',
+ '[list=a][*]item[/list]',
+ '[list=a:][*:]item[/*:m:][/list:o:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item roman',
+ '[list=i][*]item[/list]',
+ '[list=i:][*:]item[/*:m:][/list:o:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item disc',
+ '[list=disc][*]item[/list]',
+ '[list=disc:][*:]item[/*:m:][/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item circle',
+ '[list=circle][*]item[/list]',
+ '[list=circle:][*:]item[/*:m:][/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple list-item square',
+ '[list=square][*]item[/list]',
+ '[list=square:][*:]item[/*:m:][/list:u:]',
+ ),
+ array(
+ 'Test default bbcodes: simple img',
+ '[img]https://area51.phpbb.com/images/area51.png[/img]',
+ '[img:]https&#58;//area51&#46;phpbb&#46;com/images/area51&#46;png[/img:]',
+ ),
+ array(
+ 'Test default bbcodes: simple url',
+ '[url]https://area51.phpbb.com/[/url]',
+ '[url:]https&#58;//area51&#46;phpbb&#46;com/[/url:]',
+ ),
+ array(
+ 'Test default bbcodes: simple url with description',
+ '[url=https://area51.phpbb.com/]Area51[/url]',
+ '[url=https&#58;//area51&#46;phpbb&#46;com/:]Area51[/url:]',
+ ),
+ array(
+ 'Test default bbcodes: simple email',
+ '[email]bbcode-test@phpbb.com[/email]',
+ '[email:]bbcode-test@phpbb&#46;com[/email:]',
+ ),
+ array(
+ 'Test default bbcodes: simple email with description',
+ '[email=bbcode-test@phpbb.com]Email[/email]',
+ '[email=bbcode-test@phpbb&#46;com:]Email[/email:]',
+ ),
+ array(
+ 'Test default bbcodes: simple attachment',
+ '[attachment=0]filename[/attachment]',
+ '[attachment=0:]<!-- ia0 -->filename<!-- ia0 -->[/attachment:]',
+ ),
+
+ // Special cases for quote which were reported as bugs before
+ array(
+ 'PHPBB3-1401 - correct: parsed',
+ '[quote=&quot;&#91;test]test&quot;]test [ test[/quote]',
+ '[quote=&quot;&#91;test]test&quot;:]test [ test[/quote:]',
+ ),
+ array(
+ 'PHPBB3-6117 - correct: parsed',
+ '[quote]test[/quote] test ] and [ test [quote]test[/quote]',
+ '[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]',
+ ),
+ array(
+ 'PHPBB3-6200 - correct: parsed',
+ '[quote=&quot;[&quot;]test[/quote]',
+ '[quote=&quot;&#91;&quot;:]test[/quote:]',
+ ),
+ array(
+ 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted',
+ '[quote]test[/[/b]quote] test [/quote][/quote] test',
+ '[quote:]test[/[/b]quote] test [/quote:][/quote] test',
+ ),
+ array(
+ 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed',
+ '[quote=&quot;a&quot;]a[/quote][quote=&quot;a]a[/quote]',
+ '[quote=&quot;a&quot;:]a[/quote:][quote=&quot;a]a[/quote]',
+ ),
+
+ // Simple bbcodes nesting
+ array(
+ 'Allow textual bbcodes in textual bbcodes',
+ '[b]bold [i]bold + italic[/i][/b]',
+ '[b:]bold [i:]bold + italic[/i:][/b:]',
+ ),
+ array(
+ 'Allow textual bbcodes in url with description',
+ '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]',
+ '[url=https&#58;//area51&#46;phpbb&#46;com/:]Area51 [i:]italic[/i:][/url:]',
+ ),
+ array(
+ 'Allow url with description in textual bbcodes',
+ '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]',
+ '[i:]italic [url=https&#58;//area51&#46;phpbb&#46;com/:]Area51[/url:][/i:]',
+ ),
+
+ // Nesting bbcodes into quote usernames
+ array(
+ 'Allow textual bbcodes in usernames',
+ '[quote=&quot;[i]test[/i]&quot;]test[/quote]',
+ '[quote=&quot;[i:]test[/i:]&quot;:]test[/quote:]',
+ ),
+ array(
+ 'Allow links bbcodes in usernames',
+ '[quote=&quot;[url=https://area51.phpbb.com/]test[/url]&quot;]test[/quote]',
+ '[quote=&quot;[url=https&#58;//area51&#46;phpbb&#46;com/:]test[/url:]&quot;:]test[/quote:]',
+ ),
+ array(
+ 'Allow img bbcodes in usernames - Username displayed the image',
+ '[quote=&quot;[img]https://area51.phpbb.com/images/area51.png[/img]&quot;]test[/quote]',
+ '[quote=&quot;[img:]https&#58;//area51&#46;phpbb&#46;com/images/area51&#46;png[/img:]&quot;:]test[/quote:]',
+ ),
+ array(
+ 'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]',
+ '[quote=&quot;[flash]http://www.phpbb.com/[/flash]&quot;]test[/quote]',
+ '[quote=&quot;&#91;flash]http://www.phpbb.com/&#91;/flash]&quot;:]test[/quote:]',
+ ),
+ array(
+ 'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]',
+ '[quote=&quot;[quote]test[/quote]&quot;]test[/quote]',
+ '[quote=&quot;&#91;quote]test&#91;/quote]&quot;:]test[/quote:]',
+ ),
+
+ // Do not parse bbcodes in code boxes
+ array(
+ 'Do not parse textual bbcodes in code',
+ '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]',
+ '[code:]unparsed code &#91;b&#93;bold &#91;i&#93;bold + italic&#91;/i&#93;&#91;/b&#93;[/code:]',
+ ),
+ array(
+ 'Do not parse quote bbcodes in code',
+ '[code]unparsed code [quote=&quot;username&quot;]quoted[/quote][/code]',
+ '[code:]unparsed code &#91;quote=&quot;username&quot;&#93;quoted&#91;/quote&#93;[/code:]',
+ ),
+
+ // New user friendly mixed nesting
+ array(
+ 'Textual bbcode nesting into textual bbcode',
+ '[b]bold [i]bold + italic[/b] italic[/i]',
+ '[b:]bold [i:]bold + italic[/b:] italic[/i:]',
+ 'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider bbcode_firstpass_data
+ */
+ public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false)
+ {
+ if ($incomplete)
+ {
+ $this->markTestIncomplete($incomplete);
+ }
+
+ global $user, $request;
+ $user = new phpbb_mock_user;
+ $request = new phpbb_mock_request;
+
+ $bbcode = new bbcode_firstpass();
+ $bbcode->message = $message;
+ $bbcode->bbcode_init(false);
+ $bbcode->parse_bbcode();
+ $this->assertEquals($expected, $bbcode->message);
+ }
+}
diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php
index 6b5afe5808..83176abe4c 100644
--- a/tests/bbcode/url_bbcode_test.php
+++ b/tests/bbcode/url_bbcode_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -11,7 +15,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
-require_once dirname(__FILE__) . '/../mock/user.php';
class phpbb_url_bbcode_test extends phpbb_test_case
{
@@ -51,8 +54,9 @@ class phpbb_url_bbcode_test extends phpbb_test_case
*/
public function test_url($description, $message, $expected)
{
- global $user;
+ global $user, $request;
$user = new phpbb_mock_user;
+ $request = new phpbb_mock_request;
$bbcode = new bbcode_firstpass();
$bbcode->message = $message;
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index d687db622a..0e81f4372a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -14,28 +18,24 @@ require_once $phpbb_root_path . 'includes/startup.php';
$table_prefix = 'phpbb_';
require_once $phpbb_root_path . 'includes/constants.php';
+require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx;
+require_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
+
+$phpbb_class_loader_mock = new \phpbb\class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php");
+$phpbb_class_loader_mock->register();
+$phpbb_class_loader_ext = new \phpbb\class_loader('\\', $phpbb_root_path . 'ext/', "php");
+$phpbb_class_loader_ext->register();
+$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php");
+$phpbb_class_loader->register();
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_functional_test_case.php';
+require_once 'test_framework/phpbb_ui_test_case.php';
-if (version_compare(PHP_VERSION, '5.3.0-dev', '>='))
+if (version_compare(PHP_VERSION, '5.3.19', ">=") && file_exists(__DIR__ . '/vendor/autoload.php'))
{
- if (getenv('PHPBB_NO_COMPOSER_AUTOLOAD'))
- {
- if (getenv('PHPBB_AUTOLOAD'))
- {
- require(getenv('PHPBB_AUTOLOAD'));
- }
- }
- else
- {
- if (!file_exists($phpbb_root_path . 'vendor/autoload.php'))
- {
- trigger_error('You have not set up composer dependencies. See http://getcomposer.org/.', E_USER_ERROR);
- }
- require($phpbb_root_path . 'vendor/autoload.php');
- }
- require_once 'test_framework/phpbb_functional_test_case.php';
+ require_once __DIR__ . '/vendor/autoload.php';
}
diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php
new file mode 100644
index 0000000000..10130b465b
--- /dev/null
+++ b/tests/cache/apc_driver_test.php
@@ -0,0 +1,57 @@
+<?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.
+*
+*/
+
+// Important: apc.enable_cli=1 must be in php.ini.
+// http://forums.devshed.com/php-development-5/apc-problem-561290.html
+// http://php.net/manual/en/apc.configuration.php
+
+require_once dirname(__FILE__) . '/common_test_case.php';
+
+class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case
+{
+ protected static $config;
+ protected $driver;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ static public function setUpBeforeClass()
+ {
+ if (!extension_loaded('apc'))
+ {
+ self::markTestSkipped('APC extension is not loaded');
+ }
+
+ $php_ini = new \phpbb\php\ini;
+
+ if (!$php_ini->get_bool('apc.enabled'))
+ {
+ self::markTestSkipped('APC is not enabled. Make sure apc.enabled=1 in php.ini');
+ }
+
+ if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli'))
+ {
+ self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini');
+ }
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->driver = new \phpbb\cache\driver\apc;
+ $this->driver->purge();
+ }
+}
diff --git a/tests/cache/cache_memory.php b/tests/cache/cache_memory.php
index c468cb4658..806edb963a 100644
--- a/tests/cache/cache_memory.php
+++ b/tests/cache/cache_memory.php
@@ -1,15 +1,17 @@
<?php
/**
-*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
+ *
+ * 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/acm/acm_memory.php';
-
-class phpbb_cache_memory extends acm_memory
+class phpbb_cache_memory extends \phpbb\cache\driver\memory
{
protected $data = array();
diff --git a/tests/cache/cache_memory_test.php b/tests/cache/cache_memory_test.php
index 7a529c1d04..9f92e8d8dc 100644
--- a/tests/cache/cache_memory_test.php
+++ b/tests/cache/cache_memory_test.php
@@ -1,17 +1,22 @@
<?php
/**
-*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
+ *
+ * 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__) . '/cache_memory.php';
class phpbb_cache_memory_test extends phpbb_database_test_case
{
protected $cache;
+ protected $db;
public function getDataSet()
{
@@ -25,6 +30,7 @@ class phpbb_cache_memory_test extends phpbb_database_test_case
$this->cache = new phpbb_cache_memory();
$db = $this->new_dbal();
+ $this->db = $db;
}
static public function cache_single_query_data()
@@ -97,13 +103,11 @@ class phpbb_cache_memory_test extends phpbb_database_test_case
*/
public function test_cache_single_query($sql_queries, $table)
{
- global $db;
-
foreach ($sql_queries as $query)
{
- $sql_request_res = $db->sql_query($query[0]);
+ $sql_request_res = $this->db->sql_query($query[0]);
- $this->cache->sql_save($query[0], $sql_request_res, 1);
+ $this->cache->sql_save($this->db, $query[0], $sql_request_res, 1);
$results = array();
$query_id = $this->cache->sql_load($query[0]);
diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php
new file mode 100644
index 0000000000..ee0649a755
--- /dev/null
+++ b/tests/cache/common_test_case.php
@@ -0,0 +1,102 @@
+<?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.
+*
+*/
+
+abstract class phpbb_cache_common_test_case extends phpbb_database_test_case
+{
+ public function test_get_put_exists()
+ {
+ $this->assertFalse($this->driver->_exists('test_key'));
+ $this->assertSame(false, $this->driver->get('test_key'));
+
+ $this->driver->put('test_key', 'test_value');
+
+ $this->assertTrue($this->driver->_exists('test_key'));
+ $this->assertEquals(
+ 'test_value',
+ $this->driver->get('test_key'),
+ 'File ACM put and get'
+ );
+ }
+
+ public function test_purge()
+ {
+ $this->driver->put('test_key', 'test_value');
+
+ $this->assertEquals(
+ 'test_value',
+ $this->driver->get('test_key'),
+ 'File ACM put and get'
+ );
+
+ $this->driver->purge();
+
+ $this->assertSame(false, $this->driver->get('test_key'));
+ }
+
+ public function test_destroy()
+ {
+ $this->driver->put('first_key', 'first_value');
+ $this->driver->put('second_key', 'second_value');
+
+ $this->assertEquals(
+ 'first_value',
+ $this->driver->get('first_key')
+ );
+ $this->assertEquals(
+ 'second_value',
+ $this->driver->get('second_key')
+ );
+
+ $this->driver->destroy('first_key');
+
+ $this->assertFalse($this->driver->_exists('first_key'));
+ $this->assertEquals(
+ 'second_value',
+ $this->driver->get('second_key')
+ );
+ }
+
+ public function test_cache_sql()
+ {
+ global $db, $cache, $phpbb_root_path, $phpEx;
+ $config = new phpbb\config\config(array());
+ $db = $this->new_dbal();
+ $cache = new \phpbb\cache\service($this->driver, $config, $db, $phpbb_root_path, $phpEx);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+
+ $result = $db->sql_query($sql, 300);
+ $first_result = $db->sql_fetchrow($result);
+ $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0);
+ $this->assertEquals($expected, $first_result);
+
+ $sql = 'DELETE FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+
+ $this->assertEquals($expected, $db->sql_fetchrow($result));
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql);
+
+ $no_cache_result = $db->sql_fetchrow($result);
+ $this->assertSame(false, $no_cache_result);
+
+ $db->sql_close();
+ }
+}
diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php
new file mode 100644
index 0000000000..471316847d
--- /dev/null
+++ b/tests/cache/file_driver_test.php
@@ -0,0 +1,73 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
+{
+ private $cache_dir;
+ protected $driver;
+
+ public function __construct()
+ {
+ $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/';
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ if (file_exists($this->cache_dir))
+ {
+ // cache directory possibly left after aborted
+ // or failed run earlier
+ $this->remove_cache_dir();
+ }
+ $this->create_cache_dir();
+
+ $this->driver = new \phpbb\cache\driver\file($this->cache_dir);
+ }
+
+ protected function tearDown()
+ {
+ if (file_exists($this->cache_dir))
+ {
+ $this->remove_cache_dir();
+ }
+
+ parent::tearDown();
+ }
+
+ private function create_cache_dir()
+ {
+ $this->get_test_case_helpers()->makedirs($this->cache_dir);
+ }
+
+ private function remove_cache_dir()
+ {
+ $iterator = new DirectoryIterator($this->cache_dir);
+ foreach ($iterator as $file)
+ {
+ if ($file != '.' && $file != '..')
+ {
+ unlink($this->cache_dir . '/' . $file);
+ }
+ }
+ rmdir($this->cache_dir);
+ }
+}
diff --git a/tests/cache/fixtures/cache_memory.xml b/tests/cache/fixtures/cache_memory.xml
index 6954c7b76b..9c19ebb7ba 100644
--- a/tests/cache/fixtures/cache_memory.xml
+++ b/tests/cache/fixtures/cache_memory.xml
@@ -49,8 +49,6 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>1</value>
@@ -58,8 +56,6 @@
<value>user 1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -68,8 +64,6 @@
<value>user 2</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
@@ -78,8 +72,6 @@
<value>user 3</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
</dataset>
diff --git a/tests/cache/fixtures/config.xml b/tests/cache/fixtures/config.xml
new file mode 100644
index 0000000000..9d395b685c
--- /dev/null
+++ b/tests/cache/fixtures/config.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ <row>
+ <value>foo</value>
+ <value>23</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php
new file mode 100644
index 0000000000..b9f96732f5
--- /dev/null
+++ b/tests/cache/null_driver_test.php
@@ -0,0 +1,77 @@
+<?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_cache_null_driver_test extends phpbb_database_test_case
+{
+ protected $driver;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->driver = new \phpbb\cache\driver\null;
+ }
+
+ public function test_get_put()
+ {
+ $this->assertSame(false, $this->driver->get('key'));
+
+ $this->driver->put('key', 'value');
+
+ // null driver does not cache
+ $this->assertSame(false, $this->driver->get('key'));
+ }
+
+ public function test_purge()
+ {
+ $this->assertNull($this->driver->purge());
+ }
+
+ public function test_destroy()
+ {
+ $this->assertNull($this->driver->destroy('foo'));
+ }
+
+ public function test_cache_sql()
+ {
+ global $db, $cache, $phpbb_root_path, $phpEx;
+ $config = new phpbb\config\config(array());
+ $db = $this->new_dbal();
+ $cache = new \phpbb\cache\service($this->driver, $config, $db, $phpbb_root_path, $phpEx);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+ $first_result = $db->sql_fetchrow($result);
+ $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0);
+ $this->assertEquals($expected, $first_result);
+
+ $sql = 'DELETE FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ // As null cache driver does not actually cache,
+ // this should return no results
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+
+ $this->assertSame(false, $db->sql_fetchrow($result));
+
+ $db->sql_close();
+ }
+}
diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php
new file mode 100644
index 0000000000..387e6ca855
--- /dev/null
+++ b/tests/cache/redis_driver_test.php
@@ -0,0 +1,53 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case
+{
+ protected static $config;
+ protected $driver;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ static public function setUpBeforeClass()
+ {
+ if (!extension_loaded('redis'))
+ {
+ self::markTestSkipped('redis extension is not loaded');
+ }
+
+ $config = phpbb_test_case_helpers::get_test_config();
+ if (isset($config['redis_host']) || isset($config['redis_port']))
+ {
+ $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost';
+ $port = isset($config['redis_port']) ? $config['redis_port'] : 6379;
+ self::$config = array('host' => $host, 'port' => $port);
+ }
+ else
+ {
+ self::markTestSkipped('Test redis host/port is not specified');
+ }
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->driver = new \phpbb\cache\driver\redis(self::$config['host'], self::$config['port']);
+ $this->driver->purge();
+ }
+}
diff --git a/tests/captcha/qa_test.php b/tests/captcha/qa_test.php
new file mode 100644
index 0000000000..1f2f9f3070
--- /dev/null
+++ b/tests/captcha/qa_test.php
@@ -0,0 +1,94 @@
+<?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_captcha_qa_test extends \phpbb_database_test_case
+{
+ protected $request;
+
+ /** @var \phpbb\captcha\plugins\qa */
+ protected $qa;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
+ }
+
+ public function setUp()
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+
+ parent::setUp();
+
+ $this->request = new \phpbb_mock_request();
+ request_var(false, false, false, false, $this->request);
+ $this->qa = new \phpbb\captcha\plugins\qa('phpbb_captcha_questions', 'phpbb_captcha_answers', 'phpbb_qa_confirm');
+ }
+
+ public function test_is_installed()
+ {
+ $this->assertFalse($this->qa->is_installed());
+
+ $this->qa->install();
+
+ $this->assertTrue($this->qa->is_installed());
+ }
+
+ public function test_set_get_name()
+ {
+ $this->assertNull($this->qa->get_service_name());
+ $this->qa->set_name('foobar');
+ $this->assertSame('foobar', $this->qa->get_service_name());
+ }
+
+ public function data_acp_get_question_input()
+ {
+ return array(
+ array("foobar\ntest\nyes", array(
+ 'question_text' => '',
+ 'strict' => false,
+ 'lang_iso' => '',
+ 'answers' => array('foobar', 'test', 'yes')
+ )),
+ array("foobar\ntest\n \nyes", array(
+ 'question_text' => '',
+ 'strict' => false,
+ 'lang_iso' => '',
+ 'answers' => array(
+ 0 => 'foobar',
+ 1 => 'test',
+ 3 => 'yes',
+ )
+ )),
+ array('', array(
+ 'question_text' => '',
+ 'strict' => false,
+ 'lang_iso' => '',
+ 'answers' => '',
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider data_acp_get_question_input
+ */
+ public function test_acp_get_question_input($value, $expected)
+ {
+ $this->request->overwrite('answers', $value);
+
+ $this->assertEquals($expected, $this->qa->acp_get_question_input());
+ }
+}
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
new file mode 100644
index 0000000000..ffb14b0720
--- /dev/null
+++ b/tests/class_loader/class_loader_test.php
@@ -0,0 +1,101 @@
+<?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_class_loader_test extends \phpbb_test_case
+{
+ public function setUp()
+ {
+ global $phpbb_class_loader;
+ $phpbb_class_loader->unregister();
+
+ global $phpbb_class_loader_ext;
+ $phpbb_class_loader_ext->unregister();
+ }
+
+ public function tearDown()
+ {
+ global $phpbb_class_loader_ext;
+ $phpbb_class_loader_ext->register();
+
+ global $phpbb_class_loader;
+ $phpbb_class_loader->register();
+ }
+
+ public function test_resolve_path()
+ {
+ $prefix = dirname(__FILE__) . '/';
+ $class_loader = new \phpbb\class_loader('phpbb\\', $prefix . 'phpbb/');
+
+ $prefix .= 'phpbb/';
+
+ $this->assertEquals(
+ $prefix . 'class_name.php',
+ $class_loader->resolve_path('\\phpbb\\class_name'),
+ 'Top level class'
+ );
+ $this->assertEquals(
+ $prefix . 'dir/class_name.php',
+ $class_loader->resolve_path('\\phpbb\\dir\\class_name'),
+ 'Class in a directory'
+ );
+ $this->assertEquals(
+ $prefix . 'dir/subdir/class_name.php',
+ $class_loader->resolve_path('\\phpbb\\dir\\subdir\\class_name'),
+ 'Class in a sub-directory'
+ );
+ $this->assertEquals(
+ $prefix . 'dir2/dir2.php',
+ $class_loader->resolve_path('\\phpbb\\dir2\\dir2'),
+ 'Class with name of dir within dir'
+ );
+ }
+
+ public function test_resolve_cached()
+ {
+ $cache_map = array(
+ 'class_loader___phpbb__' => array('\\phpbb\\a\\cached_name' => 'a/cached_name'),
+ 'class_loader___' => array('\\phpbb\\ext\\foo' => 'foo'),
+ );
+ $cache = new phpbb_mock_cache($cache_map);
+
+ $prefix = dirname(__FILE__) . '/';
+ $class_loader = new \phpbb\class_loader('phpbb\\', $prefix . 'phpbb/', 'php', $cache);
+ $class_loader_ext = new \phpbb\class_loader('\\', $prefix . 'phpbb/', 'php', $cache);
+
+ $prefix .= 'phpbb/';
+
+ $this->assertEquals(
+ $prefix . 'dir/class_name.php',
+ $class_loader->resolve_path('\\phpbb\\dir\\class_name'),
+ 'Class in a directory'
+ );
+
+ $this->assertFalse($class_loader->resolve_path('\\phpbb\\ext\\foo'));
+ $this->assertFalse($class_loader_ext->resolve_path('\\phpbb\\a\\cached_name'));
+
+ $this->assertEquals(
+ $prefix . 'a/cached_name.php',
+ $class_loader->resolve_path('\\phpbb\\a\\cached_name'),
+ 'Cached class found'
+ );
+
+ $this->assertEquals(
+ $prefix . 'foo.php',
+ $class_loader_ext->resolve_path('\\phpbb\\ext\\foo'),
+ 'Cached class found in alternative loader'
+ );
+
+ $cache_map['class_loader___phpbb__']['\\phpbb\\dir\\class_name'] = 'dir/class_name';
+ $cache->check($this, $cache_map);
+ }
+}
diff --git a/tests/class_loader/phpbb/class_name.php b/tests/class_loader/phpbb/class_name.php
new file mode 100644
index 0000000000..64a3fa646e
--- /dev/null
+++ b/tests/class_loader/phpbb/class_name.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace phpbb;
+
+class class_name
+{
+}
+
diff --git a/tests/class_loader/phpbb/dir/class_name.php b/tests/class_loader/phpbb/dir/class_name.php
new file mode 100644
index 0000000000..1cd39a1181
--- /dev/null
+++ b/tests/class_loader/phpbb/dir/class_name.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace phpbb\dir;
+
+class class_name
+{
+}
+
diff --git a/tests/class_loader/phpbb/dir/subdir/class_name.php b/tests/class_loader/phpbb/dir/subdir/class_name.php
new file mode 100644
index 0000000000..89affbc847
--- /dev/null
+++ b/tests/class_loader/phpbb/dir/subdir/class_name.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace phpbb\dir\subdir;
+
+class class_name
+{
+}
+
diff --git a/tests/class_loader/phpbb/dir2/dir2.php b/tests/class_loader/phpbb/dir2/dir2.php
new file mode 100644
index 0000000000..b273511fcd
--- /dev/null
+++ b/tests/class_loader/phpbb/dir2/dir2.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace phpbb;
+
+class dir2
+{
+}
+
diff --git a/tests/composer.json b/tests/composer.json
new file mode 100644
index 0000000000..057e0115a5
--- /dev/null
+++ b/tests/composer.json
@@ -0,0 +1,5 @@
+{
+ "require-dev": {
+ "facebook/webdriver": "~1.1"
+ }
+}
diff --git a/tests/composer.lock b/tests/composer.lock
new file mode 100644
index 0000000000..f172de4669
--- /dev/null
+++ b/tests/composer.lock
@@ -0,0 +1,63 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "25ad22c35c19f2b0a2331640fb6b5577",
+ "content-hash": "617c33144bd2877c3c9a78f167a871b6",
+ "packages": [],
+ "packages-dev": [
+ {
+ "name": "facebook/webdriver",
+ "version": "1.1.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/facebook/php-webdriver.git",
+ "reference": "0b889d7de7461439f8a3bbcca46e0f696cb27986"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/0b889d7de7461439f8a3bbcca46e0f696cb27986",
+ "reference": "0b889d7de7461439f8a3bbcca46e0f696cb27986",
+ "shasum": ""
+ },
+ "require": {
+ "ext-curl": "*",
+ "php": ">=5.3.19"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "4.6.*"
+ },
+ "suggest": {
+ "phpdocumentor/phpdocumentor": "2.*"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Facebook\\WebDriver\\": "lib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Apache-2.0"
+ ],
+ "description": "A PHP client for WebDriver",
+ "homepage": "https://github.com/facebook/php-webdriver",
+ "keywords": [
+ "facebook",
+ "php",
+ "selenium",
+ "webdriver"
+ ],
+ "time": "2016-06-04 00:02:34"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": []
+}
diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php
index ce193cf3ba..56c406b206 100644
--- a/tests/compress/compress_test.php
+++ b/tests/compress/compress_test.php
@@ -1,11 +1,15 @@
<?php
/**
- *
- * @package testing
- * @copyright (c) 2012 phpBB Group
- * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
- *
- */
+*
+* 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_admin.php';
@@ -25,6 +29,12 @@ class phpbb_compress_test extends phpbb_test_case
'dir/subdir/4.txt',
);
+ protected $conflicts = array(
+ '1_1.txt',
+ '1_2.txt',
+ 'dir/2_1.txt',
+ );
+
protected function setUp()
{
// Required for compress::add_file
@@ -88,6 +98,11 @@ class phpbb_compress_test extends phpbb_test_case
);
$compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt');
$compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt');
+
+ // Add multiples of the same file to check conflicts are handled
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file($this->path . 'dir/2.txt', $this->path);
}
protected function valid_extraction($extra = array())
@@ -150,7 +165,7 @@ class phpbb_compress_test extends phpbb_test_case
$compress->mode = 'r';
$compress->open();
$compress->extract('tests/compress/' . self::EXTRACT_DIR);
- $this->valid_extraction();
+ $this->valid_extraction($this->conflicts);
}
/**
@@ -168,6 +183,6 @@ class phpbb_compress_test extends phpbb_test_case
$compress = new compress_zip('r', $zip);
$compress->extract('tests/compress/' . self::EXTRACT_DIR);
- $this->valid_extraction();
+ $this->valid_extraction($this->conflicts);
}
}
diff --git a/tests/config/config_test.php b/tests/config/config_test.php
new file mode 100644
index 0000000000..380b4336a7
--- /dev/null
+++ b/tests/config/config_test.php
@@ -0,0 +1,124 @@
+<?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_test extends phpbb_test_case
+{
+ public function test_offset_exists()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+
+ $this->assertTrue(isset($config['foo']));
+ $this->assertFalse(isset($config['foobar']));
+ }
+
+ public function test_offset_get()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+ $this->assertEquals('bar', $config['foo']);
+ }
+
+ public function test_offset_get_missing()
+ {
+ $config = new \phpbb\config\config(array());
+ $this->assertEquals('', $config['foo']);
+ }
+
+ public function test_offset_set()
+ {
+ $config = new \phpbb\config\config(array());
+ $config['foo'] = 'x';
+ $this->assertEquals('x', $config['foo']);
+ }
+
+ public function test_offset_unset_fails()
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $config = new \phpbb\config\config(array('foo' => 'x'));
+ unset($config['foo']);
+ }
+
+ public function test_count()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+ $this->assertEquals(1, count($config));
+ }
+
+ public function test_iterate()
+ {
+ $vars = array('foo' => '23', 'bar' => '42');
+ $config = new \phpbb\config\config($vars);
+
+ $count = 0;
+ foreach ($config as $key => $value)
+ {
+ $this->assertTrue(isset($vars[$key]));
+ $this->assertEquals($vars[$key], $value);
+
+ $count++;
+ }
+
+ $this->assertEquals(count($vars), $count);
+ }
+
+ public function test_set_overwrite()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'x'));
+ $config->set('foo', 'bar');
+ $this->assertEquals('bar', $config['foo']);
+ }
+
+ public function test_set_new()
+ {
+ $config = new \phpbb\config\config(array());
+ $config->set('foo', 'bar');
+ $this->assertEquals('bar', $config['foo']);
+ }
+
+ public function test_set_atomic_overwrite()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+ $this->assertTrue($config->set_atomic('foo', 'bar', '23'));
+ $this->assertEquals('23', $config['foo']);
+ }
+
+ public function test_set_atomic_new()
+ {
+ $config = new \phpbb\config\config(array());
+ $this->assertTrue($config->set_atomic('foo', false, '23'));
+ $this->assertEquals('23', $config['foo']);
+ }
+
+ public function test_set_atomic_failure()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+ $this->assertFalse($config->set_atomic('foo', 'wrong', '23'));
+ $this->assertEquals('bar', $config['foo']);
+ }
+
+ public function test_increment()
+ {
+ $config = new \phpbb\config\config(array('foo' => '23'));
+ $config->increment('foo', 3);
+ $this->assertEquals(26, $config['foo']);
+ $config->increment('foo', 1);
+ $this->assertEquals(27, $config['foo']);
+ }
+
+ public function test_delete()
+ {
+ $config = new \phpbb\config\config(array('foo' => 'bar'));
+
+ $config->delete('foo');
+ $this->assertFalse(isset($config['foo']));
+ }
+}
diff --git a/tests/config/db_test.php b/tests/config/db_test.php
new file mode 100644
index 0000000000..713e6cb6d9
--- /dev/null
+++ b/tests/config/db_test.php
@@ -0,0 +1,168 @@
+<?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_db_test extends phpbb_database_test_case
+{
+ private $cache;
+ private $db;
+ private $config;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->cache = new phpbb_mock_cache;
+ $this->db = $this->new_dbal();
+ $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ }
+
+ public function test_load_config()
+ {
+ $this->assertEquals('23', $this->config['foo']);
+ $this->assertEquals('42', $this->config['bar']);
+ }
+
+ public function test_load_cached()
+ {
+ $cache = new phpbb_mock_cache(array('config' => array('x' => 'y')));
+ $this->config = new \phpbb\config\db($this->db, $cache, 'phpbb_config');
+
+ $this->assertTrue(!isset($this->config['foo']));
+ $this->assertEquals('42', $this->config['bar']);
+
+ $this->assertEquals('y', $this->config['x']);
+ }
+
+ public function test_offset_set()
+ {
+ $this->config['foo'] = 'x'; // temporary set
+ $this->assertEquals('x', $this->config['foo']);
+
+ $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->assertEquals('23', $config2['foo']);
+ }
+
+ public function test_set_overwrite()
+ {
+ $this->config->set('foo', '17');
+ $this->assertEquals('17', $this->config['foo']);
+
+ // re-read config and populate cache
+ $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->cache->checkVar($this, 'config', array('foo' => '17'));
+ }
+
+ public function test_set_overwrite_uncached()
+ {
+ $this->config->set('bar', '17', false);
+
+ // re-read config and populate cache
+ $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->cache->checkVar($this, 'config', array('foo' => '23'));
+ }
+
+ public function test_set_new()
+ {
+ $this->config->set('foobar', '5');
+ $this->assertEquals('5', $this->config['foobar']);
+
+ // re-read config and populate cache
+ $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5'));
+ }
+
+ public function test_set_new_uncached()
+ {
+ $this->config->set('foobar', '5', false);
+ $this->assertEquals('5', $this->config['foobar']);
+
+ // re-read config and populate cache
+ $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config');
+ $this->cache->checkVar($this, 'config', array('foo' => '23'));
+ }
+
+ public function test_set_atomic_overwrite()
+ {
+ $this->assertTrue($this->config->set_atomic('foo', '23', '17'));
+ $this->assertEquals('17', $this->config['foo']);
+ }
+
+ public function test_set_atomic_new()
+ {
+ $this->assertTrue($this->config->set_atomic('foobar', false, '5'));
+ $this->assertEquals('5', $this->config['foobar']);
+ }
+
+ public function test_set_atomic_failure()
+ {
+ $this->assertFalse($this->config->set_atomic('foo', 'wrong', '17'));
+ $this->assertEquals('23', $this->config['foo']);
+ }
+
+ public function test_increment()
+ {
+ $this->config->increment('foo', 3);
+ $this->assertEquals(26, $this->config['foo']);
+ $this->config->increment('foo', 1);
+ $this->assertEquals(27, $this->config['foo']);
+ }
+
+ public function test_increment_new()
+ {
+ $this->config->increment('foobar', 3);
+ $this->assertEquals(3, $this->config['foobar']);;
+ }
+
+ public function test_delete()
+ {
+ $this->assertTrue(isset($this->config['foo']));
+ $this->config->delete('foo');
+ $this->cache->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($this->config['foo']));
+
+ // re-read config and populate cache
+ $cache2 = new phpbb_mock_cache;
+ $config2 = new \phpbb\config\db($this->db, $cache2, 'phpbb_config');
+ $cache2->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($config2['foo']));
+ }
+
+ public function test_delete_write_read_not_cacheable()
+ {
+ // bar is dynamic
+ $this->assertTrue(isset($this->config['bar']));
+ $this->config->delete('bar');
+ $this->cache->checkVarUnset($this, 'bar');
+ $this->assertFalse(isset($this->config['bar']));
+
+ $this->config->set('bar', 'new bar', false);
+ $this->assertEquals('new bar', $this->config['bar']);
+ }
+
+ public function test_delete_write_read_cacheable()
+ {
+ // foo is not dynamic
+ $this->assertTrue(isset($this->config['foo']));
+ $this->config->delete('foo');
+ $this->cache->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($this->config['foo']));
+
+ $this->config->set('foo', 'new foo', true);
+ $this->assertEquals('new foo', $this->config['foo']);
+ }
+}
diff --git a/tests/config/db_text_test.php b/tests/config/db_text_test.php
new file mode 100644
index 0000000000..a91abf990f
--- /dev/null
+++ b/tests/config/db_text_test.php
@@ -0,0 +1,127 @@
+<?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_db_text_test extends phpbb_database_test_case
+{
+ /** @var \phpbb\config\db_text */
+ protected $config_text;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/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');
+ }
+
+ public function test_get()
+ {
+ $this->assertSame('23', $this->config_text->get('foo'));
+ $this->assertSame('string-de-ding', $this->config_text->get('meh'));
+ }
+
+ public function test_get_nonexisting()
+ {
+ $this->assertNull($this->config_text->get('noooooo'));
+ }
+
+ public function test_set_new_get()
+ {
+ $this->config_text->set('barz', 'phpbb');
+ $this->assertSame('phpbb', $this->config_text->get('barz'));
+ }
+
+ public function test_set_replace_get()
+ {
+ $this->config_text->set('foo', '24');
+ $this->assertSame('24', $this->config_text->get('foo'));
+ }
+
+ public function test_set_same_value_get()
+ {
+ $this->config_text->set('foo', '23');
+ $this->assertSame('23', $this->config_text->get('foo'));
+ }
+
+ public function test_set_get_long_string()
+ {
+ $expected = str_repeat('ABC', 10000);
+ $this->config_text->set('long', $expected);
+ $this->assertSame($expected, $this->config_text->get('long'));
+ }
+
+ public function test_delete_get()
+ {
+ $this->config_text->delete('foo');
+ $this->assertNull($this->config_text->get('foo'));
+
+ $this->assertSame('42', $this->config_text->get('bar'));
+ $this->assertSame('string-de-ding', $this->config_text->get('meh'));
+ }
+
+ public function test_get_array_empty()
+ {
+ $this->assertEmpty($this->config_text->get_array(array('key1', 'key2')));
+ }
+
+ public function test_get_array_subset()
+ {
+ $expected = array(
+ 'bar' => '42',
+ 'foo' => '23',
+ );
+
+ $actual = $this->config_text->get_array(array_keys($expected));
+ ksort($actual);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function test_set_array_get_array_subset()
+ {
+ $set_array_param = array(
+ // New entry
+ 'baby' => 'phpBB',
+ // Entry update
+ 'bar' => '64',
+ // Entry update - same value
+ 'foo' => '23',
+ );
+
+ $this->config_text->set_array($set_array_param);
+
+ $expected = array_merge($set_array_param, array(
+ 'foo' => '23',
+ ));
+
+ $actual = $this->config_text->get_array(array_keys($expected));
+ ksort($actual);
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function test_delete_array_get_remaining()
+ {
+ $this->config_text->delete_array(array('foo', 'bar'));
+
+ $this->assertNull($this->config_text->get('bar'));
+ $this->assertNull($this->config_text->get('foo'));
+
+ $this->assertSame('string-de-ding', $this->config_text->get('meh'));
+ }
+}
diff --git a/tests/config/fixtures/config.xml b/tests/config/fixtures/config.xml
new file mode 100644
index 0000000000..9d395b685c
--- /dev/null
+++ b/tests/config/fixtures/config.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ <row>
+ <value>foo</value>
+ <value>23</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/config/fixtures/config_text.xml b/tests/config/fixtures/config_text.xml
new file mode 100644
index 0000000000..5acac13ea3
--- /dev/null
+++ b/tests/config/fixtures/config_text.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config_text">
+ <column>config_name</column>
+ <column>config_value</column>
+ <row>
+ <value>foo</value>
+ <value>23</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>42</value>
+ </row>
+ <row>
+ <value>meh</value>
+ <value>string-de-ding</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/config_php_file_test.php b/tests/config_php_file_test.php
new file mode 100644
index 0000000000..c319678108
--- /dev/null
+++ b/tests/config_php_file_test.php
@@ -0,0 +1,40 @@
+<?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->assertNull($config_php->get('bar'));
+ $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->assertNull($config_php->get('foo'));
+ $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all());
+ }
+
+ public function test_non_existent_file()
+ {
+ $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/non_existent/', 'php');
+ $this->assertNull($config_php->get('bar'));
+ $this->assertNull($config_php->get('foo'));
+ $this->assertSame(array(), $config_php->get_all());
+ }
+}
diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php
new file mode 100644
index 0000000000..96988c1028
--- /dev/null
+++ b/tests/console/cache/purge_test.php
@@ -0,0 +1,95 @@
+<?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 Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use phpbb\console\command\cache\purge;
+
+require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php';
+
+class phpbb_console_command_cache_purge_test extends phpbb_test_case
+{
+ protected $cache_dir;
+ protected $cache;
+ protected $command_name;
+ protected $db;
+ protected $config;
+
+ public function __construct()
+ {
+ $this->cache_dir = dirname(__FILE__) . '/tmp/cache/';
+ }
+
+ protected function setUp()
+ {
+ if (file_exists($this->cache_dir))
+ {
+ // cache directory possibly left after aborted
+ // or failed run earlier
+ $this->remove_cache_dir();
+ }
+ $this->create_cache_dir();
+
+ $this->cache = new \phpbb\cache\driver\file($this->cache_dir);
+
+ $this->db = $this->getMock('\phpbb\db\driver\driver_interface');
+
+ $this->config = new \phpbb\config\config(array('assets_version' => 1));
+ $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ }
+
+ public function test_purge()
+ {
+ $this->cache->put('test_key', 'test_value');
+
+ $this->assertEquals(
+ 'test_value',
+ $this->cache->get('test_key'),
+ 'File ACM put and get'
+ );
+
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertSame(false, $this->cache->get('test_key'));
+ $this->assertSame(2, $this->config['assets_version']);
+ }
+
+ private function create_cache_dir()
+ {
+ $this->get_test_case_helpers()->makedirs($this->cache_dir);
+ }
+
+ private function remove_cache_dir()
+ {
+ $iterator = new DirectoryIterator($this->cache_dir);
+ foreach ($iterator as $file)
+ {
+ if ($file != '.' && $file != '..')
+ {
+ unlink($this->cache_dir . '/' . $file);
+ }
+ }
+ rmdir($this->cache_dir);
+ }
+
+ public function get_command_tester()
+ {
+ $application = new Application();
+ $application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config));
+
+ $command = $application->find('cache:purge');
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+}
diff --git a/tests/console/config/config_test.php b/tests/console/config/config_test.php
new file mode 100644
index 0000000000..7c098af004
--- /dev/null
+++ b/tests/console/config/config_test.php
@@ -0,0 +1,251 @@
+<?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 Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+
+class phpbb_console_command_config_test extends phpbb_test_case
+{
+ protected $config;
+ protected $command_name;
+ protected $user;
+
+ public function setUp()
+ {
+ $this->config = new \phpbb\config\config(array());
+
+ $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user->method('lang')->will($this->returnArgument(0));
+ }
+
+ public function test_set_dynamic()
+ {
+ $this->assertEmpty($this->config);
+
+ $command_tester = $this->get_command_tester('set');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'value' => 'test_value',
+ '--dynamic' => true,
+ ));
+
+ $this->assertSame($this->config['test_key'], 'test_value');
+ }
+
+ public function test_set_no_dynamic()
+ {
+ $this->assertEmpty($this->config);
+
+ $command_tester = $this->get_command_tester('set');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'value' => 'test_value',
+ '--dynamic' => false,
+ ));
+
+ $this->assertSame($this->config['test_key'], 'test_value');
+ }
+
+ public function test_set_atomic_dynamic()
+ {
+ $this->assertEmpty($this->config);
+
+ $this->config->set('test_key', 'old_value', true);
+ $this->assertSame($this->config['test_key'], 'old_value');
+
+ $command_tester = $this->get_command_tester('set_atomic');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'old' => 'old_value',
+ 'new' => 'new_value',
+ '--dynamic' => true,
+ ));
+
+ $this->assertSame($this->config['test_key'], 'new_value');
+ }
+
+ public function test_set_atomic_no_dynamic()
+ {
+ $this->assertEmpty($this->config);
+
+ $this->config->set('test_key', 'old_value', false);
+ $this->assertSame($this->config['test_key'], 'old_value');
+
+ $command_tester = $this->get_command_tester('set_atomic');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'old' => 'old_value',
+ 'new' => 'new_value',
+ '--dynamic' => false,
+ ));
+
+ $this->assertSame($this->config['test_key'], 'new_value');
+ }
+
+ public function test_set_atomic_error_dynamic()
+ {
+ $this->assertEmpty($this->config);
+
+ $this->config->set('test_key', 'wrong_value', true);
+ $this->assertSame($this->config['test_key'], 'wrong_value');
+
+ $command_tester = $this->get_command_tester('set_atomic');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'old' => 'old_value',
+ 'new' => 'new_value',
+ '--dynamic' => true,
+ ));
+
+ $this->assertSame($this->config['test_key'], 'wrong_value');
+ }
+
+ public function test_get_no_new_line()
+ {
+ $this->config->set('test_key', 'test_value', false);
+ $this->assertSame($this->config['test_key'], 'test_value');
+
+ $command_tester = $this->get_command_tester('get');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ '--no-newline' => true,
+ ));
+
+ $this->assertSame($this->config['test_key'], $command_tester->getDisplay());
+ }
+
+ public function test_get_new_line()
+ {
+ $this->config->set('test_key', 'test_value', false);
+ $this->assertSame($this->config['test_key'], 'test_value');
+
+ $command_tester = $this->get_command_tester('get');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ '--no-newline' => false,
+ ));
+
+ $this->assertSame($this->config['test_key'] . PHP_EOL, $command_tester->getDisplay());
+ }
+
+ public function test_get_error()
+ {
+ $this->config->set('test_key', 'test_value', false);
+ $this->assertSame($this->config['test_key'], 'test_value');
+
+ $command_tester = $this->get_command_tester('get');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'wrong_key',
+ '--no-newline' => false,
+ ));
+
+ $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay());
+ }
+
+ public function test_increment_dynamic()
+ {
+ $this->config->set('test_key', 0, false);
+ $this->assertSame($this->config['test_key'], 0);
+
+ $command_tester = $this->get_command_tester('increment');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'increment' => 2,
+ '--dynamic' => true,
+ ));
+
+ $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
+ $this->assertSame(2, $this->config['test_key']);
+ }
+
+ public function test_increment_no_dynamic()
+ {
+ $this->config->set('test_key', 0, false);
+ $this->assertSame($this->config['test_key'], 0);
+
+ $command_tester = $this->get_command_tester('increment');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'increment' => 2,
+ '--dynamic' => false,
+ ));
+
+ $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
+ $this->assertSame(2, $this->config['test_key']);
+ }
+
+ public function test_increment_no_set()
+ {
+ $this->assertEmpty($this->config);
+
+ $command_tester = $this->get_command_tester('increment');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ 'increment' => 2,
+ '--dynamic' => true,
+ ));
+
+ $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay());
+ $this->assertSame(2, $this->config['test_key']);
+ }
+
+ public function test_delete_ok()
+ {
+ $this->config->set('test_key', 'test_value', false);
+ $this->assertSame($this->config['test_key'], 'test_value');
+
+ $command_tester = $this->get_command_tester('delete');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'test_key',
+ ));
+
+ $this->assertContains('CLI_CONFIG_DELETE_SUCCESS', $command_tester->getDisplay());
+ $this->assertEmpty($this->config);
+ }
+
+ public function test_delete_error()
+ {
+ $this->assertEmpty($this->config);
+
+ $command_tester = $this->get_command_tester('delete');
+ $command_tester->execute(array(
+ 'command' => $this->command_name,
+ 'key' => 'wrong_key',
+ ));
+
+ $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay());
+ $this->assertEmpty($this->config);
+ }
+
+ public function get_command_tester($class_name)
+ {
+ $command_complete_name = '\phpbb\console\command\config' . '\\' . $class_name;
+ $application = new Application();
+ $application->add(new $command_complete_name($this->user, $this->config));
+ $command = $application->find('config:' . $this->command_name);
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+}
diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php
new file mode 100644
index 0000000000..22423304be
--- /dev/null
+++ b/tests/console/cron/cron_list_test.php
@@ -0,0 +1,103 @@
+<?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__) . '/tasks/simple_ready.php';
+require_once dirname(__FILE__) . '/tasks/simple_not_ready.php';
+
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use phpbb\console\command\cron\cron_list;
+
+class phpbb_console_command_cron_list_test extends phpbb_test_case
+{
+ /** @var \phpbb\cron\manager */
+ protected $cron_manager;
+
+ /** @var \phpbb\user */
+ protected $user;
+
+ protected $command_name;
+
+ protected $command_tester;
+
+ protected function setUp()
+ {
+ $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user->method('lang')->will($this->returnArgument(0));
+ }
+
+ public function test_no_task()
+ {
+ $this->initiate_test(0, 0);
+ $this->assertContains('CRON_NO_TASKS', $this->command_tester->getDisplay());
+ }
+
+ public function test_only_ready()
+ {
+ $this->initiate_test(2, 0);
+ $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
+ }
+
+ public function test_only_not_ready()
+ {
+ $this->initiate_test(0, 2);
+ $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
+ }
+
+ public function test_both_ready()
+ {
+ $this->initiate_test(2, 2);
+ $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay())));
+ }
+
+ public function get_cron_manager(array $tasks)
+ {
+ global $pathEx, $phpbb_root_path;
+ $i = 1;
+ foreach ($tasks as $task)
+ {
+ $task->set_name('command' . $i);
+ $i++;
+ }
+ $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx);
+ }
+
+ public function get_command_tester()
+ {
+ $application = new Application();
+ $application->add(new cron_list($this->user, $this->cron_manager));
+
+ $command = $application->find('cron:list');
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+
+ public function initiate_test($number_ready, $number_not_ready)
+ {
+ $tasks = array();
+
+ for ($i = 0; $i < $number_ready; $i++)
+ {
+ $tasks[] = new phpbb_cron_task_simple_ready();
+ }
+
+ for ($i = 0; $i < $number_not_ready; $i++)
+ {
+ $tasks[] = new phpbb_cron_task_simple_not_ready();
+ }
+
+ $this->get_cron_manager($tasks);
+ $this->command_tester = $this->get_command_tester();
+ $this->command_tester->execute(array('command' => $this->command_name), array('decorated' => false));
+ }
+}
diff --git a/tests/console/cron/fixtures/config.xml b/tests/console/cron/fixtures/config.xml
new file mode 100644
index 0000000000..2cb683d409
--- /dev/null
+++ b/tests/console/cron/fixtures/config.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ </table>
+</dataset>
diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php
new file mode 100644
index 0000000000..f76e967484
--- /dev/null
+++ b/tests/console/cron/run_test.php
@@ -0,0 +1,158 @@
+<?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 Symfony\Component\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use phpbb\console\command\cron\run;
+
+require_once dirname(__FILE__) . '/tasks/simple.php';
+require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php';
+
+class phpbb_console_command_cron_run_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $config;
+ protected $lock;
+ protected $user;
+ protected $cron_manager;
+ protected $command_name;
+ protected $task;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ public function setUp()
+ {
+ global $db, $config, $phpbb_root_path, $phpEx;
+
+ $db = $this->db = $this->new_dbal();
+ $config = $this->config = new \phpbb\config\config(array('cron_lock' => '0'));
+ set_config(null, null, null, $this->config);
+ $this->lock = new \phpbb\lock\db('cron_lock', $this->config, $this->db);
+
+ $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user->method('lang')->will($this->returnArgument(0));
+
+ $this->task = new phpbb_cron_task_simple();
+ $tasks = array(
+ $this->task,
+ );
+ $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phbEx);
+
+ $this->assertSame('0', $config['cron_lock']);
+ }
+
+ public function test_normal_use()
+ {
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertSame('', $command_tester->getDisplay());
+ $this->assertSame(true, $this->task->executed);
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_verbose_mode()
+ {
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true));
+
+ $this->assertContains('RUNNING_TASK', $command_tester->getDisplay());
+ $this->assertSame(true, $this->task->executed);
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_error_lock()
+ {
+ $this->lock->acquire();
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertContains('CRON_LOCK_ERROR', $command_tester->getDisplay());
+ $this->assertSame(false, $this->task->executed);
+ $this->assertSame(1, $exit_status);
+ }
+
+ public function test_no_task()
+ {
+ $tasks = array(
+ );
+ $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertSame('', $command_tester->getDisplay());
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_no_task_verbose()
+ {
+ $tasks = array(
+ );
+ $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true));
+
+ $this->assertContains('CRON_NO_TASK', $command_tester->getDisplay());
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_arg_valid()
+ {
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple'));
+
+ $this->assertSame('', $command_tester->getDisplay());
+ $this->assertSame(true, $this->task->executed);
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_arg_invalid()
+ {
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'foo'));
+
+ $this->assertContains('CRON_NO_SUCH_TASK', $command_tester->getDisplay());
+ $this->assertSame(false, $this->task->executed);
+ $this->assertSame(2, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function test_arg_valid_verbose()
+ {
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple', '--verbose' => true));
+
+ $this->assertContains('RUNNING_TASK', $command_tester->getDisplay());
+ $this->assertSame(true, $this->task->executed);
+ $this->assertSame(0, $exit_status);
+ $this->assertSame(false, $this->lock->owns_lock());
+ }
+
+ public function get_command_tester()
+ {
+ $application = new Application();
+ $application->add(new run($this->user, $this->cron_manager, $this->lock));
+
+ $command = $application->find('cron:run');
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+}
diff --git a/tests/console/cron/tasks/simple.php b/tests/console/cron/tasks/simple.php
new file mode 100644
index 0000000000..194c52afe1
--- /dev/null
+++ b/tests/console/cron/tasks/simple.php
@@ -0,0 +1,27 @@
+<?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_cron_task_simple extends \phpbb\cron\task\base
+{
+ public $executed = false;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ $this->executed = true;
+ }
+}
diff --git a/tests/console/cron/tasks/simple_not_ready.php b/tests/console/cron/tasks/simple_not_ready.php
new file mode 100644
index 0000000000..887768e5fe
--- /dev/null
+++ b/tests/console/cron/tasks/simple_not_ready.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_cron_task_simple_not_ready extends \phpbb\cron\task\base
+{
+ public function run()
+ {
+ }
+
+ public function should_run()
+ {
+ return false;
+ }
+}
diff --git a/tests/console/cron/tasks/simple_ready.php b/tests/console/cron/tasks/simple_ready.php
new file mode 100644
index 0000000000..47970e104f
--- /dev/null
+++ b/tests/console/cron/tasks/simple_ready.php
@@ -0,0 +1,8 @@
+<?php
+
+class phpbb_cron_task_simple_ready extends \phpbb\cron\task\base
+{
+ public function run()
+ {
+ }
+}
diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php
new file mode 100644
index 0000000000..6ad6351a0c
--- /dev/null
+++ b/tests/content_visibility/delete_post_test.php
@@ -0,0 +1,350 @@
+<?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_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+require_once dirname(__FILE__) . '/../mock/search.php';
+
+class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_post.xml');
+ }
+
+ public function delete_post_data()
+ {
+ $info_data = array(
+ 'topic_first_post_id' => 1,
+ 'topic_last_post_id' => 3,
+ 'topic_posts_approved' => 3,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_visibility' => ITEM_APPROVED,
+ 'post_time' => 2,
+ 'post_visibility' => ITEM_APPROVED,
+ 'post_postcount' => true,
+ 'poster_id' => 1,
+ 'post_reported' => false,
+ );
+
+ return array(
+ array(
+ 1, 1, 2,
+ array_merge($info_data, array(
+ 'post_time' => 2,
+ )),
+ false, 'harddelete',
+ array(
+ array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ //array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 1,
+ 'topic_last_post_id' => 3,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ array(
+ 1, 1, 1,
+ array_merge($info_data, array(
+ 'post_time' => 1,
+ )),
+ false, 'harddelete',
+ array(
+ //array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 2,
+ 'topic_last_post_id' => 3,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ array(
+ 1, 1, 3,
+ array_merge($info_data, array(
+ 'post_time' => 3,
+ )),
+ false, 'harddelete',
+ array(
+ array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ //array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 1,
+ 'topic_last_post_id' => 2,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ array(
+ 1, 1, 2,
+ array_merge($info_data, array(
+ 'post_time' => 2,
+ )),
+ true, 'soft delete',
+ array(
+ array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
+ array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 1,
+ 'topic_last_post_id' => 3,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 1,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ array(
+ 1, 1, 1,
+ array_merge($info_data, array(
+ 'post_time' => 1,
+ )),
+ true, 'soft delete',
+ array(
+ array('post_id' => 1, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
+ array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 2,
+ 'topic_last_post_id' => 3,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 1,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ array(
+ 1, 1, 3,
+ array_merge($info_data, array(
+ 'post_time' => 3,
+ )),
+ true, 'soft delete',
+ array(
+ array('post_id' => 1, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => ITEM_APPROVED, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => 'soft delete'),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_APPROVED,
+ 'topic_first_post_id' => 1,
+ 'topic_last_post_id' => 2,
+ 'topic_posts_approved' => 2,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 1,
+ 'topic_delete_reason' => '',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+
+ array(
+ 2, 2, 4,
+ array(
+ 'topic_first_post_id' => 4,
+ 'topic_last_post_id' => 4,
+ 'topic_posts_approved' => 1,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_visibility' => ITEM_APPROVED,
+ 'post_time' => 4,
+ 'post_visibility' => ITEM_APPROVED,
+ 'post_postcount' => true,
+ 'poster_id' => 1,
+ 'post_reported' => false,
+ ),
+ false, 'harddelete',
+ array(
+ ),
+ array(
+ ),
+ array(
+ array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 0),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+
+ array(
+ 2, 2, 4,
+ array(
+ 'topic_first_post_id' => 4,
+ 'topic_last_post_id' => 4,
+ 'topic_posts_approved' => 1,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 0,
+ 'topic_visibility' => ITEM_APPROVED,
+ 'post_time' => 4,
+ 'post_visibility' => ITEM_APPROVED,
+ 'post_postcount' => true,
+ 'poster_id' => 1,
+ 'post_reported' => false,
+ ),
+ true, 'soft delete',
+ array(
+ array('post_id' => 4, 'post_visibility' => ITEM_DELETED, 'post_delete_reason' => ''),
+ ),
+ array(
+ array(
+ 'topic_visibility' => ITEM_DELETED,
+ 'topic_first_post_id' => 4,
+ 'topic_last_post_id' => 4,
+ 'topic_posts_approved' => 0,
+ 'topic_posts_unapproved' => 0,
+ 'topic_posts_softdeleted' => 1,
+ 'topic_delete_reason' => 'soft delete',
+ ),
+ ),
+ array(
+ array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0),
+ ),
+ array(
+ array('user_posts' => 3),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_post_data
+ */
+ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum, $expected_user)
+ {
+ global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ $config['search_type'] = 'phpbb_mock_search';
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $phpbb_config = new \phpbb\config\config(array('num_posts' => 3, 'num_topics' => 1));
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ set_config_count(null, null, null, $phpbb_config);
+
+ // Create auth mock
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'), $this->anything())
+ ->will($this->returnValueMap(array(
+ array('m_approve', 1, true),
+ )));
+ $user = new \phpbb\user('\phpbb\datetime');
+
+ $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, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
+
+ delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
+
+ $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
+ FROM phpbb_posts
+ WHERE topic_id = ' . $topic_id . '
+ ORDER BY post_id ASC');
+
+ $this->assertEquals($expected_posts, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+
+ $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_delete_reason
+ FROM phpbb_topics
+ WHERE topic_id = ' . $topic_id);
+
+ $this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+
+ $result = $db->sql_query('SELECT forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, forum_last_post_id
+ FROM phpbb_forums
+ WHERE forum_id = ' . $forum_id);
+
+ $this->assertEquals($expected_forum, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+
+ $sql = 'SELECT user_posts
+ FROM ' . USERS_TABLE . '
+ WHERE user_id = ' . (int) $data['poster_id'];
+ $result = $db->sql_query($sql);
+
+ $this->assertEquals($expected_user, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/content_visibility/fixtures/delete_post.xml b/tests/content_visibility/fixtures/delete_post.xml
new file mode 100644
index 0000000000..c29ad23019
--- /dev/null
+++ b/tests/content_visibility/fixtures/delete_post.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_forums">
+ <column>forum_id</column>
+ <column>forum_posts_approved</column>
+ <column>forum_posts_unapproved</column>
+ <column>forum_posts_softdeleted</column>
+ <column>forum_topics_approved</column>
+ <column>forum_topics_unapproved</column>
+ <column>forum_topics_softdeleted</column>
+ <column>forum_last_post_id</column>
+ <column>forum_parents</column>
+ <column>forum_desc</column>
+ <column>forum_rules</column>
+
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_visibility</column>
+ <column>topic_title</column>
+ <column>topic_first_post_id</column>
+ <column>topic_last_post_id</column>
+ <column>topic_delete_user</column>
+ <column>topic_delete_time</column>
+ <column>topic_delete_reason</column>
+ <column>topic_posts_approved</column>
+ <column>topic_posts_unapproved</column>
+ <column>topic_posts_softdeleted</column>
+
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>1</value>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>4</value>
+ <value>4</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_time</column>
+ <column>post_text</column>
+ <column>post_delete_user</column>
+ <column>post_delete_time</column>
+ <column>post_delete_reason</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Approved</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>3</value>
+ <value>Approved</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>4</value>
+ <value>Approved</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_posts</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ <value>user 1</value>
+ <value>user 1</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/content_visibility/fixtures/get_forums_visibility_sql.xml b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml
new file mode 100644
index 0000000000..658d34398f
--- /dev/null
+++ b/tests/content_visibility/fixtures/get_forums_visibility_sql.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_visibility</column>
+ <column>topic_title</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>2</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>2</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>2</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>3</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>3</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>3</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>2</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>2</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>2</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>7</value>
+ <value>3</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>8</value>
+ <value>3</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>9</value>
+ <value>3</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/content_visibility/fixtures/get_visibility_sql.xml b/tests/content_visibility/fixtures/get_visibility_sql.xml
new file mode 100644
index 0000000000..146244263e
--- /dev/null
+++ b/tests/content_visibility/fixtures/get_visibility_sql.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_visibility</column>
+ <column>topic_title</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/content_visibility/fixtures/set_post_visibility.xml b/tests/content_visibility/fixtures/set_post_visibility.xml
new file mode 100644
index 0000000000..1b8dac2670
--- /dev/null
+++ b/tests/content_visibility/fixtures/set_post_visibility.xml
@@ -0,0 +1,238 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_visibility</column>
+ <column>topic_title</column>
+ <column>topic_first_post_id</column>
+ <column>topic_last_post_id</column>
+ <column>topic_posts_approved</column>
+ <column>topic_posts_softdeleted</column>
+ <column>topic_posts_unapproved</column>
+ <column>topic_attachment</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>2 Approved posts</value>
+ <value>5</value>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Only 1 Approved posts</value>
+ <value>8</value>
+ <value>8</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+
+ <row>
+ <value>10</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Only 3 posts (2 with attachments)</value>
+ <value>10</value>
+ <value>12</value>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ </row>
+
+ <row>
+ <value>11</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Only 2 posts (1 with attachments)</value>
+ <value>13</value>
+ <value>14</value>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_text</column>
+ <column>post_attachment</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ <value>0</value>
+ </row>
+
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved 2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>3</value>
+ <value>2</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Softdeleted</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>1</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>1</value>
+ <value>10</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Softdeleted</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>11</value>
+ <value>1</value>
+ <value>10</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Softdeleted</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>12</value>
+ <value>1</value>
+ <value>10</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>13</value>
+ <value>1</value>
+ <value>11</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>14</value>
+ <value>1</value>
+ <value>11</value>
+ <value>10</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_posts</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>user 1</value>
+ <value>user 1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>user 2</value>
+ <value>user 2</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>user 3</value>
+ <value>user 3</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/content_visibility/fixtures/set_topic_visibility.xml b/tests/content_visibility/fixtures/set_topic_visibility.xml
new file mode 100644
index 0000000000..02ab5f16fe
--- /dev/null
+++ b/tests/content_visibility/fixtures/set_topic_visibility.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>topic_visibility</column>
+ <column>topic_title</column>
+ <column>topic_first_post_id</column>
+ <column>topic_last_post_id</column>
+ <column>topic_delete_user</column>
+ <column>topic_delete_time</column>
+ <column>topic_delete_reason</column>
+
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Soft deleted</value>
+ <value>4</value>
+ <value>5</value>
+ <value>2</value>
+ <value>123</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_text</column>
+ <column>post_delete_user</column>
+ <column>post_delete_time</column>
+ <column>post_delete_reason</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Approved</value>
+ <value>2</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Soft deleted</value>
+ <value>2</value>
+ <value>123</value>
+ <value>manually</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>2</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Soft deleted by topic soft delete</value>
+ <value>2</value>
+ <value>123</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>1</value>
+ <value>2</value>
+ <value>1</value>
+ <value>2</value>
+ <value>Soft deleted before the topic was soft deleted</value>
+ <value>2</value>
+ <value>120</value>
+ <value>manually</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>1</value>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ <value>Unapproved before the topic was soft deleted</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_posts</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>user 1</value>
+ <value>user 1</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php
new file mode 100644
index 0000000000..28e463ecb5
--- /dev/null
+++ b/tests/content_visibility/get_forums_visibility_sql_test.php
@@ -0,0 +1,149 @@
+<?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_content_visibility_get_forums_visibility_sql_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml');
+ }
+
+ public function get_forums_visibility_sql_data()
+ {
+ return array(
+ array(
+ 'phpbb_topics',
+ 'topic', array(1, 2, 3), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ array('topic_id' => 3),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ array('topic_id' => 7),
+ array('topic_id' => 8),
+ array('topic_id' => 9),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', array(1, 2), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ array('topic_id' => 3),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', array(1, 2, 3), '',
+ array(
+ array('m_approve', true, array(2 => true)),
+ ),
+ array(
+ array('topic_id' => 2),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ array('topic_id' => 8),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(1, 2, 3), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ array('post_id' => 3),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ array('post_id' => 7),
+ array('post_id' => 8),
+ array('post_id' => 9),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(1, 2), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ array('post_id' => 3),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(1, 2, 3), '',
+ array(
+ array('m_approve', true, array(2 => true)),
+ ),
+ array(
+ array('post_id' => 2),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ array('post_id' => 8),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_forums_visibility_sql_data
+ */
+ public function test_get_forums_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+
+ // Create auth mock
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_getf')
+ ->with($this->stringContains('_'), $this->anything())
+ ->will($this->returnValueMap($permissions));
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $result = $db->sql_query('SELECT ' . $mode . '_id
+ FROM ' . $table . '
+ WHERE ' . $content_visibility->get_forums_visibility_sql($mode, $forum_ids, $table_alias) . '
+ ORDER BY ' . $mode . '_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php
new file mode 100644
index 0000000000..586bae8668
--- /dev/null
+++ b/tests/content_visibility/get_global_visibility_sql_test.php
@@ -0,0 +1,149 @@
+<?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_content_visibility_get_global_visibility_sql_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_forums_visibility_sql.xml');
+ }
+
+ public function get_global_visibility_sql_data()
+ {
+ return array(
+ array(
+ 'phpbb_topics',
+ 'topic', array(), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ array('topic_id' => 3),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ array('topic_id' => 7),
+ array('topic_id' => 8),
+ array('topic_id' => 9),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', array(3), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ array('topic_id' => 3),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', array(), '',
+ array(
+ array('m_approve', true, array(2 => true)),
+ ),
+ array(
+ array('topic_id' => 2),
+ array('topic_id' => 4),
+ array('topic_id' => 5),
+ array('topic_id' => 6),
+ array('topic_id' => 8),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ array('post_id' => 3),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ array('post_id' => 7),
+ array('post_id' => 8),
+ array('post_id' => 9),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(3), '',
+ array(
+ array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
+ ),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ array('post_id' => 3),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', array(), '',
+ array(
+ array('m_approve', true, array(2 => true)),
+ ),
+ array(
+ array('post_id' => 2),
+ array('post_id' => 4),
+ array('post_id' => 5),
+ array('post_id' => 6),
+ array('post_id' => 8),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_global_visibility_sql_data
+ */
+ public function test_get_global_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+
+ // Create auth mock
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_getf')
+ ->with($this->stringContains('_'), $this->anything())
+ ->will($this->returnValueMap($permissions));
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $result = $db->sql_query('SELECT ' . $mode . '_id
+ FROM ' . $table . '
+ WHERE ' . $content_visibility->get_global_visibility_sql($mode, $forum_ids, $table_alias) . '
+ ORDER BY ' . $mode . '_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php
new file mode 100644
index 0000000000..9ae2d2fdc4
--- /dev/null
+++ b/tests/content_visibility/get_visibility_sql_test.php
@@ -0,0 +1,96 @@
+<?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_content_visibility_get_visibility_sql_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/get_visibility_sql.xml');
+ }
+
+ public function get_visibility_sql_data()
+ {
+ return array(
+ array(
+ 'phpbb_posts',
+ 'post', 1, '',
+ array(
+ array('m_approve', 1, true),
+ ),
+ array(
+ array('post_id' => 1),
+ array('post_id' => 2),
+ array('post_id' => 3),
+ ),
+ ),
+ array(
+ 'phpbb_posts',
+ 'post', 1, '',
+ array(
+ ),
+ array(
+ array('post_id' => 2),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', 1, '',
+ array(
+ array('m_approve', 1, true),
+ ),
+ array(
+ array('topic_id' => 1),
+ array('topic_id' => 2),
+ array('topic_id' => 3),
+ ),
+ ),
+ array(
+ 'phpbb_topics',
+ 'topic', 1, '',
+ array(),
+ array(
+ array('topic_id' => 2),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_visibility_sql_data
+ */
+ public function test_get_visibility_sql($table, $mode, $forum_id, $table_alias, $permissions, $expected)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+
+ // Create auth mock
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'), $this->anything())
+ ->will($this->returnValueMap($permissions));
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $result = $db->sql_query('SELECT ' . $mode . '_id
+ FROM ' . $table . '
+ WHERE ' . $content_visibility->get_visibility_sql($mode, $forum_id, $table_alias) . '
+ ORDER BY ' . $mode . '_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php
new file mode 100644
index 0000000000..36ebf58374
--- /dev/null
+++ b/tests/content_visibility/set_post_visibility_test.php
@@ -0,0 +1,192 @@
+<?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_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_post_visibility.xml');
+ }
+
+ public function set_post_visibility_data()
+ {
+ return array(
+ array(
+ ITEM_APPROVED,
+ 1, 1, 1,
+ 2, time(), 'approve',
+ true, false,
+ array(
+ array('post_id' => 1, 'post_visibility' => 1, 'post_delete_reason' => 'approve'),
+ array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 1, 'topic_last_post_id' => 2),
+ ),
+ ),
+ array(
+ ITEM_APPROVED,
+ 3, 1, 1,
+ 2, time(), 'approve',
+ false, true,
+ array(
+ array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => 1, 'post_delete_reason' => 'approve'),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 2, 'topic_last_post_id' => 3),
+ ),
+ ),
+ array(
+ ITEM_DELETED,
+ 2, 1, 1,
+ 2, time(), 'deleted',
+ true, true,
+ array(
+ array('post_id' => 1, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
+ array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3),
+ ),
+ ),
+ array(
+ ITEM_DELETED,
+ 5, 2, 1,
+ 2, time(), 'deleted',
+ true, false,
+ array(
+ array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
+ array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 6, 'topic_last_post_id' => 6),
+ ),
+ ),
+ array(
+ ITEM_DELETED,
+ 6, 2, 1,
+ 2, time(), 'deleted',
+ false, true,
+ array(
+ array('post_id' => 4, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 6, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
+ array('post_id' => 7, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 5, 'topic_last_post_id' => 5),
+ ),
+ ),
+ array(
+ ITEM_DELETED,
+ 8, 3, 1,
+ 2, time(), 'deleted',
+ true, true,
+ array(
+ array('post_id' => 8, 'post_visibility' => 2, 'post_delete_reason' => 'deleted'),
+ ),
+ array(
+ array('topic_visibility' => 2, 'topic_first_post_id' => 8, 'topic_last_post_id' => 8),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider set_post_visibility_data
+ */
+ public function test_set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected, $expected_topic)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $content_visibility->set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
+
+ $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
+ FROM phpbb_posts
+ WHERE topic_id = ' . $topic_id . '
+ ORDER BY post_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+
+ $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id
+ FROM phpbb_topics
+ WHERE topic_id = ' . $topic_id);
+
+ $this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+ }
+
+ public function set_post_soft_deleted_data()
+ {
+ return array(
+ array(
+ 10, 10, 10,
+ 1, time(), 'soft-deleted',
+ true, false,
+ array(array('topic_attachment' => 1)),
+ ),
+ array(
+ 13, 11, 10,
+ 1, time(), 'soft-deleted',
+ true, false,
+ array(array('topic_attachment' => 0)),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider set_post_soft_deleted_data
+ */
+ public function test_set_post_soft_deleted($post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $expected)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest);
+
+ $result = $db->sql_query('SELECT topic_attachment
+ FROM phpbb_topics
+ WHERE topic_id = ' . $topic_id);
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php
new file mode 100644
index 0000000000..6c34f42167
--- /dev/null
+++ b/tests/content_visibility/set_topic_visibility_test.php
@@ -0,0 +1,113 @@
+<?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_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/set_topic_visibility.xml');
+ }
+
+ public function set_topic_visibility_data()
+ {
+ return array(
+ array(
+ ITEM_DELETED, 1, 1,
+ 2, time(), 'delete', false,
+ array(
+ array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => 'manually'),
+ array('post_id' => 3, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete'),
+ ),
+ ),
+ array(
+ ITEM_DELETED, 1, 1,
+ 2, time(), 'delete-forced', true,
+ array(
+ array('post_id' => 1, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ array('post_id' => 2, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ array('post_id' => 3, 'post_visibility' => 2, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 2, 'topic_first_post_id' => 1, 'topic_last_post_id' => 3, 'topic_delete_reason' => 'delete-forced'),
+ ),
+ ),
+ array(
+ ITEM_APPROVED, 2, 1,
+ 2, time(), 'approved', false,
+ array(
+ array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 5, 'post_visibility' => 2, 'post_delete_reason' => 'manually'),
+ array('post_id' => 6, 'post_visibility' => 0, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 4, 'topic_delete_reason' => 'approved'),
+ ),
+ ),
+ array(
+ ITEM_APPROVED, 2, 1,
+ 2, time(), 'approved-forced', true,
+ array(
+ array('post_id' => 4, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 5, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ array('post_id' => 6, 'post_visibility' => 1, 'post_delete_reason' => ''),
+ ),
+ array(
+ array('topic_visibility' => 1, 'topic_first_post_id' => 4, 'topic_last_post_id' => 6, 'topic_delete_reason' => 'approved-forced'),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider set_topic_visibility_data
+ */
+ public function test_set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all, $expected_posts, $expected_topic)
+ {
+ global $cache, $db, $auth, $phpbb_root_path, $phpEx;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $user = new \phpbb\user('\phpbb\datetime');
+ $config = new phpbb\config\config(array());
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
+
+ $content_visibility->set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all);
+
+ $result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
+ FROM phpbb_posts
+ WHERE topic_id = ' . $topic_id . '
+ ORDER BY post_id ASC');
+
+ $this->assertEquals($expected_posts, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+
+ $result = $db->sql_query('SELECT topic_visibility, topic_first_post_id, topic_last_post_id, topic_delete_reason
+ FROM phpbb_topics
+ WHERE topic_id = ' . $topic_id);
+
+ $this->assertEquals($expected_topic, $db->sql_fetchrowset($result));
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php
new file mode 100644
index 0000000000..ea77a289c9
--- /dev/null
+++ b/tests/controller/common_helper_route.php
@@ -0,0 +1,467 @@
+<?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';
+
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
+
+abstract class phpbb_controller_common_helper_route extends phpbb_test_case
+{
+ protected $root_path;
+ private $user;
+ private $config;
+ private $template;
+ private $extension_manager;
+ private $request;
+ private $symfony_request;
+ private $provider;
+ private $filesystem;
+ private $phpbb_path_helper;
+
+ public function setUp()
+ {
+ global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ )
+ );
+ $this->generate_route_objects();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $this->user = new \phpbb\user('\phpbb\datetime');
+
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context());
+ }
+
+ protected function get_phpbb_root_path()
+ {
+ return '';
+ }
+
+ protected function get_uri()
+ {
+ return '/app.php';
+ }
+
+ protected function get_base_uri()
+ {
+ return $this->get_uri();
+ }
+
+ protected function get_script_name()
+ {
+ return 'app.php';
+ }
+
+ protected function path_to_app()
+ {
+ return '';
+ }
+
+ protected function generate_route_objects()
+ {
+ global $request;
+
+ $this->request = new phpbb_mock_request();
+ $this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER);
+ $this->request->overwrite('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER);
+ $this->request->overwrite('REQUEST_URI', $this->get_base_uri(), \phpbb\request\request_interface::SERVER);
+ $this->request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER);
+ $this->request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER);
+
+ $request = $this->request;
+
+ $this->symfony_request = new \phpbb\symfony_request(
+ $this->request
+ );
+ $this->filesystem = new \phpbb\filesystem();
+ $this->phpbb_path_helper = new \phpbb\path_helper(
+ $this->symfony_request,
+ $this->filesystem,
+ $this->request,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $finder = new \phpbb\finder(
+ new \phpbb\filesystem(),
+ dirname(__FILE__) . '/',
+ new phpbb_mock_cache()
+ );
+ $finder->set_extensions(array_keys($this->extension_manager->all_enabled()));
+ $this->provider = new \phpbb\controller\provider();
+ $this->provider->find_routing_files($finder);
+ $this->provider->find(dirname(__FILE__) . '/');
+ // Set correct current phpBB root path
+ $this->root_path = $this->get_phpbb_root_path();
+ }
+
+ public function helper_url_data_no_rewrite()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_no_rewrite()
+ */
+ public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id), $description);
+ }
+
+ public function helper_url_data_with_rewrite()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_with_rewrite()
+ */
+ public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id), $description);
+ }
+
+ public function helper_url_data_absolute()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_absolute()
+ */
+ public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
+ }
+
+ public function helper_url_data_relative_path()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'app.php/foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, 'app.php/foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, 'app.php/foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, 'app.php/foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_relative_path()
+ */
+ public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
+ }
+
+ public function helper_url_data_network()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_network()
+ */
+ public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
+ }
+//TODO
+ public function helper_url_data_absolute_with_rewrite()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_absolute_with_rewrite()
+ */
+ public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
+ }
+
+ public function helper_url_data_relative_path_with_rewrite()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, 'foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, 'foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, 'foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_relative_path_with_rewrite()
+ */
+ public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
+ }
+
+ public function helper_url_data_network_with_rewrite()
+ {
+ return array(
+ array('controller2', array('t' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller2', array('t' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2', 'parameters in params-argument as array'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid', 'params-argument (array) using session_id'),
+
+ // Testing anchors
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+ array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the &amp; or ?
+ array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'),
+ array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_network_with_rewrite()
+ */
+ public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
+ }
+
+ public function helper_url_data_force_server_vars()
+ {
+ return array(
+ array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_URL, 'http://my_server:443/my/board/app.php/foo'),
+ array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::ABSOLUTE_URL, 'https://my_server:444/my/board/foo'),
+ array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:443/my/board/app.php/foo'),
+ array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:444/my/board/foo'),
+ array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/app.php/foo'),
+ array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/foo'),
+ array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'app.php/foo'),
+ array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'foo'),
+ );
+ }
+
+ /**
+ * @dataProvider helper_url_data_force_server_vars()
+ */
+ public function test_helper_url_force_server_vars($enable_mod_rewrite, $force_server_vars, $server_name, $server_port, $script_path, $server_protocol, $type, $expected)
+ {
+ $this->config = new \phpbb\config\config(array(
+ 'enable_mod_rewrite' => $enable_mod_rewrite,
+ 'force_server_vars' => $force_server_vars,
+ 'server_name' => $server_name,
+ 'server_port' => $server_port,
+ 'script_path' => $script_path,
+ 'server_protocol' => $server_protocol,
+ ));
+
+ $helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/');
+ static::assertEquals($expected, $helper->route('controller1', array(), false, false, $type));
+
+ }
+}
diff --git a/tests/controller/config/routing.yml b/tests/controller/config/routing.yml
new file mode 100644
index 0000000000..1e7df02684
--- /dev/null
+++ b/tests/controller/config/routing.yml
@@ -0,0 +1,3 @@
+core_controller:
+ path: /core_foo
+ defaults: { _controller: core_foo.controller:bar }
diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml
new file mode 100644
index 0000000000..e4412af3d7
--- /dev/null
+++ b/tests/controller/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ core_foo.controller:
+ class: phpbb\controller\foo
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
new file mode 100644
index 0000000000..62feee3fed
--- /dev/null
+++ b/tests/controller/controller_test.php
@@ -0,0 +1,88 @@
+<?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';
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
+class phpbb_controller_controller_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ ));
+ }
+
+ public function test_provider()
+ {
+ $provider = new \phpbb\controller\provider();
+ $provider->find_routing_files($this->extension_manager->get_finder());
+ $routes = $provider->find(__DIR__)->get_routes();
+
+ // This will need to be updated if any new routes are defined
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller'));
+ $this->assertEquals('/core_foo', $routes->get('core_controller')->getPath());
+
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller1'));
+ $this->assertEquals('/foo', $routes->get('controller1')->getPath());
+
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('controller2'));
+ $this->assertEquals('/foo/bar', $routes->get('controller2')->getPath());
+
+ $this->assertNull($routes->get('controller_noroute'));
+ }
+
+ public function test_controller_resolver()
+ {
+ $container = new ContainerBuilder();
+ // YamlFileLoader only uses one path at a time, so we need to loop
+ // through all of the ones we are using.
+ foreach (array(__DIR__.'/config', __DIR__ . '/ext/vendor2/foo/config') as $path)
+ {
+ $loader = new YamlFileLoader($container, new FileLocator($path));
+ $loader->load('services.yml');
+ }
+
+ // Autoloading classes within the tests folder does not work
+ // so I'll include them manually.
+ if (!class_exists('vendor2\\foo\\controller'))
+ {
+ include(__DIR__ . '/ext/vendor2/foo/controller.php');
+ }
+ if (!class_exists('phpbb\\controller\\foo'))
+ {
+ include(__DIR__.'/phpbb/controller/foo.php');
+ }
+
+ $resolver = new \phpbb\controller\resolver(new \phpbb\user('\phpbb\datetime'), $container, dirname(__FILE__) . '/');
+ $symfony_request = new Request();
+ $symfony_request->attributes->set('_controller', 'foo.controller:handle');
+
+ $this->assertEquals($resolver->getController($symfony_request), array(new foo\controller, 'handle'));
+
+ $symfony_request = new Request();
+ $symfony_request->attributes->set('_controller', 'core_foo.controller:bar');
+
+ $this->assertEquals($resolver->getController($symfony_request), array(new phpbb\controller\foo, 'bar'));
+ }
+}
diff --git a/tests/controller/ext/vendor2/foo/config/routing.yml b/tests/controller/ext/vendor2/foo/config/routing.yml
new file mode 100644
index 0000000000..e3e8ee5f98
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/config/routing.yml
@@ -0,0 +1,7 @@
+controller1:
+ path: /foo
+ defaults: { _controller: foo.controller:handle }
+
+include_controller2:
+ resource: "routing_2.yml"
+ prefix: /foo
diff --git a/tests/controller/ext/vendor2/foo/config/routing_2.yml b/tests/controller/ext/vendor2/foo/config/routing_2.yml
new file mode 100644
index 0000000000..ee05898c66
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/config/routing_2.yml
@@ -0,0 +1,6 @@
+controller2:
+ path: /bar
+ defaults: { _controller: foo.controller:handle }
+controller3:
+ path: /bar/p-{p}
+ defaults: { _controller: foo.controller:handle }
diff --git a/tests/controller/ext/vendor2/foo/config/services.yml b/tests/controller/ext/vendor2/foo/config/services.yml
new file mode 100644
index 0000000000..9ed67d5bc2
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ foo.controller:
+ class: foo\controller
diff --git a/tests/controller/ext/vendor2/foo/controller.php b/tests/controller/ext/vendor2/foo/controller.php
new file mode 100644
index 0000000000..ce2233b3c9
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/controller.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace foo;
+
+use Symfony\Component\HttpFoundation\Response;
+
+class controller
+{
+ /**
+ * Handle method
+ *
+ * @return null
+ */
+ public function handle()
+ {
+ return new Response('Test', 200);
+ }
+}
diff --git a/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml b/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml
new file mode 100644
index 0000000000..20810a8f25
--- /dev/null
+++ b/tests/controller/ext/vendor2/foo/subfolder/config/routing.yml
@@ -0,0 +1,3 @@
+controller_noroute:
+ path: /donotfindthis
+ defaults: { _controller: foo.controller:handle }
diff --git a/tests/controller/helper_route_adm_subdir_test.php b/tests/controller/helper_route_adm_subdir_test.php
new file mode 100644
index 0000000000..f27ac81b04
--- /dev/null
+++ b/tests/controller/helper_route_adm_subdir_test.php
@@ -0,0 +1,33 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_adm_subdir_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return './../../';
+ }
+
+ protected function get_uri()
+ {
+ return '/adm/subdir/index.php';
+ }
+
+ protected function get_script_name()
+ {
+ return 'index.php';
+ }
+}
diff --git a/tests/controller/helper_route_adm_test.php b/tests/controller/helper_route_adm_test.php
new file mode 100644
index 0000000000..86dc36ef1f
--- /dev/null
+++ b/tests/controller/helper_route_adm_test.php
@@ -0,0 +1,33 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_adm_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return './../';
+ }
+
+ protected function get_uri()
+ {
+ return '/adm/index.php';
+ }
+
+ protected function get_script_name()
+ {
+ return 'index.php';
+ }
+}
diff --git a/tests/controller/helper_route_other_app.php b/tests/controller/helper_route_other_app.php
new file mode 100644
index 0000000000..e5513a5180
--- /dev/null
+++ b/tests/controller/helper_route_other_app.php
@@ -0,0 +1,37 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_other_app_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return './../';
+ }
+
+ protected function get_uri()
+ {
+ return '/foo/app.php';
+ }
+
+ protected function get_script_name()
+ {
+ return 'app.php';
+ }
+
+ protected function path_to_app()
+ {
+ return 'foo/';
+ }
+}
diff --git a/tests/controller/helper_route_root_test.php b/tests/controller/helper_route_root_test.php
new file mode 100644
index 0000000000..63a2f2f8f7
--- /dev/null
+++ b/tests/controller/helper_route_root_test.php
@@ -0,0 +1,33 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return '';
+ }
+
+ protected function get_uri()
+ {
+ return '/app.php';
+ }
+
+ protected function get_script_name()
+ {
+ return 'app.php';
+ }
+}
diff --git a/tests/controller/helper_route_slash_test.php b/tests/controller/helper_route_slash_test.php
new file mode 100644
index 0000000000..3db5ec19e5
--- /dev/null
+++ b/tests/controller/helper_route_slash_test.php
@@ -0,0 +1,43 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_slash_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return './../';
+ }
+
+ protected function get_uri()
+ {
+ return '/phpBB3/app.php';
+ }
+
+ protected function get_base_uri()
+ {
+ return '/phpBB3/';
+ }
+
+ protected function get_script_name()
+ {
+ return 'app.php';
+ }
+
+ protected function path_to_app()
+ {
+ return 'phpBB3/';
+ }
+}
diff --git a/tests/controller/helper_route_unclean_path_test.php b/tests/controller/helper_route_unclean_path_test.php
new file mode 100644
index 0000000000..9d8b62bc1c
--- /dev/null
+++ b/tests/controller/helper_route_unclean_path_test.php
@@ -0,0 +1,33 @@
+<?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__) . '/common_helper_route.php';
+
+class phpbb_controller_helper_route_unclean_path_test extends phpbb_controller_common_helper_route
+{
+ protected function get_phpbb_root_path()
+ {
+ return './../';
+ }
+
+ protected function get_uri()
+ {
+ return '/adm/../bertie/index.php';
+ }
+
+ protected function get_script_name()
+ {
+ return 'index.php';
+ }
+}
diff --git a/tests/controller/phpbb/controller/foo.php b/tests/controller/phpbb/controller/foo.php
new file mode 100644
index 0000000000..98669f428f
--- /dev/null
+++ b/tests/controller/phpbb/controller/foo.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace phpbb\controller;
+
+use Symfony\Component\HttpFoundation\Response;
+
+class foo
+{
+ /**
+ * Bar method
+ *
+ * @return null
+ */
+ public function bar()
+ {
+ return new Response('bar()', 200);
+ }
+}
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php
new file mode 100644
index 0000000000..5c474dca4f
--- /dev/null
+++ b/tests/cron/ext/testext/cron/dummy_task.php
@@ -0,0 +1,32 @@
+<?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_ext_testext_cron_dummy_task extends \phpbb\cron\task\base
+{
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php
new file mode 100644
index 0000000000..1ef28c5cca
--- /dev/null
+++ b/tests/cron/includes/cron/task/core/dummy_task.php
@@ -0,0 +1,32 @@
+<?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_cron_task_core_dummy_task extends \phpbb\cron\task\base
+{
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php
new file mode 100644
index 0000000000..ada175a501
--- /dev/null
+++ b/tests/cron/includes/cron/task/core/second_dummy_task.php
@@ -0,0 +1,32 @@
+<?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_cron_task_core_second_dummy_task extends \phpbb\cron\task\base
+{
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
new file mode 100644
index 0000000000..f4dd69b19b
--- /dev/null
+++ b/tests/cron/manager_test.php
@@ -0,0 +1,80 @@
+<?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__) . '/includes/cron/task/core/dummy_task.php';
+require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php';
+require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php';
+require_once dirname(__FILE__) . '/tasks/simple_ready.php';
+require_once dirname(__FILE__) . '/tasks/simple_not_runnable.php';
+require_once dirname(__FILE__) . '/tasks/simple_should_not_run.php';
+
+class phpbb_cron_manager_test extends \phpbb_test_case
+{
+ public function setUp()
+ {
+ $this->manager = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_dummy_task(),
+ new phpbb_cron_task_core_second_dummy_task(),
+ new phpbb_ext_testext_cron_dummy_task(),
+ ));
+ $this->task_name = 'phpbb_cron_task_core_dummy_task';
+ }
+
+ public function test_manager_finds_shipped_task_by_name()
+ {
+ $task = $this->manager->find_task($this->task_name);
+ $this->assertInstanceOf('\phpbb\cron\task\wrapper', $task);
+ $this->assertEquals($this->task_name, $task->get_name());
+ }
+
+ public function test_manager_finds_all_ready_tasks()
+ {
+ $tasks = $this->manager->find_all_ready_tasks();
+ $this->assertEquals(3, sizeof($tasks));
+ }
+
+ public function test_manager_finds_one_ready_task()
+ {
+ $task = $this->manager->find_one_ready_task();
+ $this->assertInstanceOf('\phpbb\cron\task\wrapper', $task);
+ }
+
+ public function test_manager_finds_only_ready_tasks()
+ {
+ $manager = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_simple_ready(),
+ new phpbb_cron_task_core_simple_not_runnable(),
+ new phpbb_cron_task_core_simple_should_not_run(),
+ ));
+ $tasks = $manager->find_all_ready_tasks();
+ $task_names = $this->tasks_to_names($tasks);
+ $this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names);
+ }
+
+ private function tasks_to_names($tasks)
+ {
+ $names = array();
+ foreach ($tasks as $task)
+ {
+ $names[] = $task->get_name();
+ }
+ return $names;
+ }
+
+ private function create_cron_manager($tasks)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
+ }
+}
diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php
new file mode 100644
index 0000000000..4951b5b4b9
--- /dev/null
+++ b/tests/cron/tasks/simple_not_runnable.php
@@ -0,0 +1,18 @@
+<?php
+
+class phpbb_cron_task_core_simple_not_runnable extends \phpbb\cron\task\base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+
+ public function is_runnable()
+ {
+ return false;
+ }
+}
diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php
new file mode 100644
index 0000000000..245d9ba738
--- /dev/null
+++ b/tests/cron/tasks/simple_ready.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_cron_task_core_simple_ready extends \phpbb\cron\task\base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+}
diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php
new file mode 100644
index 0000000000..7bd9df31b6
--- /dev/null
+++ b/tests/cron/tasks/simple_should_not_run.php
@@ -0,0 +1,18 @@
+<?php
+
+class phpbb_cron_task_core_simple_should_not_run extends \phpbb\cron\task\base
+{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
+ public function run()
+ {
+ }
+
+ public function should_run()
+ {
+ return false;
+ }
+}
diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php
new file mode 100644
index 0000000000..8968619bb5
--- /dev/null
+++ b/tests/datetime/from_format_test.php
@@ -0,0 +1,126 @@
+<?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__) . '/../mock/lang.php';
+
+class phpbb_datetime_from_format_test extends phpbb_test_case
+{
+ public function from_format_data()
+ {
+ return array(
+ array(
+ 'UTC',
+ 'Y-m-d',
+ '2012-06-08',
+ ),
+
+ array(
+ 'Europe/Berlin',
+ 'Y-m-d H:i:s',
+ '2012-06-08 14:01:02',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider from_format_data()
+ */
+ public function test_from_format($timezone, $format, $expected)
+ {
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->timezone = new DateTimeZone($timezone);
+ $user->lang['datetime'] = array(
+ 'TODAY' => 'Today',
+ 'TOMORROW' => 'Tomorrow',
+ 'YESTERDAY' => 'Yesterday',
+ 'AGO' => array(
+ 0 => 'less than a minute ago',
+ 1 => '%d minute ago',
+ 2 => '%d minutes ago',
+ ),
+ );
+
+ $timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone));
+ $this->assertEquals($expected, $user->format_date($timestamp, $format, true));
+ }
+
+
+ public function relative_format_date_data()
+ {
+ // If the current time is too close to the testing time,
+ // the relative time will use "x minutes ago" instead of "today ..."
+ // So we use 18:01 in the morning and 06:01 in the afternoon.
+ $testing_time = gmdate('H') <= 12 ? '18:01' : '06:01';
+
+ return array(
+ array(
+ gmdate('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, false,
+ gmdate('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time,
+ ),
+
+ array(
+ gmdate('Y-m-d', time() + 86400) . ' ' . $testing_time, false,
+ 'Tomorrow ' . $testing_time,
+ ),
+ array(
+ gmdate('Y-m-d', time() + 86400) . ' ' . $testing_time, true,
+ gmdate('Y-m-d', time() + 86400) . ' ' . $testing_time,
+ ),
+
+ array(
+ gmdate('Y-m-d') . ' ' . $testing_time, false,
+ 'Today ' . $testing_time,
+ ),
+ array(
+ gmdate('Y-m-d') . ' ' . $testing_time, true,
+ gmdate('Y-m-d') . ' ' . $testing_time,
+ ),
+
+ array(
+ gmdate('Y-m-d', time() - 86400) . ' ' . $testing_time, false,
+ 'Yesterday ' . $testing_time,
+ ),
+ array(
+ gmdate('Y-m-d', time() - 86400) . ' ' . $testing_time, true,
+ gmdate('Y-m-d', time() - 86400) . ' ' . $testing_time,
+ ),
+
+ array(
+ gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false,
+ gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider relative_format_date_data()
+ */
+ public function test_relative_format_date($timestamp, $forcedate, $expected)
+ {
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->timezone = new DateTimeZone('UTC');
+ $user->lang['datetime'] = array(
+ 'TODAY' => 'Today',
+ 'TOMORROW' => 'Tomorrow',
+ 'YESTERDAY' => 'Yesterday',
+ 'AGO' => array(
+ 0 => 'less than a minute ago',
+ 1 => '%d minute ago',
+ 2 => '%d minutes ago',
+ ),
+ );
+
+ $timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC'));
+ $this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate));
+ }
+}
diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php
index e87fc1c6bd..1ed8ea29e3 100644
--- a/tests/dbal/auto_increment_test.php
+++ b/tests/dbal/auto_increment_test.php
@@ -1,14 +1,17 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/db/db_tools.php';
class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
{
@@ -27,7 +30,7 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->tools = new phpbb_db_tools($this->db);
+ $this->tools = new \phpbb\db\tools($this->db);
$this->table_data = array(
'COLUMNS' => array(
diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php
new file mode 100644
index 0000000000..5f1c7d61fa
--- /dev/null
+++ b/tests/dbal/case_test.php
@@ -0,0 +1,73 @@
+<?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_case_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function test_case_int()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(1, (int) $db->sql_fetchfield('test_num'));
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(2, (int) $db->sql_fetchfield('test_num'));
+ }
+
+ public function test_case_string()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('foo', $db->sql_fetchfield('test_string'));
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
+ }
+
+ public function test_case_column()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
+ FROM phpbb_config
+ WHERE config_name = 'config1'";
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('config1', $db->sql_fetchfield('test_string'));
+
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
+ FROM phpbb_config
+ WHERE config_value = 'bar'";
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
+ }
+}
diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php
new file mode 100644
index 0000000000..00e7e107aa
--- /dev/null
+++ b/tests/dbal/concatenate_test.php
@@ -0,0 +1,68 @@
+<?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_concatenate_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function test_concatenate_string()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string
+ FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array(
+ 'config_name' => 'config1',
+ 'string' => 'config1append',
+ ),
+ array(
+ 'config_name' => 'config2',
+ 'string' => 'config2append',
+ ),
+ ),
+ $db->sql_fetchrowset($result)
+ );
+ }
+
+ public function test_concatenate_statement()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string
+ FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array(
+ 'config_name' => 'config1',
+ 'string' => 'config1foo',
+ ),
+ array(
+ 'config_name' => 'config2',
+ 'string' => 'config2bar',
+ ),
+ ),
+ $db->sql_fetchrowset($result)
+ );
+ }
+}
diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php
index 505ce28fa1..1ae34bd2b6 100644
--- a/tests/dbal/connect_test.php
+++ b/tests/dbal/connect_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -22,9 +26,7 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case
$config = $this->get_database_config();
- require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
- $dbal = 'dbal_' . $config['dbms'];
- $db = new $dbal();
+ $db = new $config['dbms']();
// Failure to connect results in a trigger_error call in dbal.
// phpunit converts triggered errors to exceptions.
diff --git a/tests/dbal/cross_join_test.php b/tests/dbal/cross_join_test.php
index 6c6b8a8449..7ba937ccc6 100644
--- a/tests/dbal/cross_join_test.php
+++ b/tests/dbal/cross_join_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index c20e46011f..5832b966d8 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -1,18 +1,23 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/db/db_tools.php';
class phpbb_dbal_db_tools_test extends phpbb_database_test_case
{
+ /** @var \phpbb\db\driver\driver_interface */
protected $db;
+ /** @var \phpbb\db\tools */
protected $tools;
protected $table_exists;
protected $table_data;
@@ -27,7 +32,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->tools = new phpbb_db_tools($this->db);
+ $this->tools = new \phpbb\db\tools($this->db);
$this->table_data = array(
'COLUMNS' => array(
@@ -41,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'),
@@ -106,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' => '',
@@ -139,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)),
@@ -208,6 +216,50 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist'));
}
+ public function test_column_change_with_index()
+ {
+ // Create column
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012', array('DECIMAL', 0)));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
+
+ // Create index over the column
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012'));
+ $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012', array('c_bug_12012', 'c_bool')));
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012'));
+
+ // Change type from int to string
+ $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12012', array('VCHAR:100', '')));
+
+ // Remove the index
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012'));
+ $this->assertTrue($this->tools->sql_index_drop('prefix_table_name', 'i_bug_12012'));
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012'));
+
+ // Remove the column
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012'));
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
+ }
+
+ public function test_column_change_with_composite_primary()
+ {
+ // Remove the old primary key
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_id', array('UINT', 0)));
+
+ // Create a composite key
+ $this->assertTrue($this->tools->sql_create_primary_key('prefix_table_name', array('c_id', 'c_uint')));
+
+ // Create column
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12643', array('DECIMAL', 0)));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
+
+ // Change type from int to string
+ $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12643', array('VCHAR:100', '')));
+ }
+
public function test_column_remove()
{
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
@@ -217,6 +269,39 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
}
+ public function test_column_remove_similar_name()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar'));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size'));
+
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_vchar'));
+
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_vchar'));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size'));
+ }
+
+ public function test_column_remove_with_index()
+ {
+ // Create column
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012_2', array('UINT', 4)));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
+
+ // Create index over the column
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2'));
+ $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_2', array('c_bug_12012_2', 'c_bool')));
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2'));
+
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3'));
+ $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_3', array('c_bug_12012_2')));
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3'));
+
+ // Remove the column
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012_2'));
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
+ }
+
public function test_column_remove_primary()
{
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
@@ -253,9 +338,9 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertFalse($this->tools->sql_table_exists('prefix_test_table'));
}
- public function test_peform_schema_changes_drop_tables()
+ public function test_perform_schema_changes_drop_tables()
{
- $db_tools = $this->getMock('phpbb_db_tools', array(
+ $db_tools = $this->getMock('\phpbb\db\tools', array(
'sql_table_exists',
'sql_table_drop',
), array(&$this->db));
@@ -279,9 +364,9 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
));
}
- public function test_peform_schema_changes_drop_columns()
+ public function test_perform_schema_changes_drop_columns()
{
- $db_tools = $this->getMock('phpbb_db_tools', array(
+ $db_tools = $this->getMock('\phpbb\db\tools', array(
'sql_column_exists',
'sql_column_remove',
), array(&$this->db));
@@ -330,4 +415,11 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id'));
$this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq_ts_id'));
}
+
+ public function test_create_int_default_null()
+ {
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
+ $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2')));
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
+ }
}
diff --git a/tests/dbal/fixtures/massmail_crossjoin.xml b/tests/dbal/fixtures/massmail_crossjoin.xml
index ef0a2b7149..1050ba067e 100644
--- a/tests/dbal/fixtures/massmail_crossjoin.xml
+++ b/tests/dbal/fixtures/massmail_crossjoin.xml
@@ -14,16 +14,12 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>mass email</value>
<value>mass email</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -31,8 +27,6 @@
<value>banned</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
@@ -40,8 +34,6 @@
<value>not in group</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
<table name="phpbb_user_group">
diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml
new file mode 100644
index 0000000000..25be4d4129
--- /dev/null
+++ b/tests/dbal/fixtures/migrator.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_migrations">
+ <column>migration_name</column>
+ <column>migration_depends_on</column>
+ <column>migration_schema_done</column>
+ <column>migration_data_done</column>
+ <column>migration_data_state</column>
+ <column>migration_start_time</column>
+ <column>migration_end_time</column>
+ <row>
+ <value>installed_migration</value>
+ <value></value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1234</value>
+ <value>5678</value>
+ </row>
+ </table>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <row>
+ <value>foo</value>
+ <value>bar</value>
+ </row>
+ </table>
+</dataset>
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/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml
new file mode 100644
index 0000000000..e85c43ee25
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_module.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_modules">
+ <column>module_id</column>
+ <column>module_enabled</column>
+ <column>module_display</column>
+ <column>module_basename</column>
+ <column>module_class</column>
+ <column>parent_id</column>
+ <column>left_id</column>
+ <column>right_id</column>
+ <column>module_langname</column>
+ <column>module_mode</column>
+ <column>module_auth</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>0</value>
+ <value>1</value>
+ <value>6</value>
+ <value>ACP_CAT</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>acp_test</value>
+ <value>acp</value>
+ <value>1</value>
+ <value>2</value>
+ <value>3</value>
+ <value>ACP_MODULE</value>
+ <value>test</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>1</value>
+ <value>4</value>
+ <value>5</value>
+ <value>ACP_FORUM_BASED_PERMISSIONS</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>0</value>
+ <value>7</value>
+ <value>12</value>
+ <value>ACP_CAT_FORUMS</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>4</value>
+ <value>8</value>
+ <value>11</value>
+ <value>ACP_FORUM_BASED_PERMISSIONS</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>5</value>
+ <value>9</value>
+ <value>10</value>
+ <value>ACP_FORUM_BASED_PERMISSIONS_CHILD_1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>ucp</value>
+ <value>0</value>
+ <value>13</value>
+ <value>18</value>
+ <value>UCP_MAIN_CAT</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>1</value>
+ <value>1</value>
+ <value>ucp_subcat</value>
+ <value>ucp</value>
+ <value>7</value>
+ <value>14</value>
+ <value>17</value>
+ <value>UCP_SUBCATEGORY</value>
+ <value>ucp_test</value>
+ <value></value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>1</value>
+ <value>1</value>
+ <value>ucp_module</value>
+ <value>ucp</value>
+ <value>8</value>
+ <value>15</value>
+ <value>16</value>
+ <value>UCP_MODULE</value>
+ <value>ucp_module_test</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml
new file mode 100644
index 0000000000..c07956fa85
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_permission.xml
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_acl_options">
+ <column>auth_option_id</column>
+ <column>auth_option</column>
+ <column>is_global</column>
+ <column>is_local</column>
+ <column>founder_only</column>
+ <row>
+ <value>1</value>
+ <value>global</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>local</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>both</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>a_test</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>m_test</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>u_test</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ </table>
+
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_name</column>
+ <column>group_desc</column>
+ <row>
+ <value>2</value>
+ <value>REGISTERED</value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>GLOBAL_MODERATORS</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>ADMINISTRATORS</value>
+ <value></value>
+ </row>
+ </table>
+
+ <table name="phpbb_acl_groups">
+ <column>group_id</column>
+ <column>auth_role_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>2</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>10</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ </table>
+
+ <table name="phpbb_acl_roles">
+ <column>role_id</column>
+ <column>role_name</column>
+ <column>role_type</column>
+ <column>role_description</column>
+ <row>
+ <value>1</value>
+ <value>ROLE_ADMIN_STANDARD</value>
+ <value>a_</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>ROLE_USER_FULL</value>
+ <value>u_</value>
+ <value></value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>ROLE_MOD_FULL</value>
+ <value>m_</value>
+ <value></value>
+ </row>
+ </table>
+
+ <table name="phpbb_acl_roles_data">
+ <column>role_id</column>
+ <column>auth_option_id</column>
+ <column>auth_setting</column>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml
index 47b384c47f..d51dcd0320 100644
--- a/tests/dbal/fixtures/styles.xml
+++ b/tests/dbal/fixtures/styles.xml
@@ -5,35 +5,39 @@
<column>style_name</column>
<column>style_copyright</column>
<column>style_active</column>
- <column>template_id</column>
- <column>theme_id</column>
- <column>imageset_id</column>
+ <column>style_path</column>
+ <column>bbcode_bitfield</column>
+ <column>style_parent_id</column>
+ <column>style_parent_tree</column>
<row>
<value>1</value>
<value>prosilver</value>
- <value>&amp;copy; phpBB Group</value>
- <value>1</value>
- <value>1</value>
- <value>1</value>
+ <value>&amp;copy; phpBB Limited</value>
<value>1</value>
+ <value>prosilver</value>
+ <value>kNg=</value>
+ <value>0</value>
+ <value></value>
</row>
<row>
<value>2</value>
<value>prosilver2</value>
- <value>&amp;copy; phpBB Group</value>
+ <value>&amp;copy; phpBB Limited</value>
<value>0</value>
- <value>2</value>
- <value>2</value>
- <value>2</value>
+ <value>prosilver2</value>
+ <value>kNg=</value>
+ <value>0</value>
+ <value></value>
</row>
<row>
<value>3</value>
<value>Prosilver1</value>
- <value>&amp;copy; phpBB Group</value>
+ <value>&amp;copy; phpBB Limited</value>
<value>0</value>
- <value>3</value>
- <value>3</value>
- <value>3</value>
+ <value>prosilver1</value>
+ <value>kNg=</value>
+ <value>1</value>
+ <value>prosilver</value>
</row>
</table>
</dataset>
diff --git a/tests/dbal/fixtures/three_users.xml b/tests/dbal/fixtures/three_users.xml
index a50e3e8634..a601e539e1 100644
--- a/tests/dbal/fixtures/three_users.xml
+++ b/tests/dbal/fixtures/three_users.xml
@@ -5,31 +5,23 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>barfoo</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
<value>foobar</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
<value>bertie</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
</dataset>
diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php
new file mode 100644
index 0000000000..d564754892
--- /dev/null
+++ b/tests/dbal/migration/dummy.php
@@ -0,0 +1,31 @@
+<?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_migration_dummy extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('installed_migration');
+ }
+
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ 'phpbb_config' => array(
+ 'extra_column' => array('UINT', 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order.php b/tests/dbal/migration/dummy_order.php
new file mode 100644
index 0000000000..5ab8f5d129
--- /dev/null
+++ b/tests/dbal/migration/dummy_order.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_dbal_migration_dummy_order extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_tables' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'COLUMNS' => array(
+ 'foobar1' => array('BOOL', 0),
+ 'foobar3' => array('BOOL', 0),
+ ),
+ 'PRIMARY_KEY' => array('foobar1'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_0.php b/tests/dbal/migration/dummy_order_0.php
new file mode 100644
index 0000000000..4caea76704
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_0.php
@@ -0,0 +1,26 @@
+<?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_migration_dummy_order_0 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar2' => array('BOOL', 0, 'after' => 'foobar1'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_1.php b/tests/dbal/migration/dummy_order_1.php
new file mode 100644
index 0000000000..ea512765fa
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_1.php
@@ -0,0 +1,26 @@
+<?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_migration_dummy_order_1 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar4' => array('BOOL', 0, 'after' => 'foobar3'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_2.php b/tests/dbal/migration/dummy_order_2.php
new file mode 100644
index 0000000000..a7669b1ac8
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_2.php
@@ -0,0 +1,26 @@
+<?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_migration_dummy_order_2 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar5' => array('BOOL', 0, 'after' => 'non-existing'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_3.php b/tests/dbal/migration/dummy_order_3.php
new file mode 100644
index 0000000000..501db09b7e
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_3.php
@@ -0,0 +1,26 @@
+<?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_migration_dummy_order_3 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar6' => array('BOOL', 0, 'after' => ''),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_4.php b/tests/dbal/migration/dummy_order_4.php
new file mode 100644
index 0000000000..77bb5a24b3
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_4.php
@@ -0,0 +1,26 @@
+<?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_migration_dummy_order_4 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar7' => array('BOOL', 0),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/dummy_order_5.php b/tests/dbal/migration/dummy_order_5.php
new file mode 100644
index 0000000000..8f92392a8b
--- /dev/null
+++ b/tests/dbal/migration/dummy_order_5.php
@@ -0,0 +1,27 @@
+<?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_migration_dummy_order_5 extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'column_order_test1' => array(
+ 'foobar8' => array('BOOL', 0, 'after' => 'foobar3'),
+ 'foobar9' => array('BOOL', 0, 'after' => 'foobar3'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php
new file mode 100644
index 0000000000..a7a8a41694
--- /dev/null
+++ b/tests/dbal/migration/fail.php
@@ -0,0 +1,45 @@
+<?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_migration_fail extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column' => array('BOOL', 1),
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column',
+ ),
+ ),
+ );
+ }
+
+ function update_data()
+ {
+ return array(
+ array('config.add', array('foobar3', true)),
+ array('config.update', array('does_not_exist', true)),
+ );
+ }
+}
diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php
new file mode 100644
index 0000000000..481250ea77
--- /dev/null
+++ b/tests/dbal/migration/if.php
@@ -0,0 +1,48 @@
+<?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_migration_if extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('if', array(
+ true,
+ array('custom', array(array(&$this, 'test_true'))),
+ )),
+ array('if', array(
+ false,
+ array('custom', array(array(&$this, 'test_false'))),
+ )),
+ );
+ }
+
+ function test_true()
+ {
+ global $migrator_test_if_true_failed;
+
+ $migrator_test_if_true_failed = !$migrator_test_if_true_failed;
+ }
+
+ function test_false()
+ {
+ global $migrator_test_if_false_failed;
+
+ $migrator_test_if_false_failed = !$migrator_test_if_false_failed;
+ }
+}
diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php
new file mode 100644
index 0000000000..83edaae23a
--- /dev/null
+++ b/tests/dbal/migration/installed.php
@@ -0,0 +1,34 @@
+<?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_migration_installed extends \phpbb\db\migration\migration
+{
+ function effectively_installed()
+ {
+ return true;
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array(&$this, 'test'))),
+ );
+ }
+
+ function test()
+ {
+ global $migrator_test_installed_failed;
+
+ $migrator_test_installed_failed = true;
+ }
+}
diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php
new file mode 100644
index 0000000000..c0333b084d
--- /dev/null
+++ b/tests/dbal/migration/recall.php
@@ -0,0 +1,42 @@
+<?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_migration_recall extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array(&$this, 'test_call'))),
+ );
+ }
+
+ // This function should be called 10 times
+ function test_call($input)
+ {
+ global $migrator_test_call_input;
+
+ $migrator_test_call_input = (int) $input;
+
+ if ($migrator_test_call_input < 10)
+ {
+ return ($migrator_test_call_input + 1);
+ }
+
+ return;
+ }
+}
diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php
new file mode 100644
index 0000000000..7da65a83f1
--- /dev/null
+++ b/tests/dbal/migration/revert.php
@@ -0,0 +1,52 @@
+<?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_migration_revert extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ 'phpbb_config' => array(
+ 'bar_column' => array('UINT', 1),
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ 'phpbb_config' => array(
+ 'bar_column',
+ ),
+ ),
+ );
+ }
+
+ function update_data()
+ {
+ return array(
+ array('config.add', array('foobartest', 0)),
+ array('custom', array(array(&$this, 'my_custom_function'))),
+ );
+ }
+
+ function my_custom_function()
+ {
+ global $migrator_test_revert_counter;
+
+ $migrator_test_revert_counter += 1;
+ }
+}
diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php
new file mode 100644
index 0000000000..43e9a4aa42
--- /dev/null
+++ b/tests/dbal/migration/revert_with_dependency.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_dbal_migration_revert_with_dependency extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('phpbb_dbal_migration_revert');
+ }
+}
diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php
new file mode 100644
index 0000000000..38663bcc16
--- /dev/null
+++ b/tests/dbal/migration/schema.php
@@ -0,0 +1,48 @@
+<?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_migration_schema extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column1' => array('BOOL', 1),
+ ),
+ ),
+ 'add_tables' => array(
+ $this->table_prefix . 'foobar' => array(
+ 'COLUMNS' => array(
+ 'module_id' => array('UINT:3', NULL, 'auto_increment'),
+ ),
+ 'PRIMARY_KEY' => 'module_id',
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column1',
+ ),
+ ),
+ 'drop_tables' => array(
+ $this->table_prefix . 'foobar',
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php
new file mode 100644
index 0000000000..11c87a6b85
--- /dev/null
+++ b/tests/dbal/migration/unfulfillable.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_dbal_migration_unfulfillable extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration');
+ }
+
+ function update_schema()
+ {
+ trigger_error('Schema update of migration with unfulfillable dependency was run!');
+ }
+
+ function update_data()
+ {
+ trigger_error('Data update of migration with unfulfillable dependency was run!');
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
new file mode 100644
index 0000000000..798200eef1
--- /dev/null
+++ b/tests/dbal/migrator_test.php
@@ -0,0 +1,315 @@
+<?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__) . '/migration/dummy.php';
+require_once dirname(__FILE__) . '/migration/unfulfillable.php';
+require_once dirname(__FILE__) . '/migration/if.php';
+require_once dirname(__FILE__) . '/migration/recall.php';
+require_once dirname(__FILE__) . '/migration/revert.php';
+require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
+require_once dirname(__FILE__) . '/migration/fail.php';
+require_once dirname(__FILE__) . '/migration/installed.php';
+require_once dirname(__FILE__) . '/migration/schema.php';
+
+class phpbb_dbal_migrator_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $db_tools;
+ protected $migrator;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->db_tools = new \phpbb\db\tools($this->db);
+
+ $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config');
+
+ $tools = array(
+ new \phpbb\db\migration\tool\config($this->config),
+ );
+
+ $container = new phpbb_mock_container_builder();
+
+ $this->migrator = new \phpbb\db\migrator(
+ $container,
+ $this->config,
+ $this->db,
+ $this->db_tools,
+ 'phpbb_migrations',
+ dirname(__FILE__) . '/../../phpBB/',
+ 'php',
+ 'phpbb_',
+ $tools,
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $this->migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
+ $user = new \phpbb\user('\phpbb\datetime');
+
+ $this->extension_manager = new \phpbb\extension\manager(
+ $container,
+ $this->db,
+ $this->config,
+ new phpbb\filesystem(),
+ $user,
+ 'phpbb_ext',
+ dirname(__FILE__) . '/../../phpBB/',
+ 'php',
+ null
+ );
+ }
+
+ public function test_update()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
+
+ // schema
+ $this->migrator->update();
+ $this->assertFalse($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('success' => '1')),
+ "SELECT 1 as success
+ FROM phpbb_migrations
+ WHERE migration_name = 'phpbb_dbal_migration_dummy'
+ AND migration_start_time >= " . (time() - 1) . "
+ AND migration_start_time <= " . (time() + 1),
+ 'Start time set correctly'
+ );
+
+ // data
+ $this->migrator->update();
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Dummy migration created extra_column with value 1 in all rows.'
+ );
+
+ $this->assertSqlResultEquals(
+ array(array('success' => '1')),
+ "SELECT 1 as success
+ FROM phpbb_migrations
+ WHERE migration_name = 'phpbb_dbal_migration_dummy'
+ AND migration_start_time <= migration_end_time
+ AND migration_end_time >= " . (time() - 1) . "
+ AND migration_end_time <= " . (time() + 1),
+ 'End time set correctly'
+ );
+
+ // cleanup
+ $this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
+ }
+
+ public function test_unfulfillable()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Dummy migration was run, even though an unfulfillable migration was found.'
+ );
+
+ $this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
+ }
+
+ public function test_if()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_if'));
+
+ // Don't like this, but I'm not sure there is any other way to do this
+ global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
+ $migrator_test_if_true_failed = true;
+ $migrator_test_if_false_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertFalse($migrator_test_if_true_failed, 'True test failed');
+ $this->assertFalse($migrator_test_if_false_failed, 'False test failed');
+
+ while ($this->migrator->migration_state('phpbb_dbal_migration_if') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_if');
+ }
+
+ $this->assertFalse($migrator_test_if_true_failed, 'True test after revert failed');
+ $this->assertFalse($migrator_test_if_false_failed, 'False test after revert failed');
+ }
+
+ public function test_recall()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_recall'));
+
+ global $migrator_test_call_input;
+
+ // Run the schema first
+ $this->migrator->update();
+
+ $i = 0;
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+
+ $this->assertSame($i, $migrator_test_call_input);
+
+ $i++;
+ }
+
+ $this->assertSame(10, $migrator_test_call_input);
+ }
+
+ public function test_revert()
+ {
+ global $migrator_test_revert_counter;
+
+ // Make sure there are no other migrations in the db, this could cause issues
+ $this->db->sql_query("DELETE FROM phpbb_migrations");
+ $this->migrator->load_migration_state();
+
+ $migrator_test_revert_counter = 0;
+
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency'));
+
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
+
+ // Install the migration first
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false);
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false);
+
+ $this->assertSqlResultEquals(
+ array(array('bar_column' => '1')),
+ "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Installing revert migration failed to create bar_column.'
+ );
+
+ $this->assertTrue(isset($this->config['foobartest']));
+
+ while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_revert');
+ }
+
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
+
+ $this->assertFalse(isset($this->config['foobartest']));
+
+ $sql = 'SELECT * FROM phpbb_config';
+ $result = $this->db->sql_query_limit($sql, 1);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ if (isset($row['bar_column']))
+ {
+ $this->fail('Revert did not remove test_column.');
+ }
+
+ $this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again');
+ }
+
+ public function test_fail()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
+
+ $this->assertFalse(isset($this->config['foobar3']));
+
+ try
+ {
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+ }
+ catch (\phpbb\db\migration\exception $e) {}
+
+ // Failure should have caused an automatic roll-back, so this should not exist.
+ $this->assertFalse(isset($this->config['foobar3']));
+
+ $sql = 'SELECT * FROM phpbb_config';
+ $result = $this->db->sql_query_limit($sql, 1);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ if (isset($row['test_column']))
+ {
+ $this->fail('Revert did not remove test_column.');
+ }
+ }
+
+ public function test_installed()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_installed'));
+
+ global $migrator_test_installed_failed;
+ $migrator_test_installed_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false);
+
+ if ($migrator_test_installed_failed)
+ {
+ $this->fail('Installed test failed');
+ }
+ }
+
+ public function test_schema()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_schema'));
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->db_tools->sql_column_exists('phpbb_config', 'test_column1'));
+ $this->assertTrue($this->db_tools->sql_table_exists('phpbb_foobar'));
+
+ while ($this->migrator->migration_state('phpbb_dbal_migration_schema'))
+ {
+ $this->migrator->revert('phpbb_dbal_migration_schema');
+ }
+
+ $this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1'));
+ $this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar'));
+ }
+}
diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php
new file mode 100644
index 0000000000..13e0c13e3c
--- /dev/null
+++ b/tests/dbal/migrator_tool_config_test.php
@@ -0,0 +1,90 @@
+<?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_test extends phpbb_test_case
+{
+ public function setup()
+ {
+ $this->config = new \phpbb\config\config(array());
+
+ $this->tool = new \phpbb\db\migration\tool\config($this->config);
+
+ parent::setup();
+ }
+
+ public function test_add()
+ {
+ $this->tool->add('foo', 'bar');
+ $this->assertEquals('bar', $this->config['foo']);
+ }
+
+ public function test_add_twice()
+ {
+ $this->tool->add('foo', 'bar');
+ $this->assertEquals('bar', $this->config['foo']);
+
+ $this->tool->add('foo', 'bar2');
+ $this->assertEquals('bar', $this->config['foo']);
+ }
+
+ public function test_update()
+ {
+ $this->config->set('foo', 'bar');
+
+ $this->tool->update('foo', 'bar2');
+ $this->assertEquals('bar2', $this->config['foo']);
+ }
+
+ public function test_update_if_equals()
+ {
+ $this->config->set('foo', 'bar');
+
+ $this->tool->update_if_equals('', 'foo', 'bar2');
+ $this->assertEquals('bar', $this->config['foo']);
+
+ $this->tool->update_if_equals('bar', 'foo', 'bar2');
+ $this->assertEquals('bar2', $this->config['foo']);
+ }
+
+ public function test_remove()
+ {
+ $this->config->set('foo', 'bar');
+
+ $this->tool->remove('foo');
+ $this->assertFalse(isset($this->config['foo']));
+ }
+
+ public function test_reverse_add()
+ {
+ $this->config->set('foo', 'bar');
+
+ $this->tool->reverse('add', 'foo');
+ $this->assertFalse(isset($this->config['foo']));
+ }
+
+ public function test_reverse_remove()
+ {
+ $this->config->delete('foo');
+
+ $this->tool->reverse('remove', 'foo');
+ $this->assertEquals('', $this->config['foo']);
+ }
+
+ public function test_reverse_update_if_equals()
+ {
+ $this->config->set('foo', 'bar');
+
+ $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar');
+ $this->assertEquals('test', $this->config['foo']);
+ }
+}
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/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php
new file mode 100644
index 0000000000..bbe543f347
--- /dev/null
+++ b/tests/dbal/migrator_tool_module_test.php
@@ -0,0 +1,305 @@
+<?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_dbal_migrator_tool_module_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
+ }
+
+ public function setup()
+ {
+ // Need global $db, $user for delete_module function in acp_modules
+ global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user, $phpbb_log;
+
+ parent::setup();
+
+ // Force add_log function to not be used
+ $skip_add_log = true;
+
+ $db = $this->db = $this->new_dbal();
+ $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $user = $this->user = new \phpbb\user('\phpbb\user');
+
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
+ }
+
+ public function exists_data_acp()
+ {
+ return array(
+ // Test the existing category
+ array(
+ '',
+ 'ACP_CAT',
+ true,
+ ),
+ array(
+ 0,
+ 'ACP_CAT',
+ true,
+ ),
+
+ // Test the existing module
+ array(
+ '',
+ 'ACP_MODULE',
+ false,
+ ),
+ array(
+ false,
+ 'ACP_MODULE',
+ true,
+ ),
+ array(
+ 'ACP_CAT',
+ 'ACP_MODULE',
+ true,
+ ),
+
+ // Test for non-existant modules
+ array(
+ '',
+ 'ACP_NON_EXISTANT_CAT',
+ false,
+ ),
+ array(
+ 'ACP_CAT',
+ 'ACP_NON_EXISTANT_MODULE',
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider exists_data_acp
+ */
+ public function test_exists_acp($parent, $module, $expected)
+ {
+ $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
+ }
+
+ public function exists_data_ucp()
+ {
+ return array(
+ // Test the existing category
+ array(
+ '',
+ 'UCP_MAIN_CAT',
+ true,
+ ),
+ array(
+ 0,
+ 'UCP_MAIN_CAT',
+ true,
+ ),
+
+ // Test the existing module
+ array(
+ '',
+ 'UCP_SUBCATEGORY',
+ false,
+ ),
+ array(
+ false,
+ 'UCP_SUBCATEGORY',
+ true,
+ ),
+ array(
+ 'UCP_MAIN_CAT',
+ 'UCP_SUBCATEGORY',
+ true,
+ ),
+ array(
+ 'UCP_SUBCATEGORY',
+ 'UCP_MODULE',
+ true,
+ ),
+
+ // Test for non-existant modules
+ array(
+ '',
+ 'UCP_NON_EXISTANT_CAT',
+ false,
+ ),
+ array(
+ 'UCP_MAIN_CAT',
+ 'UCP_NON_EXISTANT_MODULE',
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider exists_data_ucp
+ */
+ public function test_exists_ucp($parent, $module, $expected)
+ {
+ $this->assertEquals($expected, $this->tool->exists('ucp', $parent, $module));
+ }
+
+ public function test_add()
+ {
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
+
+ // Should throw an exception when trying to add a module that already exists
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ $this->fail('Exception not thrown');
+ }
+ catch (Exception $e) {}
+
+ try
+ {
+ $this->tool->add('acp', 'ACP_NEW_CAT', array(
+ 'module_basename' => 'acp_new_module',
+ 'module_langname' => 'ACP_NEW_MODULE',
+ 'module_mode' => 'test',
+ 'module_auth' => '',
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
+
+ // Test adding module when plural parent module_langname exists
+ // PHPBB3-14703
+ // Adding fail
+ try
+ {
+ $this->tool->add('acp', 'ACP_FORUM_BASED_PERMISSIONS', array(
+ 'module_basename' => 'acp_new_permissions_module',
+ 'module_langname' => 'ACP_NEW_PERMISSIONS_MODULE',
+ 'module_mode' => 'test',
+ 'module_auth' => '',
+ ));
+ $this->fail('Exception not thrown');
+ }
+ catch (Exception $e)
+ {
+ $this->assertEquals('phpbb\db\migration\exception', get_class($e));
+ $this->assertEquals('MODULE_EXIST_MULTIPLE', $e->getMessage());
+ }
+
+ // Test adding module when plural parent module_langname exists
+ // PHPBB3-14703
+ // Adding success
+ try
+ {
+ $this->tool->add('acp', 'ACP_FORUM_BASED_PERMISSIONS', array(
+ 'module_basename' => 'acp_new_permissions_module',
+ 'module_langname' => 'ACP_NEW_PERMISSIONS_MODULE',
+ 'module_mode' => 'test',
+ 'module_auth' => '',
+ 'after' => 'ACP_FORUM_BASED_PERMISSIONS_CHILD_1',
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 'ACP_FORUM_BASED_PERMISSIONS', 'ACP_NEW_PERMISSIONS_MODULE'));
+
+ // Test adding UCP modules
+ // Test adding new UCP category
+ try
+ {
+ $this->tool->add('ucp', 0, 'UCP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('ucp', 0, 'UCP_NEW_CAT'));
+
+ // Test adding new UCP subcategory
+ try
+ {
+ $this->tool->add('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT'));
+
+ // Test adding new UCP module
+ try
+ {
+ $this->tool->add('ucp', 'UCP_NEW_SUBCAT', array(
+ 'module_basename' => 'ucp_new_module',
+ 'module_langname' => 'UCP_NEW_MODULE',
+ 'module_mode' => 'ucp_test',
+ 'module_auth' => '',
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_SUBCAT', 'UCP_NEW_MODULE'));
+ }
+
+ public function test_remove()
+ {
+ try
+ {
+ $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE'));
+ }
+
+ public function test_reverse()
+ {
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+
+ try
+ {
+ $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
+ }
+}
diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php
new file mode 100644
index 0000000000..2d673864f7
--- /dev/null
+++ b/tests/dbal/migrator_tool_permission_test.php
@@ -0,0 +1,223 @@
+<?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_dbal_migrator_tool_permission_test extends phpbb_database_test_case
+{
+ public $group_ids = array(
+ 'REGISTERED' => 2,
+ 'GLOBAL_MODERATORS' => 4,
+ 'ADMINISTRATORS' => 5,
+ );
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
+ }
+
+ public function setup()
+ {
+ // Global $db and $cache are needed in acp/auth.php constructor
+ global $phpbb_root_path, $phpEx, $db, $cache;
+
+ parent::setup();
+
+ $db = $this->db = $this->new_dbal();
+ $cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $this->auth = new \phpbb\auth\auth();
+
+ $this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
+ }
+
+ public function exists_data()
+ {
+ return array(
+ array(
+ 'global',
+ true,
+ true,
+ ),
+ array(
+ 'local',
+ false,
+ true,
+ ),
+ array(
+ 'both',
+ true,
+ true,
+ ),
+ array(
+ 'both',
+ false,
+ true,
+ ),
+ array(
+ 'does_not_exist',
+ true,
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider exists_data
+ */
+ public function test_exists($auth_option, $global, $expected)
+ {
+ $this->assertEquals($expected, $this->tool->exists($auth_option, $global));
+ }
+
+ public function test_add()
+ {
+ try
+ {
+ $this->tool->add('new', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('new', true));
+ $this->assertEquals(false, $this->tool->exists('new', false));
+
+ try
+ {
+ $this->tool->add('new', false);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('new', false));
+
+ // Should fail (duplicate)
+ try
+ {
+ $this->tool->add('new', true);
+ $this->fail('Did not throw exception on duplicate');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_remove()
+ {
+ try
+ {
+ $this->tool->remove('global', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('global', true));
+
+ try
+ {
+ $this->tool->remove('both', false);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('both', false));
+
+ // Should fail (does not exist)
+ try
+ {
+ $this->tool->remove('new', true);
+ $this->fail('Did not throw exception on duplicate');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_reverse()
+ {
+ try
+ {
+ $this->tool->reverse('remove', 'global_test', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertTrue($this->tool->exists('global_test', true));
+
+ try
+ {
+ $this->tool->reverse('add', 'global_test', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse($this->tool->exists('global_test', true));
+ }
+
+ public function test_permission_set_data()
+ {
+ return array(
+ array(
+ 'ADMINISTRATORS',
+ 'a_test',
+ 'group',
+ true,
+ ),
+ array(
+ 'GLOBAL_MODERATORS',
+ 'm_test',
+ 'group',
+ true,
+ ),
+ array(
+ 'REGISTERED',
+ 'u_test',
+ 'group',
+ true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider test_permission_set_data
+ */
+ public function test_permission_set($group_name, $auth_option, $type, $has_permission)
+ {
+ $this->tool->permission_set($group_name, $auth_option, $type, $has_permission);
+ $administrators_perm = $this->auth->acl_group_raw_data($this->group_ids['ADMINISTRATORS'], $auth_option);
+ $global_moderators_perm = $this->auth->acl_group_raw_data($this->group_ids['GLOBAL_MODERATORS'], $auth_option);
+ $registered_users_perm = $this->auth->acl_group_raw_data($this->group_ids['REGISTERED'], $auth_option);
+
+ switch($group_name)
+ {
+ case 'GLOBAL_MODERATORS':
+ $this->assertEquals(false, empty($administrators_perm), 'm_test is not empty for Administrators');
+ $this->assertEquals(false, empty($global_moderators_perm), 'm_test is not empty for Global moderators');
+ $this->assertEquals(true, empty($registered_users_perm), 'm_test empty for Registered users');
+ break;
+
+ case 'ADMINISTRATORS':
+ $this->assertEquals(false, empty($administrators_perm), 'a_test is not empty for Administrators');
+ $this->assertEquals(true, empty($global_moderators_perm), 'a_test is empty for Global moderators');
+ $this->assertEquals(true, empty($registered_users_perm), 'a_test is empty for Registered users');
+ break;
+
+ case 'REGISTERED':
+ $this->assertEquals(false, empty($administrators_perm), 'u_test is not empty for Administrators');
+ $this->assertEquals(false, empty($global_moderators_perm), 'u_test is not empty for Global moderators');
+ $this->assertEquals(false, empty($registered_users_perm), 'u_test is not empty for Registered users');
+ break;
+ }
+ }
+}
diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php
index e17295a4ea..b101d28c7d 100644
--- a/tests/dbal/order_lower_test.php
+++ b/tests/dbal/order_lower_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -18,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');
}
@@ -36,29 +40,32 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case
array(
'style_id' => 1,
'style_name' => 'prosilver',
- 'style_copyright' => '&copy; phpBB Group',
+ 'style_copyright' => '&copy; phpBB Limited',
'style_active' => 1,
- 'template_id' => 1,
- 'theme_id' => 1,
- 'imageset_id' => 1
+ 'style_path' => 'prosilver',
+ 'bbcode_bitfield' => 'kNg=',
+ 'style_parent_id' => 0,
+ 'style_parent_tree' => '',
),
array(
'style_id' => 3,
'style_name' => 'Prosilver1',
- 'style_copyright' => '&copy; phpBB Group',
+ 'style_copyright' => '&copy; phpBB Limited',
'style_active' => 0,
- 'template_id' => 3,
- 'theme_id' => 3,
- 'imageset_id' => 3
+ 'style_path' => 'prosilver1',
+ 'bbcode_bitfield' => 'kNg=',
+ 'style_parent_id' => 1,
+ 'style_parent_tree' => 'prosilver',
),
array(
'style_id' => 2,
'style_name' => 'prosilver2',
- 'style_copyright' => '&copy; phpBB Group',
+ 'style_copyright' => '&copy; phpBB Limited',
'style_active' => 0,
- 'template_id' => 2,
- 'theme_id' => 2,
- 'imageset_id' => 2
+ 'style_path' => 'prosilver2',
+ 'bbcode_bitfield' => 'kNg=',
+ 'style_parent_id' => 0,
+ 'style_parent_tree' => '',
)
),
$db->sql_fetchrowset($result)
diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php
new file mode 100644
index 0000000000..f13c7ce032
--- /dev/null
+++ b/tests/dbal/schema_test.php
@@ -0,0 +1,42 @@
+<?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_dbal_schema_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function test_config_value_multibyte()
+ {
+ $db = $this->new_dbal();
+
+ $value = str_repeat("\xC3\x84", 255);
+ $sql = "INSERT INTO phpbb_config
+ (config_name, config_value)
+ VALUES ('name', '$value')";
+ $result = $db->sql_query($sql);
+
+ $sql = "SELECT config_value
+ FROM phpbb_config
+ WHERE config_name = 'name'";
+ $result = $db->sql_query_limit($sql, 1);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $this->assertEquals($value, $row['config_value']);
+ }
+}
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index 6dbab05a41..b7074552ba 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -17,7 +21,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml');
}
- static public function return_on_error_select_data()
+ public function return_on_error_select_data()
{
return array(
array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))),
@@ -44,7 +48,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $db->sql_fetchrowset($result));
}
- static public function fetchrow_data()
+ public function fetchrow_data()
{
return array(
array('', array(array('username_clean' => 'barfoo'),
@@ -95,7 +99,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
- static public function fetchfield_data()
+ public function fetchfield_data()
{
return array(
array('', array('barfoo', 'foobar', 'bertie')),
@@ -192,7 +196,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $ary);
}
- static public function like_expression_data()
+ public function like_expression_data()
{
// * = any_char; # = one_char
return array(
@@ -215,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
@@ -229,7 +233,67 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
- static public function in_set_data()
+ public function not_like_expression_data()
+ {
+ // * = any_char; # = one_char
+ return array(
+ array('barfoo', array(
+ array('username_clean' => 'foobar'),
+ array('username_clean' => 'bertie')
+ )),
+ array('bar', array(
+ array('username_clean' => 'barfoo'),
+ array('username_clean' => 'foobar'),
+ array('username_clean' => 'bertie'),
+ )),
+ array('bar*', array(
+ array('username_clean' => 'foobar'),
+ array('username_clean' => 'bertie'))
+ ),
+ array('*bar*', array(array('username_clean' => 'bertie'))),
+ array('b*r', array(
+ array('username_clean' => 'barfoo'),
+ array('username_clean' => 'foobar'),
+ array('username_clean' => 'bertie')
+ )),
+ array('b*e', array(
+ array('username_clean' => 'barfoo'),
+ array('username_clean' => 'foobar')
+ )),
+ array('#b*e', array(
+ array('username_clean' => 'barfoo'),
+ array('username_clean' => 'foobar'),
+ array('username_clean' => 'bertie')
+ )),
+ array('b####e', array(
+ array('username_clean' => 'barfoo'),
+ array('username_clean' => 'foobar')
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider not_like_expression_data
+ */
+ public function test_not_like_expression($like_expression, $expected)
+ {
+ $db = $this->new_dbal();
+
+ $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_not_like_expression($like_expression) : '';
+
+ $result = $db->sql_query('SELECT username_clean
+ FROM phpbb_users
+ ' . (($where) ? ' WHERE ' . $where : '') . '
+ ORDER BY user_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+
+ $db->sql_freeresult($result);
+ }
+
+ public function in_set_data()
{
return array(
array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))),
@@ -303,7 +367,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
- static public function build_array_data()
+ public function build_array_data()
{
return array(
array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))),
diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php
new file mode 100644
index 0000000000..07d7318358
--- /dev/null
+++ b/tests/dbal/sql_affected_rows_test.php
@@ -0,0 +1,68 @@
+<?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_sql_affected_rows_test extends phpbb_database_test_case
+{
+ /** @var \phpbb\db\driver\driver_interface */
+ protected $db;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->db = $this->new_dbal();
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ public function test_update()
+ {
+ $sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = 'bertie'";
+ $this->db->sql_query($sql);
+
+ $this->assertEquals(2, $this->db->sql_affectedrows());
+ }
+
+ public function test_update_all_matched_unequal_updated()
+ {
+ $sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = 'foo'";
+ $this->db->sql_query($sql);
+
+ $this->assertEquals(2, $this->db->sql_affectedrows());
+ }
+
+ public function test_update_same_value_matched_unequal_updated()
+ {
+ $sql = 'UPDATE ' . CONFIG_TABLE . "
+ SET config_value = 'foo'
+ WHERE config_value = 'foo'";
+ $this->db->sql_query($sql);
+
+ $this->assertEquals(1, $this->db->sql_affectedrows());
+ }
+
+ public function test_insert()
+ {
+ $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
+ 'config_name' => 'bertie',
+ 'config_value' => 'rules',
+ ));
+ $this->db->sql_query($sql);
+
+ $this->assertEquals(1, $this->db->sql_affectedrows());
+ }
+}
diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php
new file mode 100644
index 0000000000..eae0abceba
--- /dev/null
+++ b/tests/dbal/sql_insert_buffer_test.php
@@ -0,0 +1,120 @@
+<?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_sql_insert_buffer_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $buffer;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_config', 2);
+ $this->assert_config_count(2);
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ public function test_multi_insert_disabled_insert_and_flush()
+ {
+ $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());
+ $this->assert_config_count(3);
+ }
+
+ public function test_multi_insert_enabled_insert_and_flush()
+ {
+ $this->check_multi_insert_support();
+ $this->assertFalse($this->buffer->insert($this->get_row(1)));
+ $this->assert_config_count(2);
+ $this->assertTrue($this->buffer->flush());
+ $this->assert_config_count(3);
+ }
+
+ public function test_multi_insert_disabled_insert_with_flush()
+ {
+ $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)));
+ $this->assert_config_count(4);
+ }
+
+ public function test_multi_insert_enabled_insert_with_flush()
+ {
+ $this->check_multi_insert_support();
+ $this->assertFalse($this->buffer->insert($this->get_row(1)));
+ $this->assert_config_count(2);
+ $this->assertTrue($this->buffer->insert($this->get_row(2)));
+ $this->assert_config_count(4);
+ }
+
+ public function test_multi_insert_disabled_insert_all_and_flush()
+ {
+ $this->db->set_multi_insert(false);
+ $this->assertTrue($this->buffer->insert_all($this->get_rows(3)));
+ $this->assert_config_count(5);
+ }
+
+ public function test_multi_insert_enabled_insert_all_and_flush()
+ {
+ $this->check_multi_insert_support();
+ $this->assertTrue($this->buffer->insert_all($this->get_rows(3)));
+ $this->assert_config_count(4);
+ $this->assertTrue($this->buffer->flush());
+ $this->assert_config_count(5);
+ }
+
+ protected function assert_config_count($num_configs)
+ {
+ $sql = 'SELECT COUNT(*) AS num_configs
+ FROM phpbb_config';
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs'));
+ $this->db->sql_freeresult($result);
+ }
+
+ protected function check_multi_insert_support()
+ {
+ if (!$this->db->get_multi_insert())
+ {
+ $this->markTestSkipped('Database does not support multi_insert');
+ }
+ }
+
+ protected function get_row($rownum)
+ {
+ return array(
+ 'config_name' => "name$rownum",
+ 'config_value' => "value$rownum",
+ 'is_dynamic' => '0',
+ );
+ }
+
+ protected function get_rows($n)
+ {
+ $result = array();
+ for ($i = 0; $i < $n; ++$i)
+ {
+ $result[] = $this->get_row($i);
+ }
+ return $result;
+ }
+}
diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php
index 8975cfbfb1..a1b589c578 100644
--- a/tests/dbal/write_sequence_test.php
+++ b/tests/dbal/write_sequence_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -33,13 +37,15 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case
{
$db = $this->new_dbal();
+ // dbal uses cache
+ global $cache;
+ $cache = new phpbb_mock_cache();
+
$sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array(
'username' => $username,
'username_clean' => $username,
'user_permissions' => '',
'user_sig' => '',
- 'user_occ' => '',
- 'user_interests' => '',
));
$db->sql_query($sql);
diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php
index ecfd774896..2426f2b0be 100644
--- a/tests/dbal/write_test.php
+++ b/tests/dbal/write_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -16,7 +20,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
}
- static public function build_array_insert_data()
+ public function build_array_insert_data()
{
return array(
array(array(
@@ -64,7 +68,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
FROM phpbb_config';
$result = $db->sql_query($sql);
$rows = $db->sql_fetchrowset($result);
-
+
$this->assertEquals(1, sizeof($rows));
$this->assertEquals('config2', $rows[0]['config_name']);
@@ -104,7 +108,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
- static public function update_data()
+ public function update_data()
{
return array(
array(
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php
new file mode 100644
index 0000000000..1a7eb4698c
--- /dev/null
+++ b/tests/di/create_container_test.php
@@ -0,0 +1,205 @@
+<?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.
+*
+*/
+
+namespace
+{
+ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+ class phpbb_di_container_test extends \phpbb_test_case
+ {
+ protected $config_php;
+
+ /**
+ * @var \phpbb\di\container_builder
+ */
+ protected $builder;
+ protected $phpbb_root_path;
+ protected $filename;
+
+ public function setUp()
+ {
+ $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('core.table_prefix'));
+
+ // 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_dump_container()
+ {
+ $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_use_extensions()
+ {
+ $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);
+
+ // 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'));
+ }
+ }
+}
+
+namespace phpbb\db\driver
+{
+ class container_mock extends \phpbb\db\driver\driver
+ {
+ public function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
+ {
+ }
+
+ public function sql_query($query = '', $cache_ttl = 0)
+ {
+ }
+
+ public function sql_fetchrow($query_id = false)
+ {
+ }
+
+ public function sql_freeresult($query_id = false)
+ {
+ }
+
+ function sql_server_info($raw = false, $use_cache = true)
+ {
+ }
+
+ function sql_affectedrows()
+ {
+ }
+
+ function sql_rowseek($rownum, &$query_id)
+ {
+ }
+
+ function sql_nextid()
+ {
+ }
+
+ function sql_escape($msg)
+ {
+ }
+
+ function sql_like_expression($expression)
+ {
+ }
+
+ function sql_not_like_expression($expression)
+ {
+ }
+
+ function sql_fetchrowset($query_id = false)
+ {
+ return array(
+ array('ext_name' => 'vendor/enabled'),
+ );
+ }
+ }
+}
diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php
new file mode 100644
index 0000000000..04e20f63d8
--- /dev/null
+++ b/tests/di/fixtures/config.php
@@ -0,0 +1,11 @@
+<?php
+// phpBB 3.1.x auto-generated configuration file
+// Do not change anything in this file!
+$dbms = 'container_mock';
+$dbhost = '127.0.0.1';
+$dbport = '';
+$dbname = 'phpbb';
+$dbuser = 'root';
+$dbpasswd = '';
+$table_prefix = 'phpbb_';
+$acm_type = '\phpbb\cache\driver\null';
diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml
new file mode 100644
index 0000000000..913a2603c9
--- /dev/null
+++ b/tests/di/fixtures/config/services.yml
@@ -0,0 +1,17 @@
+parameters:
+ core: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dbal.conn.driver:
+ synthetic: true
+
+ 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..d6246d3bc0
--- /dev/null
+++ b/tests/di/fixtures/other_config/services.yml
@@ -0,0 +1,17 @@
+parameters:
+ other_config: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dbal.conn.driver:
+ synthetic: true
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php
new file mode 100644
index 0000000000..f920299048
--- /dev/null
+++ b/tests/download/http_byte_range_test.php
@@ -0,0 +1,68 @@
+<?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_download.php';
+
+class phpbb_download_http_byte_range_test extends phpbb_test_case
+{
+ public function test_find_range_request()
+ {
+ // Missing 'bytes=' prefix
+ $GLOBALS['request'] = new phpbb_mock_request();
+ $GLOBALS['request']->set_header('Range', 'bztes=');
+ $this->assertEquals(false, phpbb_find_range_request());
+ unset($GLOBALS['request']);
+
+ $GLOBALS['request'] = new phpbb_mock_request();
+ $_ENV['HTTP_RANGE'] = 'bztes=';
+ $this->assertEquals(false, phpbb_find_range_request());
+ unset($_ENV['HTTP_RANGE']);
+
+ $GLOBALS['request'] = new phpbb_mock_request();
+ $GLOBALS['request']->set_header('Range', 'bytes=0-0,123-125');
+ $this->assertEquals(array('0-0', '123-125'), phpbb_find_range_request());
+ unset($GLOBALS['request']);
+ }
+
+ /**
+ * @dataProvider parse_range_request_data()
+ */
+ public function test_parse_range_request($request_array, $filesize, $expected)
+ {
+ $this->assertEquals($expected, phpbb_parse_range_request($request_array, $filesize));
+ }
+
+ public function parse_range_request_data()
+ {
+ return array(
+ // Does not read until the end of file.
+ array(
+ array('3-4'),
+ 10,
+ false,
+ ),
+
+ // Valid request, handle second range.
+ array(
+ array('0-0', '120-125'),
+ 125,
+ array(
+ 'byte_pos_start' => 120,
+ 'byte_pos_end' => 124,
+ 'bytes_requested' => 5,
+ 'bytes_total' => 125,
+ )
+ ),
+ );
+ }
+}
diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php
new file mode 100644
index 0000000000..bfee265add
--- /dev/null
+++ b/tests/download/http_user_agent_test.php
@@ -0,0 +1,134 @@
+<?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_download.php';
+
+class phpbb_download_http_user_agent_test extends phpbb_test_case
+{
+ public function user_agents_check_greater_ie_version()
+ {
+ return array(
+ // user agent
+ // IE version
+ // expected
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
+ 7,
+ true,
+ ),
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
+ 7,
+ true,
+ ),
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)',
+ 7,
+ true,
+ ),
+ array(
+ 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36',
+ 7,
+ false,
+ ),
+ array(
+ 'Googlebot-Image/1.0',
+ 7,
+ false,
+ ),
+ array(
+ 'Googlebot/2.1 ( http://www.google.com/bot.html)',
+ 7,
+ false,
+ ),
+ array(
+ 'Lynx/2.8.3dev.9 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6',
+ 7,
+ false,
+ ),
+ array(
+ 'Links (0.9x; Linux 2.4.7-10 i686)',
+ 7,
+ false,
+ ),
+ array(
+ 'Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;)',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.01 [en]',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.24',
+ 7,
+ false,
+ ),
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
+ 8,
+ true,
+ ),
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
+ 9,
+ true,
+ ),
+ array(
+ 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)',
+ 10,
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider user_agents_check_greater_ie_version
+ */
+ public function test_is_greater_ie_version($user_agent, $version, $expected)
+ {
+ $this->assertEquals($expected, phpbb_is_greater_ie_version($user_agent, $version));
+ }
+}
diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php
index d67dea3719..b92c4fa6bb 100644
--- a/tests/error_collector_test.php
+++ b/tests/error_collector_test.php
@@ -1,20 +1,23 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/error_collector.php';
class phpbb_error_collector_test extends phpbb_test_case
{
public function test_collection()
{
- $collector = new phpbb_error_collector;
+ $collector = new \phpbb\error_collector(E_ALL | E_STRICT); // php set_error_handler() default
$collector->install();
// Cause a warning
@@ -32,4 +35,32 @@ class phpbb_error_collector_test extends phpbb_test_case
$this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents);
$this->assertStringEndsWith(" line $line", $error_contents);
}
+
+ public function test_collection_with_mask()
+ {
+ $collector = new \phpbb\error_collector(E_ALL & ~E_NOTICE); // not collecting notices
+ $collector->install();
+
+ // Cause a warning
+ 1/0; $line = __LINE__;
+
+ // Cause a notice
+ $array = array('ITEM' => 'value');
+ $value = $array[ITEM]; $line2 = __LINE__;
+
+ $collector->uninstall();
+
+ // The notice should not be collected
+ $this->assertEmpty($collector->errors[1]);
+
+ list($errno, $msg_text, $errfile, $errline) = $collector->errors[0];
+ $error_contents = $collector->format_errors();
+
+ $this->assertEquals($errno, 2);
+
+ // Unfortunately $error_contents will contain the full path here,
+ // because the tests directory is outside of phpbb root path.
+ $this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents);
+ $this->assertStringEndsWith(" line $line", $error_contents);
+ }
}
diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php
new file mode 100644
index 0000000000..7bba5bf337
--- /dev/null
+++ b/tests/event/dispatcher_test.php
@@ -0,0 +1,33 @@
+<?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_event_dispatcher_test extends phpbb_test_case
+{
+ public function test_trigger_event()
+ {
+ $dispatcher = new \phpbb\event\dispatcher(new phpbb_mock_container_builder());
+
+ $dispatcher->addListener('core.test_event', function (\phpbb\event\data $event) {
+ $event['foo'] = $event['foo'] . '2';
+ $event['bar'] = $event['bar'] . '2';
+ });
+
+ $foo = 'foo';
+ $bar = 'bar';
+
+ $vars = array('foo', 'bar');
+ $result = $dispatcher->trigger_event('core.test_event', compact($vars));
+
+ $this->assertSame(array('foo' => 'foo2', 'bar' => 'bar2'), $result);
+ }
+}
diff --git a/tests/event/exception_listener_test.php b/tests/event/exception_listener_test.php
new file mode 100644
index 0000000000..4d3453cd83
--- /dev/null
+++ b/tests/event/exception_listener_test.php
@@ -0,0 +1,100 @@
+<?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 exception_listener extends phpbb_test_case
+{
+ public function phpbb_exception_data()
+ {
+ return array(
+ array(
+ true,
+ new \Exception(),
+ array(
+ 'status_code' => 500,
+ ),
+ ),
+ array(
+ true,
+ new \Exception('AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 500,
+ 'content' => 'AJAX_ERROR_TEXT',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\runtime_exception('AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 500,
+ 'content' => 'Something went wrong when processing your request.',
+ ),
+ ),
+ array(
+ true,
+ new \Symfony\Component\HttpKernel\Exception\HttpException(404, 'AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 404,
+ 'content' => 'AJAX_ERROR_TEXT',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\http_exception(404, 'AJAX_ERROR_TEXT'),
+ array(
+ 'status_code' => 404,
+ 'content' => 'Something went wrong when processing your request.',
+ ),
+ ),
+ array(
+ true,
+ new \phpbb\exception\http_exception(404, 'CURRENT_TIME', array('today')),
+ array(
+ 'status_code' => 404,
+ 'content' => 'It is currently today',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider phpbb_exception_data
+ */
+ public function test_phpbb_exception($is_ajax, $exception, $expected)
+ {
+ $request = \Symfony\Component\HttpFoundation\Request::create('test.php', 'GET', array(), array(), array(), $is_ajax ? array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') : array());
+
+ $template = $this->getMockBuilder('\phpbb\template\twig\twig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->add_lang('common');
+
+ $exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $user);
+
+ $event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
+ $exception_listener->on_kernel_exception($event);
+
+ $response = $event->getResponse();
+
+ $this->assertEquals($expected['status_code'], $response->getStatusCode());
+ $this->assertEquals($is_ajax, $response instanceof \Symfony\Component\HttpFoundation\JsonResponse);
+
+ if (isset($expected['content']))
+ {
+ $this->assertContains($expected['content'], $response->getContent());
+ }
+ }
+}
diff --git a/tests/event/export_php_test.php b/tests/event/export_php_test.php
new file mode 100644
index 0000000000..21bbb0620a
--- /dev/null
+++ b/tests/event/export_php_test.php
@@ -0,0 +1,49 @@
+<?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_event_export_php_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path;
+ $this->exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ }
+
+ static public function crawl_php_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\php_exporter($phpbb_root_path);
+ $files = $exporter->get_recursive_file_list($phpbb_root_path);
+
+ $data_provider = array();
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($file);
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file)
+ {
+ $this->assertGreaterThanOrEqual(0, $this->exporter->crawl_php_file($file));
+ }
+}
diff --git a/tests/event/fixtures/adm/style/acp_bbcodes.html b/tests/event/fixtures/adm/style/acp_bbcodes.html
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/event/fixtures/adm/style/acp_bbcodes.html
diff --git a/tests/event/fixtures/default.test b/tests/event/fixtures/default.test
new file mode 100644
index 0000000000..edfe4823dc
--- /dev/null
+++ b/tests/event/fixtures/default.test
@@ -0,0 +1,9 @@
+<?php
+
+/**
+* Description
+*
+* @event default.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('default.dispatch');
diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test
new file mode 100644
index 0000000000..b042ca0377
--- /dev/null
+++ b/tests/event/fixtures/duplicate_event.test
@@ -0,0 +1,19 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @var int start Start item of this page
+ * @since 3.1.0-a3
+ */
+ $vars = array('start');
+ extract($phpbb_dispatcher->trigger_event('duplicate.trigger', compact($vars)));
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event duplicate.trigger
+ * @since 3.1.0-b1
+ */
+ $phpbb_dispatcher->dispatch('duplicate.trigger');
diff --git a/tests/event/fixtures/extra_description.test b/tests/event/fixtures/extra_description.test
new file mode 100644
index 0000000000..ce8f97ce89
--- /dev/null
+++ b/tests/event/fixtures/extra_description.test
@@ -0,0 +1,11 @@
+<?php
+
+/**
+* Description
+*
+* NOTE: This will not be exported
+*
+* @event extra_description.dispatch
+* @since 3.1.0-b2
+*/
+$phpbb_dispatcher->dispatch('extra_description.dispatch');
diff --git a/tests/event/fixtures/missing_var.test b/tests/event/fixtures/missing_var.test
new file mode 100644
index 0000000000..7ced5e93dc
--- /dev/null
+++ b/tests/event/fixtures/missing_var.test
@@ -0,0 +1,17 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @var array attachments List of attachments
+ * @var array user_poster_data Poster's data from user cache
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/none.test b/tests/event/fixtures/none.test
new file mode 100644
index 0000000000..6e2267024b
--- /dev/null
+++ b/tests/event/fixtures/none.test
@@ -0,0 +1,6 @@
+<?php
+
+/**
+* Hi there :)
+*/
+echo 1 + 2;
diff --git a/tests/event/fixtures/normal_events.md.test b/tests/event/fixtures/normal_events.md.test
new file mode 100644
index 0000000000..47921c4e57
--- /dev/null
+++ b/tests/event/fixtures/normal_events.md.test
@@ -0,0 +1,20 @@
+acp_bbcodes_actions_append
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a3
+* Changed: 3.1.0-a4
+* Purpose: desc1
+
+acp_bbcodes_actions_prepend
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a5
+* Purpose: desc2
+
+acp_bbcodes_actions_prepend2
+===
+* Location: adm/style/acp_bbcodes.html
+* Since: 3.1.0-a4
+* Changed: 3.1.0-a5 Moved up
+* Changed: 3.1.0-a6 Moved down
+* Purpose: desc2
diff --git a/tests/event/fixtures/trigger.test b/tests/event/fixtures/trigger.test
new file mode 100644
index 0000000000..7cd6a7b956
--- /dev/null
+++ b/tests/event/fixtures/trigger.test
@@ -0,0 +1,15 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test
new file mode 100644
index 0000000000..5e0720d13b
--- /dev/null
+++ b/tests/event/fixtures/trigger_many_vars.test
@@ -0,0 +1,65 @@
+<?php
+
+ /**
+ * This event allows you to modify template variables for the posting screen
+ *
+ * @event core.posting_modify_template_vars
+ * @var array post_data Array with post data
+ * @var array moderators Array with forum moderators
+ * @var string mode What action to take if the form is submitted
+ * post|reply|quote|edit|delete|bump|smilies|popup
+ * @var string page_title Title of the mode page
+ * @var bool s_topic_icons Whether or not to show the topic icons
+ * @var string form_enctype If attachments are allowed for this form
+ * "multipart/form-data" or empty string
+ * @var string s_action The URL to submit the POST data to
+ * @var string s_hidden_fields Concatenated hidden input tags of posting form
+ * @var int post_id ID of the post
+ * @var int topic_id ID of the topic
+ * @var int forum_id ID of the forum
+ * @var bool submit Whether or not the form has been submitted
+ * @var bool preview Whether or not the post is being previewed
+ * @var bool save Whether or not a draft is being saved
+ * @var bool load Whether or not a draft is being loaded
+ * @var bool delete Whether or not the post is being deleted
+ * @var bool cancel Whether or not to cancel the form (returns to
+ * viewtopic or viewforum depending on if the user
+ * is posting a new topic or editing a post)
+ * @var array error Any error strings; a non-empty array aborts
+ * form submission.
+ * NOTE: Should be actual language strings, NOT
+ * language keys.
+ * @var bool refresh Whether or not to retain previously submitted data
+ * @var array page_data Posting page data that should be passed to the
+ * posting page via $template->assign_vars()
+ * @var object message_parser The message parser object
+ * @since 3.1.0-a1
+ * @changed 3.1.0-b3 Added vars post_data, moderators, mode, page_title,
+ * s_topic_icons, form_enctype, s_action, s_hidden_fields,
+ * post_id, topic_id, forum_id, submit, preview, save, load,
+ * delete, cancel, refresh, error, page_data, message_parser
+ */
+ $vars = array(
+ 'post_data',
+ 'moderators',
+ 'mode',
+ 'page_title',
+ 's_topic_icons',
+ 'form_enctype',
+ 's_action',
+ 's_hidden_fields',
+ 'post_id',
+ 'topic_id',
+ 'forum_id',
+ 'submit',
+ 'preview',
+ 'save',
+ 'load',
+ 'delete',
+ 'cancel',
+ 'refresh',
+ 'error',
+ 'page_data',
+ 'message_parser',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
diff --git a/tests/event/fixtures/trigger_wspace.test b/tests/event/fixtures/trigger_wspace.test
new file mode 100644
index 0000000000..0334a9c80b
--- /dev/null
+++ b/tests/event/fixtures/trigger_wspace.test
@@ -0,0 +1,15 @@
+<?php
+
+ /**
+ * Event after the post data has been assigned to the template
+ *
+ * @event core.trigger
+ * @var int start Start item of this page
+ * @var int current_row_number Number of the post on this page
+ * @var int end Number of posts on this page
+ * @var array row Array with original post and user data
+ * @var array cp_row Custom profile field data of the poster
+ * @since 3.1.0-a3
+ */
+ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
+ extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));
diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php
new file mode 100644
index 0000000000..1a51204cbe
--- /dev/null
+++ b/tests/event/md_exporter_test.php
@@ -0,0 +1,160 @@
+<?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_event_md_exporter_test extends phpbb_test_case
+{
+ static public function crawl_eventsmd_data()
+ {
+ return array(
+ array('normal_events.md.test', null, null, array(
+ 'acp_bbcodes_actions_append' => array(
+ 'event' => 'acp_bbcodes_actions_append',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a3',
+ 'changed' => array(
+ '3.1.0-a4' => '',
+ ),
+ 'description' => 'desc1' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend' => array(
+ 'event' => 'acp_bbcodes_actions_prepend',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a5',
+ 'changed' => array(),
+ 'description' => 'desc2' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend2' => array(
+ 'event' => 'acp_bbcodes_actions_prepend2',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a4',
+ 'changed' => array(
+ '3.1.0-a5' => 'Moved up',
+ '3.1.0-a6' => 'Moved down',
+ ),
+ 'description' => 'desc2' . "\n",
+ ),
+ )),
+ array('normal_events.md.test', '3.1.0-a5', '3.1.0-a5', array(
+ 'acp_bbcodes_actions_prepend' => array(
+ 'event' => 'acp_bbcodes_actions_prepend',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a5',
+ 'changed' => array(),
+ 'description' => 'desc2' . "\n",
+ ),
+ 'acp_bbcodes_actions_prepend2' => array(
+ 'event' => 'acp_bbcodes_actions_prepend2',
+ 'files' => array(
+ 'prosilver' => array(),
+ 'subsilver2' => array(),
+ 'adm' => array('acp_bbcodes.html'),
+ ),
+ 'since' => '3.1.0-a4',
+ 'changed' => array(
+ '3.1.0-a5' => 'Moved up',
+ '3.1.0-a6' => 'Moved down',
+ ),
+ 'description' => 'desc2' . "\n",
+ ),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_eventsmd_data
+ *
+ * @param string $file
+ * @param string $min_version
+ * @param string $max_version
+ * @param array $events
+ */
+ public function test_crawl_eventsmd($file, $min_version, $max_version, $events)
+ {
+ $exporter = new \phpbb\event\md_exporter(dirname(__FILE__) . '/fixtures/', null, $min_version, $max_version);
+ $this->assertSame(sizeof($events), $exporter->crawl_eventsmd($file, 'adm'));
+ $this->assertEquals($events, $exporter->get_events());
+ }
+
+ static public function crawl_phpbb_eventsmd_data()
+ {
+ return array(
+ array('styles'),
+ array('adm'),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_phpbb_eventsmd_data
+ */
+ public function test_crawl_phpbb_eventsmd($filter)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter));
+ }
+
+ static public function crawl_template_file_data()
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $data_provider = array();
+
+ $styles = array(
+ 'adm/style/' => 'adm',
+ 'styles/prosilver/template/' => 'styles',
+ 'styles/subsilver2/template/' => 'styles',
+ );
+ foreach ($styles as $path => $filter)
+ {
+ $files = $exporter->get_recursive_file_list($phpbb_root_path . $path, $path);
+ foreach ($files as $file)
+ {
+ $data_provider[] = array($filter, $path . $file);
+ }
+ }
+
+ return $data_provider;
+ }
+
+ /**
+ * @dataProvider crawl_template_file_data
+ */
+ public function test_crawl_template_file($filter, $file)
+ {
+ global $phpbb_root_path;
+ $exporter = new \phpbb\event\md_exporter($phpbb_root_path);
+ $exporter->crawl_eventsmd('docs/events.md', $filter);
+ $events = $exporter->crawl_file_for_events($file);
+
+ $this->assertGreaterThanOrEqual(0, sizeof($events));
+ $this->assertTrue($exporter->validate_events_from_file($file, $events));
+ }
+}
diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php
new file mode 100644
index 0000000000..692a57f93c
--- /dev/null
+++ b/tests/event/php_exporter_test.php
@@ -0,0 +1,740 @@
+<?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_event_php_exporter_test extends phpbb_test_case
+{
+ /** @var \phpbb\event\php_exporter */
+ protected $exporter;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/');
+ }
+
+ static public function crawl_php_file_data()
+ {
+ return array(
+ array(
+ 'default.test',
+ array(
+ 'default.dispatch' => array(
+ 'event' => 'default.dispatch',
+ 'file' => 'default.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'extra_description.test',
+ array(
+ 'extra_description.dispatch' => array(
+ 'event' => 'extra_description.dispatch',
+ 'file' => 'extra_description.test',
+ 'arguments' => array(),
+ 'since' => '3.1.0-b2',
+ 'description' => 'Description',
+ ),
+ ),
+ ),
+ array(
+ 'trigger.test',
+ array(
+ 'core.trigger' => array(
+ 'event' => 'core.trigger',
+ 'file' => 'trigger.test',
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
+ 'since' => '3.1.0-a3',
+ 'description' => 'Event after the post data has been assigned to the template',
+ ),
+ ),
+ ),
+ array(
+ 'trigger_wspace.test',
+ array(
+ 'core.trigger' => array(
+ 'event' => 'core.trigger',
+ 'file' => 'trigger_wspace.test',
+ 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'),
+ 'since' => '3.1.0-a3',
+ 'description' => 'Event after the post data has been assigned to the template',
+ ),
+ ),
+ ),
+ array(
+ 'trigger_many_vars.test',
+ array(
+ 'core.posting_modify_template_vars' => array(
+ 'event' => 'core.posting_modify_template_vars',
+ 'file' => 'trigger_many_vars.test',
+ 'arguments' => array(
+ 'cancel', 'delete', 'error', 'form_enctype', 'forum_id',
+ 'load', 'message_parser', 'mode', 'moderators', 'page_data',
+ 'page_title', 'post_data', 'post_id', 'preview', 'refresh',
+ 's_action', 's_hidden_fields', 's_topic_icons', 'save',
+ 'submit', 'topic_id',
+ ),
+ 'since' => '3.1.0-a1',
+ 'description' => 'This event allows you to modify template variables for the posting screen',
+ ),
+ ),
+ ),
+ array(
+ 'none.test',
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_data
+ */
+ public function test_crawl_php_file($file, $expected)
+ {
+ $this->exporter->crawl_php_file($file);
+ $this->assertEquals($expected, $this->exporter->get_events());
+ }
+
+ static public function crawl_php_file_throws_data()
+ {
+ return array(
+ array('missing_var.test', null),
+ array('duplicate_event.test', 10),
+ );
+ }
+
+ /**
+ * @dataProvider crawl_php_file_throws_data
+ */
+ public function test_crawl_php_file_throws($file, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->crawl_php_file($file);
+ }
+
+ static public function validate_since_data()
+ {
+ return array(
+ array('* @since 3.1.0-a1', '3.1.0-a1'),
+ array('* @since 3.1.0-b3', '3.1.0-b3'),
+ array(' * @since 3.1.0-b3', '3.1.0-b3'),
+ array('* @since 3.1.0-RC2', '3.1.0-RC2'),
+ array(' * @since 3.1.0-a1', '3.1.0-a1'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_data
+ */
+ public function test_validate_since($since, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_since($since));
+ }
+
+ static public function validate_since_throws_data()
+ {
+ return array(
+ array('* @since 3.1.0-a1 '),
+ array('* @since 3.1.0-a1 bertie is cool'),
+ array('bertie* @since 3.1.0-a1'),
+ array('* @since 3.1-A2'),
+ array('* @since 3.1.0-rc1'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_since_throws($since)
+ {
+ $this->exporter->validate_since($since);
+ }
+
+ static public function validate_event_data()
+ {
+ return array(
+ array('test.event', '* @event test.event', 'test.event'),
+ array('test.event2', ' * @event test.event2', 'test.event2'),
+ array('test.event', ' * @event test.event', 'test.event'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_data
+ */
+ public function test_validate_event($event_name, $event, $expected)
+ {
+ $this->assertEquals($expected, $this->exporter->validate_event($event_name, $event));
+ }
+
+ static public function validate_event_throws_data()
+ {
+ return array(
+ array('test.event', '* @event test.event bertie is cool', 2),
+ array('test.event', 'bertie* @event test.event', 2),
+ );
+ }
+
+ /**
+ * @dataProvider validate_event_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_event_throws($event_name, $event, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+ $this->exporter->validate_event($event_name, $event);
+ }
+
+ static public function validate_vars_docblock_array_data()
+ {
+ return array(
+ array(array('abc', 'def'), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_data
+ */
+ public function test_validate_vars_docblock_array($vars_array, $vars_docblock)
+ {
+ $this->assertNull($this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock));
+ }
+
+ static public function validate_vars_docblock_array_throws_data()
+ {
+ return array(
+ array(array('abc', 'def'), array()),
+ array(array('abc', 'def'), array('abc')),
+ array(array('abc', 'defg'), array('abc', 'def')),
+ array(array('abc'), array('abc', 'def')),
+ array(array(), array('abc', 'def')),
+ );
+ }
+
+ /**
+ * @dataProvider validate_vars_docblock_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock)
+ {
+ $this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock);
+ }
+
+ static public function get_dispatch_name_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'),
+ array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'),
+ array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_data
+ */
+ public function test_get_dispatch_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, true));
+ }
+
+ static public function get_dispatch_name_throws_data()
+ {
+ return array(
+ array("\$phpbb_dispatcher->dispatch();"),
+ array("\$phpbb_dispatcher->dispatch('');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch.2one');"),
+ array("\$phpbb_dispatcher->dispatch('dispatch');"),
+ );
+ }
+
+ /**
+ * @dataProvider get_dispatch_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_dispatch_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, true);
+ }
+
+ static public function get_trigger_event_name_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'),
+ array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'),
+ array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_data
+ */
+ public function test_get_trigger_event_name($event_line, $expected)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->assertEquals($expected, $this->exporter->get_event_name(0, false));
+ }
+
+ static public function get_trigger_event_name_throws_data()
+ {
+ return array(
+ array("extract(\$phpbb_dispatcher->trigger_event());"),
+ array("extract(\$phpbb_dispatcher->trigger_event(''));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.2one'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch'));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"),
+ array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"),
+ array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'),
+ );
+ }
+
+ /**
+ * @dataProvider get_trigger_event_name_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_trigger_event_name_throws($event_line)
+ {
+ $this->exporter->set_content(array($event_line));
+ $this->exporter->get_event_name(0, false);
+ }
+
+ static public function get_vars_from_array_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\');',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ array('bertie'),
+ ),
+ array(
+ array(
+ "\t/**",
+ "\t*/",
+ "\t\$vars = array('_Strange123', 'phpBB3_Test');",
+ "\t\$this->dispatcher->dispatch('test');",
+ ),
+ 3,
+ array('_Strange123', 'phpBB3_Test'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_data
+ */
+ public function test_get_vars_from_array($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_array());
+ }
+
+ static public function get_vars_from_array_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 2,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = $bertie;',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'$bertie\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array();',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'t1\', \'t2\', \'t3\', \'t4\', \'t5\', \'t6\', \'t7\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'test2\', \'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\'\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$vars = array(\'bertie\',\'basically_valid\');',
+ '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
+ ),
+ 3,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_array_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_array_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_array();
+ }
+
+ static public function get_vars_from_docblock_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ array('name1', 'name2'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_data
+ */
+ public function test_get_vars_from_docblock($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->get_vars_from_docblock());
+ }
+
+ static public function get_vars_from_docblock_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1',
+ '* @var array name2 Description test',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 2,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @var int name1 Description',
+ '* @var array $name2 Description',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 4,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_vars_from_docblock_throws_data
+ * @expectedException LogicException
+ */
+ public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->get_vars_from_docblock();
+ }
+
+ static public function find_since_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 3,
+ 1,
+ ),
+ array(
+ array(
+ '* @since 3.1.0-a1',
+ '/**',
+ '* @since 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_data
+ */
+ public function test_find_since($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_since());
+ }
+
+ static public function find_since_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a1',
+ '*/',
+ '/**',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @var',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ array(
+ array(
+ '/**',
+ '* @since 3.1.0-a2',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 3,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_since_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_since_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_since();
+ }
+
+ static public function find_description_data()
+ {
+ return array(
+ array(
+ array(
+ '/**',
+ '* Hello Bertie!',
+ '* @since 3.1.0-a1',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 1,
+ ),
+ array(
+ array(
+ ' /**',
+ ' * Hello Bertie!',
+ ' *',
+ ' * @since 3.1.0-a1',
+ ' * @changed 3.1.0-a2',
+ ' */',
+ ' $phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 6,
+ 1,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_data
+ */
+ public function test_find_description($lines, $event_line, $expected)
+ {
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->assertEquals($expected, $this->exporter->find_description());
+ }
+
+ static public function find_description_throws_data()
+ {
+ return array(
+ array(
+ array(
+ '$vars = array();',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 1,
+ 1,
+ ),
+ array(
+ array(
+ '/**',
+ '* @changed 3.1.0-a1',
+ '* @changed 3.1.0-a2',
+ '* @changed 3.1.0-a3',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 5,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '*',
+ '* @since 3.1.0-a2',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ array(
+ array(
+ '/**',
+ '* ',
+ '* @event',
+ '*/',
+ '$phpbb_dispatcher->dispatch(\'test\');',
+ ),
+ 4,
+ 2,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider find_description_throws_data
+ * @expectedException LogicException
+ */
+ public function test_find_description_throws($lines, $event_line, $exception_code)
+ {
+ $this->setExpectedException('LogicException', '', $exception_code);
+
+ $this->exporter->set_current_event('', $event_line);
+ $this->exporter->set_content($lines);
+ $this->exporter->find_description();
+ }
+}
diff --git a/tests/extension/ext/barfoo/composer.json b/tests/extension/ext/barfoo/composer.json
new file mode 100644
index 0000000000..05bb099707
--- /dev/null
+++ b/tests/extension/ext/barfoo/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "vendor/barfoo",
+ "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": "GNU GPL v2",
+ "authors": [{
+ "name": "John Smith",
+ "username": "JohnSmith27",
+ "email": "email@phpbb.com",
+ "homepage": "http://phpbb.com",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "extra": {
+ "display-name": "phpBB BarFoo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/extension/ext/barfoo/ext.php b/tests/extension/ext/barfoo/ext.php
new file mode 100644
index 0000000000..0de403424c
--- /dev/null
+++ b/tests/extension/ext/barfoo/ext.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor\barfoo;
+
+class ext extends \phpbb\extension\base
+{
+}
diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json
new file mode 100644
index 0000000000..d49aab47cd
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "vendor/moo",
+ "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": "GNU GPL v2",
+ "authors": [{
+ "name": "John Smith",
+ "username": "JohnSmith27",
+ "email": "email@phpbb.com",
+ "homepage": "http://phpbb.com",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "extra": {
+ "display-name": "phpBB Moo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/extension/ext/vendor/moo/ext.php b/tests/extension/ext/vendor/moo/ext.php
new file mode 100644
index 0000000000..41ef570452
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/ext.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace vendor\moo;
+
+class ext extends \phpbb\extension\base
+{
+ static public $purged;
+
+ public function purge_step($old_state)
+ {
+ self::$purged = true;
+
+ return false;
+ }
+}
diff --git a/tests/extension/ext/vendor/moo/feature_class.php b/tests/extension/ext/vendor/moo/feature_class.php
new file mode 100644
index 0000000000..cb8bb3da56
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/feature_class.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor\moo;
+
+class feature_class
+{
+}
diff --git a/tests/extension/ext/vendor2/bar/acp/a_info.php b/tests/extension/ext/vendor2/bar/acp/a_info.php
new file mode 100644
index 0000000000..8132df587f
--- /dev/null
+++ b/tests/extension/ext/vendor2/bar/acp/a_info.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace vendor2\bar\acp;
+
+class a_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => 'vendor2\\bar\\acp\\a_module',
+ 'title' => 'Bar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')),
+ ),
+ );
+ }
+}
diff --git a/tests/extension/ext/vendor2/bar/acp/a_module.php b/tests/extension/ext/vendor2/bar/acp/a_module.php
new file mode 100644
index 0000000000..3a3d105790
--- /dev/null
+++ b/tests/extension/ext/vendor2/bar/acp/a_module.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor2\bar\acp;
+
+class a_module
+{
+}
diff --git a/tests/extension/ext/vendor2/bar/composer.json b/tests/extension/ext/vendor2/bar/composer.json
new file mode 100644
index 0000000000..9d2ed86a0c
--- /dev/null
+++ b/tests/extension/ext/vendor2/bar/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "vendor2/bar",
+ "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/vendor2/bar/ext.php b/tests/extension/ext/vendor2/bar/ext.php
new file mode 100644
index 0000000000..f94ab9ad81
--- /dev/null
+++ b/tests/extension/ext/vendor2/bar/ext.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace vendor2\bar;
+
+class ext extends \phpbb\extension\base
+{
+ static public $state;
+
+ public function enable_step($old_state)
+ {
+ // run 4 steps, then quit
+ if ($old_state === 4)
+ {
+ return false;
+ }
+
+ if ($old_state === false)
+ {
+ $old_state = 0;
+ }
+
+ self::$state = ++$old_state;
+
+ return self::$state;
+ }
+}
diff --git a/tests/extension/ext/vendor2/bar/migrations/migration.php b/tests/extension/ext/vendor2/bar/migrations/migration.php
new file mode 100644
index 0000000000..71caa34fd9
--- /dev/null
+++ b/tests/extension/ext/vendor2/bar/migrations/migration.php
@@ -0,0 +1,18 @@
+<?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.
+*
+*/
+
+namespace vendor2\bar\migrations;
+
+class migration extends \phpbb\db\migration\migration
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/a_class.php b/tests/extension/ext/vendor2/foo/a_class.php
new file mode 100644
index 0000000000..06278c0e0c
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/a_class.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor2\foo;
+
+class a_class
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/acp/a_info.php b/tests/extension/ext/vendor2/foo/acp/a_info.php
new file mode 100644
index 0000000000..e1eaa340b7
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/acp/a_info.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace vendor2\foo\acp;
+
+class a_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => 'vendor2\\foo\\acp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),
+ ),
+ );
+ }
+}
diff --git a/tests/extension/ext/vendor2/foo/acp/a_module.php b/tests/extension/ext/vendor2/foo/acp/a_module.php
new file mode 100644
index 0000000000..78d91af2fe
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/acp/a_module.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor2\foo\acp;
+
+class a_module
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/acp/fail_info.php b/tests/extension/ext/vendor2/foo/acp/fail_info.php
new file mode 100644
index 0000000000..d9b4353957
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/acp/fail_info.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace vendor2\foo\acp;
+
+/*
+* Due to the mismatch between the class name and the file name, this module
+* file shouldn't be found by the extension finder
+*/
+class foo_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => 'vendor2\foo\acp\fail_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')),
+ ),
+ );
+ }
+}
diff --git a/tests/extension/ext/vendor2/foo/acp/fail_module.php b/tests/extension/ext/vendor2/foo/acp/fail_module.php
new file mode 100644
index 0000000000..c8a5eae745
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/acp/fail_module.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace vendor2\foo\acp;
+
+/*
+* Due to the mismatch between the class name and the file name of the module
+* info file, this module's info file shouldn't be found
+*/
+class fail_module
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/b_class.php b/tests/extension/ext/vendor2/foo/b_class.php
new file mode 100644
index 0000000000..3d0f193908
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/b_class.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor2\foo;
+
+class b_class
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/composer.json b/tests/extension/ext/vendor2/foo/composer.json
new file mode 100644
index 0000000000..efcdfc338f
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "vendor2/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 Foo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/extension/ext/vendor2/foo/ext.php b/tests/extension/ext/vendor2/foo/ext.php
new file mode 100644
index 0000000000..15480fe92a
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/ext.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace vendor2\foo;
+
+class ext extends \phpbb\extension\base
+{
+ static public $disabled;
+
+ public function disable_step($old_state)
+ {
+ self::$disabled = true;
+
+ return false;
+ }
+}
diff --git a/tests/extension/ext/vendor2/foo/mcp/a_info.php b/tests/extension/ext/vendor2/foo/mcp/a_info.php
new file mode 100644
index 0000000000..b5599fde65
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/mcp/a_info.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace vendor2\foo\mcp;
+
+class a_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => 'vendor2\\foo\\mcp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')),
+ ),
+ );
+ }
+}
diff --git a/tests/extension/ext/vendor2/foo/mcp/a_module.php b/tests/extension/ext/vendor2/foo/mcp/a_module.php
new file mode 100644
index 0000000000..fe29783827
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/mcp/a_module.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor2\foo\mcp;
+
+class a_module
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/sub/type/alternative.php b/tests/extension/ext/vendor2/foo/sub/type/alternative.php
new file mode 100644
index 0000000000..1eaf794609
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/sub/type/alternative.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace foo\sub\type;
+
+class alternative
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/type/alternative.php b/tests/extension/ext/vendor2/foo/type/alternative.php
new file mode 100644
index 0000000000..8f753491ef
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/type/alternative.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace foo\type;
+
+class alternative
+{
+}
diff --git a/tests/extension/ext/vendor2/foo/type/dummy/empty.txt b/tests/extension/ext/vendor2/foo/type/dummy/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/type/dummy/empty.txt
diff --git a/tests/extension/ext/vendor2/foo/typewrong/error.php b/tests/extension/ext/vendor2/foo/typewrong/error.php
new file mode 100644
index 0000000000..5020926043
--- /dev/null
+++ b/tests/extension/ext/vendor2/foo/typewrong/error.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace foo\typewrong;
+
+class error
+{
+}
diff --git a/tests/extension/ext/vendor3/bar/ext.php b/tests/extension/ext/vendor3/bar/ext.php
new file mode 100644
index 0000000000..37a5e92059
--- /dev/null
+++ b/tests/extension/ext/vendor3/bar/ext.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace vendor3\bar;
+
+class ext extends \phpbb\extension\base
+{
+ static public $state;
+
+ public function enable_step($old_state)
+ {
+ // run 4 steps, then quit
+ if ($old_state === 4)
+ {
+ return false;
+ }
+
+ if ($old_state === false)
+ {
+ $old_state = 0;
+ }
+
+ self::$state = ++$old_state;
+
+ return self::$state;
+ }
+}
diff --git a/tests/extension/ext/vendor3/bar/my/hidden_class.php b/tests/extension/ext/vendor3/bar/my/hidden_class.php
new file mode 100644
index 0000000000..38eb59aadf
--- /dev/null
+++ b/tests/extension/ext/vendor3/bar/my/hidden_class.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace vendor3\bar\my;
+
+class hidden_class
+{
+}
diff --git a/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html b/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html
new file mode 100644
index 0000000000..00c2a84a18
--- /dev/null
+++ b/tests/extension/ext/vendor3/bar/styles/prosilver/template/foobar_body.html
@@ -0,0 +1 @@
+bertie rules!
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/ext/vendor4/bar/composer.json b/tests/extension/ext/vendor4/bar/composer.json
new file mode 100644
index 0000000000..1a2fddc3f4
--- /dev/null
+++ b/tests/extension/ext/vendor4/bar/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "vendor4/bar",
+ "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/vendor4/bar/styles/all/template/foobar_body.html b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html
new file mode 100644
index 0000000000..c8f8cf957e
--- /dev/null
+++ b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html
@@ -0,0 +1 @@
+All folder
diff --git a/tests/extension/extension_base_test.php b/tests/extension/extension_base_test.php
new file mode 100644
index 0000000000..eee38186db
--- /dev/null
+++ b/tests/extension/extension_base_test.php
@@ -0,0 +1,79 @@
+<?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_extension_extension_base_test extends phpbb_test_case
+{
+ protected static $reflection_method_get_migration_file_list;
+
+ /** @var phpbb_mock_extension_manager */
+ protected $extension_manager;
+
+ public static function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ $reflection_class = new ReflectionClass('\phpbb\extension\base');
+ self::$reflection_method_get_migration_file_list = $reflection_class->getMethod('get_migration_file_list');
+ self::$reflection_method_get_migration_file_list->setAccessible(true);
+ }
+
+ public function setUp()
+ {
+ $container = new phpbb_mock_container_builder();
+ $migrator = new phpbb_mock_migrator();
+ $container->set('migrator', $migrator);
+
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ 'vendor3/bar' => array(
+ 'ext_name' => 'vendor3/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor3/bar/',
+ ),
+ 'vendor2/bar' => array(
+ 'ext_name' => 'vendor2/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/bar/',
+ ),
+ ),
+ $container);
+ }
+
+ public function data_test_suffix_get_classes()
+ {
+ return array(
+ array(
+ 'vendor2/bar',
+ array(
+ '\vendor2\bar\migrations\migration',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_test_suffix_get_classes
+ */
+ public function test_suffix_get_classes($extension_name, $expected)
+ {
+ $extension = $this->extension_manager->get_extension($extension_name);
+ $this->assertEquals($expected, self::$reflection_method_get_migration_file_list->invoke($extension));
+ }
+}
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php
new file mode 100644
index 0000000000..2116cc057b
--- /dev/null
+++ b/tests/extension/finder_test.php
@@ -0,0 +1,309 @@
+<?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_extension_finder_test extends phpbb_test_case
+{
+ /** @var \phpbb\extension\manager */
+ protected $extension_manager;
+ /** @var \phpbb\finder */
+ protected $finder;
+
+ public function setUp()
+ {
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ 'vendor3/bar' => array(
+ 'ext_name' => 'vendor3/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor3/bar/',
+ ),
+ ));
+
+ $this->finder = $this->extension_manager->get_finder();
+ }
+
+ public function test_suffix_get_classes()
+ {
+ $classes = $this->finder
+ ->core_path('phpbb/default/')
+ ->extension_suffix('_class')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\phpbb\default\implementation',
+ '\vendor2\foo\a_class',
+ '\vendor2\foo\b_class',
+ '\vendor3\bar\my\hidden_class',
+ ),
+ $classes
+ );
+ }
+
+ public function set_extensions_data()
+ {
+ return array(
+ array(
+ array(),
+ array('\phpbb\default\implementation'),
+ ),
+ array(
+ array('vendor3/bar'),
+ array(
+ '\phpbb\default\implementation',
+ '\vendor3\bar\my\hidden_class',
+ ),
+ ),
+ array(
+ array('vendor2/foo', 'vendor3/bar'),
+ array(
+ '\phpbb\default\implementation',
+ '\vendor2\foo\a_class',
+ '\vendor2\foo\b_class',
+ '\vendor3\bar\my\hidden_class',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider set_extensions_data
+ */
+ public function test_set_extensions($extensions, $expected)
+ {
+ $classes = $this->finder
+ ->set_extensions($extensions)
+ ->core_path('phpbb/default/')
+ ->extension_suffix('_class')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals($expected, $classes);
+ }
+
+ public function test_get_directories()
+ {
+ $dirs = $this->finder
+ ->directory('/type')
+ ->get_directories();
+
+ sort($dirs);
+ $this->assertEquals(array(
+ dirname(__FILE__) . '/ext/vendor2/foo/type/',
+ ), $dirs);
+ }
+
+ public function test_prefix_get_directories()
+ {
+ $dirs = $this->finder
+ ->prefix('ty')
+ ->get_directories();
+
+ sort($dirs);
+ $this->assertEquals(array(
+ dirname(__FILE__) . '/ext/vendor2/foo/sub/type/',
+ dirname(__FILE__) . '/ext/vendor2/foo/type/',
+ dirname(__FILE__) . '/ext/vendor2/foo/typewrong/',
+ ), $dirs);
+ }
+
+ public function test_prefix_get_classes()
+ {
+ $classes = $this->finder
+ ->core_path('phpbb/default/')
+ ->extension_prefix('hidden_')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\phpbb\default\implementation',
+ '\vendor3\bar\my\hidden_class',
+ ),
+ $classes
+ );
+ }
+
+ public function test_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->core_path('phpbb/default/')
+ ->extension_directory('type')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\phpbb\default\implementation',
+ '\vendor2\foo\sub\type\alternative',
+ '\vendor2\foo\type\alternative',
+ ),
+ $classes
+ );
+ }
+
+ public function test_absolute_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->directory('/type/')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\vendor2\foo\type\alternative',
+ ),
+ $classes
+ );
+ }
+
+ public function test_non_absolute_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->directory('type/')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\vendor2\foo\sub\type\alternative',
+ '\vendor2\foo\type\alternative',
+ ),
+ $classes
+ );
+ }
+
+ public function test_sub_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->directory('/sub/type')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\vendor2\foo\sub\type\alternative',
+ ),
+ $classes
+ );
+ }
+
+ public function test_uncleansub_directory_get_classes()
+ {
+ $classes = $this->finder
+ ->directory('/sub/../sub/type')
+ ->get_classes();
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\vendor2\foo\sub\type\alternative',
+ ),
+ $classes
+ );
+ }
+
+ public function test_find_from_extension()
+ {
+ $files = $this->finder
+ ->extension_directory('/type')
+ ->find_from_extension('vendor2/foo', dirname(__FILE__) . '/ext/vendor2/foo/');
+ $classes = $this->finder->get_classes_from_files($files);
+
+ sort($classes);
+ $this->assertEquals(
+ array(
+ '\vendor2\foo\type\alternative',
+ '\vendor2\foo\type\dummy\empty',
+ ),
+ $classes
+ );
+ }
+
+ /**
+ * These do not work because of changes with PHPBB3-11386
+ * They do not seem neccessary to me, so I am commenting them out for now
+ public function test_get_classes_create_cache()
+ {
+ $cache = new phpbb_mock_cache;
+ $finder = new \phpbb\finder(new \phpbb\filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name');
+ $finder->set_extensions(array_keys($this->extension_manager->all_enabled()));
+ $files = $finder->suffix('_class.php')->get_files();
+
+ $expected_files = array(
+ 'ext/bar/my/hidden_class.php' => 'bar',
+ 'ext/foo/a_class.php' => 'foo',
+ 'ext/foo/b_class.php' => 'foo',
+ );
+
+ $query = array(
+ 'core_path' => false,
+ 'core_suffix' => '_class.php',
+ 'core_prefix' => false,
+ 'core_directory' => false,
+ 'extension_suffix' => '_class.php',
+ 'extension_prefix' => false,
+ 'extension_directory' => false,
+ 'is_dir' => false,
+ );
+
+ $cache->checkAssociativeVar($this, '_custom_cache_name', array(
+ md5(serialize($query)) => $expected_files,
+ ), false);
+ }
+
+ public function test_cached_get_files()
+ {
+ $query = array(
+ 'core_path' => 'phpbb/foo',
+ 'core_suffix' => false,
+ 'core_prefix' => false,
+ 'core_directory' => 'bar',
+ 'extension_suffix' => false,
+ 'extension_prefix' => false,
+ 'extension_directory' => false,
+ 'is_dir' => false,
+ );
+
+ $finder = new \phpbb\finder(
+ new \phpbb\filesystem(),
+ dirname(__FILE__) . '/',
+ new phpbb_mock_cache(array(
+ '_ext_finder' => array(
+ md5(serialize($query)) => array('file_name' => 'extension'),
+ ),
+ ))
+ );
+ $finder->set_extensions(array_keys($this->extension_manager->all_enabled()));
+
+ $classes = $finder
+ ->core_path($query['core_path'])
+ ->core_directory($query['core_directory'])
+ ->get_files();
+
+ sort($classes);
+ $this->assertEquals(
+ array(dirname(__FILE__) . '/file_name'),
+ $classes
+ );
+ }
+ */
+}
diff --git a/tests/extension/fixtures/extensions.xml b/tests/extension/fixtures/extensions.xml
new file mode 100644
index 0000000000..6846162f0f
--- /dev/null
+++ b/tests/extension/fixtures/extensions.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_ext">
+ <column>ext_name</column>
+ <column>ext_active</column>
+ <column>ext_state</column>
+ <row>
+ <value>vendor2/foo</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ <row>
+ <value>vendor/moo</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/extension/includes/acp/acp_foobar.php b/tests/extension/includes/acp/acp_foobar.php
new file mode 100644
index 0000000000..c4591cae07
--- /dev/null
+++ b/tests/extension/includes/acp/acp_foobar.php
@@ -0,0 +1,29 @@
+<?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.
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class acp_foobar
+{
+ var $u_action;
+
+ function main($id, $mode)
+ {
+ }
+}
diff --git a/tests/extension/includes/acp/info/acp_foobar.php b/tests/extension/includes/acp/info/acp_foobar.php
new file mode 100644
index 0000000000..870225ba4f
--- /dev/null
+++ b/tests/extension/includes/acp/info/acp_foobar.php
@@ -0,0 +1,27 @@
+<?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 acp_foobar_info
+{
+ function module()
+ {
+ return array(
+ 'filename' => 'acp_foobar',
+ 'title' => 'ACP Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),
+ ),
+ );
+ }
+}
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
new file mode 100644
index 0000000000..0eeb060936
--- /dev/null
+++ b/tests/extension/manager_test.php
@@ -0,0 +1,187 @@
+<?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__) . '/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
+{
+ protected $extension_manager;
+ protected $class_loader;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->extension_manager = $this->create_extension_manager();
+ }
+
+ 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', 'vendor3/foo', 'vendor4/bar'), array_keys($this->extension_manager->all_available()));
+ }
+
+ public function test_all_enabled()
+ {
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ }
+
+ 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;
+
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->extension_manager->enable('vendor2/bar');
+ $this->assertEquals(array('vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
+
+ $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;
+
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->extension_manager->disable('vendor2/foo');
+ $this->assertEquals(array(), array_keys($this->extension_manager->all_enabled()));
+ $this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured()));
+
+ $this->assertTrue(vendor2\foo\ext::$disabled);
+ }
+
+ public function test_purge()
+ {
+ vendor\moo\ext::$purged = false;
+
+ $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->extension_manager->purge('vendor/moo');
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled()));
+ $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_configured()));
+
+ $this->assertTrue(vendor\moo\ext::$purged);
+ }
+
+ public function test_enabled_no_cache()
+ {
+ $extension_manager = $this->create_extension_manager(false);
+
+ $this->assertEquals(array('vendor2/foo'), array_keys($extension_manager->all_enabled()));
+ }
+
+ protected function create_extension_manager($with_cache = true)
+ {
+
+ $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/';
+ $php_ext = 'php';
+ $table_prefix = 'phpbb_';
+ $user = new \phpbb\user('\phpbb\user');
+
+ $container = new phpbb_mock_container_builder();
+
+ $migrator = new \phpbb\db\migrator(
+ $container,
+ $config,
+ $db,
+ $db_tools,
+ 'phpbb_migrations',
+ $phpbb_root_path,
+ $php_ext,
+ $table_prefix,
+ array(),
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $migrator);
+
+ return new \phpbb\extension\manager(
+ $container,
+ $db,
+ $config,
+ new \phpbb\filesystem(),
+ $user,
+ 'phpbb_ext',
+ dirname(__FILE__) . '/',
+ $php_ext,
+ ($with_cache) ? new phpbb_mock_cache() : null
+ );
+ }
+}
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
new file mode 100644
index 0000000000..2a746d3792
--- /dev/null
+++ b/tests/extension/metadata_manager_test.php
@@ -0,0 +1,343 @@
+<?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_extension_metadata_manager_test extends phpbb_database_test_case
+{
+ protected $class_loader;
+ protected $extension_manager;
+
+ protected $cache;
+ protected $config;
+ protected $db;
+ protected $db_tools;
+ protected $table_prefix;
+ protected $phpbb_root_path;
+ protected $phpEx;
+ protected $migrator;
+ protected $template;
+ protected $user;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->cache = new phpbb_mock_cache();
+ $this->config = new \phpbb\config\config(array(
+ 'version' => '3.1.0',
+ ));
+ $this->db = $this->new_dbal();
+ $this->db_tools = new \phpbb\db\tools($this->db);
+ $this->phpbb_root_path = dirname(__FILE__) . '/';
+ $this->phpEx = 'php';
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ $this->table_prefix = 'phpbb_';
+
+ $this->template = new \phpbb\template\twig\twig(
+ new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $this->phpbb_root_path,
+ $this->phpEx
+ ),
+ $this->config,
+ $this->user,
+ new \phpbb\template\context()
+ );
+
+ $container = new phpbb_mock_container_builder();
+
+ $this->migrator = new \phpbb\db\migrator(
+ $container,
+ $this->config,
+ $this->db,
+ $this->db_tools,
+ 'phpbb_migrations',
+ $this->phpbb_root_path,
+ 'php',
+ $this->table_prefix,
+ array(),
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $this->migrator);
+
+ $this->extension_manager = new \phpbb\extension\manager(
+ $container,
+ $this->db,
+ $this->config,
+ new \phpbb\filesystem(),
+ $this->user,
+ 'phpbb_ext',
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->cache
+ );
+ }
+
+ // Should fail from missing composer.json
+ public function test_bar()
+ {
+ $ext_name = 'vendor3/bar';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ try
+ {
+ $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'));
+ }
+ }
+
+ // Should be the same as a direct json_decode of the composer.json file
+ public function test_foo()
+ {
+ $ext_name = 'vendor2/foo';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ try
+ {
+ $metadata = $manager->get_metadata();
+ }
+ catch (\phpbb\extension\exception $e)
+ {
+ $this->fail($e);
+ }
+
+ $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/vendor2/foo/composer.json'), true);
+ array_walk_recursive($json, array($manager, 'sanitize_json'));
+
+ $this->assertEquals($metadata, $json);
+ }
+
+ public function validator_non_existing_data()
+ {
+ 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($field_name);
+ $this->fail('Exception not triggered');
+ }
+ catch(\phpbb\extension\exception $e)
+ {
+ $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)
+ {
+ $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors'));
+ }
+
+ $manager->merge_metadata(array(
+ 'authors' => array(
+ array(),
+ ),
+ ));
+
+ try
+ {
+ $manager->validate_authors();
+ $this->fail('Exception not triggered');
+ }
+ catch (\phpbb\extension\exception $e)
+ {
+ $this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name'));
+ }
+ }
+
+ public function validator_invalid_data()
+ {
+ return array(
+ array('name', 'asdf'),
+ array('type', 'asdf'),
+ array('license', ''),
+ array('version', ''),
+ );
+ }
+
+ /**
+ * @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(
+ $field_name => $field_value,
+ ));
+
+ try
+ {
+ $manager->validate($field_name);
+ $this->fail('Exception not triggered');
+ }
+ catch(\phpbb\extension\exception $e)
+ {
+ $this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', $field_name));
+ }
+ }
+
+ public function test_validator_valid()
+ {
+ $ext_name = 'validator';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ // Valid data
+ $manager->set_metadata(array(
+ 'name' => 'test/foo',
+ 'type' => 'phpbb-extension',
+ 'license' => 'GPL v2',
+ 'version' => '1.0.0',
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate('enable'));
+ }
+ catch(\phpbb\extension\exception $e)
+ {
+ $this->fail($e);
+ }
+ }
+
+ public function validator_requirements_data()
+ {
+ return array(
+ array(
+ '10.0.0',
+ '100.2.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
+ ),
+ array(
+ '5.3.0',
+ '3.1.0-beta',
+ true,
+ true,
+ ),
+ array(
+ '>' . phpversion(),
+ '>3.1.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
+ ),
+ array(
+ '<' . phpversion(),
+ '<3.1.0',
+ false,
+ false,
+ 'Versions are not compared at the moment',
+ ),
+ array(
+ phpversion(),
+ '3.1.0',
+ true,
+ true,
+ ),
+ array(
+ '>=' . phpversion(),
+ '>=3.1.0',
+ true,
+ true,
+ ),
+ array(
+ '<=' . phpversion(),
+ '<=3.1.0',
+ true,
+ true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validator_requirements_data
+ */
+ public function test_validator_requirements($php_version, $phpbb_version, $expected_php, $expected_phpbb, $incomplete_reason = '')
+ {
+ if ($incomplete_reason)
+ {
+ $this->markTestIncomplete($incomplete_reason);
+ }
+
+ $ext_name = 'validator';
+ $manager = $this->get_metadata_manager($ext_name);
+ // Too high of requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => $php_version,
+ ),
+ 'extra' => array(
+ 'soft-require' => array(
+ 'phpbb/phpbb' => $phpbb_version, // config is set to 3.1.0
+ ),
+ ),
+ ));
+
+ $this->assertEquals($expected_php, $manager->validate_require_php());
+ $this->assertEquals($expected_phpbb, $manager->validate_require_phpbb());
+ }
+
+ /**
+ * Get an instance of the metadata manager
+ *
+ * @param string $ext_name
+ * @return phpbb_mock_metadata_manager
+ */
+ private function get_metadata_manager($ext_name)
+ {
+ return new phpbb_mock_metadata_manager(
+ $ext_name,
+ $this->config,
+ $this->extension_manager,
+ $this->template,
+ $this->user,
+ $this->phpbb_root_path
+ );
+ }
+}
diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php
new file mode 100644
index 0000000000..21f1c6aca5
--- /dev/null
+++ b/tests/extension/modules_test.php
@@ -0,0 +1,238 @@
+<?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__) . '/ext/vendor2/foo/acp/a_info.php';
+require_once dirname(__FILE__) . '/ext/vendor2/foo/mcp/a_info.php';
+require_once dirname(__FILE__) . '/ext/vendor2/foo/acp/fail_info.php';
+require_once dirname(__FILE__) . '/ext/vendor2/bar/acp/a_info.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_module.php';
+
+class phpbb_extension_modules_test extends phpbb_test_case
+{
+ protected $extension_manager;
+ protected $finder;
+
+ public function setUp()
+ {
+ global $phpbb_extension_manager;
+
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ 'vendor3/bar' => array(
+ 'ext_name' => 'vendor3/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor3/bar/',
+ ),
+ ));
+ $phpbb_extension_manager = $this->extension_manager;
+
+ $this->acp_modules = new acp_modules();
+ }
+
+ public function test_get_module_infos()
+ {
+ global $phpbb_root_path;
+
+// $this->markTestIncomplete('Modules no speak namespace! Going to get rid of db modules altogether and fix this test after.');
+
+ // Correctly set the root path for this test to this directory, so the classes can be found
+ $phpbb_root_path = dirname(__FILE__) . '/';
+
+ // Find acp module info files
+ $this->acp_modules->module_class = 'acp';
+ $acp_modules = $this->acp_modules->get_module_infos();
+ $this->assertEquals(array(
+ 'vendor2\\foo\\acp\\a_module' => array(
+ 'filename' => 'vendor2\\foo\\acp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),
+ ),
+ ),
+ 'acp_foobar' => array(
+ 'filename' => 'acp_foobar',
+ 'title' => 'ACP Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),
+ ),
+ ),
+ ), $acp_modules);
+
+ // Find mcp module info files
+ $this->acp_modules->module_class = 'mcp';
+ $acp_modules = $this->acp_modules->get_module_infos();
+ $this->assertEquals(array(
+ 'vendor2\\foo\\mcp\\a_module' => array(
+ 'filename' => 'vendor2\\foo\\mcp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')),
+ ),
+ ),
+ ), $acp_modules);
+
+ // Find a specific module info file (mcp_a_module)
+ $this->acp_modules->module_class = 'mcp';
+ $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module');
+ $this->assertEquals(array(
+ 'vendor2\\foo\\mcp\\a_module' => array(
+ 'filename' => 'vendor2\\foo\\mcp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')),
+ ),
+ ),
+ ), $acp_modules);
+
+ // Find a specific module info file (mcp_a_module) with passing the module_class
+ $this->acp_modules->module_class = '';
+ $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module', 'mcp');
+ $this->assertEquals(array(
+ 'vendor2\\foo\\mcp\\a_module' => array(
+ 'filename' => 'vendor2\\foo\\mcp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')),
+ ),
+ ),
+ ), $acp_modules);
+
+ // The mcp module info file we're looking for shouldn't exist
+ $this->acp_modules->module_class = 'mcp';
+ $acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail');
+ $this->assertEquals(array(), $acp_modules);
+
+ // As there are no ucp modules we shouldn't find any
+ $this->acp_modules->module_class = 'ucp';
+ $acp_modules = $this->acp_modules->get_module_infos();
+ $this->assertEquals(array(), $acp_modules);
+
+ // Get module info of specified extension module
+ $this->acp_modules->module_class = 'acp';
+ $acp_modules = $this->acp_modules->get_module_infos('foo_acp_a_module');
+ $this->assertEquals(array(
+ 'vendor2\\foo\\acp\\a_module' => array (
+ 'filename' => 'vendor2\\foo\\acp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array (
+ 'config' => array ('title' => 'Config', 'auth' => 'ext_vendor2/foo', 'cat' => array ('ACP_MODS')),
+ ),
+ ),
+ ), $acp_modules);
+
+ // No specific module and module class set to an incorrect name
+ $acp_modules = $this->acp_modules->get_module_infos('', 'wcp', true);
+ $this->assertEquals(array(), $acp_modules);
+
+ // No specific module, no module_class set in the function parameter, and an incorrect module class
+ $this->acp_modules->module_class = 'wcp';
+ $acp_modules = $this->acp_modules->get_module_infos();
+ $this->assertEquals(array(), $acp_modules);
+
+ // No specific module, module class set to false (will default to the above acp)
+ // Setting $use_all_available will cause get_module_infos() to also load not enabled extensions (vendor2/bar)
+ $this->acp_modules->module_class = 'acp';
+ $acp_modules = $this->acp_modules->get_module_infos('', false, true);
+ $this->assertEquals(array(
+ 'vendor2\\foo\\acp\\a_module' => array(
+ 'filename' => 'vendor2\\foo\\acp\\a_module',
+ 'title' => 'Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => 'ext_vendor2/foo', 'cat' => array('ACP_MODS')),
+ ),
+ ),
+ 'acp_foobar' => array(
+ 'filename' => 'acp_foobar',
+ 'title' => 'ACP Foobar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')),
+ ),
+ ),
+ 'vendor2\\bar\\acp\\a_module' => array(
+ 'filename' => 'vendor2\\bar\\acp\\a_module',
+ 'title' => 'Bar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')),
+ ),
+ )
+ ), $acp_modules);
+
+ // Specific module set to disabled extension
+ $acp_modules = $this->acp_modules->get_module_infos('vendor2_bar_acp_a_module', 'acp', true);
+ $this->assertEquals(array(
+ 'vendor2\\bar\\acp\\a_module' => array(
+ 'filename' => 'vendor2\\bar\\acp\\a_module',
+ 'title' => 'Bar',
+ 'version' => '3.1.0-dev',
+ 'modes' => array(
+ 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')),
+ ),
+ )
+ ), $acp_modules);
+ }
+
+ public function module_auth_test_data()
+ {
+ return array(
+ // module_auth, expected result
+ array('ext_foo', false),
+ array('ext_foo/bar', false),
+ array('ext_vendor3/bar', false),
+ array('ext_vendor2/foo', true),
+ );
+ }
+
+ /**
+ * @dataProvider module_auth_test_data
+ */
+ public function test_modules_auth($module_auth, $expected)
+ {
+ global $phpbb_extension_manager, $phpbb_dispatcher;
+
+ $phpbb_extension_manager = $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor2/foo' => array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor2/foo/',
+ ),
+ 'vendor3/bar' => array(
+ 'ext_name' => 'vendor3/bar',
+ 'ext_active' => '0',
+ 'ext_path' => 'ext/vendor3/bar/',
+ ),
+ )
+ );
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $this->assertEquals($expected, p_master::module_auth($module_auth, 0));
+ }
+}
diff --git a/tests/extension/phpbb/default/implementation.php b/tests/extension/phpbb/default/implementation.php
new file mode 100644
index 0000000000..91d5f8aa2f
--- /dev/null
+++ b/tests/extension/phpbb/default/implementation.php
@@ -0,0 +1,5 @@
+<?php
+
+class phpbb_default_impl_class implements phpbb_default_interface
+{
+}
diff --git a/tests/feed/attachments_base_test.php b/tests/feed/attachments_base_test.php
new file mode 100644
index 0000000000..c980dfd3d7
--- /dev/null
+++ b/tests/feed/attachments_base_test.php
@@ -0,0 +1,94 @@
+<?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__) . '/attachments_mock_feed.php');
+
+class phpbb_feed_attachments_base_test extends phpbb_database_test_case
+{
+ protected $filesystem;
+
+ /** @var \phpbb_feed_attachments_mock_feed */
+ protected $attachments_mocks_feed;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../extension/fixtures/extensions.xml');
+ }
+
+ public function setUp()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $this->filesystem = new \phpbb\filesystem();
+ $config = new \phpbb\config\config(array());
+ $user = new \phpbb\user('\phpbb\datetime');
+ $feed_helper = new \phpbb\feed\helper($config, $user, $phpbb_root_path, $phpEx);
+ $db = $this->new_dbal();
+ $cache = new \phpbb_mock_cache();
+ $auth = new \phpbb\auth\auth();
+ $content_visibility = new \phpbb\content_visibility(
+ $auth,
+ $config,
+ new \phpbb_mock_event_dispatcher(),
+ $db,
+ $user,
+ $phpbb_root_path,
+ $phpEx,
+ FORUMS_TABLE,
+ POSTS_TABLE,
+ TOPICS_TABLE,
+ USERS_TABLE
+ );
+
+ $this->attachments_mocks_feed = new \phpbb_feed_attachments_mock_feed(
+ $feed_helper,
+ $config,
+ $db,
+ $cache,
+ $user,
+ $auth,
+ $content_visibility,
+ new \phpbb_mock_event_dispatcher(),
+ $phpEx
+ );
+ }
+
+ public function data_fetch_attachments()
+ {
+ return array(
+ array(array(0), array(0)),
+ array(array(), array(1)),
+ array(array(), array(), 'RuntimeException')
+ );
+ }
+
+ /**
+ * @dataProvider data_fetch_attachments
+ */
+ public function test_fetch_attachments($post_ids, $topic_ids, $expected_exception = false)
+ {
+ $this->attachments_mocks_feed->post_ids = $post_ids;
+ $this->attachments_mocks_feed->topic_ids = $topic_ids;
+
+ if ($expected_exception !== false)
+ {
+ $this->setExpectedException($expected_exception);
+
+ $this->attachments_mocks_feed->get_sql();
+ }
+ else
+ {
+ $this->assertTrue($this->attachments_mocks_feed->get_sql());
+ }
+ }
+}
diff --git a/tests/feed/attachments_mock_feed.php b/tests/feed/attachments_mock_feed.php
new file mode 100644
index 0000000000..0e623fed24
--- /dev/null
+++ b/tests/feed/attachments_mock_feed.php
@@ -0,0 +1,31 @@
+<?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.
+ *
+ */
+
+/**
+ * Board wide feed (aka overall feed)
+ *
+ * This will give you the newest {$this->num_items} posts
+ * from the whole board.
+ */
+class phpbb_feed_attachments_mock_feed extends \phpbb\feed\attachments_base
+{
+ public $topic_ids = array();
+ public $post_ids = array();
+
+ function get_sql()
+ {
+ parent::fetch_attachments($this->post_ids, $this->topic_ids);
+
+ return true;
+ }
+}
diff --git a/tests/functions/clean_path_test.php b/tests/filesystem/clean_path_test.php
index bcbe9838d9..c585b17155 100644
--- a/tests/functions/clean_path_test.php
+++ b/tests/filesystem/clean_path_test.php
@@ -1,17 +1,27 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_clean_path_test extends phpbb_test_case
+class phpbb_filesystem_clean_path_test extends phpbb_test_case
{
- public function clean_path_test_data()
+ protected $filesystem;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->filesystem = new \phpbb\filesystem();
+ }
+
+ public function clean_path_data()
{
return array(
array('foo', 'foo'),
@@ -22,6 +32,8 @@ class phpbb_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'),
@@ -33,12 +45,10 @@ class phpbb_clean_path_test extends phpbb_test_case
}
/**
- * @dataProvider clean_path_test_data
+ * @dataProvider clean_path_data
*/
public function test_clean_path($input, $expected)
{
- $output = phpbb_clean_path($input);
-
- $this->assertEquals($expected, $output);
+ $this->assertEquals($expected, $this->filesystem->clean_path($input));
}
}
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/acp_groups_test.php b/tests/functional/acp_groups_test.php
index 3d8cabb086..9dfdc93474 100644
--- a/tests/functional/acp_groups_test.php
+++ b/tests/functional/acp_groups_test.php
@@ -1,21 +1,124 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/common_groups_test.php';
+require_once dirname(__FILE__) . '/common_groups_test_case.php';
/**
* @group functional
*/
-class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test
+class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test_case
{
+ protected $form_data;
+
protected function get_url()
{
return 'adm/index.php?i=groups&mode=manage&action=edit';
}
+
+ public function acp_group_test_data()
+ {
+ return array(
+ 'both_yes' => array(
+ 5,
+ true,
+ true,
+ ),
+ 'legend_no_teampage' => array(
+ 5,
+ true,
+ false,
+ ),
+ 'no_legend_teampage' => array(
+ 5,
+ false,
+ true,
+ ),
+ 'both_no' => array(
+ 5,
+ false,
+ false,
+ ),
+ 'no_change' => array(
+ 5,
+ NULL,
+ NULL,
+ ),
+ 'back_to_default' => array(
+ 5,
+ true,
+ true,
+ ),
+ // Remove and add moderators back in order to reset
+ // group order to default one
+ 'mods_both_no' => array(
+ 4,
+ false,
+ false,
+ ),
+ 'mods_back_to_default' => array(
+ 4,
+ true,
+ true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider acp_group_test_data
+ */
+ public function test_acp_groups_teampage($group_id, $tick_legend, $tick_teampage)
+ {
+ $this->group_manage_login();
+
+ // Manage Administrators group
+ $form = $this->get_group_manage_form($group_id);
+ $this->form_data[0] = $form->getValues();
+
+ if (isset($tick_legend) && isset($tick_teampage))
+ {
+ if ($tick_legend)
+ {
+ $form['group_legend']->tick();
+ }
+ else
+ {
+ $form['group_legend']->untick();
+ }
+
+ if ($tick_teampage)
+ {
+ $form['group_teampage']->tick();
+ }
+ else
+ {
+ $form['group_teampage']->untick();
+ }
+ }
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text());
+
+ $form = $this->get_group_manage_form($group_id);
+ if (!isset($tick_legend) && !isset($tick_teampage))
+ {
+ $this->form_data[1] = $form->getValues();
+ unset($this->form_data[0]['creation_time'], $this->form_data[0]['form_token'], $this->form_data[1]['creation_time'], $this->form_data[1]['form_token']);
+ $this->assertEquals($this->form_data[0], $this->form_data[1]);
+ }
+ else
+ {
+ $this->form_data = $form->getValues();
+ $this->assertEquals($tick_legend, $this->form_data['group_legend']);
+ $this->assertEquals($tick_teampage, $this->form_data['group_teampage']);
+ }
+ }
}
diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php
new file mode 100644
index 0000000000..0a40e76057
--- /dev/null
+++ b/tests/functional/acp_permissions_test.php
@@ -0,0 +1,127 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/permissions');
+ }
+
+ public function test_permissions_tab()
+ {
+ // Permissions tab
+ // XXX hardcoded id
+ $crawler = self::request('GET', 'adm/index.php?i=16&sid=' . $this->sid);
+ // these language strings are html
+ $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content());
+ }
+
+ public function test_select_user()
+ {
+ // User permissions
+ $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
+ $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content());
+
+ // Select admin
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $data = array('username[0]' => 'admin');
+ $form->setValues($data);
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+ }
+
+ public function permissions_data()
+ {
+ return array(
+ // description
+ // permission type
+ // permission name
+ // mode
+ // object name
+ // object id
+ array(
+ 'user permission',
+ 'u_',
+ 'u_hideonline',
+ 'setting_user_global',
+ 'user_id',
+ 2,
+ ),
+ array(
+ 'moderator permission',
+ 'm_',
+ 'm_ban',
+ 'setting_mod_global',
+ 'group_id',
+ 4,
+ ),
+ /* Admin does not work yet, probably because founder can do everything
+ array(
+ 'admin permission',
+ 'a_',
+ 'a_forum',
+ 'setting_admin_global',
+ 'group_id',
+ 5,
+ ),
+ */
+ );
+ }
+
+ /**
+ * @dataProvider permissions_data
+ */
+ public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id)
+ {
+ // Get the form
+ $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid);
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+
+ // XXX globals for \phpbb\auth\auth, refactor it later
+ global $db, $cache;
+ $db = $this->get_db();
+ $cache = new phpbb_mock_null_cache;
+
+ $auth = new \phpbb\auth\auth;
+ // XXX hardcoded id
+ $user_data = $auth->obtain_user_data(2);
+ $auth->acl($user_data);
+ $this->assertEquals(1, $auth->acl_get($permission));
+
+ // Set u_hideonline to never
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ // initially it should be a yes
+ $values = $form->getValues();
+ $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]);
+ // set to never
+ $data = array("setting[$object_id][0][$permission]" => '0');
+ $form->setValues($data);
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text());
+
+ // check acl again
+ $auth = new \phpbb\auth\auth;
+ // XXX hardcoded id
+ $user_data = $auth->obtain_user_data(2);
+ $auth->acl($user_data);
+ $this->assertEquals(0, $auth->acl_get($permission));
+ }
+}
diff --git a/tests/functional/acp_profile_field_test.php b/tests/functional/acp_profile_field_test.php
new file mode 100644
index 0000000000..88df782faa
--- /dev/null
+++ b/tests/functional/acp_profile_field_test.php
@@ -0,0 +1,71 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/profile');
+ }
+
+ public function data_add_profile_field()
+ {
+ return array(
+ array('bool', 'profilefields.type.bool',
+ array(
+ 'lang_options[0]' => 'foo',
+ 'lang_options[1]' => 'bar',
+ ),
+ array(),
+ ),
+ array('dropdown', 'profilefields.type.dropdown',
+ array(
+ 'lang_options' => "foo\nbar\nbar\nfoo",
+ ),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_add_profile_field
+ */
+ public function test_add_profile_field($name, $type, $page1_settings, $page2_settings)
+ {
+ // Custom profile fields page
+ $crawler = self::request('GET', 'adm/index.php?i=acp_profile&mode=profile&sid=' . $this->sid);
+ // these language strings are html
+ $form = $crawler->selectButton('Create new field')->form(array(
+ 'field_ident' => $name,
+ 'field_type' => $type,
+ ));
+ $crawler = self::submit($form);
+
+ // Fill form for profile field options
+ $form = $crawler->selectButton('Profile type specific options')->form($page1_settings);
+ $crawler = self::submit($form);
+
+ // Fill form for profile field specific options
+ $form = $crawler->selectButton('Save')->form($page2_settings);
+ $crawler= self::submit($form);
+
+ $this->assertContainsLang('ADDED_PROFILE_FIELD', $crawler->text());
+ }
+}
diff --git a/tests/functional/acp_registration_test.php b/tests/functional/acp_registration_test.php
new file mode 100644
index 0000000000..ef9843679e
--- /dev/null
+++ b/tests/functional/acp_registration_test.php
@@ -0,0 +1,55 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_acp_registration_test extends phpbb_functional_test_case
+{
+ protected function set_email_enable($db, $status)
+ {
+ $sql = "UPDATE phpbb_config
+ SET config_value = '" . (($status) ? '1' : '0') . "'
+ WHERE config_name = 'email_enable'";
+ $db->sql_query($sql);
+
+ $this->purge_cache();
+ }
+
+ public function test_submitting_activation_method()
+ {
+ $db = $this->get_db();
+
+ $this->set_email_enable($db, false);
+
+ $this->add_lang('acp/board');
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid);
+ $this->assertContainsLang('ACP_REGISTER_SETTINGS_EXPLAIN', $this->get_content());
+
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form['config[require_activation]']->select(USER_ACTIVATION_ADMIN);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text());
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid);
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form['config[require_activation]']->select(USER_ACTIVATION_NONE);
+ $crawler = self::submit($form);
+ $this->assertNotContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text());
+
+ $this->set_email_enable($db, true);
+ }
+}
diff --git a/tests/functional/acp_users_test.php b/tests/functional/acp_users_test.php
index 50d9a67dc1..78028aacb8 100644
--- a/tests/functional/acp_users_test.php
+++ b/tests/functional/acp_users_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php
index afb4f15fc2..76e1709afb 100644
--- a/tests/functional/auth_test.php
+++ b/tests/functional/auth_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -18,7 +22,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// check for logout link
$crawler = self::request('GET', 'index.php');
- $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
+ $this->assertContains($this->lang('LOGOUT', 'admin'), $crawler->filter('.navbar')->text());
}
public function test_login_other()
@@ -26,7 +30,26 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->create_user('anothertestuser');
$this->login('anothertestuser');
$crawler = self::request('GET', 'index.php');
- $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
+ $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text());
+ }
+
+ /**
+ * @dependsOn test_login_other
+ */
+ public function test_login_ucp_other_auth_provider()
+ {
+ global $cache, $config;
+ $cache = new phpbb_mock_null_cache;
+ $db = $this->get_db();
+ $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'";
+ $db->sql_query($sql);
+ $config['auth_method'] = 'foobar';
+ $this->login('anothertestuser');
+ $crawler = self::request('GET', 'index.php');
+ $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text());
+ $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'";
+ $db->sql_query($sql);
+ $config['auth_method'] = 'db';
}
/**
@@ -39,10 +62,19 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// logout
$crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
- $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
// look for a register link, which should be visible only when logged out
$crawler = self::request('GET', 'index.php');
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
}
+
+ public function test_acp_login()
+ {
+ $this->login();
+ $this->admin_login();
+
+ // check that we are logged in
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
+ $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
+ }
}
diff --git a/tests/functional/avatar_acp_groups_test.php b/tests/functional/avatar_acp_groups_test.php
new file mode 100644
index 0000000000..ca8c84ab2e
--- /dev/null
+++ b/tests/functional/avatar_acp_groups_test.php
@@ -0,0 +1,85 @@
+<?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__) . '/common_avatar_test_case.php';
+
+/**
+ * @group functional
+ */
+class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test_case
+{
+ public function get_url()
+ {
+ return 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5';
+ }
+
+ public function avatar_acp_groups_data()
+ {
+ return array(
+ // Correct Gravatar
+ array(
+ 'GROUP_UPDATED',
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_gravatar_email' => 'test@example.com',
+ 'avatar_gravatar_width' => 80,
+ 'avatar_gravatar_height' => 80,
+ ),
+ ),
+ // Gravatar with incorrect size
+ array(
+ 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.',
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_gravatar_email' => 'test@example.com',
+ 'avatar_gravatar_width' => 120,
+ 'avatar_gravatar_height' => 120,
+ ),
+ ),
+ // Delete avatar image to reset group settings
+ array(
+ array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'),
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_delete' => array('tick', ''),
+ ),
+ ),
+ array(
+ 'The URL you specified is invalid.',
+ 'avatar_driver_remote',
+ array(
+ 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
+ 'avatar_remote_width' => 80,
+ 'avatar_remote_height' => 80,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider avatar_acp_groups_data
+ */
+ public function test_avatar_acp_groups($expected, $avatar_type, $data)
+ {
+ $this->assert_avatar_submit($expected, $avatar_type, $data);
+ }
+
+ // Test if avatar was really deleted
+ public function test_no_avatar_acp_groups()
+ {
+ $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form_data = $form->getValues();
+ $this->assertEmpty($form_data['avatar_type']);
+ }
+}
diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php
new file mode 100644
index 0000000000..8b05a28658
--- /dev/null
+++ b/tests/functional/avatar_acp_users_test.php
@@ -0,0 +1,65 @@
+<?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__) . '/common_avatar_test_case.php';
+
+/**
+ * @group functional
+ */
+class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test_case
+{
+ public function get_url()
+ {
+ return 'adm/index.php?i=acp_users&u=2&mode=avatar';
+ }
+
+ public function avatar_acp_users_data()
+ {
+ return array(
+ // Gravatar with incorrect email
+ array(
+ 'EMAIL_INVALID_EMAIL',
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_gravatar_email' => 'test.example.com',
+ 'avatar_gravatar_width' => 80,
+ 'avatar_gravatar_height' => 80,
+ ),
+ ),
+ // Remote avatar with correct link
+ array(
+ 'USER_AVATAR_UPDATED',
+ 'avatar_driver_upload',
+ array(
+ 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
+ ),
+ ),
+ // Reset avatar settings
+ array(
+ array('CONFIRM_AVATAR_DELETE', 'USER_AVATAR_UPDATED'),
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_delete' => array('tick', ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider avatar_acp_users_data
+ */
+ public function test_avatar_acp_users($expected, $avatar_type, $data)
+ {
+ $this->assert_avatar_submit($expected, $avatar_type, $data);
+ }
+}
diff --git a/tests/functional/avatar_ucp_groups_test.php b/tests/functional/avatar_ucp_groups_test.php
new file mode 100644
index 0000000000..52ef67543e
--- /dev/null
+++ b/tests/functional/avatar_ucp_groups_test.php
@@ -0,0 +1,74 @@
+<?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__) . '/common_avatar_test_case.php';
+
+/**
+ * @group functional
+ */
+class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test_case
+{
+ public function get_url()
+ {
+ return 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5';
+ }
+
+ public function avatar_ucp_groups_data()
+ {
+ return array(
+ // Incorrect URL
+ array(
+ 'AVATAR_URL_INVALID',
+ 'avatar_driver_upload',
+ array(
+ 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80',
+ ),
+ ),
+ /*
+ // Does not work due to DomCrawler issue
+ // Valid file upload
+ array(
+ 'GROUP_UPDATED',
+ 'avatar_driver_upload',
+ array(
+ 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'),
+ ),
+ ),
+ */
+ // Correct remote avatar
+ array(
+ 'GROUP_UPDATED',
+ 'avatar_driver_remote',
+ array(
+ 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
+ 'avatar_remote_width' => 80,
+ 'avatar_remote_height' => 80,
+ ),
+ ),
+ array(
+ array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'),
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_delete' => array('tick', ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider avatar_ucp_groups_data
+ */
+ public function test_avatar_ucp_groups($expected, $avatar_type, $data)
+ {
+ $this->assert_avatar_submit($expected, $avatar_type, $data);
+ }
+}
diff --git a/tests/functional/avatar_ucp_users_test.php b/tests/functional/avatar_ucp_users_test.php
new file mode 100644
index 0000000000..2f0832e092
--- /dev/null
+++ b/tests/functional/avatar_ucp_users_test.php
@@ -0,0 +1,73 @@
+<?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__) . '/common_avatar_test_case.php';
+
+/**
+ * @group functional
+ */
+class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test_case
+{
+ public function get_url()
+ {
+ return 'ucp.php?i=ucp_profile&mode=avatar';
+ }
+
+ public function avatar_ucp_groups_data()
+ {
+ return array(
+ // Gravatar with correct settings
+ array(
+ 'PROFILE_UPDATED',
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_gravatar_email' => 'test@example.com',
+ 'avatar_gravatar_width' => 80,
+ 'avatar_gravatar_height' => 80,
+ ),
+ ),
+
+ array(
+ array('CONFIRM_AVATAR_DELETE', 'PROFILE_UPDATED'),
+ 'avatar_driver_gravatar',
+ array(
+ 'avatar_delete' => array('tick', ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider avatar_ucp_groups_data
+ */
+ public function test_avatar_ucp_groups($expected, $avatar_type, $data)
+ {
+ $this->assert_avatar_submit($expected, $avatar_type, $data);
+ }
+
+ public function test_display_upload_avatar()
+ {
+ $this->assert_avatar_submit('PROFILE_UPDATED',
+ 'avatar_driver_upload',
+ array(
+ 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg',
+ )
+ );
+
+ $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
+ $avatar_link = $crawler->filter('img')->attr('src');
+ $crawler = self::request('GET', $avatar_link . '&sid=' . $this->sid, array(), false);
+ $content = self::$client->getResponse()->getContent();
+ self::assertEquals(false, stripos(trim($content), 'debug'), 'Output contains debug message');
+ }
+}
diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php
index 18a2ad9464..b9e74a280f 100644
--- a/tests/functional/browse_test.php
+++ b/tests/functional/browse_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -29,4 +33,11 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
$crawler = self::request('GET', 'viewtopic.php?t=1');
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
}
+
+ public function test_feed()
+ {
+ $crawler = self::request('GET', 'feed.php', array(), false);
+ self::assert_response_xml();
+ $this->assertGreaterThan(0, $crawler->filter('entry')->count());
+ }
}
diff --git a/tests/functional/common_avatar_test_case.php b/tests/functional/common_avatar_test_case.php
new file mode 100644
index 0000000000..924eb1273c
--- /dev/null
+++ b/tests/functional/common_avatar_test_case.php
@@ -0,0 +1,97 @@
+<?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
+ */
+abstract class phpbb_functional_common_avatar_test_case extends phpbb_functional_test_case
+{
+ private $path;
+ private $form_content;
+
+ abstract function get_url();
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->login();
+ $this->admin_login();
+ $this->add_lang(array('acp/board', 'ucp', 'acp/users', 'acp/groups'));
+ $this->set_acp_settings();
+ }
+
+ private function set_acp_settings()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
+ // Check the default entries we should have
+ $this->assertContainsLang('ALLOW_GRAVATAR', $crawler->text());
+ $this->assertContainsLang('ALLOW_REMOTE_UPLOAD', $crawler->text());
+ $this->assertContainsLang('ALLOW_AVATARS', $crawler->text());
+ $this->assertContainsLang('ALLOW_LOCAL', $crawler->text());
+
+ // Now start setting the needed settings
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form['config[allow_avatar_local]']->select(1);
+ $form['config[allow_avatar_gravatar]']->select(1);
+ $form['config[allow_avatar_remote]']->select(1);
+ $form['config[allow_avatar_remote_upload]']->select(1);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
+ }
+
+ public function assert_avatar_submit($expected, $type, $data, $delete = false, $button_text = 'SUBMIT')
+ {
+ $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid);
+
+ // Test if setting a gravatar avatar properly works
+ $form = $crawler->selectButton($this->lang($button_text))->form();
+ $form['avatar_driver']->select($type);
+
+ foreach ($data as $key => $value)
+ {
+ if (is_array($value))
+ {
+ $form[$key]->{$value[0]}($value[1]);
+ }
+ else
+ {
+ $form[$key]->setValue($value);
+ }
+ }
+
+ $crawler = self::submit($form);
+
+ if (is_array($expected))
+ {
+ $delete_expected = $expected[1];
+ $expected = $expected[0];
+ }
+
+ try
+ {
+ $this->assertContainsLang($expected, $crawler->text());
+ }
+ catch (Exception $e)
+ {
+ $this->assertContains($expected, $crawler->text());
+ }
+
+ if ($delete)
+ {
+ $form = $crawler->selectButton('confirm')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang($delete_expected, $crawler->text());
+ }
+ }
+}
diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test_case.php
index 427a930cb9..521b7c84d2 100644
--- a/tests/functional/common_groups_test.php
+++ b/tests/functional/common_groups_test_case.php
@@ -1,19 +1,45 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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
*/
-abstract class phpbb_functional_common_groups_test extends phpbb_functional_test_case
+abstract class phpbb_functional_common_groups_test_case extends phpbb_functional_test_case
{
abstract protected function get_url();
+ /**
+ * Get group_manage form
+ * @param int $group_id ID of the group that should be managed
+ */
+ protected function get_group_manage_form($group_id = 5)
+ {
+ // Manage Administrators group
+ $crawler = self::request('GET', $this->get_url() . "&g=$group_id&sid=" . $this->sid);
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ return $form;
+ }
+
+ /**
+ * Execute login calls and add_lang() calls for tests
+ */
+ protected function group_manage_login()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->add_lang(array('ucp', 'acp/groups'));
+ }
+
// Enable all avatars in the ACP
protected function enable_all_avatars()
{
@@ -21,7 +47,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
$crawler = self::request('GET', 'adm/index.php?i=board&mode=avatar&sid=' . $this->sid);
// Check the default entries we should have
- $this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text());
+ $this->assertContains($this->lang('ALLOW_REMOTE_UPLOAD'), $crawler->text());
$this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text());
$this->assertContains($this->lang('ALLOW_LOCAL'), $crawler->text());
@@ -50,13 +76,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
*/
public function test_groups_manage($input, $expected)
{
- $this->login();
- $this->admin_login();
- $this->add_lang(array('ucp', 'acp/groups'));
+ $this->group_manage_login();
// Manage Administrators group
- $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid);
- $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form = $this->get_group_manage_form();
$form['group_colour']->setValue($input);
$crawler = self::submit($form);
$this->assertContains($this->lang($expected), $crawler->text());
@@ -65,19 +88,19 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
public function group_avatar_min_max_data()
{
return array(
- array('uploadurl', 'foo', 'TOO_SHORT'),
- array('uploadurl', 'foobar', 'AVATAR_URL_INVALID'),
- array('uploadurl', str_repeat('f', 256), 'TOO_LONG'),
- array('remotelink', 'foo', 'TOO_SHORT'),
- array('remotelink', 'foobar', 'AVATAR_URL_INVALID'),
- array('remotelink', str_repeat('f', 256), 'TOO_LONG'),
+ array('avatar_driver_upload', 'avatar_upload_url', 'foo', 'AVATAR_URL_INVALID'),
+ array('avatar_driver_upload', 'avatar_upload_url', 'foobar', 'AVATAR_URL_INVALID'),
+ array('avatar_driver_upload', 'avatar_upload_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'),
+ array('avatar_driver_remote', 'avatar_remote_url', 'foo', 'AVATAR_URL_INVALID'),
+ array('avatar_driver_remote', 'avatar_remote_url', 'foobar', 'AVATAR_URL_INVALID'),
+ array('avatar_driver_remote', 'avatar_remote_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'),
);
}
/**
* @dataProvider group_avatar_min_max_data
*/
- public function test_group_avatar_min_max($form_name, $input, $expected)
+ public function test_group_avatar_min_max($avatar_type, $form_name, $input, $expected)
{
$this->login();
$this->admin_login();
@@ -86,6 +109,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
$crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $form['avatar_driver']->setValue($avatar_type);
$form[$form_name]->setValue($input);
$crawler = self::submit($form);
$this->assertContains($this->lang($expected), $crawler->text());
diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php
new file mode 100644
index 0000000000..1e863210e6
--- /dev/null
+++ b/tests/functional/download_test.php
@@ -0,0 +1,296 @@
+<?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/functions_posting.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_download_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Download #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function test_create_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ ));
+
+ // Test creating topic
+ $post = $this->create_topic($this->data['forums']['Download #1'], 'Download Topic #1', 'This is a test topic posted by the testing framework.', array('upload_files' => 1));
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Download Topic #1', $crawler->filter('html')->text());
+ $this->data['topics']['Download Topic #1'] = (int) $post['topic_id'];
+ $this->data['posts']['Download Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Download #1'], $post['topic_id'], 'Re: Download Topic #1-#2', 'This is a test post posted by the testing framework.', array('upload_files' => 1));
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Download Topic #1-#2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Download Topic #1-#2'] = (int) $post2['post_id'];
+ }
+
+ public function test_download_accessible()
+ {
+ if (!class_exists('finfo'))
+ {
+ $this->markTestSkipped('Unable to run test with fileinfo disabled');
+ }
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ 'topics' => array(
+ 'Download Topic #1',
+ ),
+ 'posts' => array(
+ 'Download Topic #1',
+ 'Re: Download Topic #1-#2',
+ ),
+ 'attachments' => true,
+ ));
+
+ // Download attachment as guest
+ $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
+ self::assert_response_status_code(200);
+ $content = self::$client->getResponse()->getContent();
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ self::assertEquals('image/jpeg', $finfo->buffer($content));
+ }
+
+ public function test_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ 'topics' => array(
+ 'Download Topic #1',
+ ),
+ 'posts' => array(
+ 'Download Topic #1',
+ 'Re: Download Topic #1-#2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Download #1']}&p={$this->data['posts']['Re: Download Topic #1-#2']}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Download Topic #1']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_download_softdeleted_post()
+ {
+ if (!class_exists('finfo'))
+ {
+ $this->markTestSkipped('Unable to run test with fileinfo disabled');
+ }
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ 'topics' => array(
+ 'Download Topic #1',
+ ),
+ 'posts' => array(
+ 'Download Topic #1',
+ 'Re: Download Topic #1-#2',
+ ),
+ 'attachments' => true,
+ ));
+ $this->add_lang('viewtopic');
+
+ // No download attachment as guest
+ $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
+ self::assert_response_html(404);
+ $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text());
+
+ // Login as admin and try again, should work now.
+ $this->login();
+
+ // Download attachment as admin
+ $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
+ self::assert_response_status_code(200);
+ $content = self::$client->getResponse()->getContent();
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ self::assertEquals('image/jpeg', $finfo->buffer($content));
+ }
+
+ public function test_softdelete_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ 'topics' => array(
+ 'Download Topic #1',
+ ),
+ 'posts' => array(
+ 'Download Topic #1',
+ 'Re: Download Topic #1-#2',
+ ),
+ ));
+
+ $this->add_lang('posting');
+ $crawler = $this->get_quickmod_page($this->data['topics']['Download Topic #1'], 'DELETE_TOPIC');
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Download Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Download Topic #1', $crawler->filter('h2')->text());
+ }
+
+ public function test_download_softdeleted_topic()
+ {
+ if (!class_exists('finfo'))
+ {
+ $this->markTestSkipped('Unable to run test with fileinfo disabled');
+ }
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Download #1',
+ ),
+ 'topics' => array(
+ 'Download Topic #1',
+ ),
+ 'posts' => array(
+ 'Download Topic #1',
+ 'Re: Download Topic #1-#2',
+ ),
+ 'attachments' => true,
+ ));
+ $this->add_lang('viewtopic');
+
+ // No download attachment as guest
+ $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
+ self::assert_response_html(404);
+ $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text());
+
+ // Login as admin and try again, should work now.
+ $this->login();
+
+ // Download attachment as admin
+ $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false);
+ self::assert_response_status_code(200);
+ $content = self::$client->getResponse()->getContent();
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ self::assertEquals('image/jpeg', $finfo->buffer($content));
+ }
+
+ public function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ $post_ids = array();
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ $post_ids[] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ if (isset($data['attachments']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_attachments
+ WHERE in_message = 0 AND ' . $this->db->sql_in_set('post_msg_id', $post_ids);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->data['attachments'][(int) $row['post_msg_id']] = (int) $row['attach_id'];
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+ }
+}
diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php
new file mode 100644
index 0000000000..8a71a5ce04
--- /dev/null
+++ b/tests/functional/extension_acp_test.php
@@ -0,0 +1,237 @@
+<?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_extension_acp_test extends phpbb_functional_test_case
+{
+ static private $helper;
+
+ static protected $fixtures = array(
+ './',
+ );
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/../extension/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->purge_cache();
+
+ $this->get_db();
+
+ // Clear the phpbb_ext table
+ $this->db->sql_query('DELETE FROM phpbb_ext');
+
+ // Insert our base data
+ $insert_rows = array(
+ array(
+ 'ext_name' => 'vendor2/foo',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'vendor/moo',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+
+ // do not exist
+ array(
+ 'ext_name' => 'vendor/test2',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'vendor/test3',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+ );
+ $this->db->sql_multi_insert('phpbb_ext', $insert_rows);
+
+ $this->login();
+ $this->admin_login();
+
+ $this->add_lang('acp/extensions');
+ }
+
+ public function test_list()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
+
+ $this->assertCount(1, $crawler->filter('.ext_enabled'));
+ $this->assertCount(6, $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());
+
+ $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('EXTENSION_ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('EXTENSION_DELETE_DATA', $crawler->filter('.ext_disabled')->eq(2)->text());
+
+ $this->assertContains('The “vendor/test2” extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text());
+
+ $this->assertContains('The “vendor/test3” extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text());
+
+ $this->assertContains('phpBB Bar Extension', $crawler->filter('.ext_disabled')->eq(3)->text());
+ $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(3)->text());
+ $this->assertContainsLang('EXTENSION_ENABLE', $crawler->filter('.ext_disabled')->eq(3)->text());
+
+ // Check that invalid extensions are not listed.
+ $this->assertNotContains('phpBB BarFoo Extension', $crawler->filter('.table1')->text());
+ $this->assertNotContains('barfoo', $crawler->filter('.table1')->text());
+
+ $this->assertNotContains('vendor3/bar', $crawler->filter('.table1')->text());
+ }
+
+ public function test_details()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=vendor2%2Ffoo&sid=' . $this->sid);
+
+ $validation = array(
+ 'DISPLAY_NAME' => 'phpBB Foo Extension',
+ 'CLEAN_NAME' => 'vendor2/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',
+ 'PHPBB_VERSION' => '3.1.*@dev',
+ 'PHP_VERSION' => '>=5.3',
+ 'AUTHOR_NAME' => 'John Smith',
+ 'AUTHOR_EMAIL' => 'email@phpbb.com',
+ 'AUTHOR_HOMEPAGE' => 'http://phpbb.com',
+ 'AUTHOR_ROLE' => 'N/A',
+ );
+
+ for ($i = 0; $i < $crawler->filter('dl')->count(); $i++)
+ {
+ $text = $crawler->filter('dl')->eq($i)->text();
+
+ $match = false;
+
+ foreach ($validation as $language_key => $expected)
+ {
+ if (strpos($text, $this->lang($language_key)) === 0)
+ {
+ $match = true;
+
+ $this->assertContains($expected, $text);
+ }
+ }
+
+ if (!$match)
+ {
+ $this->fail('Unexpected field: "' . $text . '"');
+ }
+ }
+ }
+
+ public function test_enable_pre()
+ {
+ // Foo is already enabled (redirect to list)
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text());
+
+ $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()
+ {
+ // Moo is not enabled (redirect to list)
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text());
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid);
+ $this->assertContains($this->lang('EXTENSION_DISABLE_CONFIRM', 'phpBB Foo Extension'), $crawler->filter('#main')->text());
+ }
+
+ public function test_delete_data_pre()
+ {
+ // test2 is not available (error)
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=test2&sid=' . $this->sid);
+ $this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('.errorbox')->text());
+
+ // foo is not disabled (redirect to list)
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text());
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContains('Are you sure that you wish to delete the data associated with “phpBB Moo Extension”?', $crawler->filter('.errorbox')->text());
+ }
+
+ public function test_actions()
+ {
+ // Access enable page without hash
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text());
+
+ // Correctly submit the enable form
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $form = $crawler->selectButton('enable')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('.successbox')->text());
+
+ // Access disable page without hash
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text());
+
+ // Correctly submit the disable form
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $form = $crawler->selectButton('disable')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('EXTENSION_DISABLE_SUCCESS', $crawler->filter('.successbox')->text());
+
+ // Access delete_data page without hash
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text());
+
+ // Correctly submit the delete data form
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $form = $crawler->selectButton('delete_data')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('EXTENSION_DELETE_DATA_SUCCESS', $crawler->filter('.successbox')->text());
+
+ // Attempt to enable invalid extension
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=barfoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_DIR_INVALID', $crawler->filter('.errorbox')->text());
+ }
+}
diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php
new file mode 100644
index 0000000000..18eb9ad4c6
--- /dev/null
+++ b/tests/functional/extension_controller_test.php
@@ -0,0 +1,181 @@
+<?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_extension_controller_test extends phpbb_functional_test_case
+{
+ protected $phpbb_extension_manager;
+
+ static private $helper;
+
+ static protected $fixtures = array(
+ 'foo/bar/config/',
+ 'foo/bar/controller/',
+ 'foo/bar/event/',
+ 'foo/bar/language/en/',
+ 'foo/bar/styles/prosilver/template/',
+ 'foo/foo/config/',
+ 'foo/foo/controller/',
+ );
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+
+ $this->purge_cache();
+ }
+
+ /**
+ * Check a controller for extension foo/bar.
+ */
+ public function test_foo_bar()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/bar', array(), false);
+ self::assert_response_status_code();
+ $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check a controller for extension foo/bar.
+ */
+ public function test_routing_resources()
+ {
+ $this->phpbb_extension_manager->enable('foo/foo');
+ $crawler = self::request('GET', 'app.php/foo/foo', array(), false);
+ self::assert_response_status_code();
+ $this->assertContains("foo/foo controller handle() method", $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/foo');
+ }
+
+ /**
+ * Check the output of a controller using the template system
+ */
+ public function test_controller_with_template()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/template');
+ $this->assertContains("I am a variable", $crawler->filter('#content')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check the error produced by calling a controller without a required
+ * argument.
+ */
+ public function test_missing_argument()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/baz', array(), false);
+ $this->assert_response_html(500);
+ $this->assertContains('Missing value for argument #1: test in class foo\bar\controller\controller:baz', $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check the status code resulting from an exception thrown by a controller
+ */
+ public function test_exception_should_result_in_500_status_code()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/exception', array(), false);
+ $this->assert_response_html(500);
+ $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check the error produced by extension at ./ext/does/not/exist.
+ *
+ * If an extension is disabled, its routes are not loaded. Because we
+ * are not looking for a controller based on a specified extension,
+ * we don't know the difference between a route in a disabled
+ * extension and a route that is not defined anyway; it is the same
+ * error message.
+ */
+ public function test_error_ext_disabled_or_404()
+ {
+ $crawler = self::request('GET', 'app.php/does/not/exist', array(), false);
+ $this->assert_response_html(404);
+ $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
+ }
+
+ /**
+ * Check the redirect after using the login_box() form
+ */
+ public function test_login_redirect()
+ {
+ $this->markTestIncomplete('Session table contains incorrect data for controllers on travis,'
+ . 'therefor the redirect fails.');
+
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/login_redirect');
+ $this->assertContainsLang('LOGIN', $crawler->filter('h2')->text());
+ $form = $crawler->selectButton('login')->form(array(
+ 'username' => 'admin',
+ 'password' => 'adminadmin',
+ ));
+ $this->assertStringStartsWith('./app.php/foo/login_redirect', $form->get('redirect')->getValue());
+
+ $crawler = self::submit($form);
+ $this->assertContains("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()');
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check the output of a controller using the template system
+ */
+ public function test_redirect()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/redirect');
+
+ $nodes = $crawler->filter('div')->extract(array('id'));
+
+ foreach ($nodes as $redirect)
+ {
+ if (strpos($redirect, 'redirect_expected') !== 0)
+ {
+ continue;
+ }
+
+ $row_num = str_replace('redirect_expected_', '', $redirect);
+
+ $redirect = $crawler->filter('#redirect_' . $row_num)->text();
+ $redirect = substr($redirect, 0, strpos($redirect, 'sid') - 1);
+ $this->assertEquals($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect);
+ }
+
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+}
diff --git a/tests/functional/extension_global_lang_test.php b/tests/functional/extension_global_lang_test.php
new file mode 100644
index 0000000000..f615114c08
--- /dev/null
+++ b/tests/functional/extension_global_lang_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.
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case
+{
+ protected $phpbb_extension_manager;
+
+ static private $helper;
+
+ static protected $fixtures = array(
+ 'foo/bar/config/',
+ 'foo/bar/event/',
+ 'foo/bar/language/en/',
+ );
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->get_db();
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+
+ $this->purge_cache();
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+
+ $this->purge_cache();
+ }
+
+ public function test_load_extension_lang_globally()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+
+ // The board index, which should contain an overwritten translation
+ $crawler = self::request('GET', 'index.php');
+
+ // language from language/en/common.php
+ $this->assertNotContains('Skip to content', $crawler->filter('.skiplink')->text());
+
+ // language from ext/foo/bar/language/en/foo_global.php
+ $this->assertContains('Overwritten by foo', $crawler->filter('.skiplink')->text());
+ }
+}
diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php
new file mode 100644
index 0000000000..ee084720e4
--- /dev/null
+++ b/tests/functional/extension_module_test.php
@@ -0,0 +1,136 @@
+<?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/acp/acp_modules.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_extension_module_test extends phpbb_functional_test_case
+{
+ protected $phpbb_extension_manager;
+
+ static private $helper;
+
+ static protected $fixtures = array(
+ './',
+ );
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ global $db;
+
+ parent::setUp();
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+ $this->phpbb_extension_manager->enable('foo/bar');
+
+ $modules = new acp_modules();
+ $db = $this->get_db();
+
+ $sql = 'SELECT module_id
+ FROM ' . MODULES_TABLE . "
+ WHERE module_langname = 'acp'
+ AND module_class = 'ACP_CAT_DOT_MODS'";
+ $result = $db->sql_query($sql);
+ $module_id = (int) $db->sql_fetchfield('module_id');
+ $db->sql_freeresult($result);
+
+ $parent_data = array(
+ 'module_basename' => '',
+ 'module_enabled' => 1,
+ 'module_display' => 1,
+ 'parent_id' => $module_id,
+ 'module_class' => 'acp',
+ 'module_langname' => 'ACP_FOOBAR_TITLE',
+ 'module_mode' => '',
+ 'module_auth' => '',
+ );
+ $modules->update_module_data($parent_data, true);
+
+ $module_data = array(
+ 'module_basename' => 'foo\\bar\\acp\\main_module',
+ 'module_enabled' => 1,
+ 'module_display' => 1,
+ 'parent_id' => $parent_data['module_id'],
+ 'module_class' => 'acp',
+ 'module_langname' => 'ACP_FOOBAR_TITLE',
+ 'module_mode' => 'mode',
+ 'module_auth' => '',
+ );
+ $modules->update_module_data($module_data, true);
+
+ $parent_data = array(
+ 'module_basename' => '',
+ 'module_enabled' => 1,
+ 'module_display' => 1,
+ 'parent_id' => 0,
+ 'module_class' => 'ucp',
+ 'module_langname' => 'UCP_FOOBAR_TITLE',
+ 'module_mode' => '',
+ 'module_auth' => '',
+ );
+ $modules->update_module_data($parent_data, true);
+
+ $module_data = array(
+ 'module_basename' => 'foo\\bar\\ucp\\main_module',
+ 'module_enabled' => 1,
+ 'module_display' => 1,
+ 'parent_id' => $parent_data['module_id'],
+ 'module_class' => 'ucp',
+ 'module_langname' => 'UCP_FOOBAR_TITLE',
+ 'module_mode' => 'mode',
+ 'module_auth' => '',
+ );
+ $modules->update_module_data($module_data, true);
+
+ $this->purge_cache();
+ }
+
+ public function test_acp()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?i=foo%5cbar%5cacp%5cmain_module&mode=mode&sid=' . $this->sid);
+ $this->assertContains('Bertie rulez!', $crawler->filter('#main')->text());
+ }
+
+ public function test_ucp()
+ {
+ $this->login();
+
+ $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid);
+ $this->assertContains('UCP_FOOBAR_TITLE', $crawler->filter('#tabs')->text());
+
+ $link = $crawler->selectLink('UCP_FOOBAR_TITLE')->link()->getUri();
+ $crawler = self::request('GET', substr($link, strpos($link, 'ucp.')));
+ $this->assertContains('UCP Extension Template Test Passed!', $crawler->filter('#content')->text());
+
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+}
diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php
new file mode 100644
index 0000000000..92d8d596c7
--- /dev/null
+++ b/tests/functional/extension_permission_lang_test.php
@@ -0,0 +1,86 @@
+<?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_extension_permission_lang_test extends phpbb_functional_test_case
+{
+ protected $phpbb_extension_manager;
+
+ static private $helper;
+
+ static protected $fixtures = array(
+ 'foo/bar/config/',
+ 'foo/bar/event/',
+ 'foo/bar/language/en/',
+ );
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->get_db();
+
+ $acl_ary = array(
+ 'auth_option' => 'u_foo',
+ 'is_global' => 1,
+ );
+
+ $sql = 'INSERT INTO phpbb_acl_options ' . $this->db->sql_build_array('INSERT', $acl_ary);
+ $this->db->sql_query($sql);
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+
+ $this->purge_cache();
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/permissions');
+ }
+
+ public function test_auto_include_permission_lang_from_extensions()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+
+ // User permissions
+ $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
+
+ // Select admin
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $data = array('username[0]' => 'admin');
+ $form->setValues($data);
+ $crawler = self::submit($form);
+
+ // language from language/en/acp/permissions_phpbb.php
+ $this->assertContains('Can attach files', $crawler->filter('body')->text());
+
+ // language from ext/foo/bar/language/en/permissions_foo.php
+ $this->assertContains('Can view foobar', $crawler->filter('body')->text());
+ }
+}
diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php
new file mode 100644
index 0000000000..e48dfc043a
--- /dev/null
+++ b/tests/functional/feed_test.php
@@ -0,0 +1,1503 @@
+<?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_feed_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ static public $init_values = array();
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->purge_cache();
+ }
+
+ public function __construct($name = null, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_feed_test' => array('init_values'),
+ );
+ }
+
+ public function test_setup_config_before_state()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ self::$init_values['post_base_items'] = (int) $values['config[feed_limit_post]'];
+ self::$init_values['topic_base_items'] = (int) $values['config[feed_limit_topic]'];
+
+ // Enable all feeds
+ $values['config[feed_enable]'] = true;
+ $values['config[feed_forum]'] = true;
+ $values['config[feed_item_statistics]'] = true;
+ $values['config[feed_overall]'] = true;
+ $values['config[feed_overall_forums]'] = true;
+ $values['config[feed_topic]'] = true;
+ $values['config[feed_topics_active]'] = true;
+ $values['config[feed_topics_new]'] = true;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+
+ // Special config (Guest can't see attachments)
+ $this->add_lang('acp/permissions');
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1");
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ $form['setting[1][0][u_download]']->select(-1);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_dump_board_state()
+ {
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+ $this->login();
+
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+
+ }
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->create_user('disapprove_user');
+ $this->add_user_group('NEWLY_REGISTERED', array('disapprove_user'));
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // 'Feeds #1.1' is a sub-forum of 'Feeds #1'
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$this->data['forums']['Feeds #1']}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1.1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #news' will be used for feed.php?mode=news
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #news',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #exclude' will not be displayed on feed.php?mode=forums
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #exclude',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function test_setup_config_after_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+
+ // News/Exclude's forums config
+ $form['feed_news_id']->select(array($this->data['forums']['Feeds #news']));
+ $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude']));
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_feeds_empty()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ // Excluded forums (and topics under them) shouldn't be displayed in feeds
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'nb_entries' => 0,
+ ),
+ array(
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'nb_entries' => 0,
+ ),
+ ),
+ 'forums' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/category[@label="Feeds #exclude"]' => 0,
+ ),
+ ),
+ ),
+ 'news' => array(
+ array(
+ 'nb_entries' => 0,
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_exclude_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #exclude'], 'Feeds #exclude - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #exclude - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_exclude()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ 'topics' => array(
+ 'Feeds #exclude - Topic #1',
+ ),
+ ));
+
+ // Assert that feeds aren't available for excluded forums
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #exclude'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #exclude - Topic #1'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_news_topics()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id'];
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id'];
+ $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Feeds #news'], $post['topic_id'], 'Re: Feeds #news - Topic #2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_news_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ 'topics' => array(
+ 'Feeds #news - Topic #1',
+ 'Feeds #news - Topic #2',
+ ),
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that the first post of the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ // News should also be displayed in other feeds
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #news'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #news - Topic #1'],
+ ),
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #news - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 3,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_news_guest()
+ {
+ $this->load_ids(array(
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that first post of the the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_sub_forum_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id'];
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_sub_forum()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // The topics of the sub-forum shouldn't be displayed
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id'];
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ 'posts' => array(
+ 'Re: Feeds #1 - Topic #2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Feeds #1']}&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_feeds_softdeleted_post_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_post_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ));
+ }
+
+ public function test_softdelete_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $this->add_lang('posting');
+ $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC');
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text());
+ }
+
+ public function test_feeds_softdeleted_topic_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_topic_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_unapproved_post()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $this->login('admin');
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #2', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1.1 - Topic #2'] = (int) $post['topic_id'];
+ $this->logout();
+
+ // Test creating a reply
+ $this->login('disapprove_user');
+ $post2 = $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text());
+ }
+
+ public function test_feeds_unapproved_post_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved post is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 9,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_post_disapprove_user()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved isn't displayed for regular users
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_unapproved_topic()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+ $this->set_flood_interval(0);
+
+ $this->login('disapprove_user');
+ $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text());
+
+ $this->logout();
+ $this->set_flood_interval(15);
+ }
+
+ protected function set_flood_interval($flood_interval)
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[flood_interval]"] = $flood_interval;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+
+ $this->logout();
+ }
+
+ public function test_feeds_unapproved_topic_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ // Assert that the unapproved topic is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 4,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 10,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_topic_disapprove_user()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_attachment_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // Test creating a topic with 1 attachment
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #3', 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]', array('upload_files' => 1));
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_attachment_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 4,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 11,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_attachment_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_missing_attachment_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ // Test creating a reply with 1 missing attachment
+ $post2 = $this->create_post($this->data['forums']['Feeds #1'], $this->data['topics']['Feeds #1 - Topic #3'], 'Re: Feeds #1 - Topic #3-1', 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_missing_attachment_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ $this->add_lang('viewtopic');
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 5,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 12,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 8,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 8,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ protected function assert_feeds($data, $username = false)
+ {
+ if ($username)
+ {
+ $this->login($username);
+ $init_values = self::$init_values[$username];
+ }
+ else
+ {
+ $init_values = self::$init_values['disapprove_user'];
+ }
+
+ foreach ($data as $mode => $feeds)
+ {
+ foreach ($feeds as $feed_data)
+ {
+ if ($mode === 'f' || $mode === 't')
+ {
+ $params = "?{$mode}={$feed_data['id']}";
+ $this->assert_feed($params, $feed_data);
+ }
+ else
+ {
+ switch ($mode) {
+ case 'forums':
+ $feed_data['nb_entries'] = ((int)$feed_data['nb_entries'] + $init_values['forums_value']);
+ break;
+ case 'overall':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['overall_value'], self::$init_values['post_base_items']);
+ break;
+ case 'topics':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_new':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_new_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_active':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_active_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'news':
+ break;
+ default:
+ $this->fail('Unsupported feed mode: ' . $mode);
+ }
+
+ $params = "?mode={$mode}";
+ $this->assert_feed($params, $feed_data);
+ }
+ }
+ }
+ }
+
+ protected function assert_feed($params, $data)
+ {
+ $crawler = self::request('GET', 'feed.php' . $params, array(), false);
+
+ if (empty($data['invalid']))
+ {
+ self::assert_response_xml();
+ $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'");
+
+ if (!empty($data['xpath']))
+ {
+
+ foreach($data['xpath'] as $xpath => $count_expected)
+ {
+ $this->assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'feed.php{$params}', Search for {$xpath}");
+ }
+ }
+
+ if (!empty($data['contents']))
+ {
+ foreach($data['contents'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['attachments']))
+ {
+ foreach($data['attachments'] as $entry_id => $attachments)
+ {
+ foreach ($attachments as $i => $attachment)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $url = self::$root_url . "download/file.php?id={$attachment['id']}";
+ $string = "Attachment #{$i}";
+
+ if ($attachment['displayed'])
+ {
+ $this->assertContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ $this->assertNotContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ else
+ {
+ $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ $this->assertNotContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ self::assert_response_html();
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $string)
+ {
+ $content = $crawler->filter('html')->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ $post_ids = array();
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ $post_ids[] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ if (isset($data['attachments']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_attachments
+ WHERE in_message = 0 AND ' . $this->db->sql_in_set('post_msg_id', $post_ids);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->data['attachments'][(int) $row['post_msg_id']][] = (int) $row['attach_id'];
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+ }
+}
diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
new file mode 100644
index 0000000000..d381fa1ae2
--- /dev/null
+++ b/tests/functional/fileupload_form_test.php
@@ -0,0 +1,145 @@
+<?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_fileupload_form_test extends phpbb_functional_test_case
+{
+ private $path;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->add_lang('posting');
+ }
+
+ public function tearDown()
+ {
+ $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/');
+ foreach ($iterator as $fileinfo)
+ {
+ if (
+ $fileinfo->isDot()
+ || $fileinfo->isDir()
+ || $fileinfo->getFilename() === 'index.htm'
+ || $fileinfo->getFilename() === '.htaccess'
+ )
+ {
+ continue;
+ }
+
+ unlink($fileinfo->getPathname());
+ }
+ }
+
+ private function upload_file($filename, $mimetype)
+ {
+ $file = array(
+ 'tmp_name' => $this->path . $filename,
+ 'name' => $filename,
+ 'type' => $mimetype,
+ 'size' => filesize($this->path . $filename),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = self::$client->request(
+ 'POST',
+ 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid,
+ array('add_file' => $this->lang('ADD_FILE')),
+ array('fileupload' => $file)
+ );
+
+ return $crawler;
+ }
+
+ public function test_empty_file()
+ {
+ $this->login();
+
+ $crawler = $this->upload_file('empty.png', 'image/png');
+ $this->assertEquals($this->lang('EMPTY_FILEUPLOAD'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_invalid_extension()
+ {
+ $this->login();
+
+ $crawler = $this->upload_file('illegal-extension.bif', 'application/octet-stream');
+ $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_disallowed_content()
+ {
+ $this->login();
+
+ $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
+ $this->assertEquals($this->lang('DISALLOWED_CONTENT'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_disallowed_content_no_check()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('ucp');
+
+ // Make sure check_attachment_content is set to false
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_attachments&mode=attach');
+
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'config[check_attachment_content]' => 0,
+ 'config[img_imagick]' => '',
+ ));
+ self::submit($form);
+
+ // Request index for correct URL
+ self::request('GET', 'index.php?sid=' . $this->sid);
+
+ $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
+
+ // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the
+ // DISALLOWED_CONTENT check
+ $this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text());
+
+ // Reset check_attachment_content to default (enabled)
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_attachments&mode=attach');
+
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'config[check_attachment_content]' => 1,
+ ));
+ self::submit($form);
+ }
+
+ public function test_too_large()
+ {
+ $this->create_user('fileupload');
+ $this->login('fileupload');
+
+ $crawler = $this->upload_file('too-large.png', 'image/png');
+ $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_valid_file()
+ {
+ $this->login();
+
+ $crawler = $this->upload_file('valid.jpg', 'image/jpeg');
+
+ // Ensure there was no error message rendered
+ $this->assertNotContains('<h2>' . $this->lang('INFORMATION') . '</h2>', $this->get_content());
+
+ // Also the file name should be in the first row of the files table
+ $this->assertEquals('valid.jpg', $crawler->filter('span.file-name')->eq(1)->text());
+ }
+}
diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php
new file mode 100644
index 0000000000..6ece150b23
--- /dev/null
+++ b/tests/functional/fileupload_remote_test.php
@@ -0,0 +1,79 @@
+<?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 __DIR__ . '/../../phpBB/includes/functions_upload.php';
+
+/**
+ * @group functional
+ */
+class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+ // Only doing this within the functional framework because we need a
+ // URL
+
+ // Global $config required by unique_id
+ // Global $user required by fileupload::remote_upload
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ public function tearDown()
+ {
+ global $config, $user;
+ $user = null;
+ $config = array();
+ }
+
+ public function test_invalid_extension()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload(self::$root_url . 'develop/blank.gif');
+ $this->assertEquals('URL_INVALID', $file->error[0]);
+ }
+
+ public function test_empty_file()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg');
+ $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);
+ }
+
+ public function test_successful_upload()
+ {
+ $upload = new fileupload('', array('gif'), 1000);
+ $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals(0, sizeof($file->error));
+ $this->assertTrue(file_exists($file->filename));
+ }
+
+ public function test_too_large()
+ {
+ $upload = new fileupload('', array('gif'), 100);
+ $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals(1, sizeof($file->error));
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php
new file mode 100644
index 0000000000..ec378e0e75
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php
@@ -0,0 +1,37 @@
+<?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.
+*
+*/
+
+namespace foo\bar\acp;
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class main_info
+{
+ function module()
+ {
+ return array(
+ 'filename' => 'foo\bar\acp\main_module',
+ 'title' => 'ACP_FOOBAR_TITLE',
+ 'version' => '1.0.0',
+ 'modes' => array(
+ 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')),
+ ),
+ );
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php
new file mode 100644
index 0000000000..ee797c718d
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php
@@ -0,0 +1,33 @@
+<?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.
+*
+*/
+
+namespace foo\bar\acp;
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class main_module
+{
+ var $u_action;
+
+ function main($id, $mode)
+ {
+ $this->tpl_name = 'foobar';
+ $this->page_title = 'Bertie';
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html
new file mode 100644
index 0000000000..3cb45c269c
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html
@@ -0,0 +1,3 @@
+<!-- INCLUDE overall_header.html -->
+Bertie rulez!
+<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/ext/foo/bar/composer.json b/tests/functional/fixtures/ext/foo/bar/composer.json
new file mode 100644
index 0000000000..f0c7f0e6c1
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "foo/bar",
+ "type": "phpbb-extension",
+ "description": "Testing extensions",
+ "homepage": "",
+ "version": "1.0.0",
+ "time": "2013-03-21 01:01:01",
+ "license": "GPL-2.0",
+ "authors": [{
+ "name": "Joas Schilling",
+ "email": "nickvergessen@phpbb.com",
+ "homepage": "http://www.phpbb.com",
+ "role": "Developer"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "extra": {
+ "display-name": "phpBB 3.1 Extension Testing",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
new file mode 100644
index 0000000000..374a58046d
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
@@ -0,0 +1,35 @@
+foo_bar_controller:
+ path: /foo/bar
+ defaults: { _controller: foo_bar.controller:handle }
+
+foo_baz_controller:
+ path: /foo/baz
+ defaults: { _controller: foo_bar.controller:baz }
+
+foo_template_controller:
+ path: /foo/template
+ defaults: { _controller: foo_bar.controller:template }
+
+foo_exception_controller:
+ path: /foo/exception
+ defaults: { _controller: foo_bar.controller:exception }
+
+foo_login_redirect_controller:
+ path: /foo/login_redirect
+ defaults: { _controller: foo_bar.controller:login_redirect }
+
+foo_redirect_controller:
+ path: /foo/redirect
+ defaults: { _controller: foo_bar.controller:redirect }
+
+foo_index_controller:
+ path: /index
+ defaults: { _controller: foo_bar.controller:redirect }
+
+foo_tests_index_controller:
+ path: /tests/index
+ defaults: { _controller: foo_bar.controller:redirect }
+
+foo_tests_dotdot_index_controller:
+ path: /tests/../index
+ defaults: { _controller: foo_bar.controller:redirect }
diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml
new file mode 100644
index 0000000000..d35be7955a
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml
@@ -0,0 +1,20 @@
+services:
+ foo_bar.controller:
+ class: foo\bar\controller\controller
+ arguments:
+ - @controller.helper
+ - @path_helper
+ - @template
+ - @config
+ - @user
+ - %core.root_path%
+ - %core.php_ext%
+
+ foo_bar.listener.permission:
+ class: foo\bar\event\permission
+ tags:
+ - { name: event.listener }
+ foo_bar.listener.user_setup:
+ class: foo\bar\event\user_setup
+ tags:
+ - { name: event.listener }
diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
new file mode 100644
index 0000000000..47d856a5df
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
@@ -0,0 +1,109 @@
+<?php
+
+namespace foo\bar\controller;
+
+use Symfony\Component\HttpFoundation\Response;
+
+class controller
+{
+ protected $template;
+ protected $helper;
+ protected $path_helper;
+ protected $config;
+ protected $user;
+
+ public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, \phpbb\user $user, $root_path, $php_ext)
+ {
+ $this->template = $template;
+ $this->helper = $helper;
+ $this->path_helper = $path_helper;
+ $this->config = $config;
+ $this->user = $user;
+ $this->root_path = $root_path;
+ $this->php_ext = $php_ext;
+ }
+
+ public function handle()
+ {
+ return new Response('foo/bar controller handle() method', 200);
+ }
+
+ public function baz($test)
+ {
+ return new Response('Value of "test" URL argument is: ' . $test);
+ }
+
+ public function template()
+ {
+ $this->template->assign_var('A_VARIABLE', 'I am a variable');
+
+ return $this->helper->render('foo_bar_body.html');
+ }
+
+ public function exception()
+ {
+ throw new \phpbb\controller\exception('Exception thrown from foo/exception route');
+ }
+
+ public function login_redirect()
+ {
+ if (!$this->user->data['is_registered'])
+ {
+ login_box();
+ }
+
+ $this->template->assign_var('A_VARIABLE', 'I am a variable');
+
+ return $this->helper->render('foo_bar_body.html');
+ }
+
+ public function redirect()
+ {
+ $url_root = generate_board_url();
+
+ $rewrite_prefix = (!empty($this->config['enable_mod_rewrite'])) ? '' : 'app.php/';
+
+ $redirects = array(
+ array(
+ append_sid($this->root_path . 'index.' . $this->php_ext),
+ 'index.php',
+ ),
+ array(
+ append_sid($this->root_path . 'foo/bar/index.' . $this->php_ext),
+ 'foo/bar/index.php',
+ ),
+ array(
+ append_sid($this->root_path . 'tests/index.' . $this->php_ext),
+ 'tests/index.php',
+ ),
+ array(
+ $this->helper->route('foo_index_controller'),
+ $rewrite_prefix . 'index',
+ ),
+ array(
+ $this->helper->route('foo_tests_index_controller'),
+ $rewrite_prefix . 'tests/index',
+ ),
+ /**
+ * Symfony does not allow /../ in routes
+ array(
+ $this->helper->route('foo_tests_dotdot_index_controller'),
+ $rewrite_prefix . 'index',
+ ),
+ */
+ );
+
+ foreach ($redirects as $redirect)
+ {
+ $this->template->assign_block_vars('redirects', array(
+ 'URL' => redirect($redirect[0], true),
+ ));
+
+ $this->template->assign_block_vars('redirects_expected', array(
+ 'URL' => $this->path_helper->clean_url($url_root . '/' . $redirect[1]),
+ ));
+ }
+
+ return $this->helper->render('redirect_body.html');
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/event/permission.php b/tests/functional/fixtures/ext/foo/bar/event/permission.php
new file mode 100644
index 0000000000..cdbdf40465
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/event/permission.php
@@ -0,0 +1,36 @@
+<?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.
+*
+*/
+
+namespace foo\bar\event;
+
+/**
+* Event listener
+*/
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+class permission implements EventSubscriberInterface
+{
+ static public function getSubscribedEvents()
+ {
+ return array(
+ 'core.permissions' => 'add_permissions',
+ );
+ }
+
+ public function add_permissions($event)
+ {
+ $permissions = $event['permissions'];
+ $permissions['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post');
+ $event['permissions'] = $permissions;
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/event/user_setup.php b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php
new file mode 100644
index 0000000000..3a60019f68
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php
@@ -0,0 +1,39 @@
+<?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.
+*
+*/
+
+namespace foo\bar\event;
+
+/**
+* Event listener
+*/
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+class user_setup implements EventSubscriberInterface
+{
+ static public function getSubscribedEvents()
+ {
+ return array(
+ 'core.user_setup' => 'add_global_translations',
+ );
+ }
+
+ public function add_global_translations($event)
+ {
+ $lang_set_ext = $event['lang_set_ext'];
+ $lang_set_ext[] = array(
+ 'ext_name' => 'foo/bar',
+ 'lang_set' => 'foo_global',
+ );
+ $event['lang_set_ext'] = $lang_set_ext;
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php
new file mode 100644
index 0000000000..1288edd5ec
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/ext.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace foo\bar;
+
+class ext extends \phpbb\extension\base
+{
+
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php b/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php
new file mode 100644
index 0000000000..a6af8680d3
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php
@@ -0,0 +1,5 @@
+<?php
+
+$lang = array_merge($lang, array(
+ 'SKIP' => 'Overwritten by foo',
+));
diff --git a/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php
new file mode 100644
index 0000000000..64b497c394
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php
@@ -0,0 +1,5 @@
+<?php
+
+$lang = array_merge($lang, array(
+ 'ACL_U_FOOBAR' => 'Can view foobar with permission foo',
+));
diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
new file mode 100644
index 0000000000..8fb6994d3d
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
@@ -0,0 +1,3 @@
+<!-- INCLUDE overall_header.html -->
+<div id="content">{A_VARIABLE}</div>
+<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html
new file mode 100644
index 0000000000..cbded623f4
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html
@@ -0,0 +1,3 @@
+<!-- INCLUDE overall_header.html -->
+<div id="content">UCP Extension Template Test Passed!</div>
+<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html
new file mode 100644
index 0000000000..2b70b0fe59
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html
@@ -0,0 +1,8 @@
+<!-- INCLUDE overall_header.html -->
+<!-- BEGIN redirects -->
+<div id="redirect_{redirects.S_ROW_COUNT}">{redirects.URL}</div>
+<!-- END redirects -->
+<!-- BEGIN redirects_expected -->
+<div id="redirect_expected_{redirects_expected.S_ROW_COUNT}">{redirects_expected.URL}</div>
+<!-- END redirects_expected -->
+<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php
new file mode 100644
index 0000000000..d34244f800
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php
@@ -0,0 +1,29 @@
+<?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.
+*
+*/
+
+namespace foo\bar\ucp;
+
+class main_info
+{
+ function module()
+ {
+ return array(
+ 'filename' => '\foo\bar\ucp\main_module',
+ 'title' => 'ACP_FOOBAR_TITLE',
+ 'version' => '1.0.0',
+ 'modes' => array(
+ 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')),
+ ),
+ );
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php
new file mode 100644
index 0000000000..f1cd03f4ab
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php
@@ -0,0 +1,25 @@
+<?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.
+*
+*/
+
+namespace foo\bar\ucp;
+
+class main_module
+{
+ var $u_action;
+
+ function main($id, $mode)
+ {
+ $this->tpl_name = 'foobar';
+ $this->page_title = 'Bertie';
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/foo/composer.json b/tests/functional/fixtures/ext/foo/foo/composer.json
new file mode 100644
index 0000000000..d85c76a6a2
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "foo/foo",
+ "type": "phpbb-extension",
+ "description": "Testing extensions",
+ "homepage": "",
+ "version": "1.0.0",
+ "time": "2013-03-21 01:01:01",
+ "license": "GPL-2.0",
+ "authors": [{
+ "name": "Tristan Darricau",
+ "email": "nicofuma@phpbb.com",
+ "homepage": "http://www.phpbb.com",
+ "role": "Developer"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "extra": {
+ "display-name": "phpBB 3.1 Extension Testing",
+ "soft-require": {
+ "phpbb/phpbb": "3.1.*@dev"
+ }
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/foo/config/resource.yml b/tests/functional/fixtures/ext/foo/foo/config/resource.yml
new file mode 100644
index 0000000000..4f2b9cce70
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/config/resource.yml
@@ -0,0 +1,3 @@
+foo_foo_controller:
+ path: /foo
+ defaults: { _controller: foo_foo.controller:handle }
diff --git a/tests/functional/fixtures/ext/foo/foo/config/routing.yml b/tests/functional/fixtures/ext/foo/foo/config/routing.yml
new file mode 100644
index 0000000000..c2c401687d
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/config/routing.yml
@@ -0,0 +1,3 @@
+foo_foo.general:
+ resource: "resource.yml"
+ prefix: /foo
diff --git a/tests/functional/fixtures/ext/foo/foo/config/services.yml b/tests/functional/fixtures/ext/foo/foo/config/services.yml
new file mode 100644
index 0000000000..b3c7719715
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ foo_foo.controller:
+ class: foo\foo\controller\controller
diff --git a/tests/functional/fixtures/ext/foo/foo/controller/controller.php b/tests/functional/fixtures/ext/foo/foo/controller/controller.php
new file mode 100644
index 0000000000..771eaeacfc
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/controller/controller.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace foo\foo\controller;
+
+use Symfony\Component\HttpFoundation\Response;
+
+class controller
+{
+ public function handle()
+ {
+ return new Response('foo/foo controller handle() method', 200);
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/foo/ext.php b/tests/functional/fixtures/ext/foo/foo/ext.php
new file mode 100644
index 0000000000..80acda74fe
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/foo/ext.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace foo\foo;
+
+class ext extends \phpbb\extension\base
+{
+
+}
diff --git a/tests/functional/fixtures/files/disallowed.jpg b/tests/functional/fixtures/files/disallowed.jpg
new file mode 100644
index 0000000000..06a437585a
--- /dev/null
+++ b/tests/functional/fixtures/files/disallowed.jpg
Binary files differ
diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/functional/fixtures/files/empty.png
diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/functional/fixtures/files/illegal-extension.bif
Binary files differ
diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png
new file mode 100644
index 0000000000..ed4b0abd80
--- /dev/null
+++ b/tests/functional/fixtures/files/too-large.png
Binary files differ
diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg
new file mode 100644
index 0000000000..95a87ddbdf
--- /dev/null
+++ b/tests/functional/fixtures/files/valid.jpg
Binary files differ
diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php
new file mode 100644
index 0000000000..64fa19557f
--- /dev/null
+++ b/tests/functional/forgot_password_test.php
@@ -0,0 +1,61 @@
+<?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_forgot_password_test extends phpbb_functional_test_case
+{
+ public function test_forgot_password_enabled()
+ {
+ global $config;
+ $this->add_lang('ucp');
+ $crawler = self::request('GET', 'ucp.php?mode=sendpassword');
+ $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text());
+ }
+
+ public function test_forgot_password_disabled()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('ucp');
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[allow_password_reset]"] = 0;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+
+ $this->logout();
+
+ $crawler = self::request('GET', 'ucp.php?mode=sendpassword');
+ $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text());
+
+ }
+
+ public function tearDown()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security');
+
+ // Enable allow_password_reset again after test
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'config[allow_password_reset]' => 1,
+ ));
+ $crawler = self::submit($form);
+ }
+}
diff --git a/tests/functional/forum_password_test.php b/tests/functional/forum_password_test.php
new file mode 100644
index 0000000000..4b2b69a92c
--- /dev/null
+++ b/tests/functional/forum_password_test.php
@@ -0,0 +1,59 @@
+<?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_forum_password_test extends phpbb_functional_test_case
+{
+ public function test_setup_forum_with_password()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Password protected',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ 'forum_password' => 'foobar',
+ 'forum_password_confirm' => 'foobar',
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function data_enter_forum_with_password()
+ {
+ return array(
+ array('foowrong', 'WRONG_PASSWORD'),
+ array('foobar', 'NO_TOPICS'),
+ );
+ }
+
+ /**
+ * @dataProvider data_enter_forum_with_password
+ */
+ public function test_enter_forum_with_password($password, $message)
+ {
+ $crawler = self::request('GET', "index.php?sid={$this->sid}");
+ preg_match('/.?f=([0-9])/', $crawler->selectLink('Password protected')->link()->getUri(), $match);
+ $crawler = self::request('GET', "viewforum.php?f={$match[1]}&sid={$this->sid}");
+ $form = $crawler->selectButton('login')->form(array(
+ 'password' => $password,
+ ));
+ $crawler = self::submit($form);
+ $this->assertContainsLang($message, $crawler->text());
+ }
+}
diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php
index 59f7341eb6..65be94f4d0 100644
--- a/tests/functional/forum_style_test.php
+++ b/tests/functional/forum_style_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functional/group_create_test.php b/tests/functional/group_create_test.php
new file mode 100644
index 0000000000..a1417b5ba0
--- /dev/null
+++ b/tests/functional/group_create_test.php
@@ -0,0 +1,35 @@
+<?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_group_create_test extends phpbb_functional_test_case
+{
+
+ public function test_create_group()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/groups');
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_groups&mode=manage&sid=' . $this->sid);
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $crawler = self::submit($form, array('group_name' => 'testtest'));
+
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $crawler = self::submit($form, array('group_name' => 'testtest'));
+
+ $this->assertContainsLang('GROUP_CREATED', $crawler->filter('#main')->text());
+ }
+}
diff --git a/tests/functional/jumpbox_test.php b/tests/functional/jumpbox_test.php
new file mode 100644
index 0000000000..f5a671b1b9
--- /dev/null
+++ b/tests/functional/jumpbox_test.php
@@ -0,0 +1,35 @@
+<?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_jumpbox_test extends phpbb_functional_test_case
+{
+ public function test_jumpbox()
+ {
+ $this->login();
+
+ $this->crawler = $this->get_quickmod_page(1, 'MERGE_TOPIC');
+ $this->check_valid_jump('Your first forum');
+
+ $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');
+ }
+
+ 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/lang_test.php b/tests/functional/lang_test.php
index 053806a431..7cffd0ef61 100644
--- a/tests/functional/lang_test.php
+++ b/tests/functional/lang_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functional/mcp_test.php b/tests/functional/mcp_test.php
index f65a7d0784..40615d66a5 100644
--- a/tests/functional/mcp_test.php
+++ b/tests/functional/mcp_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -31,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);
}
/**
@@ -64,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/memberlist_test.php b/tests/functional/memberlist_test.php
new file mode 100644
index 0000000000..1da5c39401
--- /dev/null
+++ b/tests/functional/memberlist_test.php
@@ -0,0 +1,137 @@
+<?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_memberlist_test extends phpbb_functional_test_case
+{
+ public function test_memberlist()
+ {
+ $this->create_user('memberlist-test-user');
+ // logs in as admin
+ $this->login();
+ $crawler = self::request('GET', 'memberlist.php?sid=' . $this->sid);
+ $this->assertContains('memberlist-test-user', $crawler->text());
+
+ // restrict by first character
+ $crawler = self::request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
+ $this->assertContains('memberlist-test-user', $crawler->text());
+
+ // make sure results for wrong character are not returned
+ $crawler = self::request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
+ $this->assertNotContains('memberlist-test-user', $crawler->text());
+ }
+
+ public function test_viewprofile()
+ {
+ $this->login();
+ // XXX hardcoded user id
+ $crawler = self::request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
+ $this->assertContains('admin', $crawler->filter('h2')->text());
+ }
+
+ protected function get_memberlist_leaders_table_crawler()
+ {
+ $crawler = self::request('GET', 'memberlist.php?mode=team&sid=' . $this->sid);
+ return $crawler->filter('.forumbg-table');
+ }
+
+ public function test_leaders()
+ {
+ $this->login();
+ $this->create_user('memberlist-test-moderator');
+
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+
+ // Admin in admin group, but not in moderators
+ $this->assertContains('admin', $crawler->eq(0)->text());
+ $this->assertNotContains('admin', $crawler->eq(1)->text());
+
+ // memberlist-test-user in neither group
+ $this->assertNotContains('memberlist-test-user', $crawler->eq(0)->text());
+ $this->assertNotContains('memberlist-test-user', $crawler->eq(1)->text());
+
+ // memberlist-test-moderator in neither group
+ $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text());
+ $this->assertNotContains('memberlist-test-moderator', $crawler->eq(1)->text());
+ }
+
+ public function test_leaders_remove_users()
+ {
+ $this->login();
+
+ // Remove admin from admins, but is now in moderators
+ $this->remove_user_group('ADMINISTRATORS', array('admin'));
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+ $this->assertNotContains('admin', $crawler->eq(0)->text());
+ $this->assertContains('admin', $crawler->eq(1)->text());
+
+ // Remove admin from moderators, should not be visible anymore
+ $this->remove_user_group('GLOBAL_MODERATORS', array('admin'));
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+ $this->assertNotContains('admin', $crawler->eq(0)->text());
+ $this->assertNotContains('admin', $crawler->eq(1)->text());
+ }
+
+ public function test_leaders_add_users()
+ {
+ $this->login();
+
+ // Add memberlist-test-moderator to moderators
+ $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator'));
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+ $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text());
+ $this->assertContains('memberlist-test-moderator', $crawler->eq(1)->text());
+
+ // Add admin to moderators, should be visible as moderator
+ $this->add_user_group('GLOBAL_MODERATORS', array('admin'), true);
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+ $this->assertNotContains('admin', $crawler->eq(0)->text());
+ $this->assertContains('admin', $crawler->eq(1)->text());
+
+ // Add admin to admins as leader, should be visible as admin, not moderator
+ $this->add_user_group('ADMINISTRATORS', array('admin'), true, true);
+ $crawler = $this->get_memberlist_leaders_table_crawler();
+ $this->assertContains('admin', $crawler->eq(0)->text());
+ $this->assertNotContains('admin', $crawler->eq(1)->text());
+ }
+
+ public function test_group_rank()
+ {
+ copy(__DIR__ . '/fixtures/files/valid.jpg', __DIR__ . '/../../phpBB/images/ranks/valid.jpg');
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang(array('acp/groups', 'acp/posting'));
+
+ // Set a group rank to the registered users
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_groups&mode=manage&action=edit&g=2");
+ $form = $crawler->selectButton('Submit')->form();
+ $form['group_rank']->select('1');
+ $crawler = self::submit($form);
+ $this->assertContainsLang('GROUP_UPDATED', $crawler->filter('.successbox')->text());
+
+ // Set a rank image for site_admin
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_ranks&mode=ranks&action=edit&id=1");
+ $form = $crawler->selectButton('Submit')->form();
+ $form['rank_image']->select('valid.jpg');
+ $crawler = self::submit($form);
+ $this->assertContainsLang('RANK_UPDATED', $crawler->filter('.successbox')->text());
+
+ $crawler = self::request('GET', 'memberlist.php?mode=group&g=2');
+ $this->assertContains('memberlist-test-user', $crawler->text());
+
+ unlink(__DIR__ . '/../../phpBB/images/ranks/valid.jpg');
+ }
+}
diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php
new file mode 100644
index 0000000000..0d2fdf082e
--- /dev/null
+++ b/tests/functional/metadata_manager_test.php
@@ -0,0 +1,94 @@
+<?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_metadata_manager_test extends phpbb_functional_test_case
+{
+ protected $phpbb_extension_manager;
+
+ static private $helper;
+
+ static protected $fixtures = array(
+ 'foo/bar/',
+ );
+
+ public function tearDown()
+ {
+ $this->purge_cache();
+
+ parent::tearDown();
+ }
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+ self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures);
+ }
+
+ static public function tearDownAfterClass()
+ {
+ parent::tearDownAfterClass();
+
+ self::$helper->restore_original_ext_dir();
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+
+ $this->purge_cache();
+ $this->phpbb_extension_manager->enable('foo/bar');
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/extensions');
+ }
+
+ public function test_extensions_list()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
+ $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text());
+ $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text());
+ $this->assertContains('Details', $crawler->filter('#main')->text());
+ }
+
+ public function test_extensions_details()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid);
+
+ // Test whether the details are displayed
+ $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text());
+ $this->assertContains('foo/bar', $crawler->filter('#meta_name')->text());
+
+ $this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#main')->text());
+ $this->assertContains('>=5.3', $crawler->filter('#require_php')->text());
+ // Details should be html escaped
+ // However, text() only returns the displayed text, so HTML Special Chars are decoded.
+ // So we test this directly on the content of the response.
+ $this->assertContains('<span id="require_php">&gt;=5.3</span>', $this->get_content());
+ }
+
+ public function test_extensions_details_notexists()
+ {
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid);
+
+ // Error message because the files do not exist
+ $this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('#main')->text());
+ }
+}
diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php
new file mode 100644
index 0000000000..f21d73817a
--- /dev/null
+++ b/tests/functional/notification_test.php
@@ -0,0 +1,88 @@
+<?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_notification_test extends phpbb_functional_test_case
+{
+ static public function user_subscription_data()
+ {
+ return array(
+ // Rows inserted by phpBB/install/schemas/schema_data.sql
+ // Also see PHPBB3-11460
+ array('notification.type.post_notification', true),
+ array('notification.type.topic_notification', true),
+ array('notification.type.post_notification.method.email', true),
+ array('notification.type.topic_notification.method.email', true),
+
+ // Default behaviour for in-board notifications:
+ // If user did not opt-out, in-board notifications are on.
+ array('notification.type.bookmark_notification', true),
+ array('notification.type.quote_notification', true),
+
+ // Default behaviour for email notifications:
+ // If user did not opt-in, email notifications are off.
+ array('notification.type.bookmark_notification.method.email', false),
+ array('notification.type.quote_notification.method.email', false),
+ );
+ }
+
+ /**
+ * @dataProvider user_subscription_data
+ */
+ public function test_user_subscriptions($checkbox_name, $expected_status)
+ {
+ $this->login();
+ $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
+
+ $cplist = $crawler->filter('.table1');
+ if ($expected_status)
+ {
+ $this->assert_checkbox_is_checked($cplist, $checkbox_name);
+ }
+ else
+ {
+ $this->assert_checkbox_is_unchecked($cplist, $checkbox_name);
+ }
+ }
+
+ public function test_mark_notifications_read()
+ {
+ // Create a new standard user
+ $this->create_user('notificationtestuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('notificationtestuser'));
+ $this->login('notificationtestuser');
+
+ // Post a new post that needs approval
+ $this->create_post(2, 1, 'Re: Welcome to phpBB3', 'This is a test [b]post[/b] posted by notificationtestuser.', array(), 'POST_STORED_MOD');
+ $crawler = self::request('GET', "viewtopic.php?t=1&sid={$this->sid}");
+ $this->assertNotContains('This is a test post posted by notificationtestuser.', $crawler->filter('html')->text());
+
+ // Login as admin
+ $this->logout();
+ $this->login();
+ $this->add_lang('ucp');
+
+ $crawler = self::request('GET', 'ucp.php?i=ucp_notifications');
+
+ // At least one notification should exist
+ $this->assertGreaterThan(0, $crawler->filter('#notification_list_button strong')->text());
+
+ // Get form token
+ $link = $crawler->selectLink($this->lang('NOTIFICATIONS_MARK_ALL_READ'))->link()->getUri();
+ $crawler = self::request('GET', substr($link, strpos($link, 'ucp.')));
+ $this->assertCount(1, $crawler->filter('#notification_list_button strong.badge.hidden'));
+ $this->assertEquals("0", $crawler->filter('#notification_list_button strong.badge.hidden')->text());
+ }
+}
diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php
new file mode 100644
index 0000000000..cfaf9104a8
--- /dev/null
+++ b/tests/functional/paging_test.php
@@ -0,0 +1,43 @@
+<?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_paging_test extends phpbb_functional_test_case
+{
+
+ public function test_pagination()
+ {
+ $this->login();
+
+ $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
+ for ($post_id = 1; $post_id <= 16; $post_id++)
+ {
+ $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.');
+ }
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+ $this->assertContains('post no4', $crawler->text());
+ $this->assertNotContains('post no16', $crawler->text());
+
+ $next_link = $crawler->filter('.pagination > ul > li.next > a')->attr('href');
+ $crawler = self::request('GET', $next_link);
+ $this->assertNotContains('post no4', $crawler->text());
+ $this->assertContains('post no16', $crawler->text());
+
+ $prev_link = $crawler->filter('.pagination > ul > li.previous > a')->attr('href');
+ $crawler = self::request('GET', $prev_link);
+ $this->assertContains('post no4', $crawler->text());
+ $this->assertNotContains('post no16', $crawler->text());
+ }
+}
diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php
new file mode 100644
index 0000000000..d358681ad1
--- /dev/null
+++ b/tests/functional/plupload_test.php
@@ -0,0 +1,154 @@
+<?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_plupload_test extends phpbb_functional_test_case
+{
+ const CHUNKS = 4;
+ private $path;
+
+ protected function set_extension_group_permission($val)
+ {
+ $db = $this->get_db();
+ $query = "
+ UPDATE phpbb_extension_groups
+ SET allow_in_pm = '$val'
+ WHERE group_name = 'IMAGES'
+ ";
+ $db->sql_query($query);
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->purge_cache();
+ $this->set_extension_group_permission(1);
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->add_lang('posting');
+ $this->login();
+ }
+
+ public function tearDown()
+ {
+ $this->set_extension_group_permission(0);
+ $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/');
+ foreach ($iterator as $fileinfo)
+ {
+ if (
+ $fileinfo->isDot()
+ || $fileinfo->isDir()
+ || $fileinfo->getFilename() === 'index.htm'
+ || $fileinfo->getFilename() === '.htaccess'
+ )
+ {
+ continue;
+ }
+
+ unlink($fileinfo->getPathname());
+ }
+ }
+
+ public function get_urls()
+ {
+ return array(
+ array('posting.php?mode=reply&f=2&t=1'),
+ array('ucp.php?i=pm&mode=compose'),
+ );
+ }
+
+ /**
+ * @dataProvider get_urls
+ */
+ public function test_chunked_upload($url)
+ {
+ $chunk_size = ceil(filesize($this->path . 'valid.jpg') / self::CHUNKS);
+ $handle = fopen($this->path . 'valid.jpg', 'rb');
+
+ for ($i = 0; $i < self::CHUNKS; $i++)
+ {
+ $chunk = fread($handle, $chunk_size);
+ file_put_contents($this-> path . 'chunk', $chunk);
+
+ $file = array(
+ 'tmp_name' => $this->path . 'chunk',
+ 'name' => 'blob',
+ 'type' => 'application/octet-stream',
+ 'size' => strlen($chunk),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ self::$client->setServerParameter('HTTP_X_PHPBB_USING_PLUPLOAD', '1');
+
+ $crawler = self::$client->request(
+ 'POST',
+ $url . '&sid=' . $this->sid,
+ array(
+ 'chunk' => $i,
+ 'chunks' => self::CHUNKS,
+ 'name' => md5('valid') . '.jpg',
+ 'real_filename' => 'valid.jpg',
+ 'add_file' => $this->lang('ADD_FILE'),
+ ),
+ array('fileupload' => $file),
+ array('X-PHPBB-USING-PLUPLOAD' => '1')
+ );
+
+ if ($i < self::CHUNKS - 1)
+ {
+ $this->assertContains('{"jsonrpc":"2.0","id":"id","result":null}', self::$client->getResponse()->getContent());
+ }
+ else
+ {
+ $response = json_decode(self::$client->getResponse()->getContent(), true);
+ $this->assertEquals('valid.jpg', $response['data'][0]['real_filename']);
+ }
+
+ unlink($this->path . 'chunk');
+ }
+
+ fclose($handle);
+ }
+
+ /**
+ * @dataProvider get_urls
+ */
+ public function test_normal_upload($url)
+ {
+ $file = array(
+ 'tmp_name' => $this->path . 'valid.jpg',
+ 'name' => 'valid.jpg',
+ 'type' => 'image/jpeg',
+ 'size' => filesize($this->path . 'valid.jpg'),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = self::$client->request(
+ 'POST',
+ $url . '&sid=' . $this->sid,
+ array(
+ 'chunk' => '0',
+ 'chunks' => '1',
+ 'name' => md5('valid') . '.jpg',
+ 'real_filename' => 'valid.jpg',
+ 'add_file' => $this->lang('ADD_FILE'),
+ ),
+ array('fileupload' => $file),
+ array('X-PHPBB-USING-PLUPLOAD' => '1')
+ );
+
+ $response = json_decode(self::$client->getResponse()->getContent(), true);
+ $this->assertEquals('valid.jpg', $response['data'][0]['real_filename']);
+ }
+}
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
index 7fd1e4fdcf..914233240e 100644
--- a/tests/functional/posting_test.php
+++ b/tests/functional/posting_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -22,8 +26,8 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
$crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text());
- // Test creating a reply
- $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.');
+ // Test creating a reply with bbcode
+ $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test [b]post[/b] posted by the testing framework.');
$crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
@@ -32,4 +36,124 @@ 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'
+ );
+ }
+
+ /**
+ * @testdox max_quote_depth is applied to the text populating the posting form
+ */
+ public function test_quote_depth_form()
+ {
+ $text = '0[quote]1[quote]2[/quote]1[/quote]0';
+ $expected = array(
+ 0 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]',
+ 1 => '[quote="admin"]00[/quote]',
+ 2 => '[quote="admin"]0[quote]11[/quote]0[/quote]',
+ 3 => '[quote="admin"]0[quote]1[quote]2[/quote]1[/quote]0[/quote]',
+ );
+
+ $this->login();
+ $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
+ $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text);
+ $quote_url = "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}";
+
+ $this->admin_login();
+ foreach ($expected as $quote_depth => $expected_text)
+ {
+ $this->set_quote_depth($quote_depth);
+ $crawler = self::request('GET', $quote_url);
+ $this->assertContains($expected_text, $crawler->filter('textarea#message')->text());
+ }
+ }
+
+ /**
+ * @testdox max_quote_depth is applied to the submitted text
+ */
+ public function test_quote_depth_submit()
+ {
+ $text = 'depth:0[quote]depth:1[quote]depth:2[quote]depth:3[/quote][/quote][/quote]';
+ $contains = array(
+ 0 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'),
+ 1 => array('depth:0', 'depth:1'),
+ 2 => array('depth:0', 'depth:1', 'depth:2'),
+ 3 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'),
+ );
+ $not_contains = array(
+ 0 => array(),
+ 1 => array('depth:2', 'depth:3'),
+ 2 => array('depth:3'),
+ 3 => array(),
+ );
+
+ $this->login();
+ $this->admin_login();
+ $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
+
+ for ($quote_depth = 0; $quote_depth <= 2; ++$quote_depth)
+ {
+ $this->set_quote_depth($quote_depth);
+
+ $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text);
+ $url = "viewtopic.php?p={$post['post_id']}&sid={$this->sid}";
+
+ $crawler = self::request('GET', $url);
+ $text_content = $crawler->filter('#p' . $post['post_id'])->text();
+ foreach ($contains[$quote_depth] as $contains_text)
+ {
+ $this->assertContains($contains_text, $text_content);
+ }
+ foreach ($not_contains[$quote_depth] as $not_contains_text)
+ {
+ $this->assertNotContains($not_contains_text, $text_content);
+ }
+ }
+ }
+
+ public function test_post_poll()
+ {
+ $this->login();
+
+ $post = $this->create_topic(
+ 2,
+ '[ticket/14802] Test Poll Option Spacing',
+ 'Empty/blank lines should not be additional poll options.',
+ array('poll_title' => 'Poll Title', 'poll_option_text' => "\n A \nB\n\nC \n D\nE\n\n \n")
+ );
+
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+ $this->assertEquals('Poll Title', $crawler->filter('.poll-title')->text());
+ $this->assertEquals(5, $crawler->filter('*[data-poll-option-id]')->count());
+ }
+
+ protected function set_quote_depth($depth)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+ $values['config[max_quote_depth]'] = $depth;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertEquals(1, $crawler->filter('.successbox')->count());
+ }
}
diff --git a/tests/functional/private_messages_test.php b/tests/functional/private_messages_test.php
index 15aa2b681a..1f6dc3a979 100644
--- a/tests/functional/private_messages_test.php
+++ b/tests/functional/private_messages_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php
new file mode 100644
index 0000000000..c014119b98
--- /dev/null
+++ b/tests/functional/prune_shadow_topic_test.php
@@ -0,0 +1,211 @@
+<?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_prune_shadow_topic_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+ protected $post;
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Prune Shadow',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ 'enable_shadow_prune' => true,
+ 'prune_shadow_freq' => 1,
+ 'prune_shadow_days' => 1,
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function test_create_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Prune Shadow',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ // Test creating topic
+ $this->post = $this->create_topic($this->data['forums']['Prune Shadow'], 'Prune Shadow #1', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Prune Shadow #1', $crawler->filter('html')->text());
+ $this->data['topics']['Prune Shadow #1'] = (int) $this->post['topic_id'];
+ $this->data['posts']['Prune Shadow #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ $this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Prune Shadow #1'],
+ ), 'after creating topic #1');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Prune Shadow'], $this->post['topic_id'], 'Re: Prune Shadow #1-#2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Prune Shadow #1-#2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Prune Shadow #1-#2'] = (int) $post2['post_id'];
+
+ $this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Prune Shadow #1-#2'],
+ ), 'after replying');
+ }
+
+ public function test_move_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Prune Shadow',
+ ),
+ 'topics' => array(
+ 'Prune Shadow #1',
+ ),
+ ));
+
+ $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Prune Shadow']}&i=main&action=move&mode=forum_view&start=0&topic_id_list[]={$this->data['topics']['Prune Shadow #1']}&sid={$this->sid}");
+ $form = $crawler->selectButton('confirm')->form(array(
+ 'to_forum_id' => 2,
+ 'move_leave_shadow' => true,
+ ));
+ $crawler = self::submit($form);
+
+ $this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ ), 'after moving');
+
+ $this->db = $this->get_db();
+ // Date topic 3 days back
+ $sql = 'UPDATE phpbb_topics
+ SET topic_last_post_time = ' . (time() - 60*60*24*3) . '
+ WHERE topic_id = ' . ($this->data['topics']['Prune Shadow #1'] + 1);
+ $result = $this->db->sql_query($sql);
+
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}");
+ $this->assertNotEmpty($crawler->filter('img')->last()->attr('src'));
+ self::request('GET', "cron.php?cron_type=cron.task.core.prune_shadow_topics&f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false);
+
+ $this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ ), 'after the cron job');
+ }
+
+ public function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ public function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functional/registration_test.php b/tests/functional/registration_test.php
new file mode 100644
index 0000000000..690f4ae9f2
--- /dev/null
+++ b/tests/functional/registration_test.php
@@ -0,0 +1,67 @@
+<?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_registration_test extends phpbb_functional_test_case
+{
+ public function test_disable_captcha_on_registration()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_board&mode=registration&sid={$this->sid}");
+ $form = $crawler->selectButton('Submit')->form();
+ $form['config[enable_confirm]']->setValue('0');
+ $crawler = self::submit($form);
+
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('#main .successbox')->text());
+ }
+
+ /**
+ * @depends test_disable_captcha_on_registration
+ */
+ public function test_register_new_account()
+ {
+ $this->add_lang('ucp');
+
+ $crawler = self::request('GET', 'ucp.php?mode=register');
+ $this->assertContainsLang('REGISTRATION', $crawler->filter('div.content h2')->text());
+
+ $form = $crawler->selectButton('I agree to these terms')->form();
+ $crawler = self::submit($form);
+
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'username' => 'user-reg-test',
+ 'email' => 'user-reg-test@phpbb.com',
+ 'new_password' => 'user-reg-testuser-reg-test',
+ 'password_confirm' => 'user-reg-testuser-reg-test',
+ ));
+ $form['tz']->select('Europe/Berlin');
+ $crawler = self::submit($form);
+
+ $this->assertContainsLang('ACCOUNT_ADDED', $crawler->filter('#message')->text());
+ }
+
+ /**
+ * @depends test_register_new_account
+ */
+ public function test_default_subscription_options()
+ {
+ $this->login('user-reg-test');
+ $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options&sid=' . $this->sid);
+ $this->assert_checkbox_is_checked($crawler, 'notification.type.post_notification.method.email');
+ $this->assert_checkbox_is_checked($crawler, 'notification.type.topic_notification.method.email');
+ }
+}
diff --git a/tests/functional/report_post_captcha_test.php b/tests/functional/report_post_captcha_test.php
index 8283465041..93a03bd931 100644
--- a/tests/functional/report_post_captcha_test.php
+++ b/tests/functional/report_post_captcha_test.php
@@ -1,11 +1,15 @@
<?php
/**
- *
- * @package testing
- * @copyright (c) 2013 phpBB Group
- * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
- *
- */
+*
+* 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
diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php
new file mode 100644
index 0000000000..f1e9b517d4
--- /dev/null
+++ b/tests/functional/search/base.php
@@ -0,0 +1,108 @@
+<?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
+*/
+abstract class phpbb_functional_search_base extends phpbb_functional_test_case
+{
+ protected function assert_search_found($keywords, $posts_found, $words_highlighted)
+ {
+ $crawler = self::request('GET', 'search.php?keywords=' . $keywords);
+ $this->assertEquals($posts_found, $crawler->filter('.postbody')->count());
+ $this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count());
+ }
+
+ protected function assert_search_not_found($keywords)
+ {
+ $crawler = self::request('GET', 'search.php?keywords=' . $keywords);
+ $this->assertEquals(0, $crawler->filter('.postbody')->count());
+ $split_keywords_string = str_replace(array('+', '-'), ' ', $keywords);
+ $this->assertEquals($split_keywords_string, $crawler->filter('#keywords')->attr('value'));
+ }
+
+ public function test_search_backend()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ if ($values["config[search_type]"] != $this->search_backend)
+ {
+ $values["config[search_type]"] = $this->search_backend;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+
+ $form = $crawler->selectButton('Yes')->form();
+ $values = $form->getValues();
+ $crawler = self::submit($form);
+
+ // check if search backend is not supported
+ if ($crawler->filter('.errorbox')->count() > 0)
+ {
+ $this->delete_topic($post['topic_id']);
+ $this->markTestSkipped("Search backend is not supported/running");
+ }
+ $this->create_search_index();
+ }
+
+ $this->logout();
+ $this->assert_search_found('phpbb3+installation', 1, 3);
+ $this->assert_search_found('foosubject+barsearch', 1, 2);
+ $this->assert_search_not_found('loremipsumdedo');
+
+ $this->login();
+ $this->admin_login();
+ $this->delete_search_index();
+ $this->delete_topic($post['topic_id']);
+ }
+
+ protected function create_search_index()
+ {
+ $this->add_lang('acp/search');
+ $crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
+ $form = $crawler->selectButton('Create index')->form();
+ $form_values = $form->getValues();
+ $form_values = array_merge($form_values,
+ array(
+ 'search_type' => $this->search_backend,
+ 'action' => 'create',
+ )
+ );
+ $form->setValues($form_values);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('SEARCH_INDEX_CREATED', $crawler->text());
+ }
+
+ protected function delete_search_index()
+ {
+ $this->add_lang('acp/search');
+ $crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
+ $form = $crawler->selectButton('Delete index')->form();
+ $form_values = $form->getValues();
+ $form_values = array_merge($form_values,
+ array(
+ 'search_type' => $this->search_backend,
+ 'action' => 'delete',
+ )
+ );
+ $form->setValues($form_values);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('SEARCH_INDEX_REMOVED', $crawler->text());
+ }
+}
diff --git a/tests/functional/search/mysql_test.php b/tests/functional/search/mysql_test.php
new file mode 100644
index 0000000000..a97b12e905
--- /dev/null
+++ b/tests/functional/search/mysql_test.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.
+*
+*/
+
+require_once dirname(__FILE__) . '/base.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_search_mysql_test extends phpbb_functional_search_base
+{
+ protected $search_backend = '\phpbb\search\fulltext_mysql';
+
+}
diff --git a/tests/functional/search/native_test.php b/tests/functional/search/native_test.php
new file mode 100644
index 0000000000..9908b9cdaa
--- /dev/null
+++ b/tests/functional/search/native_test.php
@@ -0,0 +1,22 @@
+<?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__) . '/base.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_search_native_test extends phpbb_functional_search_base
+{
+ protected $search_backend = '\phpbb\search\fulltext_native';
+}
diff --git a/tests/functional/search/postgres_test.php b/tests/functional/search/postgres_test.php
new file mode 100644
index 0000000000..a76cc13493
--- /dev/null
+++ b/tests/functional/search/postgres_test.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.
+*
+*/
+
+require_once dirname(__FILE__) . '/base.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_search_postgres_test extends phpbb_functional_search_base
+{
+ protected $search_backend = '\phpbb\search\fulltext_postgres';
+
+}
diff --git a/tests/functional/search/sphinx_test.php b/tests/functional/search/sphinx_test.php
new file mode 100644
index 0000000000..4bf1ab0e16
--- /dev/null
+++ b/tests/functional/search/sphinx_test.php
@@ -0,0 +1,27 @@
+<?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__) . '/base.php';
+
+/**
+* @group functional
+*/
+class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base
+{
+ protected $search_backend = '\phpbb\search\fulltext_sphinx';
+
+ public function test_search_backend()
+ {
+ $this->markTestIncomplete('Sphinx Tests are not supported');
+ }
+}
diff --git a/tests/functional/ucp_allow_pm_test.php b/tests/functional/ucp_allow_pm_test.php
new file mode 100644
index 0000000000..2d41296ddf
--- /dev/null
+++ b/tests/functional/ucp_allow_pm_test.php
@@ -0,0 +1,74 @@
+<?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_ucp_allow_pm_test extends phpbb_functional_test_case
+{
+ static protected $data = array();
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_ucp_allow_pm_test' => array('data'),
+ );
+ }
+
+ // user A sends a PM to user B where B accepts PM
+ public function test_enabled_pm_user_to_user()
+ {
+ // setup
+ $this->create_user('test_ucp_allow_pm_sender');
+ $this->login('test_ucp_allow_pm_sender');
+ self::$data['recipient_id'] = $this->create_user('test_ucp_allow_pm_recipient');
+ self::$data['pm_url'] = "ucp.php?i=pm&mode=compose&u=" . (int) self::$data['recipient_id'] . "&sid={$this->sid}";
+
+ // the actual test
+ $this->set_user_allow_pm(self::$data['recipient_id'], 1);
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
+ }
+
+ // user A sends a PM to user B where B does not accept PM
+ public function test_disabled_pm_user_to_user()
+ {
+ $this->login('test_ucp_allow_pm_sender');
+ $this->set_user_allow_pm(self::$data['recipient_id'], 0);
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('.error')->text());
+ }
+
+
+ // An admin sends a PM to user B where B does not accept PM, but cannot
+ // ignore a PM from an admin
+ public function test_disabled_pm_admin_to_user()
+ {
+ $this->login();
+ $crawler = self::request('GET', self::$data['pm_url']);
+ $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
+ }
+
+ // enable or disable PM for a user, like from ucp
+ protected function set_user_allow_pm($user_id, $allow)
+ {
+ $db = $this->get_db();
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_allow_pm = " . $allow . "
+ WHERE user_id = " . $user_id;
+ $result = $db->sql_query($sql);
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php
index 9c6b1edc5e..cd18a0fcae 100644
--- a/tests/functional/ucp_groups_test.php
+++ b/tests/functional/ucp_groups_test.php
@@ -1,21 +1,57 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/common_groups_test.php';
+require_once dirname(__FILE__) . '/common_groups_test_case.php';
/**
* @group functional
*/
-class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test
+class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test_case
{
+ protected $db;
+
protected function get_url()
{
return 'ucp.php?i=groups&mode=manage&action=edit';
}
+
+ protected function get_teampage_settings()
+ {
+ if (!isset($this->db))
+ {
+ $this->db = $this->get_db();
+ }
+ $sql = 'SELECT g.group_legend AS group_legend, t.teampage_position AS group_teampage
+ FROM ' . GROUPS_TABLE . ' g
+ LEFT JOIN ' . TEAMPAGE_TABLE . ' t
+ ON (t.group_id = g.group_id)
+ WHERE g.group_id = 5';
+ $result = $this->db->sql_query($sql);
+ $group_row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+ return $group_row;
+ }
+
+ public function test_ucp_groups_teampage()
+ {
+ $this->group_manage_login();
+
+ // Test if group_legend or group_teampage are modified while
+ // submitting the ucp_group_manage page
+ $form = $this->get_group_manage_form();
+ $teampage_settings = $this->get_teampage_settings();
+ $crawler = self::submit($form);
+ $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text());
+ $this->assertEquals($teampage_settings, $this->get_teampage_settings());
+ }
}
diff --git a/tests/functional/ucp_pm_test.php b/tests/functional/ucp_pm_test.php
new file mode 100644
index 0000000000..ddd5c8d791
--- /dev/null
+++ b/tests/functional/ucp_pm_test.php
@@ -0,0 +1,52 @@
+<?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_ucp_pm_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->login();
+ $this->admin_login();
+ }
+
+ public function test_pm_enabled()
+ {
+ $crawler = self::request('GET', 'ucp.php');
+ $this->assertContainsLang('PRIVATE_MESSAGES', $crawler->filter('html')->text());
+ }
+
+ public function test_pm_disabled()
+ {
+ $this->set_allow_pm(0);
+ $crawler = self::request('GET', 'ucp.php');
+ $this->assertNotContainsLang('PRIVATE_MESSAGES', $crawler->filter('html')->text());
+ $this->set_allow_pm(1);
+ }
+
+ protected function set_allow_pm($enable_pm)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=message');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[allow_privmsg]"] = $enable_pm;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+ }
+}
diff --git a/tests/functional/ucp_preferences_test.php b/tests/functional/ucp_preferences_test.php
new file mode 100644
index 0000000000..7ef325dc4b
--- /dev/null
+++ b/tests/functional/ucp_preferences_test.php
@@ -0,0 +1,85 @@
+<?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_ucp_preferences_test extends phpbb_functional_test_case
+{
+ public function test_submitting_preferences_view()
+ {
+ $this->add_lang('ucp');
+ $this->login();
+
+ $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view');
+ $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text());
+
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'topic_sk' => 'a',
+ 'topic_sd' => 'a',
+ 'topic_st' => '1',
+ 'post_sk' => 'a',
+ 'post_sd' => 'a',
+ 'post_st' => '1',
+ ));
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('PREFERENCES_UPDATED', $crawler->filter('#message')->text());
+ }
+
+ public function test_submitting_invalid_preferences_view()
+ {
+ $this->add_lang('ucp');
+ $this->login();
+
+ $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view');
+ $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text());
+ $form = $crawler->selectButton('Submit')->form();
+
+ if (!method_exists($form, 'disableValidation'))
+ {
+ $this->markTestIncomplete('The crawler cannot select invalid values, until Symfony 2.4!');
+ }
+
+ $form = $form->disableValidation();
+ $form['topic_sk']->select('z');
+ $form['topic_sd']->select('z');
+ $form['topic_st']->select('test');
+ $form['post_sk']->select('z');
+ $form['post_sd']->select('z');
+ $form['post_st']->select('test');
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('WRONG_DATA_POST_SD', $crawler->filter('#cp-main')->text());
+ $this->assertContainsLang('WRONG_DATA_POST_SK', $crawler->filter('#cp-main')->text());
+ $this->assertContainsLang('WRONG_DATA_TOPIC_SD', $crawler->filter('#cp-main')->text());
+ $this->assertContainsLang('WRONG_DATA_TOPIC_SK', $crawler->filter('#cp-main')->text());
+ }
+
+ public function test_read_preferences_view()
+ {
+ $this->add_lang('ucp');
+ $this->login();
+
+ $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view');
+ $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text());
+ $form = $crawler->selectButton('Submit')->form();
+
+ $this->assertEquals('a', $form->get('topic_sk')->getValue());
+ $this->assertEquals('a', $form->get('topic_sd')->getValue());
+ $this->assertEquals('1', $form->get('topic_st')->getValue());
+ $this->assertEquals('a', $form->get('post_sk')->getValue());
+ $this->assertEquals('a', $form->get('post_sd')->getValue());
+ $this->assertEquals('1', $form->get('post_st')->getValue());
+ }
+}
diff --git a/tests/functional/ucp_profile_test.php b/tests/functional/ucp_profile_test.php
new file mode 100644
index 0000000000..e7abba9255
--- /dev/null
+++ b/tests/functional/ucp_profile_test.php
@@ -0,0 +1,49 @@
+<?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_ucp_profile_test extends phpbb_functional_test_case
+{
+ public function test_submitting_profile_info()
+ {
+ $this->add_lang('ucp');
+ $this->login();
+
+ $crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info');
+ $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/user_password_reset_test.php b/tests/functional/user_password_reset_test.php
new file mode 100644
index 0000000000..3da78407cf
--- /dev/null
+++ b/tests/functional/user_password_reset_test.php
@@ -0,0 +1,169 @@
+<?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_user_password_reset_test extends phpbb_functional_test_case
+{
+ protected $user_data;
+
+ public function test_password_reset()
+ {
+ $this->add_lang('ucp');
+ $user_id = $this->create_user('reset-password-test-user');
+
+ $crawler = self::request('GET', "ucp.php?mode=sendpassword&sid={$this->sid}");
+ $form = $crawler->selectButton('submit')->form(array(
+ 'username' => 'reset-password-test-user',
+ ));
+ $crawler = self::submit($form);
+ $this->assertContainsLang('NO_EMAIL_USER', $crawler->text());
+
+ $crawler = self::request('GET', "ucp.php?mode=sendpassword&sid={$this->sid}");
+ $form = $crawler->selectButton('submit')->form(array(
+ 'username' => 'reset-password-test-user',
+ 'email' => 'nobody@example.com',
+ ));
+ $crawler = self::submit($form);
+ $this->assertContainsLang('PASSWORD_UPDATED', $crawler->text());
+
+ // Check if columns in database were updated for password reset
+ $this->get_user_data();
+ $this->assertNotNull($this->user_data['user_actkey']);
+ $this->assertNotNull($this->user_data['user_newpasswd']);
+
+ // Make sure we know the password
+ $db = $this->get_db();
+ $this->passwords_manager = $this->get_passwords_manager();
+ $sql = 'UPDATE ' . USERS_TABLE . "
+ SET user_newpasswd = '" . $db->sql_escape($this->passwords_manager->hash('reset-password-test-user')) . "'
+ WHERE user_id = " . $user_id;
+ $db->sql_query($sql);
+ }
+
+ public function test_login_after_reset()
+ {
+ $this->login('reset-password-test-user');
+ }
+
+ public function data_activate_new_password()
+ {
+ return array(
+ array('WRONG_ACTIVATION', false, 'FOOBAR'),
+ array('ALREADY_ACTIVATED', 2, 'FOOBAR'),
+ array('PASSWORD_ACTIVATED', false, false),
+ array('ALREADY_ACTIVATED', false, false),
+ );
+ }
+
+ /**
+ * @dataProvider data_activate_new_password
+ */
+ public function test_activate_new_password($expected, $user_id, $act_key)
+ {
+ $this->add_lang('ucp');
+ $this->get_user_data();
+ $user_id = (!$user_id) ? $this->user_data['user_id'] : $user_id;
+ $act_key = (!$act_key) ? $this->user_data['user_actkey'] : $act_key;
+
+ $crawler = self::request('GET', "ucp.php?mode=activate&u=$user_id&k=$act_key&sid={$this->sid}");
+ $this->assertContainsLang($expected, $crawler->text());
+ }
+
+ public function test_login()
+ {
+ $this->add_lang('ucp');
+ $crawler = self::request('GET', 'ucp.php');
+ $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('LOGIN'))->form();
+ $crawler = self::submit($form, array('username' => 'reset-password-test-user', 'password' => 'reset-password-test-user'));
+ $this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text());
+
+ $cookies = self::$cookieJar->all();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie);
+ {
+ if (substr($cookie->getName(), -4) == '_sid')
+ {
+ $this->sid = $cookie->getValue();
+ }
+ }
+
+ $this->logout();
+
+ $crawler = self::request('GET', 'ucp.php');
+ $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('LOGIN'))->form();
+ // Try logging in with the old password
+ $crawler = self::submit($form, array('username' => 'reset-password-test-user', 'password' => 'reset-password-test-userreset-password-test-user'));
+ $this->assertContains($this->lang('LOGIN_ERROR_PASSWORD', '', ''), $crawler->filter('html')->text());
+ }
+
+ /**
+ * @depends test_login
+ */
+ public function test_acivateAfterDeactivate()
+ {
+ // User is active, actkey should not exist
+ $this->get_user_data();
+ $this->assertEmpty($this->user_data['user_actkey']);
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/users');
+
+ // Go to user account page
+ $crawler = self::request('GET', 'adm/index.php?i=acp_users&mode=overview&sid=' . $this->sid);
+ $this->assertContainsLang('FIND_USERNAME', $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton('Submit')->form();
+ $crawler = self::submit($form, array('username' => 'reset-password-test-user'));
+
+ // Deactivate account and go back to overview of current user
+ $this->assertContainsLang('USER_TOOLS', $crawler->filter('html')->text());
+ $form = $crawler->filter('input[name=update]')->selectButton('Submit')->form();
+ $crawler = self::submit($form, array('action' => 'active'));
+
+ $this->assertContainsLang('USER_ADMIN_DEACTIVED', $crawler->filter('html')->text());
+ $link = $crawler->selectLink('Back to previous page')->link();
+ $crawler = self::request('GET', preg_replace('#(.+)(adm/index.php.+)#', '$2', $link->getUri()));
+
+ // Ensure again that actkey is empty after deactivation
+ $this->get_user_data();
+ $this->assertEmpty($this->user_data['user_actkey']);
+
+ // Force reactivation of account and check that act key is not empty anymore
+ $this->assertContainsLang('USER_TOOLS', $crawler->filter('html')->text());
+ $form = $crawler->filter('input[name=update]')->selectButton('Submit')->form();
+ $crawler = self::submit($form, array('action' => 'reactivate'));
+ $this->assertContainsLang('FORCE_REACTIVATION_SUCCESS', $crawler->filter('html')->text());
+
+ $this->get_user_data();
+ $this->assertNotEmpty($this->user_data['user_actkey']);
+ }
+
+ protected function get_user_data()
+ {
+ $db = $this->get_db();
+ $sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason
+ FROM ' . USERS_TABLE . "
+ WHERE username = 'reset-password-test-user'";
+ $result = $db->sql_query($sql);
+ $this->user_data = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/functional/viewforum_paging_test.php b/tests/functional/viewforum_paging_test.php
new file mode 100644
index 0000000000..4a574bebbb
--- /dev/null
+++ b/tests/functional/viewforum_paging_test.php
@@ -0,0 +1,256 @@
+<?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 viewforum_paging_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Viewforum Pagination Test #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ self::submit($form);
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Viewforum Pagination Test #2',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ self::submit($form);
+
+ $this->set_post_settings(array(
+ 'flood_interval' => 0,
+ 'topics_per_page' => 3,
+ ));
+ }
+
+ public function test_create_posts()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Viewforum Pagination Test #1',
+ 'Viewforum Pagination Test #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ for ($topic_id = 1; $topic_id <= 6; $topic_id++)
+ {
+ $this->create_topic($this->data['forums']['Viewforum Pagination Test #1'], 'Viewforum Pagination TestTopic #' . $topic_id, 'This is a test topic posted by the testing framework.');
+ }
+
+ $this->create_topic($this->data['forums']['Viewforum Pagination Test #2'], 'Viewforum Pagination TestTopic #GA1', 'This is a test topic posted by the testing framework.', array(
+ 'topic_type' => POST_GLOBAL,
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array(
+ 'forum_posts_approved' => 6,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 6,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ ), 'after creating topics');
+
+ $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #2'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ ), 'after creating GA');
+
+ // Set flood interval back to 15
+ $this->admin_login();
+ $this->set_post_settings(array(
+ 'flood_interval' => 15,
+ ));
+ }
+
+ public function test_viewforum_first_page()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Viewforum Pagination Test #1',
+ 'Viewforum Pagination Test #2',
+ ),
+ ));
+ $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1']);
+
+ // Test the topics that are displayed
+ $topiclists = $crawler->filter('.forumbg .topics');
+ $this->assertEquals(2, $topiclists->count());
+ $topiclist = $topiclists->eq(0)->filter('li');
+ $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text());
+ $topiclist = $topiclists->eq(1)->filter('li');
+ $this->assertStringEndsWith('TestTopic #6', $topiclist->eq(0)->filter('.topictitle')->text());
+ $this->assertStringEndsWith('TestTopic #5', $topiclist->eq(1)->filter('.topictitle')->text());
+ $this->assertStringEndsWith('TestTopic #4', $topiclist->eq(2)->filter('.topictitle')->text());
+
+ // Test the pagination, should only have: 1 - 2 - Next
+ $this->assertEquals(2, $crawler->filter('div.pagination')->count());
+ $top_pagination = $crawler->filter('div.pagination')->eq(0);
+ $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 1 does not match');
+ $this->assertContains('1', $top_pagination->filter('li')->eq(0)->text());
+ $this->assertContains('2', $top_pagination->filter('li')->eq(1)->text());
+ $this->assertContainsLang('NEXT', $top_pagination->filter('li')->eq(2)->text());
+ }
+
+ public function test_viewforum_second_page()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Viewforum Pagination Test #1',
+ 'Viewforum Pagination Test #2',
+ ),
+ ));
+ $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1'] . '&start=3');
+
+ // Test the topics that are displayed
+ $topiclists = $crawler->filter('.forumbg .topics');
+ $this->assertEquals(2, $topiclists->count());
+ $topiclist = $topiclists->eq(0)->filter('li');
+ $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text());
+ $topiclist = $topiclists->eq(1)->filter('li');
+ $this->assertStringEndsWith('TestTopic #3', $topiclist->eq(0)->filter('.topictitle')->text());
+ $this->assertStringEndsWith('TestTopic #2', $topiclist->eq(1)->filter('.topictitle')->text());
+ $this->assertStringEndsWith('TestTopic #1', $topiclist->eq(2)->filter('.topictitle')->text());
+
+ // Test the pagination, should only have: Previous - 1 - 2
+ $this->assertEquals(2, $crawler->filter('div.pagination')->count());
+ $top_pagination = $crawler->filter('div.pagination')->eq(0);
+ $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 2 does not match');
+ $this->assertContainsLang('PREVIOUS', $top_pagination->filter('li')->eq(0)->text());
+ $this->assertContains('1', $top_pagination->filter('li')->eq(1)->text());
+ $this->assertContains('2', $top_pagination->filter('li')->eq(2)->text());
+ }
+
+ protected function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ /**
+ * Sets the post setting via the ACP page
+ *
+ * @param array $settings
+ */
+ protected function set_post_settings($settings)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ foreach ($settings as $setting => $value)
+ {
+ $values["config[{$setting}]"] = $value;
+ }
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+ }
+
+ /**
+ * Loads forum, topic and post IDs
+ *
+ * @param array $data
+ */
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functional/visibility_disapprove_test.php b/tests/functional/visibility_disapprove_test.php
new file mode 100644
index 0000000000..6f6edba422
--- /dev/null
+++ b/tests/functional/visibility_disapprove_test.php
@@ -0,0 +1,323 @@
+<?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_visibility_disapprove_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Disapprove Test #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // Set flood interval to 0
+ $this->set_flood_interval(0);
+ }
+
+ public function test_create_posts()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Disapprove Test #1',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ // Test creating topic #1
+ $post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove Test Topic #1', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text());
+ $this->data['topics']['Disapprove Test Topic #1'] = (int) $post['topic_id'];
+ $this->data['posts']['Disapprove Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'after creating topic #1');
+
+ $this->logout();
+ $this->create_user('disapprove_testuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('disapprove_testuser'));
+ $this->login('disapprove_testuser');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Disapprove Test #1'], $post['topic_id'], 'Re: Disapprove Test Topic #1-#2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'after replying');
+
+ // Test creating topic #2
+ $post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Disapprove Test #1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'after creating topic #2');
+
+ $this->logout();
+ }
+
+ public function test_reset_flood_interval()
+ {
+ $this->login();
+ $this->admin_login();
+
+ // Set flood interval back to 15
+ $this->set_flood_interval(15);
+ }
+
+ public function test_disapprove_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Disapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Disapprove Test Topic #1',
+ 'Disapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Disapprove Test Topic #1',
+ 'Re: Disapprove Test Topic #1-#2',
+ 'Disapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'before disapproving post');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text());
+ $this->assertContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DISAPPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'after disapproving post');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Disapprove Test #1'] . '&t=' . $this->data['topics']['Disapprove Test Topic #1'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text());
+ $this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text());
+ }
+
+ public function test_disapprove_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Disapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Disapprove Test Topic #1',
+ 'Disapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Disapprove Test Topic #1',
+ 'Disapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'before disapproving topic');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DISAPPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'],
+ ), 'after disapproving topic');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewforum.php?f=' . $this->data['forums']['Disapprove Test #1'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}", array(), false);
+ self::assert_response_html(404);
+ $this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text());
+ }
+
+ protected function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ protected function set_flood_interval($flood_interval)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[flood_interval]"] = $flood_interval;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functional/visibility_reapprove_test.php b/tests/functional/visibility_reapprove_test.php
new file mode 100644
index 0000000000..5af2ddafa4
--- /dev/null
+++ b/tests/functional/visibility_reapprove_test.php
@@ -0,0 +1,419 @@
+<?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_visibility_reapprove_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Reapprove Test #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // Set flood interval to 0
+ $this->set_flood_interval(0);
+ }
+
+ public function test_create_posts()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ // Test creating topic #1
+ $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #1', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->data['topics']['Reapprove Test Topic #1'] = (int) $post['topic_id'];
+ $this->data['posts']['Reapprove Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after creating topic #1');
+
+ $this->logout();
+ $this->create_user('reapprove_testuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser'));
+ $this->login('reapprove_testuser');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Reapprove Test #1'], $post['topic_id'], 'Re: Reapprove Test Topic #1-#2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after replying');
+
+ // Test creating topic #2
+ $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Reapprove Test #1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('html')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after creating topic #2');
+
+ $this->logout();
+ }
+
+ public function test_approve_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'before approving post');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+
+ $form = $crawler->selectButton($this->lang('APPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_APPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'],
+ ), 'after approving post');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Reapprove Test #1'] . '&t=' . $this->data['topics']['Reapprove Test Topic #1'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text());
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ }
+
+ public function test_approve_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'],
+ ), 'before approving topic');
+
+ $this->add_lang('posting');
+ $this->add_lang('viewtopic');
+ $this->add_lang('mcp');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text());
+
+ $form = $crawler->selectButton($this->lang('APPROVE'))->form();
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton($this->lang('YES'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_APPROVED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'after approving topic');
+
+ $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link();
+ $link_url = $link->getUri();
+ $this->assertContains('viewtopic.php?f=' . $this->data['topic']['Reapprove Test Topic #2'], $link_url);
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text());
+ }
+
+ public function test_edit_posts()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Reapprove Test #1',
+ ),
+ 'topics' => array(
+ 'Reapprove Test Topic #1',
+ 'Reapprove Test Topic #2',
+ ),
+ 'posts' => array(
+ 'Reapprove Test Topic #1',
+ 'Re: Reapprove Test Topic #1-#2',
+ 'Reapprove Test Topic #2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'before editing post');
+
+ $this->login('reapprove_testuser');
+ $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser'));
+
+ // Test editing a post
+ $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Re: Reapprove Test Topic #1-#2']}&sid={$this->sid}";
+ $form_data = array(
+ 'message' => 'Post edited by testing framework',
+ 'subject' => 'Re: Reapprove Test Topic #1-#2',
+ 'post' => true,
+ );
+ $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 1,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 2,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'],
+ ), 'after editing post');
+
+ // Test editing a topic
+ $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Reapprove Test Topic #2']}&sid={$this->sid}";
+ $form_data = array(
+ 'message' => 'Post edited by testing framework',
+ 'subject' => 'Reapprove Test Topic #2',
+ 'post' => true,
+ );
+ $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}", array(), false);
+ self::assert_response_html(404);
+ $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('#page-body')->text());
+ $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 2,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 1,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'],
+ ), 'after editing topic');
+
+ $this->logout();
+ $this->login();
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text());
+ $this->assertContains('Post edited by testing framework', $crawler->filter('#page-body')->text());
+ }
+
+ public function test_approve_post_again()
+ {
+ $this->test_approve_post();
+ }
+
+ public function test_approve_topic_again()
+ {
+ $this->test_approve_topic();
+ }
+
+ public function test_reset_flood_interval()
+ {
+ $this->login();
+ $this->admin_login();
+
+ // Set flood interval back to 15
+ $this->set_flood_interval(15);
+ }
+
+ protected function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ protected function set_flood_interval($flood_interval)
+ {
+ $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ $values["config[flood_interval]"] = $flood_interval;
+ $form->setValues($values);
+ $crawler = self::submit($form);
+ $this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functional/visibility_softdelete_test.php b/tests/functional/visibility_softdelete_test.php
new file mode 100644
index 0000000000..6450c00c1e
--- /dev/null
+++ b/tests/functional/visibility_softdelete_test.php
@@ -0,0 +1,841 @@
+<?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_visibility_softdelete_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Soft Delete #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Soft Delete #2',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // Create second user which does not have m_delete permission
+ $this->add_lang('acp/permissions');
+
+ $second_user = $this->create_user('no m_delete moderator');
+ $this->add_user_group("GLOBAL_MODERATORS", 'no m_delete moderator', true);
+
+ // Set m_delete to never
+ $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&user_id[0]=$second_user&type=m_&sid={$this->sid}");
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ $data = array("setting[$second_user][0][m_delete]" => ACL_NEVER);
+ $form->setValues($data);
+ $crawler = self::submit($form);
+ }
+
+ public function test_create_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'initial comparison');
+
+ // Test creating topic
+ $post = $this->create_topic($this->data['forums']['Soft Delete #1'], 'Soft Delete Topic #1', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('html')->text());
+ $this->data['topics']['Soft Delete Topic #1'] = (int) $post['topic_id'];
+ $this->data['posts']['Soft Delete Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after creating topic #1');
+
+ // Test creating a reply
+ $post2 = $this->create_post($this->data['forums']['Soft Delete #1'], $post['topic_id'], 'Re: Soft Delete Topic #1-#2', 'This is a test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Soft Delete Topic #1-#2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Soft Delete Topic #1-#2'] = (int) $post2['post_id'];
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'],
+ ), 'after replying');
+
+ // Test creating another reply
+ $post3 = $this->create_post($this->data['forums']['Soft Delete #1'], $post['topic_id'], 'Re: Soft Delete Topic #1-#3', 'This is another test post posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post3['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Soft Delete Topic #1-#3', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Soft Delete Topic #1-#3'] = (int) $post3['post_id'];
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#3'],
+ ), 'after replying a second time');
+ }
+
+ public function test_softdelete_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 3,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#3'],
+ ), 'before softdelete');
+
+ $this->add_lang('posting');
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Soft Delete #1']}&p={$this->data['posts']['Re: Soft Delete Topic #1-#3']}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 1,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'],
+ ), 'after softdelete');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_softdelete_post_no_m_delete()
+ {
+ $this->login('no m_delete moderator');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 2,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 1,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'],
+ ), 'before softdelete without m_delete');
+
+ $this->add_lang('posting');
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Soft Delete #1']}&p={$this->data['posts']['Re: Soft Delete Topic #1-#2']}&sid={$this->sid}");
+ $this->assertNotContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after softdelete without m_delete');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_move_softdeleted_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3',
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'before moving #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before moving #2');
+
+ $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');
+ $form = $crawler->selectButton('Yes')->form();
+ $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text());
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'after moving #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after moving #2');
+ }
+
+ public function test_softdelete_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before softdeleting #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'before softdeleting #2');
+
+ $this->add_lang('posting');
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'DELETE_TOPIC');
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text());
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'after moving #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 3,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => 0,
+ ), 'after moving #2');
+ }
+
+ public function test_move_softdeleted_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before moving #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 3,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => 0,
+ ), 'before moving #2');
+
+ $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');
+ $form = $crawler->selectButton('Yes')->form();
+ $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text());
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 3,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => 0,
+ ), 'after moving #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'after moving #2');
+ }
+
+ public function test_restore_post()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 3,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => 0,
+ ), 'before restoring #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before restoring #2');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+
+ $this->add_lang('mcp');
+ $form = $crawler->filter('#p' . $this->data['posts']['Soft Delete Topic #1'])->selectButton($this->lang('RESTORE'))->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('RESTORE_POST', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_RESTORED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text());
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after restoring #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'after restoring #2');
+ }
+
+ public function test_split_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'before splitting #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before splitting #2');
+
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'SPLIT_TOPIC');
+
+ $this->add_lang('mcp');
+ $this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text());
+
+ $form = $crawler->selectButton('Submit')->form(array(
+ 'subject' => 'Soft Delete Topic #2 with bang',
+ ));
+ $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']);
+ $form['post_id_list'][1]->tick();
+ $crawler = self::submit($form);
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_SPLIT_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+ $this->assertNotContains('Re: Soft Delete Topic #1-#2', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 1,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after restoring #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 1,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => 0,
+ ), 'after restoring #2');
+
+ // Assert new topic title is indexed as well
+ $this->add_lang('search');
+ self::request('GET', "search.php?keywords=bang&sid={$this->sid}");
+ $this->assertContains(sprintf($this->lang['FOUND_SEARCH_MATCHES'][1], 1), self::get_content());
+ }
+
+ public function test_move_topic_back()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ 'Soft Delete Topic #2 with bang',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2 with bang'], 'MOVE_TOPIC');
+ $form = $crawler->selectButton('Yes')->form();
+ $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']);
+ $crawler = self::submit($form);
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after moving back');
+ }
+
+ public function test_merge_topics()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ 'Soft Delete Topic #2 with bang',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 1,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'before merging #1');
+
+ $this->add_lang('viewtopic');
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2 with bang']}&sid={$this->sid}");
+
+ $bookmark_tag = $crawler->filter('a.bookmark-link');
+ $this->assertContainsLang('BOOKMARK_TOPIC', $bookmark_tag->text());
+ $bookmark_link = $bookmark_tag->attr('href');
+ $crawler_bookmark = self::request('GET', $bookmark_link);
+ $this->assertContainsLang('BOOKMARK_ADDED', $crawler_bookmark->text());
+
+ $this->add_lang('mcp');
+ $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2 with bang'], '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 with bang']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}");
+ $this->assertContainsLang('MERGE_TOPICS_CONFIRM', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POSTS_MERGED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}");
+ $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text());
+ $this->assertContainsLang('POST_DELETED_ACTION', $crawler->filter('body')->text());
+ $this->assertContainsLang('BOOKMARK_TOPIC_REMOVE', $crawler->filter('body')->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after merging #1');
+ }
+
+ public function test_fork_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Soft Delete #1',
+ 'Soft Delete #2',
+ ),
+ 'topics' => array(
+ 'Soft Delete Topic #1',
+ ),
+ 'posts' => array(
+ 'Soft Delete Topic #1',
+ 'Re: Soft Delete Topic #1-#2',
+ 'Re: Soft Delete Topic #1-#3'
+ ),
+ ));
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'before forking #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 0,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 0,
+ 'forum_topics_approved' => 0,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => 0,
+ ), 'before forking #2');
+
+ $this->add_lang('mcp');
+ $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();
+ $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']);
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_FORKED_SUCCESS', $crawler->text());
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'],
+ ), 'after forking #1');
+
+ $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array(
+ 'forum_posts_approved' => 1,
+ 'forum_posts_unapproved' => 0,
+ 'forum_posts_softdeleted' => 2,
+ 'forum_topics_approved' => 1,
+ 'forum_topics_unapproved' => 0,
+ 'forum_topics_softdeleted' => 0,
+ 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'] + 3,
+ ), 'after forking #2');
+ }
+
+ public function assert_forum_details($forum_id, $details, $additional_error_message = '')
+ {
+ $this->db = $this->get_db();
+
+ $sql = 'SELECT ' . implode(', ', array_keys($details)) . '
+ FROM phpbb_forums
+ WHERE forum_id = ' . (int) $forum_id;
+ $result = $this->db->sql_query($sql);
+ $data = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
+ }
+
+ public function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+}
diff --git a/tests/functions/build_hidden_fields_for_query_params_test.php b/tests/functions/build_hidden_fields_for_query_params_test.php
new file mode 100644
index 0000000000..14cb4b9a94
--- /dev/null
+++ b/tests/functions/build_hidden_fields_for_query_params_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.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case
+{
+ public function build_hidden_fields_for_query_params_test_data()
+ {
+ return array(
+ // get
+ // post
+ // exclude
+ // expected
+ array(
+ array('foo' => 'bar'),
+ array(),
+ array(),
+ "<input type='hidden' name=\"foo\" value=\"bar\" />",
+ ),
+ array(
+ array('foo' => 'bar', 'a' => 'b'),
+ array(),
+ array(),
+ "<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />",
+ ),
+ array(
+ array('a' => 'quote"', 'b' => '<less>'),
+ array(),
+ array(),
+ "<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"&lt;less&gt;\" />",
+ ),
+ array(
+ array('a' => "quotes'\""),
+ array(),
+ array(),
+ "<input type='hidden' name=\"a\" value=\"quotes'&quot;\" />",
+ ),
+ array(
+ array('foo' => 'bar', 'a' => 'b'),
+ array('a' => 'c'),
+ array(),
+ "<input type='hidden' name=\"foo\" value=\"bar\" />",
+ ),
+ // strict equality check
+ array(
+ array('foo' => 'bar', 'a' => '0'),
+ array('a' => ''),
+ array(),
+ "<input type='hidden' name=\"foo\" value=\"bar\" />",
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_hidden_fields_for_query_params_test_data
+ */
+ public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected)
+ {
+ $request = new phpbb_mock_request($get, $post);
+ $result = phpbb_build_hidden_fields_for_query_params($request, $exclude);
+
+ $this->assertEquals($expected, $result);
+ }
+}
diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php
new file mode 100644
index 0000000000..a59b94c744
--- /dev/null
+++ b/tests/functions/build_url_test.php
@@ -0,0 +1,92 @@
+<?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_build_url_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ global $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpbb_path_helper;
+
+ parent::setUp();
+
+ $phpbb_container = new phpbb_mock_container_builder();
+ $user = new phpbb_mock_user();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $phpbb_path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ 'php'
+ );
+ $phpbb_container->set('path_helper', $phpbb_path_helper);
+ }
+ public function build_url_test_data()
+ {
+ return array(
+ array(
+ 'index.php',
+ false,
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'index.php',
+ 't',
+ 'phpBB/index.php?',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=4',
+ false,
+ 'phpBB/viewtopic.php?t=5&amp;f=4',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ 'f',
+ 'phpBB/viewtopic.php?style=1&amp;t=6',
+ ),
+ array(
+ 'viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'phpBB/viewtopic.php?',
+ ),
+ array(
+ 'http://test.phpbb.com/viewtopic.php?f=2&style=1&t=6',
+ array('f', 'style', 't'),
+ 'http://test.phpbb.com/viewtopic.php?',
+ ),
+ array(
+ 'posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E',
+ false,
+ 'phpBB/posting.php?f=2&amp;mode=delete&amp;p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E',
+ )
+ );
+ }
+
+ /**
+ * @dataProvider build_url_test_data
+ */
+ public function test_build_url($page, $strip_vars, $expected)
+ {
+ global $user, $phpbb_root_path;
+
+ $user->page['page'] = $page;
+ $output = build_url($strip_vars);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php
new file mode 100644
index 0000000000..729c0a82f0
--- /dev/null
+++ b/tests/functions/convert_30_dbms_to_31_test.php
@@ -0,0 +1,44 @@
+<?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_convert_30_dbms_to_31_test extends phpbb_test_case
+{
+ public function convert_30_dbms_to_31_data()
+ {
+ return array(
+ array('mssql'),
+ array('mssql_odbc'),
+ array('mssqlnative'),
+ array('mysql'),
+ array('mysqli'),
+ array('oracle'),
+ array('postgres'),
+ array('sqlite'),
+ );
+ }
+
+ /**
+ * @dataProvider convert_30_dbms_to_31_data
+ */
+ public function test_convert_30_dbms_to_31($input)
+ {
+ $expected = "phpbb\\db\\driver\\$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/fixtures/banned_users.xml b/tests/functions/fixtures/banned_users.xml
new file mode 100644
index 0000000000..cec3f4e51f
--- /dev/null
+++ b/tests/functions/fixtures/banned_users.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_banlist">
+ <column>ban_userid</column>
+ <column>ban_exclude</column>
+ <column>ban_end</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>0</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>0</value>
+ <value>999999999999999999999</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>0</value>
+ <value>3</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml
index 05bbe6a05e..14621a3287 100644
--- a/tests/functions/fixtures/obtain_online.xml
+++ b/tests/functions/fixtures/obtain_online.xml
@@ -15,8 +15,6 @@
<column>user_allow_viewonline</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>anonymous</value>
@@ -24,8 +22,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -34,8 +30,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
@@ -44,8 +38,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>4</value>
@@ -54,8 +46,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>5</value>
@@ -64,8 +54,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>6</value>
@@ -74,8 +62,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>7</value>
@@ -84,8 +70,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>8</value>
@@ -94,8 +78,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>9</value>
@@ -104,8 +86,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>10</value>
@@ -114,8 +94,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
</dataset>
diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml
index 12d6392ab5..ca95f94461 100644
--- a/tests/functions/fixtures/style_select.xml
+++ b/tests/functions/fixtures/style_select.xml
@@ -4,20 +4,24 @@
<column>style_id</column>
<column>style_name</column>
<column>style_active</column>
+ <column>style_parent_tree</column>
<row>
<value>1</value>
<value>prosilver</value>
<value>1</value>
+ <value></value>
</row>
<row>
<value>2</value>
<value>subsilver2</value>
<value>1</value>
+ <value></value>
</row>
<row>
<value>3</value>
<value>zoo</value>
<value>0</value>
+ <value></value>
</row>
</table>
</dataset>
diff --git a/tests/functions/fixtures/user_delete.xml b/tests/functions/fixtures/user_delete.xml
new file mode 100644
index 0000000000..4c4479d29b
--- /dev/null
+++ b/tests/functions/fixtures/user_delete.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>username</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>anonymous</value>
+ <value>anonymous</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_oauth_accounts">
+ <column>user_id</column>
+ <column>provider</column>
+ <column>oauth_provider_id</column>
+ <row>
+ <value>2</value>
+ <value>google</value>
+ <value>1234567890123456789</value>
+ </row>
+ </table>
+ <table name="phpbb_oauth_tokens">
+ <column>user_id</column>
+ <column>session_id</column>
+ <column>provider</column>
+ <column>oauth_token</column>
+ <row>
+ <value>2</value>
+ <value>897a897b797c8789997d7979879</value>
+ <value>auth.provider.oauth.service.google</value>
+ <value>{"accessToken":"ya29.YPHwCWVkrvwu1kgbYKiDNYaQ451ZuHy9OEQAGVME8if-WBzR-v7a9ftxbx41kaL)5VLEXB-6qJEvri","endOfLife":1429959670,"extraParams":{"token_type":"Bearer","id_token":"eyJhbGciOiJSUzI1NiIsImupZCI6IjE0YuRjNzc2MDQwYjUyNDZmNTI5OWFkZDVlMmQ1NWNOPTdjMDdlZTAifQ.eyJpc3MiOiJhY2NvdW90cy5nb78nbGUuY29tIiwic3ViIjoiMTExMDMwNwerNjM4MTM5NTQwMTM1IiwiYXpwIjoiOTk3MzUwMTY0NzE0LWhwOXJrYjZpcjM4MW80YjV1NjRpaGtmM29zMnRvbWxhLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJtYXJjLmFsZXhhbmRlci4zN0BnbWFpbC5jb20iLCJhdF9oYXNoIjoiWHk2b1JabnVZUWRfRTZDeDV0RkItdyIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdWQiOiI5OTczNTAxNjQ3MTQtaHA5cmtiNmlyMzgxbzRiNXU2NGloa2Yzb3MydG9tbGEuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJpYXQiOjE0Mjk5NTYwNzEsImV4cCI6MTQyOTk1OTY3MX0.C5gfSzjqwlRRvVMuTP6jfWIuEHMXn55oYHsSA3eh97n2BZL0TZHhUm4K206Fgucd6ufAphan4l0J7y6tMAHLZPr-kk6KDINxWnPG-up99reblGutay0lRYjMCcrhJAOql8EI1bi84GyliZFYHL67pE0ZtSf-CMb1CeH18TFe-Fk"},"refreshToken":null,"token_class":"OAuth\\\\OAuth2\\\\Token\\\\StdOAuth2Token"}</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functions/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml
index de7fce8a08..eb4fd90217 100644
--- a/tests/functions/fixtures/validate_email.xml
+++ b/tests/functions/fixtures/validate_email.xml
@@ -6,8 +6,6 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<column>user_email_hash</column>
<row>
<value>1</value>
@@ -15,8 +13,6 @@
<value>admin</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
<value>143317126117</value>
</row>
</table>
diff --git a/tests/functions/fixtures/validate_username.xml b/tests/functions/fixtures/validate_username.xml
index fbe398469c..1b85a2f06d 100644
--- a/tests/functions/fixtures/validate_username.xml
+++ b/tests/functions/fixtures/validate_username.xml
@@ -14,16 +14,12 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>admin</value>
<value>admin</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -31,8 +27,6 @@
<value>moderator</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
</dataset>
diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php
new file mode 100644
index 0000000000..cd1e37618a
--- /dev/null
+++ b/tests/functions/generate_string_list.php
@@ -0,0 +1,64 @@
+<?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_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_generate_string_list_test extends phpbb_test_case
+{
+ public $user;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ $this->user->data = array('user_lang' => 'en');
+ $this->user->add_lang('common');
+ }
+
+ public function generate_string_list_data()
+ {
+ return array(
+ array(
+ array(),
+ '',
+ ),
+ array(
+ array('A'),
+ 'A',
+ ),
+ array(
+ array(2 => 'A', 3 => 'B'),
+ 'A and B',
+ ),
+ array(
+ array('A' => 'A', 'B' => 'B', 'C' => 'C'),
+ 'A, B, and C',
+ ),
+ array(
+ array('A', 'B', 'C', 'D'),
+ 'A, B, C, and D',
+ )
+ );
+ }
+
+ /**
+ * @dataProvider generate_string_list_data
+ */
+ public function test_generate_string_list($items, $expected_result)
+ {
+ $result = phpbb_generate_string_list($items, $this->user);
+ $this->assertEquals($expected_result, $result);
+ }
+}
diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php
index 96ea2be132..635753d737 100644
--- a/tests/functions/get_formatted_filesize_test.php
+++ b/tests/functions/get_formatted_filesize_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/get_preg_expression_test.php b/tests/functions/get_preg_expression_test.php
new file mode 100644
index 0000000000..e74017d315
--- /dev/null
+++ b/tests/functions/get_preg_expression_test.php
@@ -0,0 +1,40 @@
+<?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_functions_get_preg_expression_test extends phpbb_test_case
+{
+ public function data_path_remove_dot_trailing_slash()
+ {
+ return array(
+ array('./../', '$2', '/..'),
+ array('/../', '$2', '/..'),
+ array('', '$2', ''),
+ array('./', '$2', ''),
+ array('/', '$2', ''),
+ array('./../../', '$2', '/../..'),
+ array('/../../', '$2', '/../..'),
+ array('./dir/', '$2', '/dir'),
+ array('./../dir/', '$2', '/../dir'),
+ );
+ }
+
+ /**
+ * @dataProvider data_path_remove_dot_trailing_slash
+ */
+ public function test_path_remove_dot_trailing_slash($input, $replace, $expected)
+ {
+ $this->assertSame($expected, preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), $replace, $input));
+ }
+}
diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php
index 4032ca5b58..612d82273e 100644
--- a/tests/functions/get_remote_file_test.php
+++ b/tests/functions/get_remote_file_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -17,6 +21,10 @@ class phpbb_functions_get_remote_file extends phpbb_test_case
{
public function test_version_phpbb_com()
{
+ global $phpbb_container;
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_container->set('file_downloader', new \phpbb\file_downloader());
+
$hostname = 'version.phpbb.com';
if (!phpbb_checkdnsrr($hostname, 'A'))
diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php
index 7630b7c58c..afa4b9b59f 100644
--- a/tests/functions/is_absolute_test.php
+++ b/tests/functions/is_absolute_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -51,6 +55,6 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case
*/
public function test_is_absolute($path, $expected)
{
- $this->assertEquals($expected, is_absolute($path));
+ $this->assertEquals($expected, phpbb_is_absolute($path));
}
}
diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php
index 3341e2a256..6762ead5a1 100644
--- a/tests/functions/language_select_test.php
+++ b/tests/functions/language_select_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/make_clickable_email_test.php b/tests/functions/make_clickable_email_test.php
new file mode 100644
index 0000000000..4c802d0487
--- /dev/null
+++ b/tests/functions/make_clickable_email_test.php
@@ -0,0 +1,222 @@
+<?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';
+
+class phpbb_functions_make_clickable_email_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $config, $user, $request;
+ $user = new phpbb_mock_user();
+ $request = new phpbb_mock_request();
+ }
+
+ /**
+ * 'e' tag for email addresses html
+ **/
+ public function data_test_make_clickable_email_positive()
+ {
+ return array(
+ array(
+ 'nobody@phpbb.com',
+ '<!-- e --><a href="mailto:nobody@phpbb.com">nobody@phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'Nobody@sub.phpbb.com',
+ '<!-- e --><a href="mailto:Nobody@sub.phpbb.com">Nobody@sub.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice.bob@foo.phpbb.com',
+ '<!-- e --><a href="mailto:alice.bob@foo.phpbb.com">alice.bob@foo.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice-foo@bar.phpbb.com',
+ '<!-- e --><a href="mailto:alice-foo@bar.phpbb.com">alice-foo@bar.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice_foo@bar.phpbb.com',
+ '<!-- e --><a href="mailto:alice_foo@bar.phpbb.com">alice_foo@bar.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice+tag@foo.phpbb.com',
+ '<!-- e --><a href="mailto:alice+tag@foo.phpbb.com">alice+tag@foo.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice&amp;tag@foo.phpbb.com',
+ '<!-- e --><a href="mailto:alice&amp;tag@foo.phpbb.com">alice&amp;tag@foo.phpbb.com</a><!-- e -->'
+ ),
+ array(
+ 'alice@phpbb.australia',
+ '<!-- e --><a href="mailto:alice@phpbb.australia">alice@phpbb.australia</a><!-- e -->'
+ ),
+
+ // Test shortened text for email > 55 characters long
+ // Email text should be turned into: first 39 chars + ' ... ' + last 10 chars
+ array(
+ 'alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong',
+ '<!-- e --><a href="mailto:alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong">alice@phpbb.topZlevelZdomainZnamesZcanZ ... ctersZlong</a><!-- e -->'
+ ),
+ array(
+ 'l3tt3rsAndNumb3rs@domain.com',
+ '<!-- e --><a href="mailto:l3tt3rsAndNumb3rs@domain.com">l3tt3rsAndNumb3rs@domain.com</a><!-- e -->'
+ ),
+ array(
+ 'has-dash@domain.com',
+ '<!-- e --><a href="mailto:has-dash@domain.com">has-dash@domain.com</a><!-- e -->'
+ ),
+ array(
+ 'hasApostrophe.o\'leary@domain.org',
+ '<!-- e --><a href="mailto:hasApostrophe.o\'leary@domain.org">hasApostrophe.o\'leary@domain.org</a><!-- e -->'
+ ),
+ array(
+ 'uncommonTLD@domain.museum',
+ '<!-- e --><a href="mailto:uncommonTLD@domain.museum">uncommonTLD@domain.museum</a><!-- e -->'
+ ),
+ array(
+ 'uncommonTLD@domain.travel',
+ '<!-- e --><a href="mailto:uncommonTLD@domain.travel">uncommonTLD@domain.travel</a><!-- e -->'
+ ),
+ array(
+ 'uncommonTLD@domain.mobi',
+ '<!-- e --><a href="mailto:uncommonTLD@domain.mobi">uncommonTLD@domain.mobi</a><!-- e -->'
+ ),
+ array(
+ 'countryCodeTLD@domain.uk',
+ '<!-- e --><a href="mailto:countryCodeTLD@domain.uk">countryCodeTLD@domain.uk</a><!-- e -->'
+ ),
+ array(
+ 'countryCodeTLD@domain.rw',
+ '<!-- e --><a href="mailto:countryCodeTLD@domain.rw">countryCodeTLD@domain.rw</a><!-- e -->'
+ ),
+ array(
+ 'numbersInDomain@911.com',
+ '<!-- e --><a href="mailto:numbersInDomain@911.com">numbersInDomain@911.com</a><!-- e -->'
+ ),
+ array(
+ 'underscore_inLocal@domain.net',
+ '<!-- e --><a href="mailto:underscore_inLocal@domain.net">underscore_inLocal@domain.net</a><!-- e -->'
+ ),
+ array(
+ 'IPInsteadOfDomain@127.0.0.1',
+ '<!-- e --><a href="mailto:IPInsteadOfDomain@127.0.0.1">IPInsteadOfDomain@127.0.0.1</a><!-- e -->'
+ ),
+ array(
+ 'IPAndPort@127.0.0.1:25',
+ '<!-- e --><a href="mailto:IPAndPort@127.0.0.1:25">IPAndPort@127.0.0.1:25</a><!-- e -->'
+ ),
+ array(
+ 'subdomain@sub.domain.com',
+ '<!-- e --><a href="mailto:subdomain@sub.domain.com">subdomain@sub.domain.com</a><!-- e -->'
+ ),
+ array(
+ 'local@dash-inDomain.com',
+ '<!-- e --><a href="mailto:local@dash-inDomain.com">local@dash-inDomain.com</a><!-- e -->'
+ ),
+ array(
+ 'dot.inLocal@foo.com',
+ '<!-- e --><a href="mailto:dot.inLocal@foo.com">dot.inLocal@foo.com</a><!-- e -->'
+ ),
+ array(
+ 'a@singleLetterLocal.org',
+ '<!-- e --><a href="mailto:a@singleLetterLocal.org">a@singleLetterLocal.org</a><!-- e -->'
+ ),
+ array(
+ 'singleLetterDomain@x.org',
+ '<!-- e --><a href="mailto:singleLetterDomain@x.org">singleLetterDomain@x.org</a><!-- e -->'
+ ),
+ array(
+ '&amp;*=?^+{}\'~@validCharsInLocal.net',
+ '<!-- e --><a href="mailto:&amp;*=?^+{}\'~@validCharsInLocal.net">&amp;*=?^+{}\'~@validCharsInLocal.net</a><!-- e -->'
+ ),
+ array(
+ 'foor@bar.newTLD',
+ '<!-- e --><a href="mailto:foor@bar.newTLD">foor@bar.newTLD</a><!-- e -->'
+ ),
+ );
+ }
+
+ public function data_test_make_clickable_email_negative()
+ {
+ return array(
+ array('foo.example.com'), // @ is missing
+ array('.foo.example.com'), // . as first character
+ array('Foo.@example.com'), // . is last in local part
+ array('foo..123@example.com'), // . doubled
+ array('a@b@c@example.com'), // @ doubled
+
+ // Emails with invalid characters
+ // (only 'valid' pieces having localparts prepended with one of the \n \t ( > chars should parsed if any)
+ array('()[]\;:,<>@example.com'), // invalid characters
+ array('abc(def@example.com', 'abc(<!-- e --><a href="mailto:def@example.com">def@example.com</a><!-- e -->'), // invalid character (
+ array('abc)def@example.com'), // invalid character )
+ array('abc[def@example.com'), // invalid character [
+ array('abc]def@example.com'), // invalid character ]
+ array('abc\def@example.com'), // invalid character \
+ array('abc;def@example.com'), // invalid character ;
+ array('abc:def@example.com'), // invalid character :
+ array('abc,def@example.com'), // invalid character ,
+ array('abc<def@example.com'), // invalid character <
+ array('abc>def@example.com', 'abc><!-- e --><a href="mailto:def@example.com">def@example.com</a><!-- e -->'), // invalid character >
+
+ // http://fightingforalostcause.net/misc/2006/compare-email-regex.php
+ array('missingDomain@.com'),
+ array('@missingLocal.org'),
+ array('missingatSign.net'),
+ array('missingDot@com'),
+ array('two@@signs.com'),
+ // Trailing colon is ignored
+ array('colonButNoPort@127.0.0.1:', '<!-- e --><a href="mailto:colonButNoPort@127.0.0.1">colonButNoPort@127.0.0.1</a><!-- e -->:'),
+
+ array(''),
+ // Trailing part after the 3rd dot is ignored
+ array('someone-else@127.0.0.1.26', '<!-- e --><a href="mailto:someone-else@127.0.0.1">someone-else@127.0.0.1</a><!-- e -->.26'),
+
+ array('.localStartsWithDot@domain.com'),
+ array('localEndsWithDot.@domain.com'),
+ array('two..consecutiveDots@domain.com'),
+ array('domainStartsWithDash@-domain.com'),
+ array('domainEndsWithDash@domain-.com'),
+ array('numbersInTLD@domain.c0m'),
+ array('missingTLD@domain.'),
+ array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'),
+ array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'),
+ array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'),
+ // The domain zone name part after the 63rd char is ignored
+ array(
+ 'alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlongZ',
+ '<!-- e --><a href="mailto:alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong">alice@phpbb.topZlevelZdomainZnamesZcanZ ... ctersZlong</a><!-- e -->Z'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_email_positive
+ */
+ public function test_email_matching_positive($email, $expected)
+ {
+ $this->assertSame($expected, make_clickable($email));
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_email_negative
+ */
+ public function test_email_matching_negative($email, $expected = null)
+ {
+ $expected = ($expected) ?: $email;
+ $this->assertSame($expected, make_clickable($email));
+ }
+}
diff --git a/tests/functions/make_clickable_test.php b/tests/functions/make_clickable_test.php
new file mode 100644
index 0000000000..63beeb06b2
--- /dev/null
+++ b/tests/functions/make_clickable_test.php
@@ -0,0 +1,180 @@
+<?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';
+
+class phpbb_functions_make_clickable_test extends phpbb_test_case
+{
+ /**
+ * Tags:
+ * 'm' - full URL like xxxx://aaaaa.bbb.cccc.
+ * 'l' - local relative board URL like http://domain.tld/path/to/board/index.php
+ * 'w' - URL without http/https protocol like www.xxxx.yyyy[/zzzz] aka 'lazy' URLs
+ * 'e' - email@domain type address
+ *
+ * Classes:
+ * "postlink-local" for 'l' URLs
+ * "postlink" for the rest of URLs
+ * empty for email addresses
+ **/
+ public function data_test_make_clickable_url_positive()
+ {
+ return array(
+ array(
+ 'http://www.phpbb.com/community/',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/community/">http://www.phpbb.com/community/</a><!-- m -->'
+ ),
+ array(
+ 'http://www.phpbb.com/path/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/path/file.ext#section">http://www.phpbb.com/path/file.ext#section</a><!-- m -->'
+ ),
+ array(
+ 'ftp://ftp.phpbb.com/',
+ '<!-- m --><a class="postlink" href="ftp://ftp.phpbb.com/">ftp://ftp.phpbb.com/</a><!-- m -->'
+ ),
+ array(
+ 'sip://bantu@phpbb.com',
+ '<!-- m --><a class="postlink" href="sip://bantu@phpbb.com">sip://bantu@phpbb.com</a><!-- m -->'
+ ),
+ array(
+ 'www.phpbb.com/community/',
+ '<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->'
+ ),
+ array(
+ 'http://testhost/viewtopic.php?t=1',
+ '<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->'
+ ),
+ array(
+ 'email@domain.com',
+ '<!-- e --><a href="mailto:email@domain.com">email@domain.com</a><!-- e -->'
+ ),
+ // Test appending punctuation mark to the URL
+ array(
+ 'http://testhost/viewtopic.php?t=1!',
+ '<!-- l --><a class="postlink-local" href="http://testhost/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->!'
+ ),
+ array(
+ 'www.phpbb.com/community/?',
+ '<!-- w --><a class="postlink" href="http://www.phpbb.com/community/">www.phpbb.com/community/</a><!-- w -->?'
+ ),
+ // Test shortened text for URL > 55 characters long
+ // URL text should be turned into: first 39 chars + ' ... ' + last 10 chars
+ array(
+ 'http://www.phpbb.com/community/path/to/long/url/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.phpbb.com/community/path/to/long/url/file.ext#section">http://www.phpbb.com/community/path/to/ ... xt#section</a><!-- m -->'
+ ),
+ );
+ }
+
+ public function data_test_make_clickable_url_idn()
+ {
+ return array(
+ array(
+ 'http://www.täst.de/community/',
+ '<!-- m --><a class="postlink" href="http://www.täst.de/community/">http://www.täst.de/community/</a><!-- m -->'
+ ),
+ array(
+ 'http://www.täst.de/path/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.täst.de/path/file.ext#section">http://www.täst.de/path/file.ext#section</a><!-- m -->'
+ ),
+ array(
+ 'ftp://ftp.täst.de/',
+ '<!-- m --><a class="postlink" href="ftp://ftp.täst.de/">ftp://ftp.täst.de/</a><!-- m -->'
+ ),
+ array(
+ 'sip://bantu@täst.de',
+ '<!-- m --><a class="postlink" href="sip://bantu@täst.de">sip://bantu@täst.de</a><!-- m -->'
+ ),
+ array(
+ 'www.täst.de/community/',
+ '<!-- w --><a class="postlink" href="http://www.täst.de/community/">www.täst.de/community/</a><!-- w -->'
+ ),
+ // Test appending punctuation mark to the URL
+ array(
+ 'http://домен.рф/viewtopic.php?t=1!',
+ '<!-- m --><a class="postlink" href="http://домен.рф/viewtopic.php?t=1">http://домен.рф/viewtopic.php?t=1</a><!-- m -->!'
+ ),
+ array(
+ 'www.домен.рф/сообщество/?',
+ '<!-- w --><a class="postlink" href="http://www.домен.рф/сообщество/">www.домен.рф/сообщество/</a><!-- w -->?'
+ ),
+ // Test shortened text for URL > 55 characters long
+ // URL text should be turned into: first 39 chars + ' ... ' + last 10 chars
+ array(
+ 'http://www.домен.рф/сообщество/путь/по/длинной/ссылке/file.ext#section',
+ '<!-- m --><a class="postlink" href="http://www.домен.рф/сообщество/путь/по/длинной/ссылке/file.ext#section">http://www.домен.рф/сообщество/путь/по/ ... xt#section</a><!-- m -->'
+ ),
+
+ // IDN with invalid characters shouldn't be parsed correctly (only 'valid' part)
+ array(
+ 'http://www.täst╫.de',
+ '<!-- m --><a class="postlink" href="http://www.täst">http://www.täst</a><!-- m -->╫.de'
+ ),
+ // IDN in emails is unsupported yet
+ array('почта@домен.рф', 'почта@домен.рф'),
+ );
+ }
+
+ public function data_test_make_clickable_local_url_idn()
+ {
+ return array(
+ array(
+ 'http://www.домен.рф/viewtopic.php?t=1',
+ '<!-- l --><a class="postlink-local" href="http://www.домен.рф/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->'
+ ),
+ // Test appending punctuation mark to the URL
+ array(
+ 'http://www.домен.рф/viewtopic.php?t=1!',
+ '<!-- l --><a class="postlink-local" href="http://www.домен.рф/viewtopic.php?t=1">viewtopic.php?t=1</a><!-- l -->!'
+ ),
+ array(
+ 'http://www.домен.рф/сообщество/?',
+ '<!-- l --><a class="postlink-local" href="http://www.домен.рф/сообщество/">сообщество/</a><!-- l -->?'
+ ),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $config, $user, $request;
+ $user = new phpbb_mock_user();
+ $request = new phpbb_mock_request();
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_url_positive
+ */
+ public function test_urls_matching_positive($url, $expected)
+ {
+ $this->assertSame($expected, make_clickable($url));
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_url_idn
+ */
+ public function test_urls_matching_idn($url, $expected)
+ {
+ $this->assertSame($expected, make_clickable($url));
+ }
+
+ /**
+ * @dataProvider data_test_make_clickable_local_url_idn
+ */
+ public function test_local_urls_matching_idn($url, $expected)
+ {
+ $this->assertSame($expected, make_clickable($url, "http://www.домен.рф"));
+ }
+}
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php
index de6451a0db..e793a4eb82 100644
--- a/tests/functions/obtain_online_test.php
+++ b/tests/functions/obtain_online_test.php
@@ -1,15 +1,18 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/auth.php';
class phpbb_functions_obtain_online_test extends phpbb_database_test_case
{
@@ -125,28 +128,28 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
{
return array(
array(0, false, array(
- 'online_userlist' => 'REGISTERED_USERS 2, 3',
- 'l_online_users' => 'ONLINE_USERS_TOTAL 5REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 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',
- 'l_online_users' => 'ONLINE_USERS_TOTAL 7REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 3GUEST_USERS_TOTAL 2',
+ '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',
- 'l_online_users' => 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1',
+ '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_GUEST 3 1',
- 'l_online_users' => 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1',
+ '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(
'online_userlist' => 'BROWSING_FORUM NO_ONLINE_USERS',
- 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0',
+ 'l_online_users' => 'ONLINE_USERS_TOTAL 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0',
)),
array(2, true, array(
- 'online_userlist' => 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0',
- 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0',
+ 'online_userlist' => 'BROWSING_FORUM_GUESTS 0 NO_ONLINE_USERS',
+ 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0 GUEST_USERS_TOTAL 0',
)),
);
}
@@ -158,18 +161,21 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
{
$this->db->sql_query('DELETE FROM phpbb_sessions');
- global $config, $user, $auth;
+ global $config, $user, $auth, $phpbb_dispatcher;
$config['load_online_guests'] = $display_guests;
+ $user = new phpbb_mock_lang();
$user->lang = $this->load_language();
- $auth = $this->getMock('auth');
+ $auth = $this->getMock('\phpbb\auth\auth');
$acl_get_map = array(
array('u_viewonline', true),
+ array('u_viewprofile', true),
);
$auth->expects($this->any())
->method('acl_get')
->with($this->stringContains('_'),
$this->anything())
->will($this->returnValueMap($acl_get_map));
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$time = time();
$this->create_guest_sessions($time);
@@ -215,25 +221,12 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
protected function load_language()
{
- $lang = array(
+ return array(
'NO_ONLINE_USERS' => 'NO_ONLINE_USERS',
'REGISTERED_USERS' => 'REGISTERED_USERS',
'BROWSING_FORUM' => 'BROWSING_FORUM %s',
'BROWSING_FORUM_GUEST' => 'BROWSING_FORUM_GUEST %s %d',
'BROWSING_FORUM_GUESTS' => 'BROWSING_FORUM_GUESTS %s %d',
);
- $vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST');
- foreach ($vars_online as $online)
- {
- $lang = array_merge($lang, array(
- $online . '_USERS_ZERO_TOTAL' => $online . '_USERS_ZERO_TOTAL %d',
- $online . '_USER_TOTAL' => $online . '_USER_TOTAL %d',
- $online . '_USERS_TOTAL' => $online . '_USERS_TOTAL %d',
- $online . '_USERS_ZERO_TOTAL_AND' => $online . '_USERS_ZERO_TOTAL_AND %d',
- $online . '_USER_TOTAL_AND' => $online . '_USER_TOTAL_AND %d',
- $online . '_USERS_TOTAL_AND' => $online . '_USERS_TOTAL_AND %d',
- ));
- }
- return $lang;
}
}
diff --git a/tests/functions/parse_cfg_file_test.php b/tests/functions/parse_cfg_file_test.php
index 69000ddf72..b47e25fbc1 100644
--- a/tests/functions/parse_cfg_file_test.php
+++ b/tests/functions/parse_cfg_file_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -19,10 +23,13 @@ class phpbb_functions_parse_cfg_file extends phpbb_test_case
'#',
'# phpBB Style Configuration File',
'#',
- '# @package phpBB3',
- '# @copyright (c) 2005 phpBB Group',
- '# @license http://opensource.org/licenses/gpl-license.php GNU Public License',
+ '# 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.',
'#',
'# At the left is the name, please do not change this',
'# At the right the value is entered',
@@ -35,24 +42,24 @@ class phpbb_functions_parse_cfg_file extends phpbb_test_case
'',
'# General Information about this style',
'name = prosilver',
- 'copyright = © phpBB Group, 2007',
+ 'copyright = © phpBB Limited, 2007',
'version = 3.0.12',
),
array(
'name' => 'prosilver',
- 'copyright' => '© phpBB Group, 2007',
+ 'copyright' => '© phpBB Limited, 2007',
'version' => '3.0.12',
),
),
array(
array(
'name = subsilver2',
- 'copyright = © 2005 phpBB Group',
+ 'copyright = © 2005 phpBB Limited',
'version = 3.0.12',
),
array(
'name' => 'subsilver2',
- 'copyright' => '© 2005 phpBB Group',
+ 'copyright' => '© 2005 phpBB Limited',
'version' => '3.0.12',
),
),
diff --git a/tests/functions/phpbb_get_banned_user_ids.php b/tests/functions/phpbb_get_banned_user_ids.php
new file mode 100644
index 0000000000..6f7607132e
--- /dev/null
+++ b/tests/functions/phpbb_get_banned_user_ids.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.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
+
+class phpbb_get_banned_user_ids_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/banned_users.xml');
+ }
+
+ public function phpbb_get_banned_user_ids_data()
+ {
+ return array(
+ // Input to phpbb_get_banned_user_ids (user_id list, ban_end)
+ // Expected output
+ array(
+ // True to get users currently banned
+ array(array(1, 2, 4, 5, 6), true),
+ array(2 => 2, 5 => 5),
+ ),
+ array(
+ // False to only get permanently banned users
+ array(array(1, 2, 4, 5, 6), false),
+ array(2 => 2),
+ ),
+ array(
+ // Unix timestamp to get users banned until that time
+ array(array(1, 2, 4, 5, 6), 2),
+ array(2 => 2, 5 => 5, 6 => 6),
+ ),
+ );
+ }
+
+ public function setUp()
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+
+ return parent::setUp();
+ }
+
+ /**
+ * @dataProvider phpbb_get_banned_user_ids_data
+ */
+ public function test_phpbb_get_banned_user_ids($input, $expected)
+ {
+ $this->assertEquals($expected, call_user_func_array('phpbb_get_banned_user_ids', $input));
+ }
+}
diff --git a/tests/functions/quoteattr_test.php b/tests/functions/quoteattr_test.php
new file mode 100644
index 0000000000..6e191f9610
--- /dev/null
+++ b/tests/functions/quoteattr_test.php
@@ -0,0 +1,48 @@
+<?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_quoteattr_test extends phpbb_test_case
+{
+ public function quoteattr_test_data()
+ {
+ return array(
+ array('foo', null, '"foo"'),
+ array('', null, '""'),
+ array(' ', null, '" "'),
+ array('<a>', null, '"&lt;a&gt;"'),
+ array('&amp;', null, '"&amp;amp;"'),
+ array('"hello"', null, "'\"hello\"'"),
+ array("'hello'", null, "\"'hello'\""),
+ array("\"'", null, "\"&quot;'\""),
+ array("a\nb", null, '"a&#10;b"'),
+ array("a\r\nb", null, '"a&#13;&#10;b"'),
+ array("a\tb", null, '"a&#9;b"'),
+ array('a b', null, '"a b"'),
+ array('"a<b"', null, "'\"a&lt;b\"'"),
+ array('foo', array('f' => 'z'), '"zoo"'),
+ array('<a>', array('a' => '&amp;'), '"&lt;&amp;&gt;"'),
+ );
+ }
+
+ /**
+ * @dataProvider quoteattr_test_data
+ */
+ public function test_quoteattr($input, $entities, $expected)
+ {
+ $output = phpbb_quoteattr($input, $entities);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/functions/style_select_test.php b/tests/functions/style_select_test.php
index 1e44f3c2cb..a918f83155 100644
--- a/tests/functions/style_select_test.php
+++ b/tests/functions/style_select_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/user_delete_test.php b/tests/functions/user_delete_test.php
new file mode 100644
index 0000000000..c224323273
--- /dev/null
+++ b/tests/functions/user_delete_test.php
@@ -0,0 +1,113 @@
+<?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_user.php';
+
+class phpbb_functions_user_delete_test extends phpbb_database_test_case
+{
+ /** @var \phpbb\db\driver\driver_interface */
+ protected $db;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_delete.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user;
+
+ $this->db = $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $phpbb_container = new phpbb_mock_container_builder();
+ $config = new \phpbb\config\config(array(
+ 'auth_method' => 'oauth',
+ 'auth_oauth_google_key' => 'foo',
+ 'auth_oauth_google_secret' => 'bar',
+ ));
+ set_config_count('foobar', 0, false, $config);
+ $cache = new \phpbb\cache\driver\null();
+ $request = new phpbb_mock_request();
+ $notification_manager = new phpbb_mock_notification_manager();
+ $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
+ $oauth_provider_google = new \phpbb\auth\provider\oauth\service\google($config, $request);
+ $oauth_provider_collection = new \phpbb\di\service_collection($phpbb_container);
+ $oauth_provider_collection->offsetSet('auth.provider.oauth.service.google', $oauth_provider_google);
+
+ $driver_helper = new \phpbb\passwords\driver\helper($config);
+ $passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
+ );
+
+ $passwords_helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
+
+ $oauth_provider = new \phpbb\auth\provider\oauth\oauth(
+ $db,
+ $config,
+ $passwords_manager,
+ $request,
+ $user,
+ 'phpbb_oauth_tokens',
+ 'phpbb_oauth_accounts',
+ $oauth_provider_collection,
+ 'phpbb_users',
+ $phpbb_container,
+ $phpbb_dispatcher,
+ $this->phpbb_root_path,
+ $this->php_ext
+ );
+ $provider_collection->offsetSet('auth.provider.oauth', $oauth_provider);
+
+ $phpbb_container->set('auth.provider.oauth', $oauth_provider);
+ $phpbb_container->set('auth.provider.oauth.service.google', $oauth_provider_google);
+ $phpbb_container->set('auth.provider_collection', $provider_collection);
+ $phpbb_container->set('notification_manager', $notification_manager);
+ }
+
+ public function test_user_delete()
+ {
+ // Check that user is linked
+ $sql = 'SELECT ot.user_id AS user_id
+ FROM phpbb_oauth_accounts oa, phpbb_oauth_tokens ot
+ WHERE oa.user_id = 2
+ AND ot.user_id = oa.user_id';
+ $result = $this->db->sql_query($sql);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEquals(array('user_id' => '2'), $row);
+
+ // user_delete() should return false
+ $this->assertFalse(user_delete('remove', array(2)));
+
+ // Make sure user link was removed
+ $sql = 'SELECT ot.user_id AS user_id
+ FROM phpbb_oauth_accounts oa, phpbb_oauth_tokens ot
+ WHERE oa.user_id = 2
+ AND ot.user_id = oa.user_id';
+ $result = $this->db->sql_query($sql);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $this->assertEmpty($row);
+ }
+}
diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php
index b92a3aa5eb..448d029d3f 100644
--- a/tests/functions/validate_data_helper.php
+++ b/tests/functions/validate_data_helper.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php
index 1dcd1361a2..9dc0db46d6 100644
--- a/tests/functions/validate_date_test.php
+++ b/tests/functions/validate_date_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php
index 9a6ce39251..b46509fda7 100644
--- a/tests/functions/validate_email_test.php
+++ b/tests/functions/validate_email_test.php
@@ -2,7 +2,7 @@
/**
*
* @package testing
-* @copyright (c) 2013 phpBB Group
+* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -47,60 +47,54 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case
$user->optionset('banned_users', array('banned@example.com'));
}
- public function test_validate_email()
+ public static function validate_email_data()
+ {
+ return array(
+ array('empty', array('EMAIL_INVALID'), ''), // email does not allow empty
+ array('allowed', array(), 'foobar@example.com'),
+ array('valid_complex', array(), "'%$~test@example.com"),
+ array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'),
+ array('taken', array(), 'admin@example.com'), // email does not check taken, should use user_email instead
+ array('banned', array(), 'banned@example.com'), // email does not check ban, should use user_email instead
+ );
+ }
+
+ /**
+ * @dataProvider validate_email_data
+ */
+ public function test_validate_email($case, $errors, $email)
{
$this->set_validation_prerequisites(false);
$this->helper->assert_valid_data(array(
- 'empty' => array(
- array(),
- '',
- array('email'),
- ),
- 'allowed' => array(
- array(),
- 'foobar@example.com',
- array('email', 'foobar@example.com'),
- ),
- 'invalid' => array(
- array('EMAIL_INVALID'),
- 'fööbar@example.com',
- array('email'),
- ),
- 'valid_complex' => array(
- array(),
- "'%$~test@example.com",
- array('email'),
- ),
- 'taken' => array(
- array('EMAIL_TAKEN'),
- 'admin@example.com',
- array('email'),
- ),
- 'banned' => array(
- array('EMAIL_BANNED'),
- 'banned@example.com',
+ $case => array(
+ $errors,
+ $email,
array('email'),
),
));
}
+ public static function validate_email_mx_data()
+ {
+ return array(
+ array('valid', array(), 'foobar@phpbb.com'),
+ array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'),
+ );
+ }
+
/**
+ * @dataProvider validate_email_mx_data
* @group slow
*/
- public function test_validate_email_mx()
+ public function test_validate_email_mx($case, $errors, $email)
{
$this->set_validation_prerequisites(true);
$this->helper->assert_valid_data(array(
- 'valid' => array(
- array(),
- 'foobar@phpbb.com',
- array('email'),
- ),
- 'no_mx' => array(
- array('DOMAIN_NO_MX_RECORD'),
- 'test@does-not-exist.phpbb.com',
+ $case => array(
+ $errors,
+ $email,
array('email'),
),
));
diff --git a/tests/functions/validate_hex_colour_test.php b/tests/functions/validate_hex_colour_test.php
index 812ebe5eeb..b2c4862458 100644
--- a/tests/functions/validate_hex_colour_test.php
+++ b/tests/functions/validate_hex_colour_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php
index 5a53c963bd..23811a94c0 100644
--- a/tests/functions/validate_jabber_test.php
+++ b/tests/functions/validate_jabber_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php
index c8a5b71021..81b56055e6 100644
--- a/tests/functions/validate_lang_iso_test.php
+++ b/tests/functions/validate_lang_iso_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php
index 73a363e003..811bed3e33 100644
--- a/tests/functions/validate_match_test.php
+++ b/tests/functions/validate_match_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php
index 4deac02ebc..798468759c 100644
--- a/tests/functions/validate_num_test.php
+++ b/tests/functions/validate_num_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php
index 4639f6cc89..c5942e79bf 100644
--- a/tests/functions/validate_password_test.php
+++ b/tests/functions/validate_password_test.php
@@ -1,12 +1,17 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_user.php';
require_once dirname(__FILE__) . '/validate_data_helper.php';
diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php
index ab44c28541..24026e4c9f 100644
--- a/tests/functions/validate_string_test.php
+++ b/tests/functions/validate_string_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions/validate_user_email_test.php b/tests/functions/validate_user_email_test.php
new file mode 100644
index 0000000000..951d5794e6
--- /dev/null
+++ b/tests/functions/validate_user_email_test.php
@@ -0,0 +1,106 @@
+<?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_user.php';
+require_once dirname(__FILE__) . '/../mock/user.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
+
+class phpbb_functions_validate_user_email_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $user;
+ protected $helper;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->user = new phpbb_mock_user;
+ $this->helper = new phpbb_functions_validate_data_helper($this);
+ }
+
+ /**
+ * Get validation prerequesites
+ *
+ * @param bool $check_mx Whether mx records should be checked
+ */
+ protected function set_validation_prerequisites($check_mx)
+ {
+ global $config, $db, $user;
+
+ $config['email_check_mx'] = $check_mx;
+ $db = $this->db;
+ $user = $this->user;
+ $user->optionset('banned_users', array('banned@example.com'));
+ }
+
+ public static function validate_user_email_data()
+ {
+ return array(
+ array('empty', array(), ''),
+ array('allowed', array(), 'foobar@example.com'),
+ array('valid_complex', array(), "'%$~test@example.com"),
+ array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'),
+ array('taken', array('EMAIL_TAKEN'), 'admin@example.com'),
+ array('banned', array('EMAIL_BANNED'), 'banned@example.com'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_user_email_data
+ */
+ public function test_validate_user_email($case, $errors, $email)
+ {
+ $this->set_validation_prerequisites(false);
+
+ $this->helper->assert_valid_data(array(
+ $case => array(
+ $errors,
+ $email,
+ array('user_email'),
+ ),
+ ));
+ }
+
+ public static function validate_user_email_mx_data()
+ {
+ return array(
+ array('valid', array(), 'foobar@phpbb.com'),
+ array('no_mx', array('DOMAIN_NO_MX_RECORD'), 'test@does-not-exist.phpbb.com'),
+ );
+ }
+
+ /**
+ * @dataProvider validate_user_email_mx_data
+ * @group slow
+ */
+ public function test_validate_user_email_mx($case, $errors, $email)
+ {
+ $this->set_validation_prerequisites(true);
+
+ $this->helper->assert_valid_data(array(
+ $case => array(
+ $errors,
+ $email,
+ array('user_email'),
+ ),
+ ));
+ }
+}
diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php
index 0819974e54..4fa5af7ff3 100644
--- a/tests/functions/validate_username_test.php
+++ b/tests/functions/validate_username_test.php
@@ -1,12 +1,17 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
require_once dirname(__FILE__) . '/../mock/cache.php';
diff --git a/tests/functions/validate_with_method_test.php b/tests/functions/validate_with_method_test.php
new file mode 100644
index 0000000000..37e05d412a
--- /dev/null
+++ b/tests/functions/validate_with_method_test.php
@@ -0,0 +1,43 @@
+<?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_user.php';
+require_once dirname(__FILE__) . '/validate_data_helper.php';
+
+class phpbb_functions_validate_with_method_test extends phpbb_test_case
+{
+ protected $helper;
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->helper = new phpbb_functions_validate_data_helper($this);
+ }
+
+ public function test_validate_date()
+ {
+ $this->helper->assert_valid_data(array(
+ 'method_call' => array(
+ array(),
+ true,
+ array(array(array($this, 'with_method'), false)),
+ ),
+ ));
+ }
+
+ public function validate_with_method($bool, $optional = false)
+ {
+ return ! $bool;
+ }
+}
diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php
new file mode 100644
index 0000000000..2e3a8adac7
--- /dev/null
+++ b/tests/functions_acp/build_cfg_template_test.php
@@ -0,0 +1,291 @@
+<?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_acp.php';
+
+class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
+{
+ public function build_cfg_template_text_data()
+ {
+ return array(
+ array(
+ array('text', 20, 255),
+ 'key_name',
+ array('config_key_name' => '1'),
+ 'config_key_name',
+ array(),
+ '<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name]" value="1" />',
+ ),
+ array(
+ array('password', 20, 128),
+ 'key_name',
+ array('config_key_name' => '2'),
+ 'config_key_name',
+ array(),
+ '<input id="key_name" type="password" size="20" maxlength="128" name="config[config_key_name]" value="********" autocomplete="off" />',
+ ),
+ array(
+ array('text', 0, 255),
+ 'key_name',
+ array('config_key_name' => '3'),
+ 'config_key_name',
+ array(),
+ '<input id="key_name" type="text" maxlength="255" name="config[config_key_name]" value="3" />',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_text_data
+ */
+ public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_dimension_data()
+ {
+ return array(
+ array(
+ array('dimension', 5, 15),
+ 'number_key_name',
+ array('config_key_name_width' => 10, 'config_key_name_height' => 20),
+ 'config_key_name',
+ array(),
+ '<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="5" max="15" name="config[config_key_name_height]" value="20" />',
+ ),
+ array(
+ array('dimension', 0, 15),
+ 'number_key_name',
+ array('config_key_name_width' => 10, 'config_key_name_height' => 20),
+ 'config_key_name',
+ array(),
+ '<input id="number_key_name" type="number" min="0" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" min="0" max="15" name="config[config_key_name_height]" value="20" />',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_dimension_data
+ */
+ public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_number_data()
+ {
+ return array(
+ array(
+ array('number', 5, 15),
+ 'number_key_name',
+ array('config_key_name' => 10),
+ 'config_key_name',
+ array(),
+ '<input id="number_key_name" type="number" min="5" max="15" name="config[config_key_name]" value="10" />',
+ ),
+ array(
+ array('number', -1, 9999),
+ 'number_key_name',
+ array('config_key_name' => 10),
+ 'config_key_name',
+ array(),
+ '<input id="number_key_name" type="number" min="-1" max="9999" name="config[config_key_name]" value="10" />',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_number_data
+ */
+ public function test_build_cfg_template_number($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_textarea_data()
+ {
+ return array(
+ array(
+ array('textarea', 5, 30),
+ 'key_name',
+ array('config_key_name' => 'phpBB'),
+ 'config_key_name',
+ array(),
+ '<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_textarea_data
+ */
+ public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_radio_data()
+ {
+ return array(
+ array(
+ array('radio', 'enabled_disabled'),
+ 'key_name',
+ array('config_key_name' => '0'),
+ 'config_key_name',
+ array(),
+ '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> DISABLED</label>',
+ ),
+ array(
+ array('radio', 'enabled_disabled'),
+ 'key_name',
+ array('config_key_name' => '1'),
+ 'config_key_name',
+ array(),
+ '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> DISABLED</label>',
+ ),
+ array(
+ array('radio', 'yes_no'),
+ 'key_name',
+ array('config_key_name' => '0'),
+ 'config_key_name',
+ array(),
+ '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> NO</label>',
+ ),
+ array(
+ array('radio', 'yes_no'),
+ 'key_name',
+ array('config_key_name' => '1'),
+ 'config_key_name',
+ array(),
+ '<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> NO</label>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_radio_data
+ */
+ public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_append_data()
+ {
+ return array(
+ array(
+ array('textarea', 5, 30),
+ 'key_name',
+ array('config_key_name' => 'phpBB'),
+ 'config_key_name',
+ array('append' => 'Bertie is cool!'),
+ '<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>Bertie is cool!',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_append_data
+ */
+ public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function build_cfg_template_select_data()
+ {
+ return array(
+ array(
+ array('select'),
+ 'key_name',
+ array('config_key_name' => '0'),
+ 'config_key_name',
+ array('method' => 'select_helper'),
+ '<select id="key_name" name="config[config_key_name]"><option value="1">First_Option</option><option value="2" selected="selected">Second_Option</option><option value="3">Third_Option</option></select>',
+ ),
+ array(
+ array('select', 8),
+ 'key_name',
+ array('config_key_name' => '1'),
+ 'config_key_name',
+ array('method' => 'select_helper'),
+ '<select id="key_name" name="config[config_key_name]" size="8"><option value="1">First_Option</option><option value="2" selected="selected">Second_Option</option><option value="3">Third_Option</option></select>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_cfg_template_select_data
+ */
+ public function test_build_cfg_template_select($tpl_type, $key, $new, $config_key, $vars, $expected)
+ {
+ global $module, $user, $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ $user->module = $this;
+ $module = $user;
+
+ $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
+ }
+
+ public function select_helper()
+ {
+ return build_select(
+ array(
+ '1' => 'First_Option',
+ '2' => 'Second_Option',
+ '3' => 'Third_Option',
+ ),
+ '2'
+ );
+ }
+}
diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php
new file mode 100644
index 0000000000..ebdc58fd64
--- /dev/null
+++ b/tests/functions_acp/build_select_test.php
@@ -0,0 +1,65 @@
+<?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_acp.php';
+
+class phpbb_functions_acp_built_select_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $user;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ public function build_select_data()
+ {
+ return array(
+ array(
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ false,
+ '<option value="test">TEST</option><option value="second">SEC_OPTION</option>',
+ ),
+ array(
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'test',
+ '<option value="test" selected="selected">TEST</option><option value="second">SEC_OPTION</option>',
+ ),
+ array(
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'second',
+ '<option value="test">TEST</option><option value="second" selected="selected">SEC_OPTION</option>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider build_select_data
+ */
+ public function test_build_select($option_ary, $option_default, $expected)
+ {
+ $this->assertEquals($expected, build_select($option_ary, $option_default));
+ }
+}
diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php
new file mode 100644
index 0000000000..5ae4e91ea2
--- /dev/null
+++ b/tests/functions_acp/h_radio_test.php
@@ -0,0 +1,130 @@
+<?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_acp.php';
+
+class phpbb_functions_acp_h_radio_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $user;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ public function h_radio_data()
+ {
+ return array(
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ false,
+ false,
+ false,
+ '<label><input type="radio" name="test_name" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'test',
+ false,
+ false,
+ '<label><input type="radio" name="test_name" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ false,
+ 'test_id',
+ false,
+ '<label><input type="radio" name="test_name" id="test_id" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'test',
+ 'test_id',
+ false,
+ '<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
+ ),
+
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ false,
+ false,
+ 'k',
+ '<label><input type="radio" name="test_name" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'test',
+ false,
+ 'k',
+ '<label><input type="radio" name="test_name" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ false,
+ 'test_id',
+ 'k',
+ '<label><input type="radio" name="test_name" id="test_id" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
+ ),
+ array(
+ 'test_name',
+ array(
+ 'test' => 'TEST',
+ 'second' => 'SEC_OPTION',
+ ),
+ 'test',
+ 'test_id',
+ 'k',
+ '<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider h_radio_data
+ */
+ public function test_h_radio($name, $input_ary, $input_default, $id, $key, $expected)
+ {
+ $this->assertEquals($expected, h_radio($name, $input_ary, $input_default, $id, $key));
+ }
+}
diff --git a/tests/functions_acp/insert_config_array_test.php b/tests/functions_acp/insert_config_array_test.php
new file mode 100644
index 0000000000..1264b35bf4
--- /dev/null
+++ b/tests/functions_acp/insert_config_array_test.php
@@ -0,0 +1,144 @@
+<?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_acp.php';
+
+class phpbb_functions_insert_config_array_test extends phpbb_test_case
+{
+ public function config_display_vars()
+ {
+ return array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ );
+ }
+
+ public function insert_config_array_data()
+ {
+ return array(
+ array( // Add a new config after 1st array item
+ array('new_config_1' => array()),
+ array('after' => 'legend1'),
+ array(
+ 'legend1' => '',
+ 'new_config_1' => array(),
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ ),
+ ),
+ array( // Add a new config after last array item
+ array('new_config_1' => array()),
+ array('after' => 'acp_config_5'),
+ array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ 'new_config_1' => array(),
+ ),
+ ),
+ array( // Add a new config before 2nd array item
+ array('new_config_1' => array()),
+ array('before' => 'acp_config_1'),
+ array(
+ 'legend1' => '',
+ 'new_config_1' => array(),
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ ),
+ ),
+ array( // Add a new config before last config item
+ array('new_config_1' => array()),
+ array('before' => 'acp_config_5'),
+ array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'new_config_1' => array(),
+ 'acp_config_5' => array(),
+ ),
+ ),
+ array( // When an array key does not exist
+ array('new_config_1' => array()),
+ array('after' => 'foobar'),
+ array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ ),
+ ),
+ array( // When after|before is not used correctly (defaults to after)
+ array('new_config_1' => array()),
+ array('foobar' => 'acp_config_1'),
+ array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'new_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ ),
+ ),
+ array( // Add a new config set after the last array item
+ array(
+ 'legend2' => array(),
+ 'new_config_1' => array(),
+ 'new_config_2' => array(),
+ 'new_config_3' => array(),
+ ),
+ array('after' => 'acp_config_5'),
+ array(
+ 'legend1' => '',
+ 'acp_config_1' => array(),
+ 'acp_config_2' => array(),
+ 'acp_config_3' => array(),
+ 'acp_config_4' => array(),
+ 'acp_config_5' => array(),
+ 'legend2' => array(),
+ 'new_config_1' => array(),
+ 'new_config_2' => array(),
+ 'new_config_3' => array(),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider insert_config_array_data
+ */
+ public function test_insert_config_array($new_config, $position, $expected)
+ {
+ $config_array = $this->config_display_vars();
+ $new_config_array = phpbb_insert_config_array($config_array, $new_config, $position);
+
+ $this->assertSame($expected, $new_config_array);
+ }
+}
diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php
new file mode 100644
index 0000000000..32738e4351
--- /dev/null
+++ b/tests/functions_acp/validate_config_vars_test.php
@@ -0,0 +1,261 @@
+<?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_acp.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $user;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ /**
+ * Data sets that don't throw an error.
+ */
+ public function validate_config_vars_fit_data()
+ {
+ return array(
+ array(
+ array(
+ 'test_bool' => array('lang' => 'TEST_BOOL', 'validate' => 'bool'),
+ 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'),
+ 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'),
+ 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'),
+ 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'),
+ 'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'),
+ 'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'),
+ 'test_int' => array('lang' => 'TEST_INT', 'validate' => 'int'),
+ 'test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32'),
+ 'test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64'),
+ 'test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang'),
+ /*
+ 'test_sp' => array('lang' => 'TEST_SP', 'validate' => 'script_path'),
+ 'test_rpath' => array('lang' => 'TEST_RPATH', 'validate' => 'rpath'),
+ 'test_rwpath' => array('lang' => 'TEST_RWPATH', 'validate' => 'rwpath'),
+ 'test_path' => array('lang' => 'TEST_PATH', 'validate' => 'path'),
+ 'test_wpath' => array('lang' => 'TEST_WPATH', 'validate' => 'wpath'),
+ */
+ ),
+ array(
+ 'test_bool' => true,
+ 'test_string' => str_repeat('a', 255),
+ 'test_string' => str_repeat("\xC3\x84", 255),
+ 'test_string_128' => str_repeat('a', 128),
+ 'test_string_128' => str_repeat("\xC3\x84", 128),
+ 'test_string_32_64' => str_repeat('a', 48),
+ 'test_string_32_64' => str_repeat("\xC3\x84", 48),
+ 'test_int' => 128,
+ 'test_int_32' => 32,
+ 'test_int_32_64' => 48,
+ 'test_lang' => 'en',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_config_vars_fit_data
+ */
+ public function test_validate_config_vars_fit($test_data, $cfg_array)
+ {
+ $phpbb_error = array();
+ validate_config_vars($test_data, $cfg_array, $phpbb_error);
+
+ $this->assertEquals(array(), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the error.
+ */
+ public function validate_config_vars_error_data()
+ {
+ return array(
+ array(
+ array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
+ array('test_string_32_64' => str_repeat('a', 20)),
+ array('SETTING_TOO_SHORT'),
+ ),
+ array(
+ array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
+ array('test_string_32_64' => str_repeat("\xC3\x84", 20)),
+ array('SETTING_TOO_SHORT'),
+ ),
+ array(
+ array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')),
+ array('test_string' => str_repeat('a', 256)),
+ array('SETTING_TOO_LONG'),
+ ),
+ array(
+ array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')),
+ array('test_string' => str_repeat("\xC3\x84", 256)),
+ array('SETTING_TOO_LONG'),
+ ),
+ array(
+ array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
+ array('test_string_32_64' => str_repeat('a', 65)),
+ array('SETTING_TOO_LONG'),
+ ),
+ array(
+ array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
+ array('test_string_32_64' => str_repeat("\xC3\x84", 65)),
+ array('SETTING_TOO_LONG'),
+ ),
+
+ array(
+ array('test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32')),
+ array('test_int_32' => 31),
+ array('SETTING_TOO_LOW'),
+ ),
+ array(
+ array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')),
+ array('test_int_32_64' => 31),
+ array('SETTING_TOO_LOW'),
+ ),
+ array(
+ array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')),
+ array('test_int_32_64' => 65),
+ array('SETTING_TOO_BIG'),
+ ),
+ array(
+ array(
+ 'test_int_min' => array('lang' => 'TEST_INT_MIN', 'validate' => 'int:32:64'),
+ 'test_int_max' => array('lang' => 'TEST_INT_MAX', 'validate' => 'int:32:64'),
+ ),
+ array(
+ 'test_int_min' => 52,
+ 'test_int_max' => 48,
+ ),
+ array('SETTING_TOO_LOW'),
+ ),
+ array(
+ array('test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang')),
+ array('test_lang' => 'this_is_no_language'),
+ array('WRONG_DATA_LANG'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_config_vars_error_data
+ */
+ public function test_validate_config_vars_error($test_data, $cfg_array, $expected)
+ {
+ $phpbb_error = array();
+ validate_config_vars($test_data, $cfg_array, $phpbb_error);
+
+ $this->assertEquals($expected, $phpbb_error);
+ }
+
+ public function data_validate_path_linux()
+ {
+ return array(
+ array('/usr/bin', 'absolute_path', true),
+ array('/usr/bin/', 'absolute_path:50:200', true),
+ array('/usr/bin/which', 'absolute_path', 'DIRECTORY_NOT_DIR'),
+ array('/foo/bar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ array('C:\Windows', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ array('.', 'absolute_path', true),
+ array('', 'absolute_path', true),
+ array('mkdir /foo/bar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ // Make sure above command didn't do anything
+ array('/foo/bar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ );
+ }
+
+ /**
+ * @dataProvider data_validate_path_linux
+ */
+ public function test_validate_path_linux($path, $validation_type, $expected)
+ {
+ if (strtolower(substr(PHP_OS, 0, 5)) !== 'linux')
+ {
+ $this->markTestSkipped('Unable to test linux specific paths on other OS.');
+ }
+
+ $error = array();
+ $config_ary = array(
+ 'path' => $path,
+ );
+
+ validate_config_vars(array(
+ 'path' => array('lang' => 'FOOBAR', 'validate' => $validation_type),
+ ),
+ $config_ary,
+ $error
+ );
+
+ if ($expected === true)
+ {
+ $this->assertEmpty($error);
+ }
+ else
+ {
+ $this->assertEquals(array($expected), $error);
+ }
+ }
+
+ public function data_validate_path_windows()
+ {
+ return array(
+ array('C:\Windows', 'absolute_path', true),
+ array('C:\Windows\\', 'absolute_path:50:200', true),
+ array('C:\Windows\explorer.exe', 'absolute_path', 'DIRECTORY_NOT_DIR'),
+ array('C:\foobar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ array('/usr/bin', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ array('.', 'absolute_path', true),
+ array('', 'absolute_path', true),
+ array('mkdir C:\Windows\foobar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ // Make sure above command didn't do anything
+ array('C:\Windows\foobar', 'absolute_path', 'DIRECTORY_DOES_NOT_EXIST'),
+ );
+ }
+
+ /**
+ * @dataProvider data_validate_path_windows
+ */
+ public function test_validate_path_windows($path, $validation_type, $expected)
+ {
+ if (strtolower(substr(PHP_OS, 0, 3)) !== 'win')
+ {
+ $this->markTestSkipped('Unable to test windows specific paths on other OS.');
+ }
+
+ $error = array();
+ $config_ary = array(
+ 'path' => $path,
+ );
+
+ validate_config_vars(array(
+ 'path' => array('lang' => 'FOOBAR', 'validate' => $validation_type),
+ ),
+ $config_ary,
+ $error
+ );
+
+ if ($expected === true)
+ {
+ $this->assertEmpty($error);
+ }
+ else
+ {
+ $this->assertEquals(array($expected), $error);
+ }
+ }
+}
diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php
new file mode 100644
index 0000000000..6408e29a26
--- /dev/null
+++ b/tests/functions_acp/validate_range_test.php
@@ -0,0 +1,168 @@
+<?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';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
+
+class phpbb_functions_acp_validate_range_test extends phpbb_test_case
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $user;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ /**
+ * Data sets that don't throw an error.
+ */
+ public function validate_range_data_fit()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 1))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65535))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => 0))),
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) -2147483648))),
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -28))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 35))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -128))),
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 127))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -16))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 16))),
+
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => ''))),
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 255)))),
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 255)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 128)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 128)))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_fit
+ */
+ public function test_validate_range_fit($test_data)
+ {
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array(), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_LOW-error.
+ */
+ public function validate_range_data_too_low()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => -1))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => -1))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 31))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => -1))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 31))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) -2147483648) - 1))),
+ array(array(array('column_type' => 'INT:32:128', 'lang' => 'TEST', 'value' => 31))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -33))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -129))),
+ array(array(array('column_type' => 'TINT:32:64', 'lang' => 'TEST', 'value' => 31))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -33))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_low
+ */
+ public function test_validate_range_too_low($test_data)
+ {
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_LOW'), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_BIG-error.
+ */
+ public function validate_range_data_too_big()
+ {
+ return array(
+ array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 2))),
+
+ array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65536))),
+ array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
+ array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
+ array(array(array('column_type' => 'INT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
+ array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 129))),
+
+ array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 128))),
+ array(array(array('column_type' => 'TINT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
+ array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 65))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_big
+ */
+ public function test_validate_range_too_big($test_data)
+ {
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_BIG'), $phpbb_error);
+ }
+
+ /**
+ * Data sets that throw the SETTING_TOO_LONG-error.
+ */
+ public function validate_range_data_too_long()
+ {
+ return array(
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 256)))),
+ array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 256)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 129)))),
+ array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 129)))),
+ );
+ }
+
+ /**
+ * @dataProvider validate_range_data_too_long
+ */
+ public function test_validate_range_too_long($test_data)
+ {
+ $phpbb_error = array();
+ validate_range($test_data, $phpbb_error);
+
+ $this->assertEquals(array('SETTING_TOO_LONG'), $phpbb_error);
+ }
+}
diff --git a/tests/functions_content/get_username_string_test.php b/tests/functions_content/get_username_string_test.php
index 48e8936cc1..01ec97f6a4 100644
--- a/tests/functions_content/get_username_string_test.php
+++ b/tests/functions_content/get_username_string_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -16,14 +20,15 @@ class phpbb_functions_content_get_username_string_test extends phpbb_test_case
{
parent::setUp();
- global $auth, $user;
- $auth = $this->getMock('auth');
+ global $auth, $phpbb_dispatcher, $user;
+ $auth = $this->getMock('\phpbb\auth\auth');
$auth->expects($this->any())
->method('acl_get')
->with($this->stringContains('_'), $this->anything())
->will($this->returnValueMap(array(
array('u_viewprofile', true),
)));
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$user->data['user_id'] = ANONYMOUS;
$user->lang['GUEST'] = 'Guest';
}
@@ -89,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>'),
);
}
@@ -108,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/functions_content/phpbb_clean_search_string_test.php b/tests/functions_content/phpbb_clean_search_string_test.php
index de642c9040..abd107097c 100644
--- a/tests/functions_content/phpbb_clean_search_string_test.php
+++ b/tests/functions_content/phpbb_clean_search_string_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php
index d4881daf7e..150b091ceb 100644
--- a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php
+++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php
index 2f01d29d15..0e27f129de 100644
--- a/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php
+++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/functions_install/ignore_new_file_on_update_test.php b/tests/functions_install/ignore_new_file_on_update_test.php
new file mode 100644
index 0000000000..822c5e6789
--- /dev/null
+++ b/tests/functions_install/ignore_new_file_on_update_test.php
@@ -0,0 +1,45 @@
+<?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_install.php';
+
+class phpbb_functions_install_ignore_new_file_on_update_test extends phpbb_test_case
+{
+ static public function ignore_new_file_on_update_data()
+ {
+ return array(
+ array('willneverexist.php', false),
+ array('includes/dirwillneverexist/newfile.php', false),
+
+ array('language/en/email/short/bookmark.txt', false),
+ array('language/languagewillneverexist/email/short/bookmark.txt', true),
+
+ array('styles/prosilver/template/bbcode.html', false),
+ array('styles/stylewillneverexist/template/bbcode.html', true),
+
+ array('styles/prosilver/theme/en/icon_user_online.gif', false),
+ array('styles/prosilver/theme/languagewillneverexist/icon_user_online.gif', true),
+
+ array('styles/prosilver/theme/imageset.css', false),
+ );
+ }
+
+ /**
+ * @dataProvider ignore_new_file_on_update_data
+ */
+ public function test_ignore_new_file_on_update($file, $expected)
+ {
+ global $phpbb_root_path;
+ $this->assertEquals($expected, phpbb_ignore_new_file_on_update($phpbb_root_path, $file));
+ }
+}
diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php
index 9a7805a819..7db69e332c 100644
--- a/tests/functions_user/delete_user_test.php
+++ b/tests/functions_user/delete_user_test.php
@@ -10,30 +10,44 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
-require_once dirname(__FILE__) . '/../mock/null_cache.php';
class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
{
- /** @var \dbal */
+ /** @var \phpbb\db\driver\driver_interface */
protected $db;
public function getDataSet()
{
- return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user.xml');
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_user.xml');
}
protected function setUp()
{
parent::setUp();
- global $cache, $config, $db;
+ global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container;
$db = $this->db = $this->new_dbal();
- $config = array(
+ $config = new \phpbb\config\config(array(
'load_online_time' => 5,
- 'search_type' => 'fulltext_mysql',
- );
+ 'search_type' => '\phpbb\search\fulltext_mysql',
+ ));
+ set_config(false, false, false, $config);
+ set_config_count(false, false, false, $config);
$cache = new phpbb_mock_null_cache();
+ $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(
+ 'auth.provider.db',
+ new phpbb_mock_auth_provider()
+ );
+ $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
+ $provider_collection->add('auth.provider.db');
+ $phpbb_container->set(
+ 'auth.provider_collection',
+ $provider_collection
+ );
}
public function first_last_post_data()
@@ -102,18 +116,18 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
),
),
array(
- 'retain', 'Bertie',
+ 'retain', true,
array(
- array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'),
+ array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'),
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
- array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'),
+ array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
),
array(
array(
'topic_id' => 1,
- 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '',
- 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '',
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 2,
@@ -122,8 +136,8 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
),
array(
'topic_id' => 3,
- 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '',
- 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '',
+ 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '',
+ 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 4,
@@ -132,14 +146,14 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
),
),
array(
- array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Bertie', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''),
array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
- array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Bertie', 'forum_last_poster_colour' => ''),
+ array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''),
array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
),
),
array(
- 'remove', 'Bertie',
+ 'remove', true,
array(
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
@@ -169,9 +183,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
/**
* @dataProvider first_last_post_data
*/
- public function test_first_last_post_info($mode, $post_username, $expected_posts, $expected_topics, $expected_forums)
+ public function test_first_last_post_info($mode, $retain_username, $expected_posts, $expected_topics, $expected_forums)
{
- $this->assertFalse(user_delete($mode, 2, $post_username));
+ $this->assertFalse(user_delete($mode, 2, $retain_username));
$sql = 'SELECT post_id, poster_id, post_username
FROM ' . POSTS_TABLE . '
@@ -201,20 +215,20 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
array(
'retain',
array(
- array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1),
- array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1),
- array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1),
- array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1),
+ array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
+ array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
+ array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
+ array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
),
array(
array('report_id' => 1, 'post_id' => 1, 'user_id' => 1),
array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
),
array(
- array('topic_id' => 1, 'topic_reported' => 1),
- array('topic_id' => 2, 'topic_reported' => 1),
- array('topic_id' => 3, 'topic_reported' => 0),
- array('topic_id' => 4, 'topic_reported' => 0),
+ array('topic_id' => 1, 'topic_reported' => 1, 'topic_delete_user' => 1),
+ array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1),
+ array('topic_id' => 3, 'topic_reported' => 0, 'topic_delete_user' => 1),
+ array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1),
),
array(
array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1),
@@ -225,15 +239,15 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
array(
'remove',
array(
- array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1),
- array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1),
+ array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
+ array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
),
array(
array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
),
array(
- array('topic_id' => 2, 'topic_reported' => 1),
- array('topic_id' => 4, 'topic_reported' => 0),
+ array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1),
+ array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1),
),
array(
array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1),
@@ -250,7 +264,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
{
$this->assertFalse(user_delete($mode, 2));
- $sql = 'SELECT post_id, post_reported, post_edit_user
+ $sql = 'SELECT post_id, post_reported, post_edit_user, post_delete_user
FROM ' . POSTS_TABLE . '
ORDER BY post_id ASC';
$result = $this->db->sql_query($sql);
@@ -264,7 +278,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
$this->assertEquals($expected_reports, $this->db->sql_fetchrowset($result), 'Report table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
- $sql = 'SELECT topic_id, topic_reported
+ $sql = 'SELECT topic_id, topic_reported, topic_delete_user
FROM ' . TOPICS_TABLE . '
ORDER BY topic_id ASC';
$result = $this->db->sql_query($sql);
diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml
index 07591389d2..56014b35d1 100644
--- a/tests/functions_user/fixtures/delete_user.xml
+++ b/tests/functions_user/fixtures/delete_user.xml
@@ -148,10 +148,11 @@
<column>post_id</column>
<column>poster_id</column>
<column>post_edit_user</column>
+ <column>post_delete_user</column>
<column>post_username</column>
<column>topic_id</column>
<column>forum_id</column>
- <column>post_approved</column>
+ <column>post_visibility</column>
<column>post_time</column>
<column>post_text</column>
<column>post_reported</column>
@@ -159,6 +160,7 @@
<value>1</value>
<value>2</value>
<value>2</value>
+ <value>2</value>
<value></value>
<value>1</value>
<value>1</value>
@@ -171,6 +173,7 @@
<value>2</value>
<value>1</value>
<value>1</value>
+ <value>1</value>
<value>Other</value>
<value>2</value>
<value>2</value>
@@ -183,6 +186,7 @@
<value>3</value>
<value>2</value>
<value>2</value>
+ <value>2</value>
<value></value>
<value>3</value>
<value>3</value>
@@ -195,6 +199,7 @@
<value>4</value>
<value>1</value>
<value>1</value>
+ <value>1</value>
<value>Other</value>
<value>4</value>
<value>4</value>
@@ -258,29 +263,34 @@
<column>post_id</column>
<column>user_id</column>
<column>report_text</column>
+ <column>reported_post_text</column>
<row>
<value>1</value>
<value>1</value>
<value>1</value>
<value>Post Removed?</value>
+ <value></value>
</row>
<row>
<value>2</value>
<value>3</value>
<value>2</value>
<value>Post Removed?</value>
+ <value></value>
</row>
<row>
<value>3</value>
<value>2</value>
<value>1</value>
<value>Keep</value>
+ <value></value>
</row>
<row>
<value>4</value>
<value>4</value>
<value>2</value>
<value>Remove Report</value>
+ <value></value>
</row>
</table>
<table name="phpbb_sessions">
@@ -303,6 +313,7 @@
<column>forum_id</column>
<column>topic_reported</column>
<column>topic_poster</column>
+ <column>topic_delete_user</column>
<column>topic_first_poster_name</column>
<column>topic_first_poster_colour</column>
<column>topic_last_poster_id</column>
@@ -313,6 +324,7 @@
<value>1</value>
<value>1</value>
<value>2</value>
+ <value>2</value>
<value></value>
<value>00AA00</value>
<value>2</value>
@@ -324,6 +336,7 @@
<value>2</value>
<value>1</value>
<value>1</value>
+ <value>1</value>
<value>Other</value>
<value></value>
<value>1</value>
@@ -335,6 +348,7 @@
<value>3</value>
<value>1</value>
<value>2</value>
+ <value>2</value>
<value></value>
<value>00AA00</value>
<value>2</value>
@@ -346,6 +360,7 @@
<value>4</value>
<value>1</value>
<value>1</value>
+ <value>1</value>
<value>Other</value>
<value></value>
<value>1</value>
@@ -355,17 +370,15 @@
</table>
<table name="phpbb_users">
<column>user_id</column>
+ <column>username</column>
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<column>user_posts</column>
<row>
<value>1</value>
<value>Anonymous</value>
- <value></value>
- <value></value>
+ <value>anonymous</value>
<value></value>
<value></value>
<value>2</value>
@@ -373,8 +386,7 @@
<row>
<value>2</value>
<value>Foobar</value>
- <value></value>
- <value></value>
+ <value>foobar</value>
<value></value>
<value></value>
<value>2</value>
@@ -461,11 +473,17 @@
</table>
<table name="phpbb_profile_fields_data">
<column>user_id</column>
+ <column>pf_phpbb_interests</column>
+ <column>pf_phpbb_occupation</column>
<row>
<value>2</value>
+ <value></value>
+ <value></value>
</row>
<row>
<value>3</value>
+ <value></value>
+ <value></value>
</row>
</table>
<table name="phpbb_moderator_cache">
diff --git a/tests/functions_user/fixtures/group_user_attributes.xml b/tests/functions_user/fixtures/group_user_attributes.xml
new file mode 100644
index 0000000000..9b1f1f504b
--- /dev/null
+++ b/tests/functions_user/fixtures/group_user_attributes.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_avatar</column>
+ <column>group_rank</column>
+ <column>group_desc</column>
+ <row>
+ <value>1</value>
+ <value>default</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value></value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>default2</value>
+ <value>3</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>group_id</column>
+ <column>user_avatar</column>
+ <column>user_rank</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>0</value>
+ <value>barfoo</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>default</value>
+ <value>1</value>
+ <value>foobar</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>custom</value>
+ <value>2</value>
+ <value>bertie</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_group">
+ <column>user_id</column>
+ <column>group_id</column>
+ <column>user_pending</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php
new file mode 100644
index 0000000000..99a15b32bf
--- /dev/null
+++ b/tests/functions_user/group_user_attributes_test.php
@@ -0,0 +1,162 @@
+<?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_user.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml');
+ }
+
+ public function group_user_attributes_data()
+ {
+ return array(
+ array(
+ 'Setting new default group without settings for user with no settings - no change',
+ 1,
+ 2,
+ array(
+ 'group_avatar' => '',
+ 'group_avatar_type' => '',
+ 'group_avatar_height' => 0,
+ 'group_avatar_width' => 0,
+ 'group_rank' => 0,
+ ),
+ array(
+ 'user_avatar' => '',
+ 'user_rank' => 0,
+ ),
+ ),
+ array(
+ 'Setting new default group without settings for user with default settings - user settings overwritten',
+ 2,
+ 2,
+ array(
+ 'group_avatar' => '',
+ 'group_avatar_type' => '',
+ 'group_avatar_height' => 0,
+ 'group_avatar_width' => 0,
+ 'group_rank' => 0,
+ ),
+ array(
+ 'user_avatar' => '',
+ 'user_rank' => 0,
+ ),
+ ),
+ array(
+ 'Setting new default group without settings for user with custom settings - no change',
+ 3,
+ 2,
+ array(
+ 'group_avatar' => '',
+ 'group_avatar_type' => '',
+ 'group_avatar_height' => 0,
+ 'group_avatar_width' => 0,
+ 'group_rank' => 0,
+ ),
+ array(
+ 'user_avatar' => 'custom',
+ 'user_rank' => 2,
+ ),
+ ),
+ array(
+ 'Setting new default group with settings for user with no settings - user settings overwritten',
+ 1,
+ 3,
+ array(
+ 'group_avatar' => 'default2',
+ 'group_avatar_type' => 'avatar.driver.upload',
+ 'group_avatar_height' => 1,
+ 'group_avatar_width' => 1,
+ 'group_rank' => 3,
+ ),
+ array(
+ 'user_avatar' => 'default2',
+ 'user_rank' => 3,
+ ),
+ ),
+ array(
+ 'Setting new default group with settings for user with default settings - user settings overwritten',
+ 2,
+ 3,
+ array(
+ 'group_avatar' => 'default2',
+ 'group_avatar_type' => 'avatar.driver.upload',
+ 'group_avatar_height' => 1,
+ 'group_avatar_width' => 1,
+ 'group_rank' => 3,
+ ),
+ array(
+ 'user_avatar' => 'default2',
+ 'user_rank' => 3,
+ ),
+ ),
+ array(
+ 'Setting new default group with settings for user with custom settings - no change',
+ 3,
+ 3,
+ array(
+ 'group_avatar' => 'default2',
+ 'group_avatar_type' => 'avatar.driver.upload',
+ 'group_avatar_height' => 1,
+ 'group_avatar_width' => 1,
+ 'group_rank' => 3,
+ ),
+ array(
+ 'user_avatar' => 'custom',
+ 'user_rank' => 2,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider group_user_attributes_data
+ */
+ public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected)
+ {
+ global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx;
+
+ $user = new phpbb_mock_user;
+ $user->ip = '';
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_clear_prefetch');
+ $cache_driver = new \phpbb\cache\driver\null();
+ $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $phpbb_container
+ ->expects($this->any())
+ ->method('get')
+ ->with('cache.driver')
+ ->will($this->returnValue($cache_driver));
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row);
+
+ $sql = 'SELECT user_avatar, user_rank
+ FROM ' . USERS_TABLE . '
+ WHERE user_id = ' . $user_id;
+ $result = $db->sql_query($sql);
+
+ $this->assertEquals(array($expected), $db->sql_fetchrowset($result));
+
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/groupposition/fixtures/legend.xml b/tests/groupposition/fixtures/legend.xml
new file mode 100644
index 0000000000..a9209309bd
--- /dev/null
+++ b/tests/groupposition/fixtures/legend.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_legend</column>
+ <column>group_desc</column>
+ <row>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/groupposition/fixtures/teampage.xml b/tests/groupposition/fixtures/teampage.xml
new file mode 100644
index 0000000000..b6c39045e3
--- /dev/null
+++ b/tests/groupposition/fixtures/teampage.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_desc</column>
+ <row>
+ <value>1</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_teampage">
+ <column>teampage_id</column>
+ <column>group_id</column>
+ <column>teampage_name</column>
+ <column>teampage_position</column>
+ <column>teampage_parent</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>category - 2 children</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value></value>
+ <value>3</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>3</value>
+ <value></value>
+ <value>4</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>0</value>
+ <value>category2 - 2 children</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>4</value>
+ <value></value>
+ <value>6</value>
+ <value>5</value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>5</value>
+ <value></value>
+ <value>7</value>
+ <value>5</value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>6</value>
+ <value></value>
+ <value>8</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php
new file mode 100644
index 0000000000..fe003e93a7
--- /dev/null
+++ b/tests/groupposition/legend_test.php
@@ -0,0 +1,407 @@
+<?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_groupposition_legend_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/legend.xml');
+ }
+
+ public function get_group_value_data()
+ {
+ return array(
+ array(1, 0, ''),
+ array(3, 2, ''),
+ array(4, 0, '\phpbb\groupposition\exception'),
+ );
+ }
+
+ /**
+ * @dataProvider get_group_value_data
+ */
+ public function test_get_group_value($group_id, $expected, $throws_exception)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ if ($throws_exception)
+ {
+ $this->setExpectedException($throws_exception);
+ }
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($expected, $test_class->get_group_value($group_id));
+ }
+
+ public function test_get_group_count()
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals(2, $test_class->get_group_count());
+ }
+
+ public function add_group_data()
+ {
+ return array(
+ array(
+ 1,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 3),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider add_group_data
+ */
+ public function test_add_group($group_id, $expected_added, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($expected_added, $test_class->add_group($group_id));
+
+ $result = $db->sql_query('SELECT group_id, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function delete_group_data()
+ {
+ return array(
+ array(
+ 1,
+ false,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ false,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 3,
+ false,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 0),
+ ),
+ ),
+ array(
+ 1,
+ true,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ true,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 3,
+ true,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_group_data
+ */
+ public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, $skip_group));
+
+ $result = $db->sql_query('SELECT group_id, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function move_up_data()
+ {
+ return array(
+ array(
+ 1,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 3,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 2),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider move_up_data
+ */
+ public function test_move_up($group_id, $excepted_moved, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($excepted_moved, $test_class->move_up($group_id));
+
+ $result = $db->sql_query('SELECT group_id, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function move_down_data()
+ {
+ return array(
+ array(
+ 1,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 2),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 3,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider move_down_data
+ */
+ public function test_move_down($group_id, $excepted_moved, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($excepted_moved, $test_class->move_down($group_id));
+
+ $result = $db->sql_query('SELECT group_id, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function move_data()
+ {
+ return array(
+ array(
+ 1,
+ 1,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 1,
+ -1,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 3,
+ 3,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 2),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 2,
+ 0,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ array(
+ 2,
+ -1,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 2),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 2,
+ -3,
+ true,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 2),
+ array('group_id' => 3, 'group_legend' => 1),
+ ),
+ ),
+ array(
+ 3,
+ -1,
+ false,
+ array(
+ array('group_id' => 1, 'group_legend' => 0),
+ array('group_id' => 2, 'group_legend' => 1),
+ array('group_id' => 3, 'group_legend' => 2),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider move_data
+ */
+ public function test_move($group_id, $increment, $excepted_moved, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\legend($db, $user);
+ $this->assertEquals($excepted_moved, $test_class->move($group_id, $increment));
+
+ $result = $db->sql_query('SELECT group_id, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
+
diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php
new file mode 100644
index 0000000000..1e61e3ebfb
--- /dev/null
+++ b/tests/groupposition/teampage_test.php
@@ -0,0 +1,645 @@
+<?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';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+
+class phpbb_groupposition_teampage_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/teampage.xml');
+ }
+
+ public function get_group_value_data()
+ {
+ return array(
+ array(2, 3, ''),
+ array(6, 8, ''),
+ array(10, 0, '\phpbb\groupposition\exception'),
+ );
+ }
+
+ /**
+ * @dataProvider get_group_value_data
+ */
+ public function test_get_group_value($group_id, $expected, $throws_exception)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ if ($throws_exception)
+ {
+ $this->setExpectedException($throws_exception);
+ }
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($expected, $test_class->get_group_value($group_id));
+ }
+
+ public function test_get_group_count()
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals(8, $test_class->get_group_count());
+ }
+
+ public function add_group_teampage_data()
+ {
+ return array(
+ array(
+ 1,
+ 2,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ 2,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 7,
+ 2,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 7,
+ 0,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider add_group_teampage_data
+ */
+ public function test_add_group_teampage($group_id, $parent_id, $expected_added, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($expected_added, $test_class->add_group_teampage($group_id, $parent_id));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function add_category_teampage_data()
+ {
+ return array(
+ array(
+ 'new',
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider add_category_teampage_data
+ */
+ public function test_add_category_teampage($group_name, $expected_added, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($expected_added, $test_class->add_category_teampage($group_name));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function delete_group_data()
+ {
+ return array(
+ array(
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_group_data
+ */
+ public function test_delete_group($group_id, $expected_deleted, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, false));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function delete_teampage_data()
+ {
+ return array(
+ array(
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_teampage_data
+ */
+ public function test_delete_teampage($teampage_id, $expected_deleted, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($expected_deleted, $test_class->delete_teampage($teampage_id, false));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function move_data()
+ {
+ return array(
+ array(
+ 1,
+ 1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ 1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 5,
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 1,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 5,
+ -1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ -1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ 3,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider move_data
+ */
+ public function test_move($group_id, $move_delta, $excepted_moved, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($excepted_moved, $test_class->move($group_id, $move_delta));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public function move_teampage_data()
+ {
+ return array(
+ array(
+ 1,
+ 1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 5,
+ 1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ 1,
+ false,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 1,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 2,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 5,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 6,
+ -1,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ ),
+ ),
+ array(
+ 8,
+ 3,
+ true,
+ array(
+ array('teampage_position' => 1, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 2, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''),
+ array('teampage_position' => 3, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'),
+ array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 5, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''),
+ array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'),
+ array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''),
+ array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider move_teampage_data
+ */
+ public function test_move_teampage($teampage_id, $move_delta, $excepted_moved, $expected)
+ {
+ global $cache;
+
+ $cache = new phpbb_mock_cache;
+ $db = $this->new_dbal();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array();
+
+ $test_class = new \phpbb\groupposition\teampage($db, $user, $cache);
+ $this->assertEquals($excepted_moved, $test_class->move_teampage($teampage_id, $move_delta));
+
+ $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name
+ FROM ' . TEAMPAGE_TABLE . '
+ ORDER BY teampage_position ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
+
diff --git a/tests/lint_test.php b/tests/lint_test.php
index b0149063bd..70046bdfd2 100644
--- a/tests/lint_test.php
+++ b/tests/lint_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -34,31 +38,34 @@ class phpbb_lint_test extends phpbb_test_case
self::markTestSkipped(sprintf('Could not run PHP_BINARY %s. Output: %s', self::$php_binary, $output));
}
}
-
- self::$exclude = array(
- dirname(__FILE__) . '/../.git',
- dirname(__FILE__) . '/../build/new_version',
- dirname(__FILE__) . '/../build/old_versions',
- dirname(__FILE__) . '/../phpBB/cache',
- // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20
- // https://gist.github.com/e003913ffd493da63cbc
- dirname(__FILE__) . '/../phpBB/vendor',
- );
}
- public function test_lint()
+ /**
+ * @dataProvider lint_data
+ */
+ public function test_lint($path)
{
if (version_compare(PHP_VERSION, '5.3.0', '<'))
{
$this->markTestSkipped('phpBB uses PHP 5.3 syntax in some files, linting on PHP < 5.3 will fail');
}
- $root = dirname(__FILE__) . '/..';
- $this->check($root);
+ $cmd = sprintf('(%s -l %s) 2>&1', self::$php_binary, escapeshellarg($path));
+ $output = array();
+ $status = 1;
+ exec($cmd, $output, $status);
+ $output = implode("\n", $output);
+ $this->assertEquals(0, $status, "PHP lint failed for $path:\n$output");
+ }
+
+ public function lint_data()
+ {
+ return $this->check(dirname(__FILE__) . '/..');
}
protected function check($root)
{
+ $files = array();
$dh = opendir($root);
while (($filename = readdir($dh)) !== false)
{
@@ -72,19 +79,25 @@ class phpbb_lint_test extends phpbb_test_case
{
continue;
}
- if (is_dir($path) && !in_array($path, self::$exclude))
+ if (is_dir($path) && !in_array($path, array(
+ dirname(__FILE__) . '/../.git',
+ dirname(__FILE__) . '/../build/new_version',
+ dirname(__FILE__) . '/../build/old_versions',
+ dirname(__FILE__) . '/../phpBB/cache',
+ dirname(__FILE__) . '/../phpBB/ext',
+ dirname(__FILE__) . '/../phpBB/store',
+ // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20
+ // https://gist.github.com/e003913ffd493da63cbc
+ dirname(__FILE__) . '/../phpBB/vendor',
+ )))
{
- $this->check($path);
+ $files = array_merge($files, $this->check($path));
}
else if (substr($filename, strlen($filename)-4) == '.php')
{
- $cmd = sprintf('(%s -l %s) 2>&1', self::$php_binary, escapeshellarg($path));
- $output = array();
- $status = 1;
- exec($cmd, $output, $status);
- $output = implode("\n", $output);
- $this->assertEquals(0, $status, "PHP lint failed for $path:\n$output");
+ $files[] = array($path);
}
}
+ return $files;
}
}
diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php
new file mode 100644
index 0000000000..6fc813cb38
--- /dev/null
+++ b/tests/lock/db_test.php
@@ -0,0 +1,101 @@
+<?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_lock_db_test extends phpbb_database_test_case
+{
+ private $db;
+ private $config;
+ private $lock;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function setUp()
+ {
+ global $db, $config;
+
+ $db = $this->db = $this->new_dbal();
+ $config = $this->config = new \phpbb\config\config(array('rand_seed' => '', 'rand_seed_last_update' => '0'));
+ set_config(null, null, null, $this->config);
+ $this->lock = new \phpbb\lock\db('test_lock', $this->config, $this->db);
+ }
+
+ public function test_new_lock()
+ {
+ $this->assertFalse($this->lock->owns_lock());
+
+ $this->assertTrue($this->lock->acquire());
+ $this->assertTrue($this->lock->owns_lock());
+ $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
+
+ $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db);
+ $this->assertFalse($lock2->acquire());
+ $this->assertFalse($lock2->owns_lock());
+
+ $this->lock->release();
+ $this->assertFalse($this->lock->owns_lock());
+ $this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
+ }
+
+ public function test_expire_lock()
+ {
+ $lock = new \phpbb\lock\db('foo_lock', $this->config, $this->db);
+ $this->assertTrue($lock->acquire());
+ }
+
+ public function test_double_lock()
+ {
+ $this->assertFalse($this->lock->owns_lock());
+
+ $this->assertTrue($this->lock->acquire());
+ $this->assertTrue($this->lock->owns_lock());
+ $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
+
+ $value = $this->config['test_lock'];
+
+ $this->assertFalse($this->lock->acquire());
+ $this->assertTrue($this->lock->owns_lock());
+ $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed');
+
+ $this->lock->release();
+ $this->assertFalse($this->lock->owns_lock());
+ $this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
+ }
+
+ public function test_double_unlock()
+ {
+ $this->assertTrue($this->lock->acquire());
+ $this->assertTrue($this->lock->owns_lock());
+ $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired');
+
+ $this->lock->release();
+ $this->assertFalse($this->lock->owns_lock());
+ $this->assertEquals('0', $this->config['test_lock'], 'First lock is released');
+
+ $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db);
+ $this->assertTrue($lock2->acquire());
+ $this->assertTrue($lock2->owns_lock());
+ $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired');
+
+ $this->lock->release();
+ $this->assertTrue($lock2->owns_lock());
+ $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored');
+
+ $lock2->release();
+ $this->assertEquals('0', $this->config['test_lock'], 'Second lock is released');
+ }
+}
diff --git a/tests/lock/fixtures/config.xml b/tests/lock/fixtures/config.xml
new file mode 100644
index 0000000000..f36c8b929a
--- /dev/null
+++ b/tests/lock/fixtures/config.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ <row>
+ <value>foo_lock</value>
+ <value>1 abcd</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php
new file mode 100644
index 0000000000..554b7e57f4
--- /dev/null
+++ b/tests/lock/flock_test.php
@@ -0,0 +1,124 @@
+<?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_lock_flock_test extends phpbb_test_case
+{
+ public function test_lock()
+ {
+ $path = __DIR__ . '/../tmp/precious';
+
+ $lock = new \phpbb\lock\flock($path);
+ $ok = $lock->acquire();
+ $this->assertTrue($ok);
+ $lock->release();
+ }
+
+ public function test_consecutive_locking()
+ {
+ $path = __DIR__ . '/../tmp/precious';
+
+ $lock = new \phpbb\lock\flock($path);
+ $ok = $lock->acquire();
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ $lock->release();
+ $this->assertFalse($lock->owns_lock());
+
+ $ok = $lock->acquire();
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ $lock->release();
+ $this->assertFalse($lock->owns_lock());
+
+ $ok = $lock->acquire();
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ $lock->release();
+ $this->assertFalse($lock->owns_lock());
+ }
+
+ /* This hangs the process.
+ public function test_concurrent_locking_fail()
+ {
+ $path = __DIR__ . '/../tmp/precious';
+
+ $lock1 = new \phpbb\lock\flock($path);
+ $ok = $lock1->acquire();
+ $this->assertTrue($ok);
+
+ $lock2 = new \phpbb\lock\flock($path);
+ $ok = $lock2->acquire();
+ $this->assertFalse($ok);
+
+ $lock->release();
+ $ok = $lock2->acquire();
+ $this->assertTrue($ok);
+ }
+ */
+
+ public function test_concurrent_locking()
+ {
+ if (!function_exists('pcntl_fork'))
+ {
+ $this->markTestSkipped('pcntl extension and pcntl_fork are required for this test');
+ }
+
+ $path = __DIR__ . '/../tmp/precious';
+
+ $pid = pcntl_fork();
+ if ($pid)
+ {
+ // parent
+ // wait 0.5 s, acquire the lock, note how long it took
+ sleep(1);
+
+ $lock = new \phpbb\lock\flock($path);
+ $start = microtime(true);
+ $ok = $lock->acquire();
+ $delta = microtime(true) - $start;
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon');
+
+ $lock->release();
+ $this->assertFalse($lock->owns_lock());
+
+ // acquire again, this should be instantaneous
+ $start = microtime(true);
+ $ok = $lock->acquire();
+ $delta = microtime(true) - $start;
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously');
+
+ // reap the child
+ $status = null;
+ pcntl_waitpid($pid, $status);
+ }
+ else
+ {
+ // child
+ // immediately acquire the lock and sleep for 2 s
+ $lock = new \phpbb\lock\flock($path);
+ $ok = $lock->acquire();
+ $this->assertTrue($ok);
+ $this->assertTrue($lock->owns_lock());
+ sleep(2);
+ $lock->release();
+ $this->assertFalse($lock->owns_lock());
+
+ // and go away silently
+ pcntl_exec('/usr/bin/env', array('true'));
+ }
+ }
+}
diff --git a/tests/log/add_test.php b/tests/log/add_test.php
new file mode 100644
index 0000000000..29d3adaeb6
--- /dev/null
+++ b/tests/log/add_test.php
@@ -0,0 +1,101 @@
+<?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_log_add_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml');
+ }
+
+ public function test_log_enabled()
+ {
+ global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
+
+ $db = $this->new_dbal();
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $this->assertTrue($log->is_enabled(), 'Initialise failed');
+
+ $log->disable();
+ $this->assertFalse($log->is_enabled(), 'Disable all failed');
+
+ $log->enable();
+ $this->assertTrue($log->is_enabled(), 'Enable all failed');
+
+ $log->disable('admin');
+ $this->assertFalse($log->is_enabled('admin'), 'Disable admin failed');
+ $this->assertTrue($log->is_enabled('user'), 'User should be enabled, is disabled');
+ $this->assertTrue($log->is_enabled(), 'Disable admin disabled all');
+
+ $log->enable('admin');
+ $this->assertTrue($log->is_enabled('admin'), 'Enable admin failed');
+ }
+
+ public function test_log_add()
+ {
+ global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher;
+
+ $db = $this->new_dbal();
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $mode = 'critical';
+ $user_id = ANONYMOUS;
+ $log_ip = 'user_ip';
+ $log_time = time();
+ $log_operation = 'LOG_OPERATION';
+ $additional_data = array();
+
+ // Add an entry successful
+ $this->assertEquals(1, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time));
+
+ // Disable logging for all types
+ $log->disable();
+ $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for all types failed');
+ $log->enable();
+
+ // Disable logging for same type
+ $log->disable('critical');
+ $this->assertFalse($log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for same type failed');
+ $log->enable();
+
+ // Disable logging for different type
+ $log->disable('admin');
+ $this->assertEquals(2, $log->add($mode, $user_id, $log_ip, $log_operation, $log_time), 'Disable for different types failed');
+ $log->enable();
+
+ // Invalid mode specified
+ $this->assertFalse($log->add('mode_does_not_exist', $user_id, $log_ip, $log_operation, $log_time));
+
+ // null user and null ip given
+ $this->assertEquals(3, $log->add($mode, null, null, $log_operation, $log_time), 'Adding log with null user_id and null user_ip failed');
+ $sql = 'SELECT user_id, log_ip FROM ' . LOG_TABLE . ' WHERE log_id = 3';
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+ $this->assertEquals(ANONYMOUS, $row['user_id'], 'Adding log with null user_id failed');
+ $this->assertEquals('', $row['log_ip'], 'Adding log with null user_ip failed');
+ }
+}
diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php
new file mode 100644
index 0000000000..ec43182a0c
--- /dev/null
+++ b/tests/log/delete_test.php
@@ -0,0 +1,157 @@
+<?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_log_delete_test extends phpbb_database_test_case
+{
+ protected $log;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_log.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher, $auth;
+
+ $db = $this->new_dbal();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->data['user_id'] = 1;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $this->log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ parent::setUp();
+ }
+
+ public function log_delete_data()
+ {
+ return array(
+ array(
+ array(1, 2),
+ array(16),
+ array(),
+ 'admin',
+ false,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 'l.log_id ASC',
+ '',
+ ),
+ array(
+ array(11),
+ array(),
+ array('keywords' => 'guest'),
+ 'mod',
+ false,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 'l.log_id ASC',
+ 'guest',
+ ),
+ array(
+ array(4, 5, 7),
+ array(),
+ array('forum_id' => 12, 'user_id' => 1),
+ 'mod',
+ false,
+ 0,
+ 0,
+ 12,
+ 0,
+ 1,
+ 0,
+ 'l.log_id ASC',
+ '',
+ ),
+ array(
+ array(12, 13),
+ array(),
+ array('forum_id' => array('IN' => array(14, 13))),
+ 'mod',
+ false,
+ 0,
+ 0,
+ array(13, 14),
+ 0,
+ 0,
+ 0,
+ 'l.log_id ASC',
+ '',
+ ),
+ array(
+ array(3, 14, 15),
+ array(3),
+ array('user_id' => array('>', 1)),
+ 'critical',
+ false,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 'l.log_id ASC',
+ '',
+ ),
+ array(
+ array(3, 14, 15),
+ array(),
+ array('keywords' => ''),
+ 'critical',
+ false,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 'l.log_id ASC',
+ '',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider log_delete_data
+ */
+ public function test_log_delete($expected_before, $expected_after, $delete_conditions, $mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords)
+ {
+ $this->assertSame($expected_before, $this->get_ids($this->log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords)), 'before');
+ $this->log->delete($mode, $delete_conditions);
+ $this->assertSame($expected_after, $this->get_ids($this->log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords)), 'after');
+ }
+
+ public function get_ids($logs)
+ {
+ $ids = array();
+ foreach ($logs as $log_entry)
+ {
+ $ids[] = (int) $log_entry['id'];
+ }
+ return $ids;
+ }
+}
diff --git a/tests/log/fixtures/delete_log.xml b/tests/log/fixtures/delete_log.xml
new file mode 100644
index 0000000000..4b2402102e
--- /dev/null
+++ b/tests/log/fixtures/delete_log.xml
@@ -0,0 +1,232 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_log">
+ <column>log_id</column>
+ <column>log_type</column>
+ <column>user_id</column>
+ <column>forum_id</column>
+ <column>topic_id</column>
+ <column>reportee_id</column>
+ <column>log_ip</column>
+ <column>log_time</column>
+ <column>log_operation</column>
+ <column>log_data</column>
+ <row>
+ <value>1</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_INSTALL_INSTALLED</value>
+ <value>a:1:{i:0;s:9:"3.1.0-dev";}</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_KEY_NOT_EXISTS</value>
+ <value>a:1:{i:0;s:15:"additional_data";}</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_CRITICAL</value>
+ <value>a:1:{i:0;s:13:"critical data";}</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>34</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>45</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value>23</value>
+ <value>56</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>45</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>2</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_USER</value>
+ <value>a:1:{i:0;s:5:"admin";}</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_USER</value>
+ <value>a:1:{i:0;s:5:"guest";}</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_SINGULAR_PLURAL</value>
+ <value>a:1:{i:0;i:2;}</value>
+ </row>
+ <row>
+ <value>11</value>
+ <value>1</value>
+ <value>1</value>
+ <value>15</value>
+ <value>3</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD3</value>
+ <value>a:1:{i:0;s:5:"guest";}</value>
+ </row>
+ <row>
+ <value>12</value>
+ <value>1</value>
+ <value>1</value>
+ <value>13</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>13</value>
+ <value>1</value>
+ <value>1</value>
+ <value>14</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>14</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>15</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>Anonymous</value>
+ <value>Anonymous</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>admin</value>
+ <value>admin</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>34</value>
+ <value>12</value>
+ </row>
+ <row>
+ <value>45</value>
+ <value>12</value>
+ </row>
+ <row>
+ <value>56</value>
+ <value>23</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/log/fixtures/empty_log.xml b/tests/log/fixtures/empty_log.xml
new file mode 100644
index 0000000000..261b6a622a
--- /dev/null
+++ b/tests/log/fixtures/empty_log.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_log">
+ <column>log_id</column>
+ <column>log_type</column>
+ <column>user_id</column>
+ <column>forum_id</column>
+ <column>topic_id</column>
+ <column>reportee_id</column>
+ <column>log_ip</column>
+ <column>log_time</column>
+ <column>log_operation</column>
+ <column>log_data</column>
+ </table>
+</dataset>
diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml
new file mode 100644
index 0000000000..ef35884444
--- /dev/null
+++ b/tests/log/fixtures/full_log.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_log">
+ <column>log_id</column>
+ <column>log_type</column>
+ <column>user_id</column>
+ <column>forum_id</column>
+ <column>topic_id</column>
+ <column>reportee_id</column>
+ <column>log_ip</column>
+ <column>log_time</column>
+ <column>log_operation</column>
+ <column>log_data</column>
+ <row>
+ <value>1</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_INSTALL_INSTALLED</value>
+ <value>a:1:{i:0;s:9:"3.1.0-dev";}</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_KEY_NOT_EXISTS</value>
+ <value>a:1:{i:0;s:15:"additional_data";}</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_CRITICAL</value>
+ <value>a:1:{i:0;s:13:"critical data";}</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>34</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>45</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value>23</value>
+ <value>56</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD</value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>1</value>
+ <value>1</value>
+ <value>12</value>
+ <value>45</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD2</value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>2</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_USER</value>
+ <value>a:1:{i:0;s:5:"admin";}</value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_USER</value>
+ <value>a:1:{i:0;s:5:"guest";}</value>
+ </row>
+ <row>
+ <value>10</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_SINGULAR_PLURAL</value>
+ <value>a:1:{i:0;i:2;}</value>
+ </row>
+ <row>
+ <value>11</value>
+ <value>1</value>
+ <value>1</value>
+ <value>15</value>
+ <value>3</value>
+ <value>0</value>
+ <value>127.0.0.1</value>
+ <value>1</value>
+ <value>LOG_MOD3</value>
+ <value>a:1:{i:0;s:5:"guest";}</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>Anonymous</value>
+ <value>Anonymous</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>admin</value>
+ <value>admin</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>34</value>
+ <value>12</value>
+ </row>
+ <row>
+ <value>45</value>
+ <value>12</value>
+ </row>
+ <row>
+ <value>56</value>
+ <value>23</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php
new file mode 100644
index 0000000000..63e468498e
--- /dev/null
+++ b/tests/log/function_add_log_test.php
@@ -0,0 +1,197 @@
+<?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_log_function_add_log_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml');
+ }
+
+ public static function add_log_function_data()
+ {
+ return array(
+ /**
+ * Case documentation
+ array(
+ // Row that is in the database afterwards
+ array(
+ 'user_id' => ANONYMOUS,
+ 'log_type' => LOG_MOD,
+ 'log_operation' => 'LOG_MOD_ADDITIONAL',
+ // log_data will be serialized
+ 'log_data' => array(
+ 'argument3',
+ ),
+ 'reportee_id' => 0,
+ 'forum_id' => 56,
+ 'topic_id' => 78,
+ ),
+ // user_id Can also be false, then ANONYMOUS is used
+ false,
+ // log_mode Used to determine the log_type
+ 'mod',
+ // Followed by some additional arguments
+ // forum_id, topic_id and reportee_id are specified before log_operation
+ // The rest is specified afterwards.
+ 56,
+ 78,
+ 'LOG_MOD_ADDITIONAL', // log_operation
+ 'argument3',
+ ),
+ */
+ array(
+ array(
+ 'user_id' => 2,
+ 'log_type' => LOG_CRITICAL,
+ 'log_operation' => 'LOG_NO_ADDITIONAL',
+ 'log_data' => '',
+ 'reportee_id' => 0,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+ ),
+ 2, 'critical', 'LOG_NO_ADDITIONAL',
+ ),
+ array(
+ array(
+ 'user_id' => 2,
+ 'log_type' => LOG_CRITICAL,
+ 'log_operation' => 'LOG_ONE_ADDITIONAL',
+ 'log_data' => array(
+ 'argument1',
+ ),
+ 'reportee_id' => 0,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+ ),
+ 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1',
+ ),
+ array(
+ array(
+ 'user_id' => ANONYMOUS,
+ 'log_type' => LOG_ADMIN,
+ 'log_operation' => 'LOG_TWO_ADDITIONAL',
+ 'log_data' => array(
+ 'argument1',
+ 'argument2',
+ ),
+ 'reportee_id' => 0,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+ ),
+ false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2',
+ ),
+ array(
+ array(
+ 'user_id' => ANONYMOUS,
+ 'log_type' => LOG_USERS,
+ 'log_operation' => 'LOG_USERS_ADDITIONAL',
+ 'log_data' => array(
+ 'argument2',
+ ),
+ 'reportee_id' => 2,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+ ),
+ false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2',
+ ),
+ array(
+ array(
+ 'user_id' => ANONYMOUS,
+ 'log_type' => LOG_MOD,
+ 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM',
+ 'log_data' => '',
+ 'reportee_id' => 0,
+ 'forum_id' => 12,
+ 'topic_id' => 34,
+ ),
+ false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM',
+ ),
+ array(
+ array(
+ 'user_id' => ANONYMOUS,
+ 'log_type' => LOG_MOD,
+ 'log_operation' => 'LOG_MOD_ADDITIONAL',
+ 'log_data' => array(
+ 'argument3',
+ ),
+ 'reportee_id' => 0,
+ 'forum_id' => 56,
+ 'topic_id' => 78,
+ ),
+ false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3',
+ ),
+ array(
+ array(
+ ),
+ false, 'mode_does_not_exist', 'LOG_MOD_ADDITIONAL', 'argument1',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider add_log_function_data
+ */
+ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null)
+ {
+ global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ if ($expected)
+ {
+ // Serialize the log data if we have some
+ if (is_array($expected['log_data']))
+ {
+ $expected['log_data'] = serialize($expected['log_data']);
+ }
+ $expected = array($expected);
+ }
+
+ $db = $this->new_dbal();
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $user->ip = 'user_ip';
+ if ($user_id)
+ {
+ $user->data['user_id'] = $user_id;
+ }
+
+ if ($additional3 != null)
+ {
+ add_log($mode, $required1, $additional1, $additional2, $additional3);
+ }
+ else if ($additional2 != null)
+ {
+ add_log($mode, $required1, $additional1, $additional2);
+ }
+ else if ($additional1 != null)
+ {
+ add_log($mode, $required1, $additional1);
+ }
+ else
+ {
+ add_log($mode, $required1);
+ }
+
+ $result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id
+ FROM ' . LOG_TABLE);
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php
new file mode 100644
index 0000000000..02e0b3912f
--- /dev/null
+++ b/tests/log/function_view_log_test.php
@@ -0,0 +1,409 @@
+<?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_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+require_once dirname(__FILE__) . '/../mock/user.php';
+require_once dirname(__FILE__) . '/../mock/cache.php';
+
+class phpbb_log_function_view_log_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml');
+ }
+
+ public static function view_log_function_data()
+ {
+ global $phpEx, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $expected_data_sets = array(
+ 1 => array(
+ 'id' => 1,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_INSTALL_INSTALLED 3.1.0-dev',
+ ),
+ 2 => array(
+ 'id' => 2,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => '{LOG KEY NOT EXISTS}<br />additional_data',
+ ),
+ 3 => array(
+ 'id' => 3,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => '{LOG CRITICAL}<br />critical data',
+ ),
+ 4 => array(
+ 'id' => 4,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 12,
+ 'topic_id' => 34,
+
+ 'viewforum' => '',
+ 'action' => '{LOG MOD}',
+ 'viewtopic' => '',
+ 'viewlogs' => '',
+ ),
+ 5 => array(
+ 'id' => 5,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 12,
+ 'topic_id' => 45,
+
+ 'viewforum' => '',
+ 'action' => '{LOG MOD}',
+ 'viewtopic' => '',
+ 'viewlogs' => '',
+ ),
+ 6 => array(
+ 'id' => 6,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 23,
+ 'topic_id' => 56,
+
+ 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'),
+ 'action' => '{LOG MOD}',
+ 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 'f=23&amp;t=56'),
+ 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&amp;mode=topic_logs&amp;t=56'),
+ ),
+ 7 => array(
+ 'id' => 7,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 12,
+ 'topic_id' => 45,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_MOD2',
+ 'viewtopic' => '',
+ 'viewlogs' => '',
+ ),
+ 8 => array(
+ 'id' => 8,
+
+ 'reportee_id' => 2,
+ 'reportee_username' => 'admin',
+ 'reportee_username_full'=> '<span class="username">admin</span>',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_USER admin',
+ ),
+ 9 => array(
+ 'id' => 9,
+
+ 'reportee_id' => 1,
+ 'reportee_username' => 'Anonymous',
+ 'reportee_username_full'=> '<span class="username">Anonymous</span>',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_USER guest',
+ ),
+ 10 => array(
+ 'id' => 10,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 0,
+ 'topic_id' => 0,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_SINGULAR_PLURAL 2',
+ ),
+ 11 => array(
+ 'id' => 11,
+
+ 'reportee_id' => 0,
+ 'reportee_username' => '',
+ 'reportee_username_full'=> '',
+
+ 'user_id' => 1,
+ 'username' => 'Anonymous',
+ 'username_full' => '<span class="username">Anonymous</span>',
+
+ 'ip' => '127.0.0.1',
+ 'time' => 1,
+ 'forum_id' => 15,
+ 'topic_id' => 3,
+
+ 'viewforum' => '',
+ 'action' => 'LOG_MOD3 guest ',
+ 'viewtopic' => '',
+ 'viewlogs' => '',
+ ),
+ );
+
+ $test_cases = array(
+ /**
+ * Case documentation
+ array(
+ // Array of datasets that should be in $log after running the function
+ 'expected' => array(5, 7),
+ // Offset that will be returned from the function
+ 'expected_returned' => 0,
+ // view_log parameters (see includes/functions_admin.php for docblock)
+ // $log is ommited!
+ 'mod', 5, 0, 12, 45,
+ ),
+ */
+ array(
+ 'expected' => array(1, 2),
+ 'expected_returned' => 0,
+ 'admin', false,
+ ),
+ array(
+ 'expected' => array(1),
+ 'expected_returned' => 0,
+ 'admin', false, 1,
+ ),
+ array(
+ 'expected' => array(2),
+ 'expected_returned' => 1,
+ 'admin', false, 1, 1,
+ ),
+ array(
+ 'expected' => array(2),
+ 'expected_returned' => 1,
+ 'admin', 0, 1, 1,
+ ),
+ array(
+ 'expected' => array(2),
+ 'expected_returned' => 1,
+ 'admin', 0, 1, 5,
+ ),
+ array(
+ 'expected' => array(3),
+ 'expected_returned' => 0,
+ 'critical', false,
+ ),
+ array(
+ 'expected' => array(),
+ 'expected_returned' => null,
+ 'mode_does_not_exist', false,
+ ),
+ array(
+ 'expected' => array(4, 5, 7),
+ 'expected_returned' => 0,
+ 'mod', 0, 5, 0, 12,
+ ),
+ array(
+ 'expected' => array(5, 7),
+ 'expected_returned' => 0,
+ 'mod', 0, 5, 0, 12, 45,
+ ),
+ array(
+ 'expected' => array(6),
+ 'expected_returned' => 0,
+ 'mod', 0, 5, 0, 23,
+ ),
+ array(
+ 'expected' => array(8),
+ 'expected_returned' => 0,
+ 'user', 0, 5, 0, 0, 0, 2,
+ ),
+ array(
+ 'expected' => array(8, 9, 10),
+ 'expected_returned' => 0,
+ 'users', 0,
+ ),
+ array(
+ 'expected' => array(1),
+ 'expected_returned' => 0,
+ 'admin', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'install',
+ ),
+ array(
+ 'expected' => array(10),
+ 'expected_returned' => 0,
+ 'user', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'plural',
+ ),
+ array(
+ 'expected' => array(11),
+ 'expected_returned' => 0,
+ 'mod', 0, 5, 0, 15, 3,
+ ),
+ );
+
+ foreach ($test_cases as $case => $case_data)
+ {
+ foreach ($case_data['expected'] as $data_set => $expected)
+ {
+ $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected];
+ }
+ }
+
+ return $test_cases;
+ }
+
+ /**
+ * @dataProvider view_log_function_data
+ */
+ public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '')
+ {
+ global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
+
+ $db = $this->new_dbal();
+ $cache = new phpbb_mock_cache;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ // Create auth mock
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $acl_get_map = array(
+ array('f_read', 23, true),
+ array('m_', 23, true),
+ );
+ $acl_gets_map = array(
+ array('a_', 'm_', 23, true),
+ );
+
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'),
+ $this->anything())
+ ->will($this->returnValueMap($acl_get_map));
+ $auth->expects($this->any())
+ ->method('acl_gets')
+ ->with($this->stringContains('_'),
+ $this->anything())
+ ->will($this->returnValueMap($acl_gets_map));
+
+ $user = new phpbb_mock_user;
+ $user->optionset('viewcensors', false);
+ // Test sprintf() of the data into the action
+ $user->lang = array(
+ 'LOG_INSTALL_INSTALLED' => 'installed: %s',
+ 'LOG_USER' => 'User<br /> %s',
+ 'LOG_MOD2' => 'Mod2',
+ 'LOG_MOD3' => 'Mod3: %1$s, %2$s',
+ 'LOG_SINGULAR_PLURAL' => array(
+ 1 => 'singular',
+ 2 => 'plural (%d)',
+ ),
+ );
+
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+
+ $log = array();
+ $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords));
+
+ $this->assertEquals($expected, $log);
+ }
+}
diff --git a/tests/mcp/fixtures/post_ip.xml b/tests/mcp/fixtures/post_ip.xml
new file mode 100644
index 0000000000..fad2193396
--- /dev/null
+++ b/tests/mcp/fixtures/post_ip.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>poster_id</column>
+ <column>post_edit_user</column>
+ <column>post_delete_user</column>
+ <column>post_username</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_visibility</column>
+ <column>post_time</column>
+ <column>post_text</column>
+ <column>post_reported</column>
+ <column>poster_ip</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ <value>127.0.0.2</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ <value>127.0.0.3</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>Other</value>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/mcp/post_ip_test.php b/tests/mcp/post_ip_test.php
new file mode 100644
index 0000000000..72a9f62774
--- /dev/null
+++ b/tests/mcp/post_ip_test.php
@@ -0,0 +1,67 @@
+<?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/mcp/mcp_post.php';
+
+class phpbb_mcp_post_ip_test extends phpbb_database_test_case
+{
+ /** @var \phpbb\db\driver\driver_interface */
+ protected $db;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/post_ip.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ }
+
+ public function data_get_num_ips()
+ {
+ return array(
+ array(2, 1),
+ array(2, 2),
+ array(0, 3),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_num_ips
+ */
+ public function test_get_num_ips($expected, $poster_id)
+ {
+ $this->assertSame($expected, phpbb_get_num_ips_for_poster($this->db, $poster_id));
+ }
+
+ public function data_get_num_posters()
+ {
+ return array(
+ array(2, '127.0.0.1'),
+ array(1, '127.0.0.2'),
+ array(1, '127.0.0.3'),
+ array(0, '127.0.0.4'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_num_posters
+ */
+ public function test_get_num_posters($expected, $ip)
+ {
+ $this->assertSame($expected, phpbb_get_num_posters_for_ip($this->db, $ip));
+ }
+}
diff --git a/tests/migrator/convert_timezones_test.php b/tests/migrator/convert_timezones_test.php
new file mode 100644
index 0000000000..7501ed2ed0
--- /dev/null
+++ b/tests/migrator/convert_timezones_test.php
@@ -0,0 +1,98 @@
+<?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_migrator_convert_timezones_test extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ $this->db = $this->new_dbal();
+ $db_tools = new \phpbb\db\tools($this->db);
+
+ // user_dst doesn't exist anymore, must re-add it to test this
+ $db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1));
+
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert_timezones.xml');
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'users' => array(
+ 'user_dst',
+ ),
+ ),
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'users' => array(
+ 'user_dst' => array('BOOL', 0),
+ ),
+ ),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+
+ $this->migration = new \phpbb\db\migration\data\v310\timezone(
+ new \phpbb\config\config(array()),
+ $this->db,
+ new \phpbb\db\tools($this->db),
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_'
+ );
+ }
+
+ protected $expected_results = array(
+ //user_id => user_timezone
+ 1 => 'Etc/GMT+12',
+ 2 => 'Etc/GMT+11',
+ 3 => 'Etc/GMT-3',
+ 4 => 'Etc/GMT-4',
+ 5 => 'America/St_Johns',
+ 6 => 'Australia/Eucla',
+ );
+
+ public function test_convert()
+ {
+ $this->migration->update_timezones(0);
+
+ $sql = 'SELECT user_id, user_timezone
+ FROM phpbb_users
+ ORDER BY user_id ASC';
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']);
+ }
+ $this->db->sql_freeresult($result);
+
+ $db_tools = new \phpbb\db\tools($this->db);
+
+ // Remove the user_dst field again
+ $db_tools->sql_column_remove('phpbb_users', 'user_dst');
+ }
+}
diff --git a/tests/migrator/fixtures/convert_timezones.xml b/tests/migrator/fixtures/convert_timezones.xml
new file mode 100644
index 0000000000..b02cf8393c
--- /dev/null
+++ b/tests/migrator/fixtures/convert_timezones.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_timezone</column>
+ <column>user_dst</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value>-12</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ <value>-12</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>4</value>
+ <value></value>
+ <value></value>
+ <value>3</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>5</value>
+ <value></value>
+ <value></value>
+ <value>-3.5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>6</value>
+ <value></value>
+ <value></value>
+ <value>8.75</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/migrator/get_schema_steps_test.php b/tests/migrator/get_schema_steps_test.php
new file mode 100644
index 0000000000..3d15d2b200
--- /dev/null
+++ b/tests/migrator/get_schema_steps_test.php
@@ -0,0 +1,204 @@
+<?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 get_schema_steps_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->helper = new \phpbb\db\migration\helper();
+ }
+
+ public function schema_provider()
+ {
+ return array(
+ array(
+ array(
+ 'add_tables' => array(
+ 'foo' => array(
+ 'COLUMNS' => array(
+ 'foobar' => array('BOOL', 0),
+ 'foobar2' => array('BOOL', 0),
+ ),
+ 'PRIMARY_KEY' => array('foobar'),
+ ),
+ 'bar' => array(
+ 'COLUMNS' => array(
+ 'barfoo' => array('BOOL', 0),
+ 'barfoor2' => array('BOOL', 0),
+ ),
+ 'PRIMARY_KEY' => array('barfoo'),
+ ),
+ ),
+ 'drop_tables' => array('table1', 'table2', 'table3'),
+ 'add_index' => array(
+ 'table1' => array(
+ 'index1' => 'column1',
+ 'index2' => 'column2',
+ ),
+ 'table2' => array(
+ 'index1' => 'column1',
+ 'index2' => 'column2',
+ ),
+ ),
+ 'add_columns' => array(
+ 'table1' => array(
+ 'column1' => array('foo'),
+ 'column2' => array('bar'),
+ ),
+ ),
+ 'change_columns' => array(
+ 'table1' => array(
+ 'column1' => array('foo'),
+ 'column2' => array('bar'),
+ ),
+ ),
+ 'drop_columns' => array(
+ 'table1' => array(
+ 'column1',
+ 'column2',
+ ),
+ ),
+ 'add_unique_index' => array(
+ 'table1' => array(
+ 'index1' => 'column1',
+ 'index2' => 'column2',
+ ),
+ ),
+ 'drop_keys' => array(
+ 'table1' => array(
+ 'column1',
+ 'column2',
+ ),
+ ),
+ 'add_primary_keys' => array(
+ 'table1' => array('foo'),
+ 'table2' => array('bar'),
+ 'table3' => array('foobar'),
+ ),
+ ),
+ array(
+ array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table1')))),
+ array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table2')))),
+ array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table3')))),
+ array('dbtools.perform_schema_changes', array(array('add_tables' => array(
+ 'foo' => array(
+ 'COLUMNS' => array(
+ 'foobar' => array('BOOL', 0),
+ 'foobar2' => array('BOOL', 0),
+ ),
+ 'PRIMARY_KEY' => array('foobar'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_tables' => array(
+ 'bar' => array(
+ 'COLUMNS' => array(
+ 'barfoo' => array('BOOL', 0),
+ 'barfoor2' => array('BOOL', 0),
+ ),
+ 'PRIMARY_KEY' => array('barfoo'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('change_columns' => array(
+ 'table1' => array(
+ 'column1' => array('foo'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('change_columns' => array(
+ 'table1' => array(
+ 'column2' => array('bar'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_columns' => array(
+ 'table1' => array(
+ 'column1' => array('foo'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_columns' => array(
+ 'table1' => array(
+ 'column2' => array('bar'),
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('drop_keys' => array(
+ 'table1' => array(
+ 0 => 'column1',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('drop_keys' => array(
+ 'table1' => array(
+ 1 => 'column2',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('drop_columns' => array(
+ 'table1' => array(
+ 0 => 'column1',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('drop_columns' => array(
+ 'table1' => array(
+ 1 => 'column2',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_primary_keys' => array(
+ 'table1' => array('foo'),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_primary_keys' => array(
+ 'table2' => array('bar'),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_primary_keys' => array(
+ 'table3' => array('foobar'),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_unique_index' => array(
+ 'table1' => array(
+ 'index1' => 'column1',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_unique_index' => array(
+ 'table1' => array(
+ 'index2' => 'column2',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_index' => array(
+ 'table1' => array(
+ 'index1' => 'column1',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_index' => array(
+ 'table1' => array(
+ 'index2' => 'column2',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_index' => array(
+ 'table2' => array(
+ 'index1' => 'column1',
+ ),
+ )))),
+ array('dbtools.perform_schema_changes', array(array('add_index' => array(
+ 'table2' => array(
+ 'index2' => 'column2',
+ ),
+ )))),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider schema_provider
+ */
+ public function test_get_schema_steps($schema_changes, $expected)
+ {
+ $this->assertEquals($expected, $this->helper->get_schema_steps($schema_changes));
+ }
+}
diff --git a/tests/migrator/reverse_update_data_test.php b/tests/migrator/reverse_update_data_test.php
new file mode 100644
index 0000000000..b85e48c64c
--- /dev/null
+++ b/tests/migrator/reverse_update_data_test.php
@@ -0,0 +1,56 @@
+<?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 reverse_update_data_test extends phpbb_test_case
+{
+ /** @var \phpbb\db\migration\helper */
+ protected $helper;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->helper = new \phpbb\db\migration\helper();
+ }
+
+ public function update_data_provider()
+ {
+ return array(
+ array(
+ array(
+ array('config.add', array('foobar', 1)),
+ array('if', array(
+ (false === true),
+ array('permission.add', array('some_data')),
+ )),
+ array('config.remove', array('foobar')),
+ array('custom', array(array($this, 'foo_bar'))),
+ array('tool.method', array('test_data')),
+ ),
+ array(
+ array('tool.reverse', array('method', 'test_data')),
+ array('config.reverse', array('remove', 'foobar')),
+ array('config.reverse', array('add', 'foobar', 1)),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider update_data_provider
+ */
+ public function test_get_schema_steps($data_changes, $expected)
+ {
+ $this->assertEquals($expected, $this->helper->reverse_update_data($data_changes));
+ }
+}
diff --git a/tests/migrator/schema_generator_test.php b/tests/migrator/schema_generator_test.php
new file mode 100644
index 0000000000..9adf518a5d
--- /dev/null
+++ b/tests/migrator/schema_generator_test.php
@@ -0,0 +1,138 @@
+<?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 __DIR__ . '/../dbal/migration/dummy_order.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_0.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_1.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_2.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_3.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_4.php';
+require_once __DIR__ . '/../dbal/migration/dummy_order_5.php';
+
+class schema_generator_test extends phpbb_test_case
+{
+ /** @var \phpbb\db\migration\schema_generator */
+ protected $generator;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->config = new \phpbb\config\config(array());
+ $this->db = new \phpbb\db\driver\sqlite();
+ $this->db_tools = new \phpbb\db\tools($this->db);
+ $this->table_prefix = 'phpbb_';
+ }
+
+ protected function get_schema_generator(array $class_names)
+ {
+ $this->generator = new \phpbb\db\migration\schema_generator($class_names, $this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
+
+ return $this->generator;
+ }
+
+ /**
+ * @expectedException \UnexpectedValueException
+ */
+ public function test_check_dependencies_fail()
+ {
+ $this->get_schema_generator(array('\phpbb\db\migration\data\v310\forgot_password'));
+
+ $this->generator->get_schema();
+ }
+
+ public function test_get_schema_success()
+ {
+ $this->get_schema_generator(array(
+ '\phpbb\db\migration\data\v30x\release_3_0_1_rc1',
+ '\phpbb\db\migration\data\v30x\release_3_0_0',
+ '\phpbb\db\migration\data\v310\boardindex'
+ ));
+
+ $this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
+ }
+
+ public function column_add_after_data()
+ {
+ return array(
+ array(
+ 'phpbb_dbal_migration_dummy_order_0',
+ array(
+ 'foobar1',
+ 'foobar2',
+ 'foobar3',
+ ),
+ ),
+ array(
+ 'phpbb_dbal_migration_dummy_order_1',
+ array(
+ 'foobar1',
+ 'foobar3',
+ 'foobar4',
+ ),
+ ),
+ array(
+ 'phpbb_dbal_migration_dummy_order_2',
+ array(
+ 'foobar1',
+ 'foobar3',
+ 'foobar5',
+ ),
+ ),
+ array(
+ 'phpbb_dbal_migration_dummy_order_3',
+ array(
+ 'foobar1',
+ 'foobar3',
+ 'foobar6',
+ ),
+ ),
+ array(
+ 'phpbb_dbal_migration_dummy_order_4',
+ array(
+ 'foobar1',
+ 'foobar3',
+ 'foobar7',
+ ),
+ ),
+ array(
+ 'phpbb_dbal_migration_dummy_order_5',
+ array(
+ 'foobar1',
+ 'foobar3',
+ 'foobar9',
+ 'foobar8',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider column_add_after_data
+ */
+ public function test_column_add_after($migration, $expected)
+ {
+ $this->get_schema_generator(array(
+ 'phpbb_dbal_migration_dummy_order',
+ $migration,
+ ));
+
+ $tables = $this->generator->get_schema();
+
+ $this->assertEquals(
+ $expected,
+ array_keys($tables[$this->table_prefix . 'column_order_test1']['COLUMNS']),
+ 'The schema generator could not position the column correctly, using the "after" option in the migration script.'
+ );
+ }
+}
diff --git a/tests/mimetype/fixtures/jpg b/tests/mimetype/fixtures/jpg
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/mimetype/fixtures/jpg
Binary files differ
diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php
new file mode 100644
index 0000000000..fa53e6c8c4
--- /dev/null
+++ b/tests/mimetype/guesser_test.php
@@ -0,0 +1,230 @@
+<?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.
+*
+*/
+
+namespace phpbb\mimetype;
+
+require_once dirname(__FILE__) . '/null_guesser.php';
+require_once dirname(__FILE__) . '/incorrect_guesser.php';
+
+function function_exists($name)
+{
+ return guesser_test::$function_exists;
+}
+
+class guesser_test extends \phpbb_test_case
+{
+ public static $function_exists = false;
+
+ protected $fileinfo_supported = false;
+
+ public function setUp()
+ {
+ global $phpbb_root_path;
+
+ $guessers = array(
+ new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
+ new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
+ new \phpbb\mimetype\extension_guesser,
+ new \phpbb\mimetype\content_guesser,
+ );
+
+ // Check if any guesser except the extension_guesser is available
+ $this->fileinfo_supported = $guessers[0]->isSupported() | $guessers[1]->isSupported() | $guessers[3]->is_supported();
+
+ // Also create a guesser that emulates not having fileinfo available
+ $this->guesser_no_fileinfo = new \phpbb\mimetype\guesser(array($guessers[2]));
+
+ $this->guesser = new \phpbb\mimetype\guesser($guessers);
+ $this->path = dirname(__FILE__);
+ $this->jpg_file = $this->path . '/fixtures/jpg';
+ $this->phpbb_root_path = $phpbb_root_path;
+ }
+
+ public function data_guess_files()
+ {
+ return array(
+ array('image/gif', 'gif'),
+ array('image/png', 'png'),
+ array('image/jpeg', 'jpg'),
+ array('image/tiff', 'tif'),
+ array('text/html', 'txt'),
+ array(false, 'foobar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_guess_files
+ */
+ public function test_guess_files($expected, $file)
+ {
+ // We will always get application/octet-stream as mimetype if only the
+ // extension guesser is supported
+ if (!$this->fileinfo_supported)
+ {
+ $this->markTestSkipped('Unable to run tests depending on fileinfo if it is not available');
+ }
+ $this->assertEquals($expected, $this->guesser->guess($this->path . '/../upload/fixture/' . $file));
+ }
+
+ public function data_guess_files_no_fileinfo()
+ {
+ return array(
+ array('application/octet-stream', 'gif'),
+ array('application/octet-stream', 'txt'),
+ array(false, 'foobar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_guess_files_no_fileinfo
+ */
+ public function test_guess_files_no_fileinfo($expected, $file)
+ {
+ $this->assertEquals($expected, $this->guesser_no_fileinfo->guess($this->path . '/../upload/fixture/' . $file));
+ }
+
+ public function test_file_not_readable()
+ {
+ @chmod($this->jpg_file, 0000);
+ if (is_readable($this->jpg_file))
+ {
+ @chmod($this->jpg_file, 0644);
+ $this->markTestSkipped('is_readable always returns true if user is superuser or chmod does not work');
+ }
+ $this->assertEquals(false, $this->guesser->guess($this->jpg_file));
+ @chmod($this->jpg_file, 0644);
+ $this->assertEquals('image/jpeg', $this->guesser->guess($this->jpg_file));
+ }
+
+ public function test_null_guess()
+ {
+ $guesser = new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\null_guesser));
+ $this->assertEquals('application/octet-stream', $guesser->guess($this->jpg_file));
+ }
+
+ public function data_incorrect_guessers()
+ {
+ return array(
+ array(array(new \phpbb\mimetype\incorrect_guesser)),
+ array(array(new \phpbb\mimetype\null_guesser(false))),
+ array(array()),
+ );
+ }
+
+ /**
+ * @dataProvider data_incorrect_guessers
+ *
+ * @expectedException \LogicException
+ */
+ public function test_incorrect_guesser($guessers)
+ {
+ $guesser = new \phpbb\mimetype\guesser($guessers);
+ }
+
+ public function data_content_guesser()
+ {
+ return array(
+ array(
+ array(
+ 'image/jpeg',
+ 'image/jpeg',
+ ),
+ array(new \phpbb\mimetype\content_guesser),
+ false,
+ ),
+ array(
+ array(
+ 'application/octet-stream',
+ 'application/octet-stream',
+ ),
+ array(new \phpbb\mimetype\content_guesser),
+ true,
+ ),
+ array(
+ array(
+ 'application/octet-stream',
+ 'image/jpeg',
+ ),
+ array(new \phpbb\mimetype\extension_guesser),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_content_guesser
+ */
+ public function test_content_guesser($expected, $guessers, $overload = false)
+ {
+ $supported = false;
+ self::$function_exists = !$overload;
+
+ if (!\function_exists('mime_content_type'))
+ {
+ $this->markTestSkipped('Emulating supported mime_content_type() when it is not supported will cause a fatal error');
+ }
+
+ // Cover possible LogicExceptions
+ foreach ($guessers as $cur_guesser)
+ {
+ $supported += $cur_guesser->is_supported();
+ }
+
+ if (!$supported)
+ {
+ $this->setExpectedException('\LogicException');
+ }
+
+ $guesser = new \phpbb\mimetype\guesser($guessers);
+ $this->assertEquals($expected[0], $guesser->guess($this->jpg_file));
+ $this->assertEquals($expected[1], $guesser->guess($this->jpg_file, $this->jpg_file . '.jpg'));
+ @copy($this->jpg_file, $this->jpg_file . '.jpg');
+ $this->assertEquals($expected[1], $guesser->guess($this->jpg_file . '.jpg'));
+ @unlink($this->jpg_file . '.jpg');
+ }
+
+ public function test_sort_priority()
+ {
+ $guessers = array(
+ 'FileinfoMimeTypeGuesser' => new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser,
+ 'extension_guesser' => new \phpbb\mimetype\extension_guesser,
+ 'FileBinaryMimeTypeGuesser' => new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser,
+ 'content_guesser' => new \phpbb\mimetype\content_guesser,
+ );
+ $guessers['content_guesser']->set_priority(5);
+ $guessers['extension_guesser']->set_priority(-5);
+ usort($guessers, array($this->guesser, 'sort_priority'));
+ $this->assertInstanceOf('\phpbb\mimetype\content_guesser', $guessers[0]);
+ $this->assertInstanceOf('\phpbb\mimetype\extension_guesser', $guessers[3]);
+ }
+
+ public function data_choose_mime_type()
+ {
+ return array(
+ array('application/octet-stream', 'application/octet-stream', null),
+ array('application/octet-stream', 'application/octet-stream', 'application/octet-stream'),
+ array('binary', 'application/octet-stream', 'binary'),
+ array('image/jpeg', 'application/octet-stream', 'image/jpeg'),
+ array('image/jpeg', 'binary', 'image/jpeg'),
+ array('image/jpeg', 'image/jpg', 'image/jpeg'),
+ array('image/jpeg', 'image/jpeg', 'binary'),
+ );
+ }
+
+ /**
+ * @dataProvider data_choose_mime_type
+ */
+ public function test_choose_mime_type($expected, $mime_type, $guess)
+ {
+ $this->assertSame($expected, $this->guesser->choose_mime_type($mime_type, $guess));
+ }
+}
diff --git a/tests/mimetype/incorrect_guesser.php b/tests/mimetype/incorrect_guesser.php
new file mode 100644
index 0000000000..f74617b7a7
--- /dev/null
+++ b/tests/mimetype/incorrect_guesser.php
@@ -0,0 +1,22 @@
+<?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.
+*
+*/
+
+namespace phpbb\mimetype;
+
+class incorrect_guesser
+{
+ public function guess($file)
+ {
+ return 'image/jpeg';
+ }
+}
diff --git a/tests/mimetype/null_guesser.php b/tests/mimetype/null_guesser.php
new file mode 100644
index 0000000000..836ff4196a
--- /dev/null
+++ b/tests/mimetype/null_guesser.php
@@ -0,0 +1,34 @@
+<?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.
+*
+*/
+
+namespace phpbb\mimetype;
+
+class null_guesser
+{
+ protected $is_supported;
+
+ public function __construct($is_supported = true)
+ {
+ $this->is_supported = $is_supported;
+ }
+
+ public function is_supported()
+ {
+ return $this->is_supported;
+ }
+
+ public function guess($file)
+ {
+ return null;
+ }
+}
diff --git a/tests/mock/auth_provider.php b/tests/mock/auth_provider.php
new file mode 100644
index 0000000000..abf0e4fdfb
--- /dev/null
+++ b/tests/mock/auth_provider.php
@@ -0,0 +1,27 @@
+<?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.
+*
+*/
+
+/**
+ * Mock auth provider class with basic functions to help test sessions.
+ */
+class phpbb_mock_auth_provider extends \phpbb\auth\provider\base
+{
+ public function login($username, $password)
+ {
+ return array(
+ 'status' => "",
+ 'error_msg' => "",
+ 'user_row' => "",
+ );
+ }
+}
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index acf4288319..5fa3d28147 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -1,22 +1,23 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_cache
+class phpbb_mock_cache implements \phpbb\cache\driver\driver_interface
{
+ protected $data;
+
public function __construct($data = array())
{
$this->data = $data;
-
- if (!isset($this->data['_bots']))
- {
- $this->data['_bots'] = array();
- }
}
public function get($var_name)
@@ -34,24 +35,6 @@ class phpbb_mock_cache
$this->data[$var_name] = $var;
}
- public function destroy($var_name, $table = '')
- {
- if ($table)
- {
- throw new Exception('Destroying tables is not implemented yet');
- }
-
- unset($this->data[$var_name]);
- }
-
- /**
- * Obtain active bots
- */
- public function obtain_bots()
- {
- return $this->data['_bots'];
- }
-
/**
* Obtain list of word censors. We don't need to parse them here,
* that is tested elsewhere.
@@ -89,17 +72,32 @@ class phpbb_mock_cache
}
}
- public function set_bots($bots)
+ public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data)
{
- $this->data['_bots'] = $bots;
+ $test->assertTrue(isset($this->data[$var_name]));
+ $test->assertEquals($data, $this->data[$var_name]);
}
- public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data)
+ public function checkAssociativeVar(PHPUnit_Framework_Assert $test, $var_name, $data, $sort = true)
{
$test->assertTrue(isset($this->data[$var_name]));
+
+ if ($sort)
+ {
+ foreach ($this->data[$var_name] as &$content)
+ {
+ sort($content);
+ }
+ }
+
$test->assertEquals($data, $this->data[$var_name]);
}
+ public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name)
+ {
+ $test->assertFalse(isset($this->data[$var_name]));
+ }
+
public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true)
{
$cache_data = $this->data;
@@ -116,5 +114,58 @@ class phpbb_mock_cache
$test->assertEquals($data, $cache_data);
}
-}
+ function load()
+ {
+ }
+ function unload()
+ {
+ }
+ function save()
+ {
+ }
+ function tidy()
+ {
+ }
+ function purge()
+ {
+ }
+ function destroy($var_name, $table = '')
+ {
+ unset($this->data[$var_name]);
+ }
+ public function _exists($var_name)
+ {
+ }
+ public function sql_load($query)
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
+ {
+ return $query_result;
+ }
+ public function sql_exists($query_id)
+ {
+ }
+ public function sql_fetchrow($query_id)
+ {
+ }
+ public function sql_fetchfield($query_id, $field)
+ {
+ }
+ public function sql_rowseek($rownum, $query_id)
+ {
+ }
+ public function sql_freeresult($query_id)
+ {
+ }
+
+ public function obtain_bots()
+ {
+ return isset($this->data['_bots']) ? $this->data['_bots'] : array();
+ }
+}
diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php
new file mode 100644
index 0000000000..297e3a65e6
--- /dev/null
+++ b/tests/mock/container_builder.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 Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ScopeInterface;
+
+class phpbb_mock_container_builder implements ContainerInterface
+{
+ protected $services = array();
+ protected $parameters = array();
+
+ /**
+ * Sets a service.
+ *
+ * @param string $id The service identifier
+ * @param object $service The service instance
+ * @param string $scope The scope of the service
+ *
+ * @api
+ */
+ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
+ {
+ $this->services[$id] = $service;
+ }
+
+ /**
+ * Gets a service.
+ *
+ * @param string $id The service identifier
+ * @param int $invalidBehavior The behavior when the service does not exist
+ *
+ * @return object The associated service
+ *
+ * @throws InvalidArgumentException if the service is not defined
+ * @throws ServiceCircularReferenceException When a circular reference is detected
+ * @throws ServiceNotFoundException When the service is not defined
+ *
+ * @see Reference
+ *
+ * @api
+ */
+ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
+ {
+ if ($this->has($id))
+ {
+ return $this->services[$id];
+ }
+
+ throw new Exception('Could not find service: ' . $id);
+ }
+
+ /**
+ * Returns true if the given service is defined.
+ *
+ * @param string $id The service identifier
+ *
+ * @return Boolean true if the service is defined, false otherwise
+ *
+ * @api
+ */
+ public function has($id)
+ {
+ return isset($this->services[$id]);
+ }
+
+ /**
+ * Gets a parameter.
+ *
+ * @param string $name The parameter name
+ *
+ * @return mixed The parameter value
+ *
+ * @throws InvalidArgumentException if the parameter is not defined
+ *
+ * @api
+ */
+ public function getParameter($name)
+ {
+ if ($this->hasParameter($name))
+ {
+ return $this->parameters[$name];
+ }
+
+ throw new Exception('Could not find parameter: ' . $name);
+ }
+
+ /**
+ * Checks if a parameter exists.
+ *
+ * @param string $name The parameter name
+ *
+ * @return Boolean The presence of parameter in container
+ *
+ * @api
+ */
+ public function hasParameter($name)
+ {
+ return isset($this->parameters[$name]);
+ }
+
+ /**
+ * Sets a parameter.
+ *
+ * @param string $name The parameter name
+ * @param mixed $value The parameter value
+ *
+ * @api
+ */
+ public function setParameter($name, $value)
+ {
+ $this->parameters[$name] = $value;
+ }
+
+ /**
+ * Enters the given scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function enterScope($name)
+ {
+ }
+
+ /**
+ * Leaves the current scope, and re-enters the parent scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function leaveScope($name)
+ {
+ }
+
+ /**
+ * Adds a scope to the container
+ *
+ * @param ScopeInterface $scope
+ *
+ * @api
+ */
+ public function addScope(ScopeInterface $scope)
+ {
+ }
+
+ /**
+ * Whether this container has the given scope
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function hasScope($name)
+ {
+ }
+
+ /**
+ * Determines whether the given scope is currently active.
+ *
+ * It does however not check if the scope actually exists.
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function isScopeActive($name)
+ {
+ }
+}
diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php
new file mode 100644
index 0000000000..ae3e7bf432
--- /dev/null
+++ b/tests/mock/controller_helper.php
@@ -0,0 +1,34 @@
+<?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_controller_helper extends \phpbb\controller\helper
+{
+ public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext)
+ {
+ $this->template = $template;
+ $this->user = $user;
+ $this->config = $config;
+ $this->symfony_request = $symfony_request;
+ $this->request = $request;
+ $this->filesystem = $filesystem;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+ $provider->find_routing_files($manager->get_finder());
+ $this->route_collection = $provider->find($phpbb_root_path_ext)->get_routes();
+ }
+
+ public function get_current_url()
+ {
+ return '';
+ }
+}
diff --git a/tests/mock/event_dispatcher.php b/tests/mock/event_dispatcher.php
new file mode 100644
index 0000000000..fa8b4a1036
--- /dev/null
+++ b/tests/mock/event_dispatcher.php
@@ -0,0 +1,29 @@
+<?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_event_dispatcher extends \phpbb\event\dispatcher
+{
+ /**
+ * Constructor.
+ *
+ * Overwrite the constructor to get rid of ContainerInterface param instance
+ */
+ public function __construct()
+ {
+ }
+
+ public function trigger_event($eventName, $data = array())
+ {
+ return array();
+ }
+}
diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php
new file mode 100644
index 0000000000..94268159a8
--- /dev/null
+++ b/tests/mock/extension_manager.php
@@ -0,0 +1,26 @@
+<?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_extension_manager extends \phpbb\extension\manager
+{
+ public function __construct($phpbb_root_path, $extensions = array(), $container = null)
+ {
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = 'php';
+ $this->extensions = $extensions;
+ $this->filesystem = new \phpbb\filesystem();
+ $this->container = $container;
+ $this->config = new \phpbb\config\config(array());
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ }
+}
diff --git a/tests/mock/file_downloader.php b/tests/mock/file_downloader.php
new file mode 100644
index 0000000000..d8951cebf6
--- /dev/null
+++ b/tests/mock/file_downloader.php
@@ -0,0 +1,27 @@
+<?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_file_downloader extends \phpbb\file_downloader
+{
+ public $data;
+
+ public function set($data)
+ {
+ $this->data = $data;
+ }
+
+ public function get($host, $directory, $filename, $port = 80, $timeout = 6)
+ {
+ return $this->data;
+ }
+}
diff --git a/tests/mock/filespec.php b/tests/mock/filespec.php
new file mode 100644
index 0000000000..7ea750afbe
--- /dev/null
+++ b/tests/mock/filespec.php
@@ -0,0 +1,36 @@
+<?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.
+*
+*/
+
+/**
+ * Mock filespec class with some basic values to help with testing the
+ * fileupload class
+ */
+class phpbb_mock_filespec
+{
+ public $filesize;
+ public $realname;
+ public $extension;
+ public $width;
+ public $height;
+ public $error = array();
+
+ public function check_content($disallowed_content)
+ {
+ return true;
+ }
+
+ public function get($property)
+ {
+ return $this->$property;
+ }
+}
diff --git a/tests/mock/filesystem_extension_manager.php b/tests/mock/filesystem_extension_manager.php
new file mode 100644
index 0000000000..fa1b1c06bc
--- /dev/null
+++ b/tests/mock/filesystem_extension_manager.php
@@ -0,0 +1,36 @@
+<?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_filesystem_extension_manager extends phpbb_mock_extension_manager
+{
+ public function __construct($phpbb_root_path)
+ {
+ $extensions = array();
+ $iterator = new DirectoryIterator($phpbb_root_path . 'ext/');
+ foreach ($iterator as $fileinfo)
+ {
+ if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 1) != '.')
+ {
+ $name = $fileinfo->getFilename();
+ $extension = array(
+ 'ext_name' => $name,
+ 'ext_active' => true,
+ 'ext_path' => 'ext/' . $name . '/',
+ );
+ $extensions[$name] = $extension;
+ }
+ }
+ ksort($extensions);
+ parent::__construct($phpbb_root_path, $extensions);
+ }
+}
diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php
new file mode 100644
index 0000000000..8cc4d77ea1
--- /dev/null
+++ b/tests/mock/fileupload.php
@@ -0,0 +1,27 @@
+<?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.
+*
+*/
+
+/**
+ * Mock fileupload class with some basic values to help with testing the
+ * filespec class
+ */
+class phpbb_mock_fileupload
+{
+ public $max_filesize = 100;
+ public $error_prefix = '';
+
+ public function valid_dimensions($filespec)
+ {
+ return true;
+ }
+}
diff --git a/tests/mock/lang.php b/tests/mock/lang.php
new file mode 100644
index 0000000000..bebbe5a29b
--- /dev/null
+++ b/tests/mock/lang.php
@@ -0,0 +1,42 @@
+<?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.
+*
+*/
+
+/**
+* phpbb_mock_lang
+* mock a user with some language-keys specified
+*/
+class phpbb_mock_lang implements ArrayAccess
+{
+ public function offsetExists($offset)
+ {
+ return true;
+ }
+
+ public function offsetGet($offset)
+ {
+ return $offset;
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ }
+
+ public function offsetUnset($offset)
+ {
+ }
+
+ public function lang()
+ {
+ return implode(' ', func_get_args());
+ }
+}
diff --git a/tests/mock/metadata_manager.php b/tests/mock/metadata_manager.php
new file mode 100644
index 0000000000..2443fad560
--- /dev/null
+++ b/tests/mock/metadata_manager.php
@@ -0,0 +1,27 @@
+<?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_metadata_manager extends \phpbb\extension\metadata_manager
+{
+ public function set_metadata($metadata)
+ {
+ array_walk_recursive($metadata, array($this, 'sanitize_json'));
+ $this->metadata = $metadata;
+ }
+
+ public function merge_metadata($metadata)
+ {
+ array_walk_recursive($metadata, array($this, 'sanitize_json'));
+ $this->metadata = array_merge($this->metadata, $metadata);
+ }
+}
diff --git a/tests/mock/migrator.php b/tests/mock/migrator.php
new file mode 100644
index 0000000000..293f115335
--- /dev/null
+++ b/tests/mock/migrator.php
@@ -0,0 +1,55 @@
+<?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_migrator extends \phpbb\db\migrator
+{
+ public function __construct()
+ {
+ }
+
+ public function load_migration_state()
+ {
+ }
+
+ public function set_migrations($class_names)
+ {
+ }
+
+ public function update()
+ {
+ }
+
+ public function revert($migration)
+ {
+ }
+
+ public function unfulfillable($name)
+ {
+ }
+
+ public function finished()
+ {
+ }
+
+ public function migration_state($migration)
+ {
+ }
+
+ public function populate_migrations($migrations)
+ {
+ }
+
+ public function create_migrations_table()
+ {
+ }
+}
diff --git a/tests/mock/notification_manager.php b/tests/mock/notification_manager.php
new file mode 100644
index 0000000000..6a590bc0ca
--- /dev/null
+++ b/tests/mock/notification_manager.php
@@ -0,0 +1,97 @@
+<?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.
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Notifications service class
+*/
+class phpbb_mock_notification_manager
+{
+ public function load_notifications()
+ {
+ return array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ );
+ }
+
+ public function mark_notifications_read()
+ {
+ }
+
+ public function mark_notifications_read_by_parent()
+ {
+ }
+
+ public function mark_notifications_read_by_id()
+ {
+ }
+
+
+ public function add_notifications()
+ {
+ return array();
+ }
+
+ public function add_notifications_for_users()
+ {
+ }
+
+ public function update_notifications()
+ {
+ }
+
+ public function delete_notifications()
+ {
+ }
+
+ public function get_subscription_types()
+ {
+ return array();
+ }
+
+ public function get_subscription_methods()
+ {
+ return array();
+ }
+
+
+ public function get_global_subscriptions()
+ {
+ return array();
+ }
+
+ public function add_subscription()
+ {
+ }
+
+ public function delete_subscription()
+ {
+ }
+
+ public function load_users()
+ {
+ }
+
+ public function get_user()
+ {
+ return null;
+ }
+}
diff --git a/tests/mock/notification_type_post.php b/tests/mock/notification_type_post.php
new file mode 100644
index 0000000000..6d8f6dc504
--- /dev/null
+++ b/tests/mock/notification_type_post.php
@@ -0,0 +1,40 @@
+<?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.
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class phpbb_mock_notification_type_post extends \phpbb\notification\type\post
+{
+ public function __construct($user_loader, $db, $cache, $user, $auth, $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
+ {
+ $this->user_loader = $user_loader;
+ $this->db = $db;
+ $this->cache = $cache;
+ $this->user = $user;
+ $this->auth = $auth;
+ $this->config = $config;
+
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+
+ $this->notification_types_table = $notification_types_table;
+ $this->notifications_table = $notifications_table;
+ $this->user_notifications_table = $user_notifications_table;
+ }
+}
diff --git a/tests/mock/notifications_auth.php b/tests/mock/notifications_auth.php
new file mode 100644
index 0000000000..1106c3004f
--- /dev/null
+++ b/tests/mock/notifications_auth.php
@@ -0,0 +1,44 @@
+<?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_notifications_auth extends \phpbb\auth\auth
+{
+ function acl_get_list($user_id = false, $opts = false, $forum_id = false)
+ {
+ $user_id = (!is_array($user_id)) ? array($user_id) : $user_id;
+ $opts = (!is_array($opts)) ? array($opts) : $opts;
+ $forum_id = (!is_array($forum_id)) ? array($forum_id) : $forum_id;
+
+ $auth_list = array();
+
+ foreach ($forum_id as $fid)
+ {
+ foreach ($opts as $opt)
+ {
+ $auth_list[$fid][$opt] = array();
+
+ foreach ($user_id as $uid)
+ {
+ $auth_list[$fid][$opt][] = $uid;
+ }
+ }
+ }
+
+ return $auth_list;
+ }
+
+ function acl_get($opt, $f = 0)
+ {
+ return true;
+ }
+}
diff --git a/tests/mock/null_cache.php b/tests/mock/null_cache.php
index aca20ca77b..5b801adf11 100644
--- a/tests/mock/null_cache.php
+++ b/tests/mock/null_cache.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -39,4 +43,9 @@ class phpbb_mock_null_cache
public function set_bots($bots)
{
}
+
+ public function sql_exists($query_id)
+ {
+ return false;
+ }
}
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/mock/request.php b/tests/mock/request.php
new file mode 100644
index 0000000000..e7217a94a9
--- /dev/null
+++ b/tests/mock/request.php
@@ -0,0 +1,138 @@
+<?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_request implements \phpbb\request\request_interface
+{
+ protected $data;
+
+ protected $super_globals_disabled = false;
+
+ public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array())
+ {
+ $this->data[\phpbb\request\request_interface::GET] = $get;
+ $this->data[\phpbb\request\request_interface::POST] = $post;
+ $this->data[\phpbb\request\request_interface::COOKIE] = $cookie;
+ $this->data[\phpbb\request\request_interface::REQUEST] = ($request === false) ? $post + $get : $request;
+ $this->data[\phpbb\request\request_interface::SERVER] = $server;
+ $this->data[\phpbb\request\request_interface::FILES] = $files;
+
+ $this->disable_super_globals();
+ }
+
+ public function overwrite($var_name, $value, $super_global = \phpbb\request\request_interface::REQUEST)
+ {
+ $this->data[$super_global][$var_name] = $value;
+ }
+
+ public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST)
+ {
+ return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
+ }
+
+ public function server($var_name, $default = '')
+ {
+ $super_global = \phpbb\request\request_interface::SERVER;
+ return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
+ }
+
+ public function header($header_name, $default = '')
+ {
+ $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
+ return $this->server($var_name, $default);
+ }
+
+ public function file($form_name)
+ {
+ $super_global = \phpbb\request\request_interface::FILES;
+ return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array();
+ }
+
+ public function is_set_post($name)
+ {
+ return $this->is_set($name, \phpbb\request\request_interface::POST);
+ }
+
+ public function is_set($var, $super_global = \phpbb\request\request_interface::REQUEST)
+ {
+ return isset($this->data[$super_global][$var]);
+ }
+
+ public function is_ajax()
+ {
+ return false;
+ }
+
+ public function is_secure()
+ {
+ return false;
+ }
+
+ public function variable_names($super_global = \phpbb\request\request_interface::REQUEST)
+ {
+ return array_keys($this->data[$super_global]);
+ }
+
+ public function get_super_global($super_global = \phpbb\request\request_interface::REQUEST)
+ {
+ return $this->data[$super_global];
+ }
+
+ public function super_globals_disabled()
+ {
+ return $this->super_globals_disabled;
+ }
+
+ public function disable_super_globals()
+ {
+ $this->super_globals_disabled = true;
+ }
+
+ public function enable_super_globals()
+ {
+ $this->super_globals_disabled = false;
+ }
+
+ /* custom methods */
+
+ public function set_header($header_name, $value)
+ {
+ $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
+ $this->data[\phpbb\request\request_interface::SERVER][$var_name] = $value;
+ }
+
+ public function merge($super_global = \phpbb\request\request_interface::REQUEST, $values)
+ {
+ $this->data[$super_global] = array_merge($this->data[$super_global], $values);
+ }
+
+ public function escape($var, $multibyte)
+ {
+ $type_cast_helper = new \phpbb\request\type_cast_helper();
+ if (is_array($var))
+ {
+ $result = array();
+ foreach ($var as $key => $value)
+ {
+ $type_cast_helper->set_var($key, $key, gettype($key), $multibyte);
+ $result[$key] = $this->escape($value, $multibyte);
+ }
+ $var = $result;
+ }
+ else
+ {
+ $type_cast_helper->set_var($var, $var, 'string', $multibyte);
+ }
+
+ return $var;
+ }
+}
diff --git a/tests/mock/search.php b/tests/mock/search.php
new file mode 100644
index 0000000000..f30876b4da
--- /dev/null
+++ b/tests/mock/search.php
@@ -0,0 +1,27 @@
+<?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_search
+{
+
+ public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
+ {
+ }
+
+ public function index_remove($post_ids, $poster_ids, $forum_ids)
+ {
+ }
+}
+
diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php
index 70a58fb6cc..29dd2a5bff 100644
--- a/tests/mock/session_testable.php
+++ b/tests/mock/session_testable.php
@@ -1,14 +1,17 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/session.php';
/**
* Extends the session class to overwrite the setting of cookies.
@@ -17,11 +20,11 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
* test it without warnings about sent headers. This class only stores cookie
* data for later verification.
*/
-class phpbb_mock_session_testable extends session
+class phpbb_mock_session_testable extends \phpbb\session
{
private $_cookies = array();
- public function set_cookie($name, $data, $time)
+ public function set_cookie($name, $data, $time, $httponly = true)
{
$this->_cookies[$name] = array($data, $time);
}
@@ -59,5 +62,9 @@ class phpbb_mock_session_testable extends session
}
}
}
+
+ public function setup()
+ {
+ }
}
diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php
new file mode 100644
index 0000000000..c751764d45
--- /dev/null
+++ b/tests/mock/sql_insert_buffer.php
@@ -0,0 +1,25 @@
+<?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_sql_insert_buffer extends \phpbb\db\sql_insert_buffer
+{
+ public function flush()
+ {
+ return (sizeof($this->buffer)) ? true : false;
+ }
+
+ public function get_buffer()
+ {
+ return $this->buffer;
+ }
+}
diff --git a/tests/mock/user.php b/tests/mock/user.php
index bd547b3973..9888337a9e 100644
--- a/tests/mock/user.php
+++ b/tests/mock/user.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -46,4 +50,9 @@ class phpbb_mock_user
}
return false;
}
+
+ public function lang()
+ {
+ return implode(' ', func_get_args());
+ }
}
diff --git a/tests/network/checkdnsrr_test.php b/tests/network/checkdnsrr_test.php
index 1942a50f06..a3852b2656 100644
--- a/tests/network/checkdnsrr_test.php
+++ b/tests/network/checkdnsrr_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/network/ftp_fsock_pasv_epsv_test.php b/tests/network/ftp_fsock_pasv_epsv_test.php
index 22f17785b8..6ed9d61dc0 100644
--- a/tests/network/ftp_fsock_pasv_epsv_test.php
+++ b/tests/network/ftp_fsock_pasv_epsv_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/network/inet_ntop_pton_test.php b/tests/network/inet_ntop_pton_test.php
new file mode 100644
index 0000000000..fae40ad74e
--- /dev/null
+++ b/tests/network/inet_ntop_pton_test.php
@@ -0,0 +1,58 @@
+<?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_network_inet_ntop_pton_test extends phpbb_test_case
+{
+ public function data_provider()
+ {
+ return array(
+ array('127.0.0.1', '7f000001'),
+ array('192.232.131.223', 'c0e883df'),
+ array('13.1.68.3', '0d014403'),
+ array('129.144.52.38', '81903426'),
+
+ array('2001:280:0:10::5', '20010280000000100000000000000005'),
+ array('fe80::200:4cff:fefe:172f', 'fe8000000000000002004cfffefe172f'),
+
+ array('::', '00000000000000000000000000000000'),
+ array('::1', '00000000000000000000000000000001'),
+ array('1::', '00010000000000000000000000000000'),
+
+ array('1:1:0:0:1::', '00010001000000000001000000000000'),
+
+ array('0:2:3:4:5:6:7:8', '00000002000300040005000600070008'),
+ array('1:2:0:4:5:6:7:8', '00010002000000040005000600070008'),
+ array('1:2:3:4:5:6:7:0', '00010002000300040005000600070000'),
+
+ array('2001:0:0:1::1', '20010000000000010000000000000001'),
+ );
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_inet_ntop($address, $hex)
+ {
+ $this->assertEquals($address, phpbb_inet_ntop(pack('H*', $hex)));
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_inet_pton($address, $hex)
+ {
+ $this->assertEquals($hex, bin2hex(phpbb_inet_pton($address)));
+ }
+}
diff --git a/tests/network/ip_normalise_test.php b/tests/network/ip_normalise_test.php
new file mode 100644
index 0000000000..1acfd4521d
--- /dev/null
+++ b/tests/network/ip_normalise_test.php
@@ -0,0 +1,68 @@
+<?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_network_ip_normalise_test extends phpbb_test_case
+{
+ public function data_provider()
+ {
+ return array(
+ // From: A Recommendation for IPv6 Address Text Representation
+ // http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
+
+ // Section 4: A Recommendation for IPv6 Text Representation
+ // Section 4.1: Handling Leading Zeros in a 16 Bit Field
+ array('2001:0db8::0001', '2001:db8::1'),
+
+ // Section 4.2: "::" Usage
+ // Section 4.2.1: Shorten As Much As Possible
+ array('2001:db8::0:1', '2001:db8::1'),
+
+ // Section 4.2.2: Handling One 16 Bit 0 Field
+ array('2001:db8::1:1:1:1:1', '2001:db8:0:1:1:1:1:1'),
+
+ // Section 4.2.3: Choice in Placement of "::"
+ array('2001:db8:0:0:1:0:0:1', '2001:db8::1:0:0:1'),
+
+ // Section 4.3: Lower Case
+ array('2001:DB8::1', '2001:db8::1'),
+
+ // Section 5: Text Representation of Special Addresses
+ // We want to show IPv4-mapped addresses as plain IPv4 addresses, though.
+ array('::ffff:192.168.0.1', '192.168.0.1'),
+ array('0000::0000:ffff:c000:0280', '192.0.2.128'),
+
+ // IPv6 addresses with the last 32-bit written in dotted-quad notation
+ // should be converted to hex-only IPv6 addresses.
+ array('2001:db8::192.0.2.128', '2001:db8::c000:280'),
+
+ // Any string not passing the IPv4 or IPv6 regular expression
+ // is supposed to result in false being returned.
+ // Valid and invalid IP addresses are tested in
+ // tests/regex/ipv4.php and tests/regex/ipv6.php.
+ array('', false),
+ array('192.168.1.256', false),
+ array('::ffff:192.168.255.256', false),
+ array('::1111:2222:3333:4444:5555:6666::', false),
+ );
+ }
+
+ /**
+ * @dataProvider data_provider
+ */
+ public function test_ip_normalise($ip_address, $expected)
+ {
+ $this->assertEquals($expected, phpbb_ip_normalise($ip_address));
+ }
+}
diff --git a/tests/notification/base.php b/tests/notification/base.php
new file mode 100644
index 0000000000..162feae557
--- /dev/null
+++ b/tests/notification/base.php
@@ -0,0 +1,140 @@
+<?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__) . '/manager_helper.php';
+
+abstract class phpbb_tests_notification_base extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ protected function get_notification_types()
+ {
+ return array(
+ 'test',
+ 'notification.type.approve_post',
+ 'notification.type.approve_topic',
+ 'notification.type.bookmark',
+ 'notification.type.disapprove_post',
+ 'notification.type.disapprove_topic',
+ 'notification.type.pm',
+ 'notification.type.post',
+ 'notification.type.post_in_queue',
+ 'notification.type.quote',
+ 'notification.type.report_pm',
+ 'notification.type.report_pm_closed',
+ 'notification.type.report_post',
+ 'notification.type.report_post_closed',
+ 'notification.type.topic',
+ 'notification.type.topic_in_queue',
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
+
+ global $db, $config, $user, $auth, $cache, $phpbb_container;
+
+ $db = $this->db = $this->new_dbal();
+ $config = $this->config = new \phpbb\config\config(array(
+ 'allow_privmsg' => true,
+ 'allow_bookmarks' => true,
+ 'allow_topic_notify' => true,
+ 'allow_forum_notify' => true,
+ ));
+ $user = $this->user = new \phpbb\user('\phpbb\datetime');
+ $this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
+ $auth = $this->auth = new phpbb_mock_notifications_auth();
+ $cache = $this->cache = new \phpbb\cache\service(
+ new \phpbb\cache\driver\null(),
+ $this->config,
+ $this->db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $phpbb_container = $this->container = new phpbb_mock_container_builder();
+
+ $this->notifications = new phpbb_notification_manager_helper(
+ array(),
+ array(),
+ $this->container,
+ $this->user_loader,
+ $this->config,
+ $this->phpbb_dispatcher,
+ $this->db,
+ $this->cache,
+ $this->user,
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_notification_types',
+ 'phpbb_notifications',
+ 'phpbb_user_notifications'
+ );
+
+ $phpbb_container->set('notification_manager', $this->notifications);
+
+ $this->notifications->setDependencies($this->auth, $this->config);
+
+ $types = array();
+ foreach ($this->get_notification_types() as $type)
+ {
+ $type_parts = explode('.', $type);
+ $class = $this->build_type('phpbb\notification\type\\' . array_pop($type_parts));
+
+ $types[$type] = $class;
+ $this->container->set($type, $class);
+ }
+
+ $this->notifications->set_var('notification_types', $types);
+
+ $this->db->sql_query('DELETE FROM phpbb_notification_types');
+ $this->db->sql_query('DELETE FROM phpbb_notifications');
+ $this->db->sql_query('DELETE FROM phpbb_user_notifications');
+ }
+
+ protected function build_type($type)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
+ }
+
+ protected function assert_notifications($expected, $options = array())
+ {
+ $notifications = $this->notifications->load_notifications(array_merge(array(
+ 'count_unread' => true,
+ 'order_by' => 'notification_time',
+ 'order_dir' => 'ASC',
+ ), $options));
+
+ $this->assertEquals(sizeof($expected), $notifications['unread_count']);
+
+ $i = 0;
+ foreach ($notifications['notifications'] as $notification)
+ {
+ foreach ($expected[$i] as $key => $value)
+ {
+ $this->assertEquals($value, $notification->$key, $i . ' ' . $key);
+ }
+
+ $i++;
+ }
+ }
+}
diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php
new file mode 100644
index 0000000000..32ab34c9bc
--- /dev/null
+++ b/tests/notification/convert_test.php
@@ -0,0 +1,112 @@
+<?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__) . '/../mock/sql_insert_buffer.php';
+
+class phpbb_notification_convert_test extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ $this->db = $this->new_dbal();
+
+ $this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert(
+ new \phpbb\config\config(array()),
+ $this->db,
+ new \phpbb\db\tools($this->db),
+ $phpbb_root_path,
+ $phpEx,
+ 'phpbb_'
+ );
+ }
+
+ public function test_convert()
+ {
+ $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications');
+ $this->migration->perform_conversion($buffer, 0);
+
+ $expected = array_merge(
+ $this->create_expected('post', 1, 'email'),
+ $this->create_expected('topic', 1, 'email'),
+
+ $this->create_expected('post', 2, 'email'),
+ $this->create_expected('topic', 2, 'email'),
+ $this->create_expected('pm', 2, 'email'),
+
+ $this->create_expected('post', 3, 'jabber'),
+ $this->create_expected('topic', 3, 'jabber'),
+
+ $this->create_expected('post', 4, 'jabber'),
+ $this->create_expected('topic', 4, 'jabber'),
+ $this->create_expected('pm', 4, 'jabber'),
+
+ $this->create_expected('post', 5, 'both'),
+ $this->create_expected('topic', 5, 'both'),
+
+ $this->create_expected('post', 6, 'both'),
+ $this->create_expected('topic', 6, 'both'),
+ $this->create_expected('pm', 6, 'both')
+ );
+
+ $this->assertEquals($expected, $buffer->get_buffer());
+ }
+
+ protected function create_expected($type, $user_id, $method = '')
+ {
+ $return = array();
+
+ if ($method !== '')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => '',
+ 'notify' => 1,
+ );
+ }
+
+ if ($method === 'email' || $method === 'both')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => 'email',
+ 'notify' => 1,
+ );
+ }
+
+ if ($method === 'jabber' || $method === 'both')
+ {
+ $return[] = array(
+ 'item_type' => $type,
+ 'item_id' => 0,
+ 'user_id' => $user_id,
+ 'method' => 'jabber',
+ 'notify' => 1,
+ );
+ }
+
+ return $return;
+ }
+}
diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php
new file mode 100644
index 0000000000..b02a563f06
--- /dev/null
+++ b/tests/notification/ext/test/notification/type/test.php
@@ -0,0 +1,91 @@
+<?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.
+*
+*/
+
+namespace phpbb\notification\type;
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+class test extends \phpbb\notification\type\base
+{
+ public function get_type()
+ {
+ return 'test';
+ }
+
+ public static function get_item_id($post)
+ {
+ return (int) $post['post_id'];
+ }
+
+ public static function get_item_parent_id($post)
+ {
+ return (int) $post['topic_id'];
+ }
+
+ public function find_users_for_notification($post, $options = array())
+ {
+ return $this->check_user_notification_options(array(0), $options);
+ }
+
+ public function create_insert_array($post, $pre_create_data = array())
+ {
+ $this->notification_time = $post['post_time'];
+
+ return parent::create_insert_array($post, $pre_create_data);
+ }
+
+ public function create_update_array($type_data)
+ {
+ $data = $this->create_insert_array($type_data);
+
+ // Unset data unique to each row
+ unset(
+ $data['notification_id'],
+ $data['notification_read'],
+ $data['user_id']
+ );
+
+ return $data;
+ }
+
+ public function get_title()
+ {
+ return 'test title';
+ }
+
+ public function users_to_query()
+ {
+ return array();
+ }
+
+ public function get_url()
+ {
+ return '';
+ }
+
+ public function get_email_template()
+ {
+ return false;
+ }
+
+ public function get_email_template_variables()
+ {
+ return array();
+ }
+}
diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml
new file mode 100644
index 0000000000..c9d8fafa97
--- /dev/null
+++ b/tests/notification/fixtures/convert.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_notify_type</column>
+ <column>user_notify_pm</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>5</value>
+ <value>2</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>6</value>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/group_request.xml b/tests/notification/fixtures/group_request.xml
new file mode 100644
index 0000000000..fbaee0a326
--- /dev/null
+++ b/tests/notification/fixtures/group_request.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/notification.xml b/tests/notification/fixtures/notification.xml
new file mode 100644
index 0000000000..c7b2d03ff1
--- /dev/null
+++ b/tests/notification/fixtures/notification.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_bookmarks">
+ </table>
+ <table name="phpbb_notifications">
+ </table>
+ <table name="phpbb_notification_types">
+ </table>
+ <table name="phpbb_topics_watch">
+ </table>
+ <table name="phpbb_user_notifications">
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
new file mode 100644
index 0000000000..a1413e2cf8
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_bookmarks">
+ <column>topic_id</column>
+ <column>user_id</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>7</value>
+ </row>
+ </table>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>notification.type.bookmark</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>notification.type.bookmark</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.bookmark</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.bookmark</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.bookmark</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.bookmark</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_notification.type.post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml
new file mode 100644
index 0000000000..ed75787c70
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_notification.type.post.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_forums_watch">
+ <column>forum_id</column>
+ <column>user_id</column>
+ <column>notify_status</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>7</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>notification.type.post</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_topics_watch">
+ <column>topic_id</column>
+ <column>user_id</column>
+ <column>notify_status</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>7</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.post</value>
+ <value>0</value>
+ <value>8</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
new file mode 100644
index 0000000000..2dea8e34dd
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>notification.type.post_in_queue</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized-mod</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>unauthorized-read</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>test glboal-permissions</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>7</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>notification.type.needs_approval</value>
+ <value>0</value>
+ <value>9</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_notification.type.quote.xml b/tests/notification/fixtures/submit_post_notification.type.quote.xml
new file mode 100644
index 0000000000..dd5bc620cd
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_notification.type.quote.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>5</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>notification.type.quote</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>test</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>unauthorized</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>disabled</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>notification.type.quote</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.quote</value>
+ <value>0</value>
+ <value>3</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.quote</value>
+ <value>0</value>
+ <value>4</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.quote</value>
+ <value>0</value>
+ <value>5</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.quote</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/submit_post_notification.type.topic.xml b/tests/notification/fixtures/submit_post_notification.type.topic.xml
new file mode 100644
index 0000000000..1ba8d05699
--- /dev/null
+++ b/tests/notification/fixtures/submit_post_notification.type.topic.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_forums_watch">
+ <column>forum_id</column>
+ <column>user_id</column>
+ <column>notify_status</column>
+ <row>
+ <value>1</value>
+ <value>6</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>7</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_notifications">
+ <column>notification_type_id</column>
+ <column>user_id</column>
+ <column>item_id</column>
+ <column>item_parent_id</column>
+ <column>notification_read</column>
+ <column>notification_data</column>
+ <row>
+ <value>1</value>
+ <value>8</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_notification_types">
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
+ <column>notification_type_enabled</column>
+ <row>
+ <value>1</value>
+ <value>notification.type.topic</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_posts">
+ <column>post_id</column>
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <column>post_text</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_topics">
+ <column>topic_id</column>
+ <column>forum_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>poster</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>noauth</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>default</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>notified</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_notifications">
+ <column>item_type</column>
+ <column>item_id</column>
+ <column>user_id</column>
+ <column>method</column>
+ <column>notify</column>
+ <row>
+ <value>notification.type.topic</value>
+ <value>0</value>
+ <value>2</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.topic</value>
+ <value>0</value>
+ <value>6</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.topic</value>
+ <value>0</value>
+ <value>7</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>notification.type.topic</value>
+ <value>0</value>
+ <value>8</value>
+ <value></value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/fixtures/user_list_trim.xml b/tests/notification/fixtures/user_list_trim.xml
new file mode 100644
index 0000000000..4f708714da
--- /dev/null
+++ b/tests/notification/fixtures/user_list_trim.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_colour</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>2</value>
+ <value>A</value>
+ <value>a</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>B</value>
+ <value>b</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>C</value>
+ <value>c</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>D</value>
+ <value>d</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>E</value>
+ <value>e</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php
new file mode 100644
index 0000000000..0d1bda95ce
--- /dev/null
+++ b/tests/notification/group_request_test.php
@@ -0,0 +1,114 @@
+<?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__) . '/base.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_notification_group_request_test extends phpbb_tests_notification_base
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_request.xml');
+ }
+
+ protected function get_notification_types()
+ {
+ return array_merge(
+ parent::get_notification_types(),
+ array(
+ 'notification.type.group_request',
+ 'notification.type.group_request_approved',
+ )
+ );
+ }
+
+ public function test_notifications()
+ {
+ global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log;
+
+ include_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
+ include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+ include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx);
+
+ set_config(false, false, false, $this->config);
+
+ $this->container->set('groupposition.legend', new \phpbb\groupposition\legend(
+ $this->db,
+ $this->user
+ ));
+ $this->container->set('groupposition.teampage', new \phpbb\groupposition\teampage(
+ $this->db,
+ $this->user,
+ $this->cache->get_driver()
+ ));
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
+ $phpbb_log = new \phpbb\log\null();
+
+ // Now on to the actual test
+
+ $group_id = false;
+ group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
+
+ // Add user 2 as group leader
+ group_user_add($group_id, 2, false, false, false, true, false);
+
+ // Add user 3 as pending
+ group_user_add($group_id, 3, false, false, false, false, true);
+
+ $this->assert_notifications(
+ array(
+ // user 3 pending notification
+ array(
+ 'item_id' => 3, // user_id of requesting join
+ 'item_parent_id' => $group_id,
+ 'user_id' => 2,
+ 'notification_read' => 0,
+ 'notification_data' => array(
+ 'group_name' => 'test',
+ ),
+ ),
+ ),
+ array(
+ 'user_id' => 2,
+ )
+ );
+
+ // Approve user 3 joining the group
+ group_user_attributes('approve', $group_id, array(3));
+
+ // user 3 pending notification should have been deleted
+ $this->assert_notifications(
+ array(),
+ array(
+ 'user_id' => 2,
+ )
+ );
+
+ $this->assert_notifications(
+ array(
+ // user 3 approved notification
+ array(
+ 'item_id' => $group_id, // user_id of requesting join
+ 'user_id' => 3,
+ 'notification_read' => 0,
+ 'notification_data' => array(
+ 'group_name' => 'test',
+ ),
+ ),
+ ),
+ array(
+ 'user_id' => 3,
+ )
+ );
+ }
+}
diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php
new file mode 100644
index 0000000000..75b7275d3a
--- /dev/null
+++ b/tests/notification/manager_helper.php
@@ -0,0 +1,71 @@
+<?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.
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Notifications service class
+*/
+class phpbb_notification_manager_helper extends \phpbb\notification\manager
+{
+ public function set_var($name, $value)
+ {
+ $this->$name = $value;
+ }
+
+ // Extra dependencies for get_*_class functions
+ protected $auth = null;
+ protected $config = null;
+ public function setDependencies($auth, $config)
+ {
+ $this->auth = $auth;
+ $this->config = $config;
+ }
+
+ /**
+ * Helper to get the notifications item type class and set it up
+ */
+ public function get_item_type_class($item_type, $data = array())
+ {
+ $item_parts = explode('.', $item_type);
+ $item_type = 'phpbb\notification\type\\' . array_pop($item_parts);
+
+ $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+
+ $item->set_notification_manager($this);
+
+ $item->set_initial_data($data);
+
+ return $item;
+ }
+
+ /**
+ * Helper to get the notifications method class and set it up
+ */
+ public function get_method_class($method_name)
+ {
+ $method_name = 'phpbb\notification\method\\' . $method_name;
+
+ $method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+
+ $method->set_notification_manager($this);
+
+ return $method;
+ }
+}
diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php
new file mode 100644
index 0000000000..79fa5338c4
--- /dev/null
+++ b/tests/notification/notification_test.php
@@ -0,0 +1,330 @@
+<?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__) . '/base.php';
+
+class phpbb_notification_test extends phpbb_tests_notification_base
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
+ }
+
+ public function test_get_notification_type_id()
+ {
+ // They should be inserted the first time
+ $post_type_id = $this->notifications->get_notification_type_id('notification.type.post');
+ $quote_type_id = $this->notifications->get_notification_type_id('notification.type.quote');
+ $test_type_id = $this->notifications->get_notification_type_id('test');
+
+ $this->assertEquals(array(
+ 'test' => $test_type_id,
+ 'notification.type.quote' => $quote_type_id,
+ 'notification.type.post' => $post_type_id,
+ ),
+ $this->notifications->get_notification_type_ids(array(
+ 'test',
+ 'notification.type.quote',
+ 'notification.type.post',
+ )
+ ));
+ $this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote'));
+
+ try
+ {
+ $this->assertEquals(false, $this->notifications->get_notification_type_id('fail'));
+
+ $this->fail('Non-existent type should throw an exception');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_get_subscription_types()
+ {
+ $subscription_types = $this->notifications->get_subscription_types();
+
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
+
+ $this->assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+
+ $this->assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
+
+ //get_subscription_types
+ //get_subscription_methods
+ }
+
+ public function test_subscriptions()
+ {
+ $expected_subscriptions = array(
+ 'notification.type.post' => array(''),
+ 'notification.type.topic' => array(''),
+ 'notification.type.quote' => array(''),
+ 'notification.type.bookmark' => array(''),
+ 'test' => array(''),
+ 'notification.type.pm' => array(''),
+ );
+
+ $subscriptions = $this->notifications->get_global_subscriptions(2);
+
+ foreach ($expected_subscriptions as $item_type => $methods)
+ {
+ $this->assert_array_content_equals($methods, $subscriptions[$item_type]);
+ }
+
+ foreach ($subscriptions as $item_type => $methods)
+ {
+ $this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]);
+ }
+
+ $this->notifications->delete_subscription('notification.type.post', 0, '', 2);
+
+ $this->assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
+
+ $this->notifications->add_subscription('notification.type.post', 0, '', 2);
+
+ $this->assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
+ }
+
+ public function test_notifications()
+ {
+ $this->db->sql_query('DELETE FROM phpbb_notification_types');
+
+ $types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test');
+ foreach ($types as $id => $type)
+ {
+ $this->db->sql_query('INSERT INTO phpbb_notification_types ' .
+ $this->db->sql_build_array('INSERT', array(
+ 'notification_type_id' => ($id + 1),
+ 'notification_type_name' => $type,
+ 'notification_type_enabled' => 1,
+ ))
+ );
+ }
+
+ // Used to test post notifications later
+ $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
+ 'topic_id' => 2,
+ 'notify_status' => NOTIFY_YES,
+ 'user_id' => 0,
+ )));
+
+ $this->assertEquals(array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ 'total_count' => 0,
+ ), $this->notifications->load_notifications(array(
+ 'count_unread' => true,
+ )));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '1',
+ 'topic_id' => '1',
+ 'post_time' => 1349413321,
+ ));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '2',
+ 'topic_id' => '2',
+ 'post_time' => 1349413322,
+ ));
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '3',
+ 'topic_id' => '2',
+ 'post_time' => 1349413323,
+ ));
+
+ $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
+ 'post_id' => '4',
+ 'topic_id' => '2',
+ 'post_time' => 1349413324,
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ));
+
+ $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
+ 'topic_id' => 2,
+ 'user_id' => 0,
+ )));
+
+ $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
+ 'post_id' => '5',
+ 'topic_id' => '2',
+ 'post_time' => 1349413325,
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ));
+
+ $this->notifications->delete_subscription('test');
+
+ $this->notifications->add_notifications('test', array(
+ 'post_id' => '6',
+ 'topic_id' => '2',
+ 'post_time' => 1349413326,
+ ));
+
+ $this->assert_notifications(
+ array(
+ array(
+ 'item_id' => 1,
+ 'item_parent_id' => 1,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413321,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 2,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413322,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 3,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413323,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413324,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ array(
+ 'item_id' => 5,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413325,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ )
+ );
+
+ // Now test updating -------------------------------
+
+ $this->notifications->update_notifications('test', array(
+ 'post_id' => '1',
+ 'topic_id' => '2', // change parent_id
+ 'post_time' => 1349413321,
+ ));
+
+ $this->notifications->update_notifications('test', array(
+ 'post_id' => '3',
+ 'topic_id' => '2',
+ 'post_time' => 1234, // change time
+ ));
+
+ $this->notifications->update_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array(
+ 'post_id' => '5',
+ 'topic_id' => '2',
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title2', // change topic_title
+ 'post_subject' => 'Re: test-title2', // change post_subject
+ 'forum_id' => 3, // change forum_id
+ 'forum_name' => 'Your second forum', // change forum_name
+ ));
+
+ $this->assert_notifications(
+ array(
+ array(
+ 'item_id' => 3,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1234,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 1,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413321,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 2,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413322,
+ 'notification_data' => array(),
+ ),
+ array(
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413324,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
+ array(
+ 'item_id' => 5,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'notification_read' => 0,
+ 'notification_time' => 1349413325,
+ 'notification_data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title2',
+ 'post_subject' => 'Re: test-title2',
+ 'post_username' => '',
+ 'forum_id' => 3,
+ 'forum_name' => 'Your second forum',
+ ),
+ ),
+ )
+ );
+ }
+}
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php
new file mode 100644
index 0000000000..5e770f71c9
--- /dev/null
+++ b/tests/notification/submit_post_base.php
@@ -0,0 +1,154 @@
+<?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/functions_posting.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+abstract class phpbb_notification_submit_post_base extends phpbb_database_test_case
+{
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
+
+ protected $item_type = '';
+
+ protected $poll_data = array();
+ protected $post_data = array(
+ 'forum_id' => 1,
+ 'topic_id' => 1,
+ 'topic_title' => 'topic_title',
+ 'icon_id' => 0,
+ 'enable_bbcode' => 0,
+ 'enable_smilies' => 0,
+ 'enable_urls' => 0,
+ 'enable_sig' => 0,
+ 'message' => '',
+ 'message_md5' => '',
+ 'attachment_data' => array(),
+ 'bbcode_bitfield' => '',
+ 'bbcode_uid' => '',
+ 'post_edit_locked' => false,
+ //'force_approved_state' => 1,
+ );
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_' . $this->item_type . '.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path;
+
+ // Database
+ $this->db = $this->new_dbal();
+ $db = $this->db;
+
+ // Auth
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'),
+ $this->anything())
+ ->will($this->returnValueMap(array(
+ array('f_noapprove', 1, true),
+ array('f_postcount', 1, true),
+ array('m_edit', 1, false),
+ )));
+
+ // Config
+ $config = new \phpbb\config\config(array('num_topics' => 1,'num_posts' => 1,));
+ set_config(null, null, null, $config);
+ set_config_count(null, null, null, $config);
+
+ $cache = new \phpbb\cache\service(
+ new \phpbb\cache\driver\null(),
+ $config,
+ $db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ // Event dispatcher
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ // User
+ $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $user->ip = '';
+ $user->data = array(
+ 'user_id' => 2,
+ 'username' => 'user-name',
+ 'is_registered' => true,
+ 'user_colour' => '',
+ );
+
+ // Request
+ $type_cast_helper = $this->getMock('\phpbb\request\type_cast_helper_interface');
+ $request = $this->getMock('\phpbb\request\request');
+
+ // Container
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
+
+ $user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
+
+ // Notification Types
+ $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'topic_in_queue', 'approve_topic', 'approve_post');
+ $notification_types_array = array();
+ foreach ($notification_types as $type)
+ {
+ $class_name = '\phpbb\notification\type\\' . $type;
+ $class = new $class_name(
+ $user_loader, $db, $cache->get_driver(), $user, $auth, $config,
+ $phpbb_root_path, $phpEx,
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+
+ $phpbb_container->set('notification.type.' . $type, $class);
+
+ $notification_types_array['notification.type.' . $type] = $class;
+ }
+
+ // Notification Manager
+ $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, array(),
+ $phpbb_container, $user_loader, $config, $phpbb_dispatcher, $db, $cache, $user,
+ $phpbb_root_path, $phpEx,
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+ $phpbb_container->set('notification_manager', $phpbb_notifications);
+ }
+
+ /**
+ * @dataProvider submit_post_data
+ */
+ public function test_submit_post($additional_post_data, $expected_before, $expected_after)
+ {
+ $sql = 'SELECT user_id, item_id, item_parent_id
+ FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
+ ORDER BY user_id ASC, item_id ASC";
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
+ $this->db->sql_freeresult($result);
+
+ $poll_data = $this->poll_data;
+ $post_data = array_merge($this->post_data, $additional_post_data);
+ submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false);
+
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));
+ $this->db->sql_freeresult($result);
+ }
+}
diff --git a/tests/notification/submit_post_type_bookmark_test.php b/tests/notification/submit_post_type_bookmark_test.php
new file mode 100644
index 0000000000..7c3b9f938f
--- /dev/null
+++ b/tests/notification/submit_post_type_bookmark_test.php
@@ -0,0 +1,94 @@
+<?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__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_bookmark_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'notification.type.bookmark';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth;
+
+ // Add additional permissions
+ $auth->expects($this->any())
+ ->method('acl_get_list')
+ ->with($this->anything(),
+ $this->stringContains('_'),
+ $this->greaterThan(0))
+ ->will($this->returnValueMap(array(
+ array(
+ array(3, 4, 5, 6, 7),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 5, 6, 7),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'bookmark'
+ */
+ public function submit_post_data()
+ {
+ return array(
+ /**
+ * Normal post
+ *
+ * User => State description
+ * 2 => Poster, should NOT receive a notification
+ * 3 => Bookmarked, should receive a notification
+ * 4 => Bookmarked, but unauthed to read, should NOT receive a notification
+ * 5 => Bookmarked, but already notified, should NOT receive a new notification
+ * 6 => Bookmarked, but option disabled, should NOT receive a notification
+ * 7 => Bookmarked, option set to default, should receive a notification
+ */
+ array(
+ array(),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * No new notifications
+ */
+ array(
+ array('force_approved_state' => false),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php
new file mode 100644
index 0000000000..1390e92d96
--- /dev/null
+++ b/tests/notification/submit_post_type_post_in_queue_test.php
@@ -0,0 +1,111 @@
+<?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__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'notification.type.post_in_queue';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth;
+
+ // Add additional permissions
+ $auth->expects($this->any())
+ ->method('acl_get_list')
+ ->with($this->anything(),
+ $this->stringContains('_'),
+ $this->greaterThan(0))
+ ->will($this->returnValueMap(array(
+ array(
+ false,
+ 'm_approve',
+ array(1, 0),
+ array(
+ 0 => array(
+ 'm_approve' => array(9),
+ ),
+ 1 => array(
+ 'm_approve' => array(3, 4, 6, 7, 8),
+ ),
+ ),
+ ),
+ array(
+ array(3, 4, 6, 7, 8, 9),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 6, 7, 8, 9),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'post_in_queue'
+ */
+ public function submit_post_data()
+ {
+ return array(
+ /**
+ * Normal post
+ *
+ * No new notifications
+ */
+ array(
+ array(),
+ array(
+ array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * User => State description
+ * 2 => Poster, should NOT receive a notification
+ * 3 => Moderator, should receive a notification
+ * 4 => Moderator, but unauthed to read, should NOT receive a notification
+ * 5 => Moderator, but unauthed to approve, should NOT receive a notification
+ * 6 => Moderator, but already notified, should STILL receive a new notification
+ * 7 => Moderator, but option disabled, should NOT receive a notification
+ * 8 => Moderator, option set to default, should receive a notification
+ * 9 => Moderator, has only global mod permissions, should receive a notification
+ */
+ array(
+ array('force_approved_state' => false),
+ array(
+ array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 9, 'item_id' => 2, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php
new file mode 100644
index 0000000000..037c326bc0
--- /dev/null
+++ b/tests/notification/submit_post_type_post_test.php
@@ -0,0 +1,100 @@
+<?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__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'notification.type.post';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth;
+
+ // Add additional permissions
+ $auth->expects($this->any())
+ ->method('acl_get_list')
+ ->with($this->anything(),
+ $this->stringContains('_'),
+ $this->greaterThan(0))
+ ->will($this->returnValueMap(array(
+ array(
+ array(3, 4, 5, 6, 7, 8),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 5, 6, 7, 8),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'post'
+ */
+ public function submit_post_data()
+ {
+ return array(
+ /**
+ * Normal post
+ *
+ * User => State description
+ * 2 => Poster, should NOT receive a notification
+ * 3 => Topic subscribed, should receive a notification
+ * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification
+ * 5 => Topic subscribed, but already notified, should NOT receive a new notification
+ * 6 => Topic and forum subscribed, should receive ONE notification
+ * 7 => Forum subscribed, should receive a notification
+ * 8 => Forum subscribed, but already notified, should NOT receive a new notification
+ */
+ array(
+ array(),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * No new notifications
+ */
+ array(
+ array('force_approved_state' => false),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php
new file mode 100644
index 0000000000..61e3840773
--- /dev/null
+++ b/tests/notification/submit_post_type_quote_test.php
@@ -0,0 +1,118 @@
+<?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__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'notification.type.quote';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth;
+
+ // Add additional permissions
+ $auth->expects($this->any())
+ ->method('acl_get_list')
+ ->with($this->anything(),
+ $this->stringContains('_'),
+ $this->greaterThan(0))
+ ->will($this->returnValueMap(array(
+ array(
+ array(3, 4, 5, 6, 7),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(3, 5, 6, 7),
+ ),
+ ),
+ ),
+ )));
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'reply'
+ * Notification item_type = 'quote'
+ */
+ public function submit_post_data()
+ {
+ return array(
+ /**
+ * Normal post
+ *
+ * User => State description
+ * 2 => Poster, should NOT receive a notification
+ * 3 => Quoted, should receive a notification
+ * 4 => Quoted, but unauthed to read, should NOT receive a notification
+ * 5 => Quoted, but already notified, should STILL receive a new notification
+ * 6 => Quoted, but option disabled, should NOT receive a notification
+ * 7 => Quoted, option set to default, should receive a notification
+ */
+ array(
+ array(
+ 'message' => implode(' ', array(
+ '[quote=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
+ '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
+ '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
+ '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
+ '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
+ '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
+ '[quote=&quot;doesn\'t exist&quot;:uid]user does not exist, should not receive a notification[/quote:uid]',
+ )),
+ 'bbcode_uid' => 'uid',
+ ),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 5, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * No new notifications
+ */
+ array(
+ array(
+ 'message' => implode(' ', array(
+ '[quote=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
+ '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
+ '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
+ '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
+ '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
+ '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
+ '[quote=&quot;doesn\'t exist&quot;:uid]user does not exist, should not receive a notification[/quote:uid]',
+ )),
+ 'bbcode_uid' => 'uid',
+ 'force_approved_state' => false,
+ ),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/notification/submit_post_type_topic_test.php b/tests/notification/submit_post_type_topic_test.php
new file mode 100644
index 0000000000..c095fbc4ba
--- /dev/null
+++ b/tests/notification/submit_post_type_topic_test.php
@@ -0,0 +1,153 @@
+<?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__) . '/submit_post_base.php';
+
+class phpbb_notification_submit_post_type_topic_test extends phpbb_notification_submit_post_base
+{
+ protected $item_type = 'notification.type.topic';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $auth, $phpbb_log;
+
+ // Add additional permissions
+ $auth->expects($this->any())
+ ->method('acl_get_list')
+ ->with($this->anything(),
+ $this->stringContains('_'),
+ $this->greaterThan(0))
+ ->will($this->returnValueMap(array(
+ array(
+ array(6, 7, 8),
+ 'f_read',
+ 1,
+ array(
+ 1 => array(
+ 'f_read' => array(7, 8),
+ ),
+ ),
+ ),
+ )));
+
+ $phpbb_log = $this->getMock('\phpbb\log\null');
+ }
+
+ /**
+ * submit_post() Notifications test
+ *
+ * submit_post() $mode = 'post'
+ * Notification item_type = 'topic'
+ */
+ public function submit_post_data()
+ {
+ return array(
+ /**
+ * Normal post
+ *
+ * User => State description
+ * 2 => Poster, should NOT receive a notification
+ * 6 => Forum subscribed, but no-auth reading, should NOT receive a notification
+ * 7 => Forum subscribed, should receive a notification
+ * 8 => Forum subscribed, but already notified, should NOT receive a new notification
+ */
+ array(
+ array(),
+ array(
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1),
+ ),
+ ),
+
+ /**
+ * Unapproved post
+ *
+ * No new notifications
+ */
+ array(
+ array('force_approved_state' => false),
+ array(
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ array(
+ array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider submit_post_data
+ */
+ public function test_submit_post($additional_post_data, $expected_before, $expected_after)
+ {
+ $sql = 'SELECT user_id, item_id, item_parent_id
+ FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
+ ORDER BY user_id ASC, item_id ASC";
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
+ $this->db->sql_freeresult($result);
+
+ $poll_data = array();
+ $post_data = array_merge($this->post_data, $additional_post_data);
+ submit_post('post', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false);
+
+ // Check whether the notifications got added successfully
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result),
+ 'Check whether the notifications got added successfully');
+ $this->db->sql_freeresult($result);
+
+ if (isset($additional_post_data['force_approved_state']) && $additional_post_data['force_approved_state'] === false)
+ {
+ return;
+ }
+
+ $reply_data = array_merge($this->post_data, array(
+ 'topic_id' => 2,
+ ));
+ $url = submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $reply_data, false, false);
+ $reply_id = 3;
+ $this->assertStringEndsWith('p' . $reply_id, $url, 'Post ID of reply is not ' . $reply_id);
+
+ // Check whether the notifications are still correct after a reply has been added
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result),
+ 'Check whether the notifications are still correct after a reply has been added');
+ $this->db->sql_freeresult($result);
+
+ $result = $this->db->sql_query(
+ 'SELECT *
+ FROM ' . POSTS_TABLE . '
+ WHERE post_id = ' . $reply_id);
+ $reply_edit_data = array_merge($this->post_data, $this->db->sql_fetchrow($result), array(
+ 'force_approved_state' => false,
+ 'post_edit_reason' => 'PHPBB3-12370',
+ ));
+ submit_post('edit', '', 'poster-name', POST_NORMAL, $poll_data, $reply_edit_data, false, false);
+
+ // Check whether the notifications are still correct after the reply has been edit
+ $result = $this->db->sql_query($sql);
+ $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result),
+ 'Check whether the notifications are still correct after the reply has been edit');
+ $this->db->sql_freeresult($result);
+ }
+}
diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php
new file mode 100644
index 0000000000..c43eff729c
--- /dev/null
+++ b/tests/notification/user_list_trim_test.php
@@ -0,0 +1,143 @@
+<?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_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
+{
+ protected $notification;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_list_trim.xml');
+ }
+
+ public function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $user, $cache, $auth;
+
+ parent::setUp();
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $db = $this->new_dbal();
+
+ $config = new \phpbb\config\config(array());
+ set_config(null, null, null, $config);
+ set_config_count(null, null, null, $config);
+
+ $cache = new \phpbb\cache\service(
+ new \phpbb\cache\driver\null(),
+ $config,
+ $db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $auth = $this->getMock('\phpbb\auth\auth');
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'),
+ $this->anything())
+ ->will($this->returnValueMap(array(
+ array('u_viewprofile', 1, false),
+ )));
+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->data = array('user_lang' => 'en');
+ $user->add_lang('common');
+
+ $user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
+ $user_loader->load_users(array(2, 3, 4, 5, 6));
+
+ $this->notification = new phpbb_mock_notification_type_post(
+ $user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null, null
+ );
+ }
+
+ public function user_list_trim_data()
+ {
+ return array(
+ array(
+ array(
+ 'topic_title' => 'Test',
+ 'poster_id' => 2,
+ 'post_username' => 'A',
+ 'responders' => null,
+ ),
+ '<strong>Reply</strong> from A in topic:',
+ ),
+ array(
+ array(
+ 'topic_title' => 'Test',
+ 'poster_id' => 2,
+ 'post_username' => 'A',
+ 'responders' => array(
+ array('username' => '', 'poster_id' => 3),
+ ),
+ ),
+ '<strong>Reply</strong> from A and <span class="username">B</span> in topic:',
+ ),
+ array(
+ array(
+ 'topic_title' => 'Test',
+ 'poster_id' => 2,
+ 'post_username' => 'A',
+ 'responders' => array(
+ array('username' => '', 'poster_id' => 3),
+ array('username' => '', 'poster_id' => 4),
+ ),
+ ),
+ '<strong>Reply</strong> from A, <span class="username">B</span>, and <span class="username">C</span> in topic:',
+ ),
+ array(
+ array(
+ 'topic_title' => 'Test',
+ 'poster_id' => 2,
+ 'post_username' => 'A',
+ 'responders' => array(
+ array('username' => '', 'poster_id' => 3),
+ array('username' => '', 'poster_id' => 4),
+ array('username' => '', 'poster_id' => 5),
+ ),
+ ),
+ '<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(
+ 'topic_title' => 'Test',
+ 'poster_id' => 2,
+ 'post_username' => 'A',
+ 'responders' => array(
+ array('username' => '', 'poster_id' => 3),
+ array('username' => '', 'poster_id' => 4),
+ array('username' => '', 'poster_id' => 5),
+ array('username' => '', 'poster_id' => 6),
+ ),
+ ),
+ '<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and 2 others in topic:',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider user_list_trim_data
+ */
+ public function test_user_list_trim($data, $expected_result)
+ {
+ $data = array('notification_data' => serialize($data));
+ $this->notification->set_initial_data($data);
+
+ $this->assertEquals($expected_result, $this->notification->get_title());
+ }
+}
diff --git a/tests/pagination/config/routing.yml b/tests/pagination/config/routing.yml
new file mode 100644
index 0000000000..2ce082c9d1
--- /dev/null
+++ b/tests/pagination/config/routing.yml
@@ -0,0 +1,6 @@
+core_controller:
+ path: /test
+ defaults: { _controller: core_foo.controller:bar, page: 1}
+core_page_controller:
+ path: /test/page/{page}
+ defaults: { _controller: core_foo.controller:bar}
diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php
new file mode 100644
index 0000000000..ea6dd999c3
--- /dev/null
+++ b/tests/pagination/pagination_test.php
@@ -0,0 +1,331 @@
+<?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__) . '/../template/template_test_case.php';
+
+class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
+{
+ protected $test_path = 'tests/pagination';
+
+ public function return_callback_implode()
+ {
+ return implode('-', func_get_args());
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnCallback(array($this, 'return_callback_implode')));
+
+ $filesystem = new \phpbb\filesystem();
+ $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array());
+ $finder = new \phpbb\finder(
+ $filesystem,
+ dirname(__FILE__) . '/',
+ new phpbb_mock_cache()
+ );
+ $finder->set_extensions(array_keys($manager->all_enabled()));
+
+ $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
+ $provider = new \phpbb\controller\provider();
+ $provider->find_routing_files($finder);
+ $provider->find(dirname(__FILE__) . '/');
+
+ $request = new phpbb_mock_request();
+ $request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER);
+ $request->overwrite('SCRIPT_FILENAME', 'app.php', \phpbb\request\request_interface::SERVER);
+ $request->overwrite('REQUEST_URI', '/app.php', \phpbb\request\request_interface::SERVER);
+
+ $symfony_request = new \phpbb\symfony_request(
+ $request
+ );
+
+ $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/');
+ $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher);
+ }
+
+ public function generate_template_pagination_data()
+ {
+ return array(
+ array(
+ 'page.php',
+ 'start',
+ 95,
+ 10,
+ 10,
+ 'pagination
+ :per_page:10
+ :current_page:2
+ :base_url:page.php
+ :previous::page.php
+ :else:1:page.php
+ :current:2:page.php?start=10
+ :else:3:page.php?start=20
+ :else:4:page.php?start=30
+ :else:5:page.php?start=40
+ :ellipsis:9:page.php?start=80
+ :else:10:page.php?start=90
+ :next::page.php?start=20
+ :u_prev:page.php
+ :u_next:page.php?start=20',
+ ),
+ array(
+ 'page.php',
+ 'start',
+ 95,
+ 10,
+ 20,
+ 'pagination
+ :per_page:10
+ :current_page:3
+ :base_url:page.php
+ :previous::page.php?start=10
+ :else:1:page.php
+ :else:2:page.php?start=10
+ :current:3:page.php?start=20
+ :else:4:page.php?start=30
+ :else:5:page.php?start=40
+ :ellipsis:9:page.php?start=80
+ :else:10:page.php?start=90
+ :next::page.php?start=30
+ :u_prev:page.php?start=10
+ :u_next:page.php?start=30',
+ ),
+ array(
+ array('routes' => array(
+ 'core_controller',
+ 'core_page_controller',
+ )),
+ 'page',
+ 95,
+ 10,
+ 10,
+ 'pagination
+ :per_page:10
+ :current_page:2
+ :base_url:
+ :previous::/test
+ :else:1:/test
+ :current:2:/test/page/2
+ :else:3:/test/page/3
+ :else:4:/test/page/4
+ :else:5:/test/page/5
+ :ellipsis:9:/test/page/9
+ :else:10:/test/page/10
+ :next::/test/page/3
+ :u_prev:/test
+ :u_next:/test/page/3',
+ ),
+ array(
+ array('routes' => array(
+ 'core_controller',
+ 'core_page_controller',
+ )),
+ 'page',
+ 95,
+ 10,
+ 20,
+ 'pagination
+ :per_page:10
+ :current_page:3
+ :base_url:
+ :previous::/test/page/2
+ :else:1:/test
+ :else:2:/test/page/2
+ :current:3:/test/page/3
+ :else:4:/test/page/4
+ :else:5:/test/page/5
+ :ellipsis:9:/test/page/9
+ :else:10:/test/page/10
+ :next::/test/page/4
+ :u_prev:/test/page/2
+ :u_next:/test/page/4',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider generate_template_pagination_data
+ */
+ public function test_generate_template_pagination($base_url, $start_name, $num_items, $per_page, $start_item, $expect)
+ {
+ $this->pagination->generate_template_pagination($base_url, 'pagination', $start_name, $num_items, $per_page, $start_item);
+ $this->template->set_filenames(array('test' => 'pagination.html'));
+
+ $this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
+ }
+
+ /**
+ * @dataProvider generate_template_pagination_data
+ */
+ public function test_generate_template_pagination_sub($base_url, $start_name, $num_items, $per_page, $start_item, $expect)
+ {
+ // Block needs to be assigned before pagination
+ $this->template->assign_block_vars('sub', array(
+ 'FOO' => 'bar',
+ ));
+
+ $this->pagination->generate_template_pagination($base_url, 'sub.pagination', $start_name, $num_items, $per_page, $start_item);
+ $this->template->set_filenames(array('test' => 'pagination_sub.html'));
+
+ $this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
+ }
+
+ /**
+ * @dataProvider generate_template_pagination_data
+ */
+ public function test_generate_template_pagination_double_nested($base_url, $start_name, $num_items, $per_page, $start_item, $expect)
+ {
+ // Block needs to be assigned before pagination
+ $this->template->assign_block_vars('sub', array(
+ 'FOO' => 'bar',
+ ));
+
+ $this->template->assign_block_vars('sub.level2', array(
+ 'BAR' => 'foo',
+ ));
+
+ $this->pagination->generate_template_pagination($base_url, 'sub.level2.pagination', $start_name, $num_items, $per_page, $start_item);
+ $this->template->set_filenames(array('test' => 'pagination_double_nested.html'));
+
+ $this->assertEquals(str_replace("\t", '', $expect), $this->display('test'));
+ }
+
+ public function on_page_data()
+ {
+ return array(
+ array(
+ 10,
+ 10,
+ 0,
+ 'PAGE_OF-1-1',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider on_page_data
+ */
+ public function test_on_page($num_items, $per_page, $start_item, $expect_return)
+ {
+ $this->assertEquals($expect_return, $this->pagination->on_page($num_items, $per_page, $start_item));
+ }
+
+ public function validate_start_data()
+ {
+ return array(
+ array(
+ 0,
+ 0,
+ 0,
+ ),
+ array(
+ -1,
+ 20,
+ 0,
+ ),
+ array(
+ 20,
+ -30,
+ 0,
+ ),
+ array(
+ 0,
+ 20,
+ 0,
+ ),
+ array(
+ 10,
+ 20,
+ 10,
+ ),
+ array(
+ 20,
+ 20,
+ 10,
+ ),
+ array(
+ 30,
+ 20,
+ 10,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider validate_start_data
+ */
+ public function test_validate_start($start, $num_items, $expect)
+ {
+ $this->assertEquals($expect, $this->pagination->validate_start($start, 10, $num_items));
+ }
+
+ public function reverse_start_data()
+ {
+ return array(
+ array(
+ 10,
+ 5,
+ 15,
+ 0,
+ ),
+ array(
+ 10,
+ 10,
+ 25,
+ 5,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider reverse_start_data
+ */
+ public function test_reverse_start($start, $limit, $num_items, $expect)
+ {
+ $this->assertEquals($expect, $this->pagination->reverse_start($start, $limit, $num_items));
+ }
+
+ public function reverse_limit_data()
+ {
+ return array(
+ array(
+ 10,
+ 10,
+ 15,
+ 5,
+ ),
+ array(
+ 20,
+ 10,
+ 15,
+ 1,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider reverse_limit_data
+ */
+ public function test_reverse_limit($start, $per_page, $num_items, $expect)
+ {
+ $this->assertEquals($expect, $this->pagination->reverse_limit($start, $per_page, $num_items));
+ }
+}
diff --git a/tests/pagination/templates/pagination.html b/tests/pagination/templates/pagination.html
new file mode 100644
index 0000000000..db63258585
--- /dev/null
+++ b/tests/pagination/templates/pagination.html
@@ -0,0 +1,15 @@
+pagination
+:per_page:{PER_PAGE}
+:current_page:{CURRENT_PAGE}
+:base_url:{BASE_URL}
+<!-- BEGIN pagination -->
+<!-- IF pagination.S_IS_PREV -->:previous:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL}
+<!-- ELSEIF pagination.S_IS_CURRENT -->:current:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL}
+<!-- ELSEIF pagination.S_IS_ELLIPSIS -->:ellipsis:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL}
+<!-- ELSEIF pagination.S_IS_NEXT -->:next:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL}
+<!-- ELSE -->:else:{pagination.PAGE_NUMBER}:{pagination.PAGE_URL}
+<!-- ENDIF -->
+<!-- END pagination -->
+<!-- IF U_PREVIOUS_PAGE -->:u_prev:{U_PREVIOUS_PAGE}<!-- ENDIF -->
+
+<!-- IF U_NEXT_PAGE -->:u_next:{U_NEXT_PAGE}<!-- ENDIF -->
diff --git a/tests/pagination/templates/pagination_double_nested.html b/tests/pagination/templates/pagination_double_nested.html
new file mode 100644
index 0000000000..c179248233
--- /dev/null
+++ b/tests/pagination/templates/pagination_double_nested.html
@@ -0,0 +1,19 @@
+pagination
+<!-- BEGIN sub -->
+<!-- BEGIN level2 -->
+:per_page:{sub.level2.PER_PAGE}
+:current_page:{sub.level2.CURRENT_PAGE}
+:base_url:{sub.level2.BASE_URL}
+<!-- BEGIN pagination -->
+<!-- IF sub.level2.pagination.S_IS_PREV -->:previous:{sub.level2.pagination.PAGE_NUMBER}:{sub.level2.pagination.PAGE_URL}
+<!-- ELSEIF sub.level2.pagination.S_IS_CURRENT -->:current:{sub.level2.pagination.PAGE_NUMBER}:{sub.level2.pagination.PAGE_URL}
+<!-- ELSEIF sub.level2.pagination.S_IS_ELLIPSIS -->:ellipsis:{sub.level2.pagination.PAGE_NUMBER}:{sub.level2.pagination.PAGE_URL}
+<!-- ELSEIF sub.level2.pagination.S_IS_NEXT -->:next:{sub.level2.pagination.PAGE_NUMBER}:{sub.level2.pagination.PAGE_URL}
+<!-- ELSE -->:else:{sub.level2.pagination.PAGE_NUMBER}:{sub.level2.pagination.PAGE_URL}
+<!-- ENDIF -->
+<!-- END pagination -->
+<!-- IF sub.level2.U_PREVIOUS_PAGE -->:u_prev:{sub.level2.U_PREVIOUS_PAGE}<!-- ENDIF -->
+
+<!-- IF sub.level2.U_NEXT_PAGE -->:u_next:{sub.level2.U_NEXT_PAGE}<!-- ENDIF -->
+<!-- END level2 -->
+<!-- END sub -->
diff --git a/tests/pagination/templates/pagination_sub.html b/tests/pagination/templates/pagination_sub.html
new file mode 100644
index 0000000000..4ec14039e0
--- /dev/null
+++ b/tests/pagination/templates/pagination_sub.html
@@ -0,0 +1,17 @@
+pagination
+<!-- BEGIN sub -->
+:per_page:{sub.PER_PAGE}
+:current_page:{sub.CURRENT_PAGE}
+:base_url:{sub.BASE_URL}
+<!-- BEGIN pagination -->
+<!-- IF sub.pagination.S_IS_PREV -->:previous:{sub.pagination.PAGE_NUMBER}:{sub.pagination.PAGE_URL}
+<!-- ELSEIF sub.pagination.S_IS_CURRENT -->:current:{sub.pagination.PAGE_NUMBER}:{sub.pagination.PAGE_URL}
+<!-- ELSEIF sub.pagination.S_IS_ELLIPSIS -->:ellipsis:{sub.pagination.PAGE_NUMBER}:{sub.pagination.PAGE_URL}
+<!-- ELSEIF sub.pagination.S_IS_NEXT -->:next:{sub.pagination.PAGE_NUMBER}:{sub.pagination.PAGE_URL}
+<!-- ELSE -->:else:{sub.pagination.PAGE_NUMBER}:{sub.pagination.PAGE_URL}
+<!-- ENDIF -->
+<!-- END pagination -->
+<!-- IF sub.U_PREVIOUS_PAGE -->:u_prev:{sub.U_PREVIOUS_PAGE}<!-- ENDIF -->
+
+<!-- IF sub.U_NEXT_PAGE -->:u_next:{sub.U_NEXT_PAGE}<!-- ENDIF -->
+<!-- END sub -->
diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php
new file mode 100644
index 0000000000..5f9fd523c9
--- /dev/null
+++ b/tests/passwords/drivers_test.php
@@ -0,0 +1,416 @@
+<?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_passwords_helper_test extends \phpbb_test_case
+{
+ public function setUp()
+ {
+ // Prepare dependencies for drivers
+ $config = new \phpbb\config\config(array());
+ $request = new phpbb_mock_request(array(), array(), array(), array(), array('password' => 'fööbar'));
+ $this->driver_helper = new \phpbb\passwords\driver\helper($config);
+ $phpbb_root_path = dirname(__FILE__) . '/../../phpBB/';
+ $php_ext = 'php';
+
+ $this->passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
+ 'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper),
+ 'passwords.driver.sha1_wcf1' => new \phpbb\passwords\driver\sha1_wcf1($config, $this->driver_helper),
+ 'passwords.driver.convert_password'=> new \phpbb\passwords\driver\convert_password($config, $this->driver_helper),
+ 'passwords.driver.sha1' => new \phpbb\passwords\driver\sha1($config, $this->driver_helper),
+ 'passwords.driver.md5_mybb' => new \phpbb\passwords\driver\md5_mybb($config, $this->driver_helper),
+ 'passwords.driver.md5_vb' => new \phpbb\passwords\driver\md5_vb($config, $this->driver_helper),
+ 'passwords.driver.sha_xf1' => new \phpbb\passwords\driver\sha_xf1($config, $this->driver_helper),
+ );
+ $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext);
+ $this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper);
+ }
+
+ public function data_helper_encode64()
+ {
+ return array(
+ array('foobar', 6, 'axqPW3aQ'),
+ array('foobar', 7, 'axqPW3aQ..'),
+ array('foobar', 5, 'axqPW34'),
+ );
+ }
+
+ /**
+ * @dataProvider data_helper_encode64
+ */
+ public function test_helper_encode64($input, $length, $output)
+ {
+ $return = $this->driver_helper->hash_encode64($input, $length);
+ $this->assertSame($output, $return);
+ }
+
+ public function data_get_random_salt()
+ {
+ return array(
+ array(24, false),
+ array(24, '/dev/foobar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_random_salt
+ */
+ public function test_get_random_salt($length, $rand_seed)
+ {
+ $rand_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed);
+ $start = microtime(true);
+
+ // Run each test for max. 1 second
+ while ((microtime(true) - $start) < 1)
+ {
+ $urandom_string = (empty($rand_seed)) ? $this->driver_helper->get_random_salt($length) : $this->driver_helper->get_random_salt($length, $rand_seed);
+ $this->assertSame($length, strlen($urandom_string));
+ $this->assertNotSame($rand_string, $urandom_string);
+ }
+ }
+
+ public function test_get_hash_settings_salted_md5()
+ {
+ $settings = $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings('$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1');
+ $this->assertEquals(array(
+ 'count' => pow(2, 11),
+ 'salt' => 'isfrtKXW',
+ 'full' => '$H$9isfrtKXW',
+ ),
+ $settings
+ );
+ $this->assertEquals(false, $this->passwords_drivers['passwords.driver.salted_md5']->get_hash_settings(false));
+ }
+
+ public function data_hash_sha1_smf()
+ {
+ return array(
+ array(false, 'test', array()),
+ array(false, 'test', ''),
+ array('6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'foobar', array('login_name' => 'test')),
+ );
+ }
+
+ /**
+ * @dataProvider data_hash_sha1_smf
+ */
+ public function test_hash_sha1_smf($expected, $password, $user_row)
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha1_smf']->hash($password, $user_row));
+ }
+
+ public function data_get_settings()
+ {
+ return array(
+ array(false, '6f9e2a1899e1f15708fd2e554103480eb53e8b57', 'passwords.driver.sha1_smf'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_settings
+ */
+ public function test_get_settings_only($expected, $hash, $driver)
+ {
+ $this->assertSame($expected, $this->passwords_drivers[$driver]->get_settings_only($hash));
+ }
+
+ public function data_md5_phpbb2_check()
+ {
+ return array(
+ array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96ae'),
+ array(false, 'foobar', 'ae2fc75e20ee25d4520766788fbc96aeddsf'),
+ array(false, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae'),
+ array(true, 'fööbar', 'ae2fc75e20ee25d4520766788fbc96ae', utf8_decode('fööbar')),
+ array(true, 'fööbar', '$H$966CepJh9RC3hFIm7aKywR6jEn0kpA0', utf8_decode('fööbar')),
+ array(true, 'fööbar', '$H$9rNjgwETtmc8befO8JL1xFMrrMw8MC.', $this->utf8_to_cp1252(utf8_decode('fööbar'))),
+ array(true, 'fööbar', '$H$9rNjgwETtmc8befO8JL1xFMrrMw8MC.', $this->utf8_to_cp1252('fööbar')),
+ );
+ }
+
+ /**
+ * @dataProvider data_md5_phpbb2_check
+ */
+ public function test_md5_phpbb2_check($expected, $password, $hash, $request_password = false)
+ {
+ if (!$request_password)
+ {
+ unset($_REQUEST['password']);
+ }
+ else
+ {
+ $_REQUEST['password'] = $request_password;
+ }
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_phpbb2']->check($password, $hash));
+ }
+
+ public function test_md5_phpbb2_hash()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_phpbb2']->hash('foobar'));
+ }
+
+ public function test_convert_password_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.convert_password']->hash('foobar'));
+ }
+
+ public function test_sha1_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha1']->hash('foobar'));
+ }
+
+ public function data_md5_mybb_check()
+ {
+ return array(
+ array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd'),
+ array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd', array('user_passwd_salt' => 'ae2fc75e')),
+ array(true, 'foobar', 'b86ee7e24008bfd2890dcfab1ed31333', array('user_passwd_salt' => 'yeOtfFO6')),
+ );
+ }
+
+ /**
+ * @dataProvider data_md5_mybb_check
+ */
+ public function test_md5_mybb_check($expected, $password, $hash, $user_row = array())
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_mybb']->check($password, $hash, $user_row));
+ }
+
+ public function test_md5_mybb_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_mybb']->hash('foobar'));
+ }
+
+ public function data_md5_vb_check()
+ {
+ return array(
+ array(false, 'foobar', '083d11daea8675b1b4b502c7e55f8dbd'),
+ array(false, 'foobar', 'b86ee7e24008bfd2890dcfab1ed31333', array('user_passwd_salt' => 'yeOtfFO6')),
+ array(true, 'foobar', 'b452c54c44c588fc095d2d000935c470', array('user_passwd_salt' => '9^F')),
+ array(true, 'foobar', 'f23a8241bd115d270c703213e3ef7f52', array('user_passwd_salt' => 'iaU*U%`CBl;/e~>D%do2m@Xf/,KZB0')),
+ array(false, 'nope', 'f23a8241bd115d270c703213e3ef7f52', array('user_passwd_salt' => 'iaU*U%`CBl;/e~>D%do2m@Xf/,KZB0')),
+ );
+ }
+
+ /**
+ * @dataProvider data_md5_vb_check
+ */
+ public function test_md5_vb_check($expected, $password, $hash, $user_row = array())
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.md5_vb']->check($password, $hash, $user_row));
+ }
+
+ public function test_md5_vb_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.md5_vb']->hash('foobar'));
+ }
+
+ public function data_sha1_wcf1_check()
+ {
+ return array(
+ array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
+ array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => 'yeOtfFO6')),
+ array(true, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => '1a783e478d63f6422783a868db667aed3a857840')),
+ );
+ }
+
+ /**
+ * @dataProvider data_sha1_wcf1_check
+ */
+ public function test_sha1_wcf1_check($expected, $password, $hash, $user_row = array())
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha1_wcf1']->check($password, $hash, $user_row));
+ }
+
+ public function test_sha1_wcf1_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha1_wcf1']->hash('foobar'));
+ }
+
+ public function data_bcrypt_wcf2_check()
+ {
+ return array(
+ array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
+ array(true, 'foobar', '$2a$08$p8h14U0jsEiVb1Luy.s8oOTXSQ0hVWUXpcNGBoCezeYNXrQyCKHfi'),
+ array(false, 'foobar', ''),
+ );
+ }
+
+ /**
+ * @dataProvider data_bcrypt_wcf2_check
+ */
+ public function test_bcrypt_wcf2_check($expected, $password, $hash)
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.bcrypt_wcf2']->check($password, $hash));
+ }
+
+ public function test_bcrypt_wcf2_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.bcrypt_wcf2']->hash('foobar'));
+ }
+
+ public function data_sha_xf1_check()
+ {
+ return array(
+ array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff'),
+ array(false, 'foobar', 'fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', array('user_passwd_salt' => 'yeOtfFO6')),
+ array(true, 'foobar', '7f65d2fa8a826d232f8134772252f8b1aaef8594b1edcabd9ab65e5b0f236ff0', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')),
+ array(true, 'foobar', '69962ae2079420573a3948cc4dedbabd35680051', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')),
+ );
+ }
+
+ /**
+ * @dataProvider data_sha_xf1_check
+ */
+ public function test_sha_xf1_check($expected, $password, $hash, $user_row = array())
+ {
+ $this->assertSame($expected, $this->passwords_drivers['passwords.driver.sha_xf1']->check($password, $hash, $user_row));
+ }
+
+ public function test_sha_xf1_driver()
+ {
+ $this->assertSame(false, $this->passwords_drivers['passwords.driver.sha_xf1']->hash('foobar'));
+ }
+
+ protected function utf8_to_cp1252($string)
+ {
+ static $transform = array(
+ "\xE2\x82\xAC" => "\x80",
+ "\xE2\x80\x9A" => "\x82",
+ "\xC6\x92" => "\x83",
+ "\xE2\x80\x9E" => "\x84",
+ "\xE2\x80\xA6" => "\x85",
+ "\xE2\x80\xA0" => "\x86",
+ "\xE2\x80\xA1" => "\x87",
+ "\xCB\x86" => "\x88",
+ "\xE2\x80\xB0" => "\x89",
+ "\xC5\xA0" => "\x8A",
+ "\xE2\x80\xB9" => "\x8B",
+ "\xC5\x92" => "\x8C",
+ "\xC5\xBD" => "\x8E",
+ "\xE2\x80\x98" => "\x91",
+ "\xE2\x80\x99" => "\x92",
+ "\xE2\x80\x9C" => "\x93",
+ "\xE2\x80\x9D" => "\x94",
+ "\xE2\x80\xA2" => "\x95",
+ "\xE2\x80\x93" => "\x96",
+ "\xE2\x80\x94" => "\x97",
+ "\xCB\x9C" => "\x98",
+ "\xE2\x84\xA2" => "\x99",
+ "\xC5\xA1" => "\x9A",
+ "\xE2\x80\xBA" => "\x9B",
+ "\xC5\x93" => "\x9C",
+ "\xC5\xBE" => "\x9E",
+ "\xC5\xB8" => "\x9F",
+ "\xC2\xA0" => "\xA0",
+ "\xC2\xA1" => "\xA1",
+ "\xC2\xA2" => "\xA2",
+ "\xC2\xA3" => "\xA3",
+ "\xC2\xA4" => "\xA4",
+ "\xC2\xA5" => "\xA5",
+ "\xC2\xA6" => "\xA6",
+ "\xC2\xA7" => "\xA7",
+ "\xC2\xA8" => "\xA8",
+ "\xC2\xA9" => "\xA9",
+ "\xC2\xAA" => "\xAA",
+ "\xC2\xAB" => "\xAB",
+ "\xC2\xAC" => "\xAC",
+ "\xC2\xAD" => "\xAD",
+ "\xC2\xAE" => "\xAE",
+ "\xC2\xAF" => "\xAF",
+ "\xC2\xB0" => "\xB0",
+ "\xC2\xB1" => "\xB1",
+ "\xC2\xB2" => "\xB2",
+ "\xC2\xB3" => "\xB3",
+ "\xC2\xB4" => "\xB4",
+ "\xC2\xB5" => "\xB5",
+ "\xC2\xB6" => "\xB6",
+ "\xC2\xB7" => "\xB7",
+ "\xC2\xB8" => "\xB8",
+ "\xC2\xB9" => "\xB9",
+ "\xC2\xBA" => "\xBA",
+ "\xC2\xBB" => "\xBB",
+ "\xC2\xBC" => "\xBC",
+ "\xC2\xBD" => "\xBD",
+ "\xC2\xBE" => "\xBE",
+ "\xC2\xBF" => "\xBF",
+ "\xC3\x80" => "\xC0",
+ "\xC3\x81" => "\xC1",
+ "\xC3\x82" => "\xC2",
+ "\xC3\x83" => "\xC3",
+ "\xC3\x84" => "\xC4",
+ "\xC3\x85" => "\xC5",
+ "\xC3\x86" => "\xC6",
+ "\xC3\x87" => "\xC7",
+ "\xC3\x88" => "\xC8",
+ "\xC3\x89" => "\xC9",
+ "\xC3\x8A" => "\xCA",
+ "\xC3\x8B" => "\xCB",
+ "\xC3\x8C" => "\xCC",
+ "\xC3\x8D" => "\xCD",
+ "\xC3\x8E" => "\xCE",
+ "\xC3\x8F" => "\xCF",
+ "\xC3\x90" => "\xD0",
+ "\xC3\x91" => "\xD1",
+ "\xC3\x92" => "\xD2",
+ "\xC3\x93" => "\xD3",
+ "\xC3\x94" => "\xD4",
+ "\xC3\x95" => "\xD5",
+ "\xC3\x96" => "\xD6",
+ "\xC3\x97" => "\xD7",
+ "\xC3\x98" => "\xD8",
+ "\xC3\x99" => "\xD9",
+ "\xC3\x9A" => "\xDA",
+ "\xC3\x9B" => "\xDB",
+ "\xC3\x9C" => "\xDC",
+ "\xC3\x9D" => "\xDD",
+ "\xC3\x9E" => "\xDE",
+ "\xC3\x9F" => "\xDF",
+ "\xC3\xA0" => "\xE0",
+ "\xC3\xA1" => "\xE1",
+ "\xC3\xA2" => "\xE2",
+ "\xC3\xA3" => "\xE3",
+ "\xC3\xA4" => "\xE4",
+ "\xC3\xA5" => "\xE5",
+ "\xC3\xA6" => "\xE6",
+ "\xC3\xA7" => "\xE7",
+ "\xC3\xA8" => "\xE8",
+ "\xC3\xA9" => "\xE9",
+ "\xC3\xAA" => "\xEA",
+ "\xC3\xAB" => "\xEB",
+ "\xC3\xAC" => "\xEC",
+ "\xC3\xAD" => "\xED",
+ "\xC3\xAE" => "\xEE",
+ "\xC3\xAF" => "\xEF",
+ "\xC3\xB0" => "\xF0",
+ "\xC3\xB1" => "\xF1",
+ "\xC3\xB2" => "\xF2",
+ "\xC3\xB3" => "\xF3",
+ "\xC3\xB4" => "\xF4",
+ "\xC3\xB5" => "\xF5",
+ "\xC3\xB6" => "\xF6",
+ "\xC3\xB7" => "\xF7",
+ "\xC3\xB8" => "\xF8",
+ "\xC3\xB9" => "\xF9",
+ "\xC3\xBA" => "\xFA",
+ "\xC3\xBB" => "\xFB",
+ "\xC3\xBC" => "\xFC",
+ "\xC3\xBD" => "\xFD",
+ "\xC3\xBE" => "\xFE",
+ "\xC3\xBF" => "\xFF"
+ );
+ return strtr($string, $transform);
+ }
+}
diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php
new file mode 100644
index 0000000000..333834ee07
--- /dev/null
+++ b/tests/passwords/manager_test.php
@@ -0,0 +1,347 @@
+<?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_passwords_manager_test extends \phpbb_test_case
+{
+ protected $passwords_drivers;
+
+ protected $pw_characters = '0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVXYZ.,_!?/\\';
+
+ protected $default_pw = 'foobar';
+
+ public function setUp()
+ {
+ // Prepare dependencies for manager and driver
+ $config = new \phpbb\config\config(array());
+ $this->driver_helper = new \phpbb\passwords\driver\helper($config);
+ $request = new phpbb_mock_request(array(), array(), array(), array(), array('password' => 'töst'));
+ $phpbb_root_path = dirname(__FILE__) . '/../../phpBB/';
+ $php_ext = 'php';
+
+ $this->passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $this->driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $this->driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $this->driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $this->driver_helper),
+ 'passwords.driver.convert_password' => new \phpbb\passwords\driver\convert_password($config, $this->driver_helper),
+ 'passwords.driver.sha1_smf' => new \phpbb\passwords\driver\sha1_smf($config, $this->driver_helper),
+ 'passwords.driver.sha1' => new \phpbb\passwords\driver\sha1($config, $this->driver_helper),
+ 'passwords.driver.sha1_wcf1' => new \phpbb\passwords\driver\sha1_wcf1($config, $this->driver_helper),
+ 'passwords.driver.md5_mybb' => new \phpbb\passwords\driver\md5_mybb($config, $this->driver_helper),
+ 'passwords.driver.md5_vb' => new \phpbb\passwords\driver\md5_vb($config, $this->driver_helper),
+ 'passwords.driver.sha_xf1' => new \phpbb\passwords\driver\sha_xf1($config, $this->driver_helper),
+ );
+ $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext);
+ $this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper);
+
+ $this->helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $this->manager = new \phpbb\passwords\manager($config, $this->passwords_drivers, $this->helper, array_keys($this->passwords_drivers));
+ }
+
+ public function hash_password_data()
+ {
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ return array(
+ array('', '2a', 60),
+ array('passwords.driver.bcrypt_2y', '2a', 60),
+ array('passwords.driver.bcrypt', '2a', 60),
+ array('passwords.driver.salted_md5', 'H', 34),
+ array('passwords.driver.foobar', '', false),
+ );
+ }
+ else
+ {
+ return array(
+ array('', '2y', 60),
+ array('passwords.driver.bcrypt_2y', '2y', 60),
+ array('passwords.driver.bcrypt', '2a', 60),
+ array('passwords.driver.salted_md5', 'H', 34),
+ array('passwords.driver.foobar', '', false),
+ );
+ }
+ }
+
+ /**
+ * @dataProvider hash_password_data
+ */
+ public function test_hash_password($type, $prefix, $length)
+ {
+ $password = $this->default_pw;
+
+ if (!$length)
+ {
+ $this->assertEquals(false, $hash = $this->manager->hash($password, $type));
+ return;
+ }
+ $time = microtime(true);
+
+ // Limit each test to 1 second
+ while ((microtime(true) - $time) < 1)
+ {
+ $hash = $this->manager->hash($password, $type);
+ preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $hash, $match);
+ $this->assertEquals($prefix, $match[1]);
+ $this->assertEquals($length, strlen($hash));
+ $password .= $this->pw_characters[mt_rand(0, 66)];
+ }
+ }
+
+ public function check_password_data()
+ {
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ return array(
+ array('passwords.driver.bcrypt'),
+ array('passwords.driver.salted_md5'),
+ array('passwords.driver.phpass'),
+ );
+ }
+ else
+ {
+ return array(
+ array('passwords.driver.bcrypt_2y'),
+ array('passwords.driver.bcrypt'),
+ array('passwords.driver.salted_md5'),
+ array('passwords.driver.phpass'),
+ );
+ }
+ }
+
+ /**
+ * @dataProvider check_password_data
+ */
+ public function test_check_password($hash_type)
+ {
+ $password = $this->default_pw;
+ $time = microtime(true);
+ // Limit each test to 1 second
+ while ((microtime(true) - $time) < 1)
+ {
+ $hash = $this->manager->hash($password, $hash_type);
+ $this->assertEquals(true, $this->manager->check($password, $hash));
+ $password .= $this->pw_characters[mt_rand(0, 66)];
+ $this->assertEquals(false, $this->manager->check($password, $hash));
+ }
+
+ // Check if convert_flag is correctly set
+ $default_type = (version_compare(PHP_VERSION, '5.3.7', '<')) ? 'passwords.driver.bcrypt' : 'passwords.driver.bcrypt_2y';
+ $this->assertEquals(($hash_type !== $default_type), $this->manager->convert_flag);
+ }
+
+
+ public function check_hash_exceptions_data()
+ {
+ return array(
+ array('3858f62230ac3c915f300c664312c63f', true),
+ array('$CP$3858f62230ac3c915f300c664312c63f', true), // md5_phpbb2
+ array('$CP$3858f62230ac3c915f300c', false),
+ array('$S$b57a939fa4f2c04413a4eea9734a0903647b7adb93181295', false),
+ array('$2a\S$kkkkaakdkdiej39023903204j2k3490234jk234j02349', false),
+ array('$H$kklk938d023k//k3023', false),
+ array('$H$3PtYMgXb39lrIWkgoxYLWtRkZtY3AY/', false),
+ array('$2a$kwiweorurlaeirw', false),
+ array('6f9e2a1899e1f15708fd2e554103480eb53e8b57', false),
+ array('6f9e2a1899e1f15708fd2e554103480eb53e8b57', false, 'foobar', array('login_name' => 'test')),
+ array('$CP$6f9e2a1899e1f15708fd2e554103480eb53e8b57', true, 'foobar', array('login_name' => 'test')), // sha1_smf
+ array('6f9e2a1899', false, 'foobar', array('login_name' => 'test')),
+ array('ae2fc75e20ee25d4520766788fbc96ae', false, 'fööbar'),
+ array('$CP$ae2fc75e20ee25d4520766788fbc96ae', false, 'fööbar'),
+ array('$CP$ae2fc75e20ee25d4520766788fbc96ae', true, utf8_decode('fööbar')), // md5_phpbb2
+ array('b86ee7e24008bfd2890dcfab1ed31333', false, 'foobar', array('user_passwd_salt' => 'yeOtfFO6')),
+ array('$CP$b86ee7e24008bfd2890dcfab1ed31333', true, 'foobar', array('user_passwd_salt' => 'yeOtfFO6')), // md5_mybb
+ array('$CP$b452c54c44c588fc095d2d000935c470', true, 'foobar', array('user_passwd_salt' => '9^F')), // md5_vb
+ array('$CP$f23a8241bd115d270c703213e3ef7f52', true, 'foobar', array('user_passwd_salt' => 'iaU*U%`CBl;/e~>D%do2m@Xf/,KZB0')), // md5_vb
+ array('$CP$fc46b9d9386167ce365ea3b891bf5dc31ddcd3ff', true, 'foobar', array('user_passwd_salt' => '1a783e478d63f6422783a868db667aed3a857840')), // sha_wcf1
+ array('$2a$08$p8h14U0jsEiVb1Luy.s8oOTXSQ0hVWUXpcNGBoCezeYNXrQyCKHfi', false),
+ array('$CP$$2a$08$p8h14U0jsEiVb1Luy.s8oOTXSQ0hVWUXpcNGBoCezeYNXrQyCKHfi', true), // bcrypt_wcf2
+ array('$CP$7f65d2fa8a826d232f8134772252f8b1aaef8594b1edcabd9ab65e5b0f236ff0', true, 'foobar', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')), // sha_xf1
+ array('$CP$69962ae2079420573a3948cc4dedbabd35680051', true, 'foobar', array('user_passwd_salt' => '15b6c02cedbd727f563dcca607a89b085287b448966f19c0cc78cae263b1e38c')), // sha_xf1
+ );
+ }
+
+ /**
+ * @dataProvider check_hash_exceptions_data
+ */
+ public function test_check_hash_exceptions($hash, $expected, $password = 'foobar', $user_row = array())
+ {
+ $this->assertEquals($expected, $this->manager->check($password, $hash, $user_row));
+ }
+
+ public function data_hash_password_length()
+ {
+ return array(
+ array('passwords.driver.bcrypt', false),
+ array('passwords.driver.bcrypt_2y', false),
+ array('passwords.driver.salted_md5', '3858f62230ac3c915f300c664312c63f'),
+ array('passwords.driver.phpass', '3858f62230ac3c915f300c664312c63f'),
+ );
+ }
+
+ /**
+ * @dataProvider data_hash_password_length
+ */
+ public function test_hash_password_length($driver, $expected)
+ {
+ $this->assertEquals($expected, $this->passwords_drivers[$driver]->hash('foobar', 'foobar'));
+ }
+
+ public function test_hash_password_8bit_bcrypt()
+ {
+ $this->assertEquals(false, $this->manager->hash('foobar𝄞', 'passwords.driver.bcrypt'));
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ $this->assertEquals(false, $this->manager->hash('foobar𝄞', 'passwords.driver.bcrypt_2y'));
+ }
+ else
+ {
+ $this->assertNotEquals(false, $this->manager->hash('foobar𝄞', 'passwords.driver.bcrypt_2y'));
+ }
+ }
+
+ public function combined_hash_data()
+ {
+ if (version_compare(PHP_VERSION, '5.3.7', '<'))
+ {
+ return array(
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.phpass',
+ array('passwords.driver.salted_md5'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.phpass', 'passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.salted_md5'),
+ false,
+ ),
+ array(
+ '$H$',
+ array('$2a$'),
+ ),
+ );
+ }
+ else
+ {
+ return array(
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt_2y'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.phpass',
+ array('passwords.driver.salted_md5'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.bcrypt_2y', 'passwords.driver.bcrypt'),
+ ),
+ array(
+ 'passwords.driver.salted_md5',
+ array('passwords.driver.salted_md5'),
+ false,
+ ),
+ array(
+ 'passwords.driver.bcrypt_2y',
+ array('passwords.driver.salted_md4'),
+ false,
+ ),
+ array(
+ '$H$',
+ array('$2y$'),
+ ),
+ );
+ }
+ }
+
+ /**
+ * @dataProvider combined_hash_data
+ */
+ public function test_combined_hash_password($first_type, $second_type, $expected = true)
+ {
+ $password = $this->default_pw;
+ $time = microtime(true);
+ // Limit each test to 1 second
+ while ((microtime(true) - $time) < 1)
+ {
+ $hash = $this->manager->hash($password, $first_type);
+ $combined_hash = $this->manager->hash($hash, $second_type);
+ $this->assertEquals($expected, $this->manager->check($password, $combined_hash));
+ $password .= $this->pw_characters[mt_rand(0, 66)];
+ $this->assertEquals(false, $this->manager->check($password, $combined_hash));
+
+ // If we are expecting the check to fail then there is
+ // no need to run this more than once
+ if (!$expected)
+ {
+ break;
+ }
+ }
+ }
+
+ public function test_unique_id()
+ {
+ $time = microtime(true);
+ $first_id = $this->driver_helper->unique_id();
+ // Limit test to 1 second
+ while ((microtime(true) - $time) < 1)
+ {
+ $this->assertNotSame($first_id, $this->driver_helper->unique_id());
+ }
+ }
+
+ public function test_check_hash_with_large_input()
+ {
+ // 16 MB password, should be rejected quite fast
+ $start_time = time();
+ $this->assertFalse($this->manager->check(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ $this->assertLessThanOrEqual(5, time() - $start_time);
+ }
+
+ public function test_hash_password_with_large_input()
+ {
+ // 16 MB password, should be rejected quite fast
+ $start_time = time();
+ $this->assertFalse($this->manager->hash(str_repeat('a', 1024 * 1024 * 16)));
+ $this->assertLessThanOrEqual(5, time() - $start_time);
+ }
+
+ public function data_test_string_compare()
+ {
+ return array(
+ array('foo', 'bar', false),
+ array(1, '1', false),
+ array('one', 'one', true),
+ array('foobar', 'foobaf', false),
+ );
+ }
+
+ /**
+ * @dataProvider data_test_string_compare
+ */
+ public function test_string_compare($a, $b, $expected)
+ {
+ $this->assertSame($expected, $this->driver_helper->string_compare($a, $b));
+ }
+}
diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php
new file mode 100644
index 0000000000..73f0e6bafc
--- /dev/null
+++ b/tests/path_helper/path_helper_test.php
@@ -0,0 +1,464 @@
+<?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_path_helper_test extends phpbb_test_case
+{
+ /** @var \phpbb\path_helper */
+ protected $path_helper;
+ protected $phpbb_root_path = '';
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $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'
+ );
+ }
+
+ /**
+ * Set the phpbb_root_path
+ *
+ * This is necessary because dataProvider functions are called
+ * before setUp or setUpBeforeClass; so we must set the path
+ * 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($filesystem)
+ {
+ $this->phpbb_root_path = $filesystem->clean_path(dirname(__FILE__) . '/../../phpBB/');
+ }
+
+ public function test_get_web_root_path()
+ {
+ // Symfony Request = null, so always should return phpbb_root_path
+ $this->assertEquals($this->phpbb_root_path, $this->path_helper->get_web_root_path());
+ }
+
+ public function basic_update_web_root_path_data()
+ {
+ $filesystem = new \phpbb\filesystem();
+ $this->set_phpbb_root_path($filesystem);
+
+ return array(
+ array(
+ 'http://www.test.com/test.php',
+ 'http://www.test.com/test.php',
+ '/',
+ ),
+ array(
+ $this->phpbb_root_path . 'test.php',
+ $this->phpbb_root_path . 'test.php',
+ ),
+ array(
+ 'test.php',
+ 'test.php',
+ ),
+ array(
+ $this->phpbb_root_path . $this->phpbb_root_path . 'test.php',
+ $filesystem->clean_path($this->phpbb_root_path . $this->phpbb_root_path . 'test.php'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider basic_update_web_root_path_data
+ */
+ public function test_basic_update_web_root_path($input, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->update_web_root_path($input));
+ }
+
+ public function update_web_root_path_data()
+ {
+ $this->set_phpbb_root_path(new \phpbb\filesystem());
+
+ return array(
+ array(
+ $this->phpbb_root_path . 'test.php',
+ '/',
+ null,
+ null,
+ '',
+ ),
+ array(
+ $this->phpbb_root_path . 'test.php',
+ '//',
+ null,
+ null,
+ './../',
+ ),
+ array(
+ $this->phpbb_root_path . 'test.php',
+ '//',
+ 'foo/bar.php',
+ 'bar.php',
+ './../',
+ ),
+ array(
+ $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',
+ '/foo/template',
+ '/phpbb3-fork/phpBB/foo/template',
+ '/phpbb3-fork/phpBB/app.php',
+ './../',
+ ),
+ array(
+ $this->phpbb_root_path . 'test.php',
+ '/',
+ '/phpbb3-fork/phpBB/app.php/',
+ '/phpbb3-fork/phpBB/app.php',
+ './../',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider update_web_root_path_data
+ */
+ public function test_update_web_root_path($input, $getPathInfo, $getRequestUri, $getScriptName, $correction)
+ {
+ $symfony_request = $this->getMock('\phpbb\symfony_request', array(), array(
+ new phpbb_mock_request(),
+ ));
+ $symfony_request->expects($this->any())
+ ->method('getPathInfo')
+ ->will($this->returnValue($getPathInfo));
+ $symfony_request->expects($this->any())
+ ->method('getRequestUri')
+ ->will($this->returnValue($getRequestUri));
+ $symfony_request->expects($this->any())
+ ->method('getScriptName')
+ ->will($this->returnValue($getScriptName));
+
+ $path_helper = new \phpbb\path_helper(
+ $symfony_request,
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $this->phpbb_root_path,
+ 'php'
+ );
+
+ $this->assertEquals($correction . $input, $path_helper->update_web_root_path($input, $symfony_request));
+ }
+
+ public function clean_url_data()
+ {
+ return array(
+ array('', ''),
+ array('://', '://'),
+ array('http://', 'http://'),
+ array('http://one/two/three', 'http://one/two/three'),
+ array('http://../one/two', 'http://../one/two'),
+ array('http://one/../two/three', 'http://two/three'),
+ array('http://one/two/../three', 'http://one/three'),
+ array('http://one/two/../../three', 'http://three'),
+ array('http://one/two/../../../three', 'http://../three'),
+ );
+ }
+
+ /**
+ * @dataProvider clean_url_data
+ */
+ public function test_clean_url($input, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->clean_url($input));
+ }
+
+ public function glue_url_params_data()
+ {
+ return array(
+ array(
+ array(),
+ '',
+ ),
+ array(
+ array('test' => 'xyz'),
+ 'test=xyz',
+ ),
+ array(
+ array('test' => 'xyz', 'var' => 'value'),
+ 'test=xyz&amp;var=value',
+ ),
+ array(
+ array('test' => null),
+ 'test',
+ ),
+ array(
+ array('test' => null, 'var' => null),
+ 'test&amp;var',
+ ),
+ array(
+ array('test' => 'xyz', 'var' => null, 'bar' => 'value'),
+ 'test=xyz&amp;var&amp;bar=value',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider glue_url_params_data
+ */
+ public function test_glue_url_params($params, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->glue_url_params($params));
+ }
+
+ public function get_url_parts_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ true,
+ array('base' => 'viewtopic.php', 'params' => array()),
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => './viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6',
+ false,
+ array('base' => 'viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ true,
+ array('base' => 'https://phpbb.com/community/viewtopic.php', 'params' => array('t' => '5', 'f' => '6')),
+ ),
+ array(
+ 'test.php?topic=post=5&amp;f=3',
+ true,
+ array('base' => 'test.php', 'params' => array('topic' => 'post=5', 'f' => '3')),
+ ),
+ array(
+ 'mcp.php?&amp;t=4&amp;f=3',
+ true,
+ array('base' => 'mcp.php', 'params' => array('t' => '4', 'f' => '3')),
+ ),
+ array(
+ 'mcp.php?=4&amp;f=3',
+ true,
+ array('base' => 'mcp.php', 'params' => array('f' => '3')),
+ ),
+ array(
+ 'index.php?ready',
+ false,
+ array('base' => 'index.php', 'params' => array('ready' => null)),
+ ),
+ array(
+ 'index.php?i=1&amp;ready',
+ true,
+ array('base' => 'index.php', 'params' => array('i' => '1', 'ready' => null)),
+ ),
+ array(
+ 'index.php?ready&i=1',
+ false,
+ array('base' => 'index.php', 'params' => array('ready' => null, 'i' => '1')),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_url_parts_data
+ */
+ public function test_get_url_parts($url, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->get_url_parts($url, $is_amp));
+ }
+
+ public function strip_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ 'sid',
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ 'f',
+ true,
+ './viewtopic.php?t=5',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('t'),
+ false,
+ 'viewtopic.php?f=6&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php?t=5&amp;f=6',
+ array('t', 'f'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider strip_url_params_data
+ */
+ public function test_strip_url_params($url, $strip, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->strip_url_params($url, $strip, $is_amp));
+ }
+
+ public function append_url_params_data()
+ {
+ return array(
+ array(
+ 'viewtopic.php',
+ array(),
+ false,
+ 'viewtopic.php',
+ ),
+ array(
+ './viewtopic.php?t=5&amp;f=6',
+ array('t' => '7'),
+ true,
+ './viewtopic.php?t=7&amp;f=6',
+ ),
+ array(
+ 'viewtopic.php?t=5&f=6&sid=19adc288814103cbb4625e74e77455aa',
+ array('p' => '5'),
+ false,
+ 'viewtopic.php?t=5&amp;f=6&amp;p=5&amp;sid=19adc288814103cbb4625e74e77455aa',
+ ),
+ array(
+ 'https://phpbb.com/community/viewtopic.php',
+ array('t' => '7', 'f' => '8'),
+ true,
+ 'https://phpbb.com/community/viewtopic.php?t=7&amp;f=8',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider append_url_params_data
+ */
+ public function test_append_url_params($url, $params, $is_amp, $expected)
+ {
+ $this->assertEquals($expected, $this->path_helper->append_url_params($url, $params, $is_amp));
+ }
+
+ 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/',
+ ),
+ array(
+ 'http://www.phpbb.com/foobar',
+ 'http://www.phpbb.com',
+ '',
+ ),
+ array(
+ 'http://www.foobar.com',
+ 'http://www.phpbb.com',
+ '/www.phpbb.com/',
+ ),
+ array(
+ 'foobar',
+ 'http://www.phpbb.com/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));
+ }
+
+ public function data_get_valid_page()
+ {
+ return array(
+ // array( current page , mod_rewrite setting , expected output )
+ array('index', true, 'index'),
+ array('index', false, 'index'),
+ array('foo/index', true, 'foo/index'),
+ array('foo/index', false, 'foo/index'),
+ array('app.php/foo', true, 'foo'),
+ array('app.php/foo', false, 'app.php/foo'),
+ array('/../app.php/foo', true, '../foo'),
+ array('/../app.php/foo', false, '../app.php/foo'),
+ array('/../example/app.php/foo/bar', true, '../example/foo/bar'),
+ array('/../example/app.php/foo/bar', false, '../example/app.php/foo/bar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_valid_page
+ */
+ public function test_get_valid_page($page, $mod_rewrite, $expected)
+ {
+ $this->assertEquals($this->phpbb_root_path . $expected, $this->path_helper->get_valid_page($page, $mod_rewrite));
+ }
+}
diff --git a/tests/plupload/plupload_test.php b/tests/plupload/plupload_test.php
new file mode 100644
index 0000000000..c3fa2b9bad
--- /dev/null
+++ b/tests/plupload/plupload_test.php
@@ -0,0 +1,53 @@
+<?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_plupload_test extends phpbb_test_case
+{
+ public function generate_resize_string_data()
+ {
+ return array(
+ array(
+ 0,
+ 0,
+ '',
+ ),
+ array(
+ 130,
+ 150,
+ 'resize: {width: 130, height: 150, quality: 85},'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider generate_resize_string_data
+ */
+ public function test_generate_resize_string($config_width, $config_height, $expected)
+ {
+ $config = new \phpbb\config\config(array(
+ 'img_max_width' => $config_width,
+ 'img_max_height' => $config_height,
+ 'upload_path' => 'files',
+ ));
+ $plupload = new \phpbb\plupload\plupload(
+ '',
+ $config,
+ new phpbb_mock_request,
+ new \phpbb\user('\phpbb\datetime'),
+ new \phpbb\php\ini,
+ new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser))
+ );
+
+ $this->assertEquals($expected, $plupload->generate_resize_string());
+ }
+}
diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php
index f705825262..0f061e9784 100644
--- a/tests/privmsgs/delete_user_pms_test.php
+++ b/tests/privmsgs/delete_user_pms_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -81,10 +85,13 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
*/
public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to)
{
- global $db;
+ global $db, $phpbb_container;
$db = $this->new_dbal();
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
+
phpbb_delete_user_pms($delete_user);
$sql = 'SELECT msg_id
diff --git a/tests/privmsgs/fixtures/delete_user_pms.xml b/tests/privmsgs/fixtures/delete_user_pms.xml
index 9a86501b7a..5f705c9fd2 100644
--- a/tests/privmsgs/fixtures/delete_user_pms.xml
+++ b/tests/privmsgs/fixtures/delete_user_pms.xml
@@ -8,8 +8,6 @@
<column>user_unread_privmsg</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>2</value>
<value>sender</value>
@@ -18,8 +16,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
@@ -29,8 +25,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>4</value>
@@ -40,8 +34,6 @@
<value>2</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>5</value>
@@ -51,8 +43,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
<table name="phpbb_privmsgs">
diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php
deleted file mode 100644
index 1f33b45ba9..0000000000
--- a/tests/profile/custom_test.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_profile_fields.php';
-
-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 dropdownFields()
- {
- 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', 'Required field should throw error for out-of-range value'),
- array(1, '1', 'FIELD_REQUIRED', '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', '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 dropdownFields
- */
- public function test_dropdown_validate($field_required, $field_value, $expected, $description)
- {
- global $db;
- $db = $this->new_dbal();
-
- $field_data = array(
- 'field_id' => 1,
- 'lang_id' => 1,
- 'field_novalue' => 1,
- 'field_required' => $field_required,
- );
-
- $cp = new custom_profile;
- $result = $cp->validate_profile_field(FIELD_DROPDOWN, $field_value, $field_data);
-
- $this->assertEquals($expected, $result, $description);
- }
-}
diff --git a/tests/profile/fixtures/profile_fields.xml b/tests/profile/fixtures/profile_fields.xml
deleted file mode 100644
index 0b2929f625..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>5</value>
- <value>Default Option</value>
- </row>
- <row>
- <value>1</value>
- <value>1</value>
- <value>1</value>
- <value>5</value>
- <value>First Alternative</value>
- </row>
- <row>
- <value>1</value>
- <value>1</value>
- <value>2</value>
- <value>5</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 a5f37a85ce..0000000000
--- a/tests/profile/get_profile_value_test.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_profile_fields.php';
-
-class phpbb_profile_get_profile_value_test extends phpbb_test_case
-{
- static public function get_profile_value_int_data()
- {
- return array(
- array(FIELD_INT, '10', true, 10),
- array(FIELD_INT, '0', true, 0),
- array(FIELD_INT, '', true, 0),
- array(FIELD_INT, null, true, 0),
- array(FIELD_INT, '10', false, 10),
- array(FIELD_INT, '0', false, 0),
- array(FIELD_INT, '', false, null),
- array(FIELD_INT, null, false, null),
- );
- }
-
- /**
- * @dataProvider get_profile_value_int_data
- */
- public function test_get_profile_value_int($type, $value, $show_novalue, $expected)
- {
- $cp = new custom_profile;
- $this->assertSame($expected, $cp->get_profile_value(array(
- 'value' => $value,
- 'data' => array(
- 'field_type' => $type,
- 'field_show_novalue' => $show_novalue,
- ),
- )));
- }
-}
diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php
new file mode 100644
index 0000000000..41c40ddb4b
--- /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', array(), array('\phpbb\datetime'));
+ $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..123955198e
--- /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', array(), array('\phpbb\datetime'));
+ $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..3845a8e96b
--- /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', array(), array('\phpbb\datetime'));
+ $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..f3db6ef01f
--- /dev/null
+++ b/tests/profilefields/type_googleplus_test.php
@@ -0,0 +1,94 @@
+<?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 __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_profilefield_type_googleplus_test extends phpbb_test_case
+{
+ protected $field;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->add_lang('ucp');
+ $request = $this->getMock('\phpbb\request\request');
+ $template = $this->getMock('\phpbb\template\template');
+
+ $this->field = new \phpbb\profilefields\type\type_googleplus(
+ $request,
+ $template,
+ $user
+ );
+ }
+ 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)
+ {
+ $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, $this->field->get_profile_contact_value($value, $field_options), $description);
+ }
+
+ public function data_validate_googleplus()
+ {
+ return array(
+ array('foobar', false),
+ array('2342340929304', false),
+ array('foo<bar', 'The field “googleplus” has invalid characters.'),
+ array('klkd.klkl', false),
+ array('kl+', 'The field “googleplus” has invalid characters.'),
+ array('foo=bar', 'The field “googleplus” has invalid characters.'),
+ array('..foo', 'The field “googleplus” has invalid characters.'),
+ array('foo..bar', 'The field “googleplus” has invalid characters.'),
+ );
+ }
+
+ /**
+ * @dataProvider data_validate_googleplus
+ */
+ public function test_validate_googleplus($input, $expected)
+ {
+ $field_data = array_merge(array('lang_name' => 'googleplus'), $this->field->get_default_option_values());
+ $this->assertSame($expected, $this->field->validate_string_profile_field('string', $input, $field_data));
+ }
+}
diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php
new file mode 100644
index 0000000000..07b22525e2
--- /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', array(), array('\phpbb\datetime'));
+ $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..0417afbfab
--- /dev/null
+++ b/tests/profilefields/type_string_test.php
@@ -0,0 +1,353 @@
+<?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', array(), array('\phpbb\datetime'));
+ $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' => '[a-zA-Z0-9]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_ONLY-field',
+ 'Required field should reject UTF-8 in alpha only field',
+ ),
+ array(
+ 'a_abc',
+ array('field_validation' => '[a-zA-Z0-9]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_ONLY-field',
+ 'Required field should reject underscore in alpha only field',
+ ),
+ array(
+ 'Hello',
+ array('field_validation' => '[a-zA-Z0-9]+'),
+ false,
+ 'Required field should accept a characters only field',
+ ),
+ array(
+ 'Valid.Username123',
+ array('field_validation' => '[a-zA-Z0-9.]+'),
+ false,
+ 'Required field should accept a alphanumeric field with dots',
+ ),
+ array(
+ 'Invalid.,username123',
+ array('field_validation' => '[a-zA-Z0-9.]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_DOTS-field',
+ 'Required field should reject field with comma',
+ ),
+ array(
+ 'Invalid._username123',
+ array('field_validation' => '[a-zA-Z0-9.]+'),
+ 'FIELD_INVALID_CHARS_ALPHA_DOTS-field',
+ 'Required field should reject field with underscore',
+ ),
+ 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',
+ ),
+ // UTF-8 string tests
+ array(
+ 'ö äö äö ä',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9]+'),
+ 'FIELD_INVALID_CHARS_LETTER_NUM_ONLY-field',
+ 'Required field should reject spaces in UTF-8 letternumeric only field',
+ ),
+ array(
+ 'Имя123',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9]+'),
+ false,
+ 'Required field should accept UTF-8 letternumeric only field',
+ ),
+ array(
+ 'Ö äö äö- ä+',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9_]+'),
+ 'FIELD_INVALID_CHARS_LETTER_NUM_UNDERSCORE-field',
+ 'Required field should reject spacers in UTF-8 letternumeric with underscore field',
+ ),
+ array(
+ 'Правильное.Имя123',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9.]+'),
+ false,
+ 'Required field should accept UTF-8 letternumeric field with dots',
+ ),
+ array(
+ 'Неправильное.,имя123',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9.]+'),
+ 'FIELD_INVALID_CHARS_LETTER_NUM_DOTS-field',
+ 'Required field should reject comma in UTF-8 letternumeric field with dots',
+ ),
+ array(
+ 'Ö äö äö- ä+',
+ array('field_validation' => '[\p{Lu}\p{Ll}0-9\x20_+\-\[\]]+'),
+ false,
+ 'Required field should accept spacers in UTF-8 letternumeric with spacers field',
+ ),
+ array(
+ 'skype.test.name,_this',
+ array('field_validation' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+'),
+ false,
+ 'Required field should accept alphanumeric value for UTF-8 letternumeric field with punctuations',
+ ),
+ array(
+ '1skype.this.should.fail',
+ array('field_validation' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+'),
+ 'FIELD_INVALID_CHARS_LETTER_NUM_PUNCTUATION-field',
+ 'Required field should reject field having leading numeric for UTF-8 letternumeric field with punctuations',
+ ),
+ );
+ }
+
+ /**
+ * @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..cc37f04f30
--- /dev/null
+++ b/tests/profilefields/type_url_test.php
@@ -0,0 +1,181 @@
+<?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', array(), array('\phpbb\datetime'));
+ $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',
+ ),
+
+ // IDN url type profilefields
+ array(
+ 'http://www.täst.de',
+ array(),
+ false,
+ 'Field should accept valid IDN',
+ ),
+ array(
+ 'http://täst.de/index.html?param1=test&param2=awesome',
+ array(),
+ false,
+ 'Field should accept valid IDN URL with params',
+ ),
+ array(
+ 'http://домен.рф/index.html/тест/path?document=get',
+ array(),
+ false,
+ 'Field should accept valid IDN URL',
+ ),
+ array(
+ 'http://домен.рф/index.html/тест/path?document[]=DocType%20test&document[]=AnotherDoc',
+ array(),
+ 'FIELD_INVALID_URL-field',
+ 'Field should reject invalid IDN 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',
+ ),
+
+ // IDN tests
+ array(
+ 'http://täst.de',
+ array('field_show_novalue' => true),
+ 'http://täst.de',
+ 'Field should return the correct raw value',
+ ),
+ array(
+ 'http://домен.рф',
+ array('field_show_novalue' => false),
+ 'http://домен.рф',
+ '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/random/gen_rand_string_test.php b/tests/random/gen_rand_string_test.php
index 3317c78ed9..1d12d0622c 100644
--- a/tests/random/gen_rand_string_test.php
+++ b/tests/random/gen_rand_string_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/censor_test.php b/tests/regex/censor_test.php
index 5929092e07..50c6778c8c 100644
--- a/tests/regex/censor_test.php
+++ b/tests/regex/censor_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/email_test.php b/tests/regex/email_test.php
index b4ea5b23aa..ede35c49bc 100644
--- a/tests/regex/email_test.php
+++ b/tests/regex/email_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/ipv4_test.php b/tests/regex/ipv4_test.php
index 38a3aa4a8e..62c2567517 100644
--- a/tests/regex/ipv4_test.php
+++ b/tests/regex/ipv4_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/ipv6_test.php b/tests/regex/ipv6_test.php
index d24217b346..41039c819d 100644
--- a/tests/regex/ipv6_test.php
+++ b/tests/regex/ipv6_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/password_complexity_test.php b/tests/regex/password_complexity_test.php
index 07453555ee..8a1a9edd41 100644
--- a/tests/regex/password_complexity_test.php
+++ b/tests/regex/password_complexity_test.php
@@ -1,12 +1,17 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_user.php';
class phpbb_password_complexity_test extends phpbb_test_case
diff --git a/tests/regex/table_prefix_test.php b/tests/regex/table_prefix_test.php
index 33bdd4ae2d..c593085b25 100644
--- a/tests/regex/table_prefix_test.php
+++ b/tests/regex/table_prefix_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/regex/url_test.php b/tests/regex/url_test.php
index b395f5cae2..e5d7c3256a 100644
--- a/tests/regex/url_test.php
+++ b/tests/regex/url_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -28,6 +32,6 @@ class phpbb_regex_url_test extends phpbb_test_case
*/
public function test_url($url, $expected)
{
- $this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#i', $url));
+ $this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#iu', $url));
}
}
diff --git a/tests/request/deactivated_super_global_test.php b/tests/request/deactivated_super_global_test.php
new file mode 100644
index 0000000000..d45f9ca666
--- /dev/null
+++ b/tests/request/deactivated_super_global_test.php
@@ -0,0 +1,25 @@
+<?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_deactivated_super_global_test extends phpbb_test_case
+{
+ /**
+ * Checks that on write access the correct error is thrown
+ */
+ public function test_write_triggers_error()
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $obj = new \phpbb\request\deactivated_super_global($this->getMock('\phpbb\request\request_interface'), 'obj', \phpbb\request\request_interface::POST);
+ $obj->offsetSet(0, 0);
+ }
+}
diff --git a/tests/request/request_test.php b/tests/request/request_test.php
new file mode 100644
index 0000000000..ebaea1f9ef
--- /dev/null
+++ b/tests/request/request_test.php
@@ -0,0 +1,271 @@
+<?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_request_test extends phpbb_test_case
+{
+ /** @var \phpbb\request\type_cast_helper_interface */
+ private $type_cast_helper;
+
+ /** @var \phpbb\request\request */
+ private $request;
+
+ protected function setUp()
+ {
+ // populate super globals
+ $_POST['test'] = 1;
+ $_GET['test'] = 2;
+ $_COOKIE['test'] = 3;
+ $_REQUEST['test'] = 3;
+ $_GET['unset'] = '';
+ $_FILES['test'] = array(
+ 'name' => 'file',
+ 'tmp_name' => 'tmp',
+ 'size' => 256,
+ 'type' => 'application/octet-stream',
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $_SERVER['HTTP_HOST'] = 'example.com';
+ $_SERVER['HTTP_ACCEPT'] = 'application/json';
+ $_SERVER['HTTP_SOMEVAR'] = '<value>';
+
+ $this->type_cast_helper = $this->getMock('\phpbb\request\type_cast_helper_interface');
+ $this->request = new \phpbb\request\request($this->type_cast_helper);
+ }
+
+ public function test_toggle_super_globals()
+ {
+ $this->assertTrue($this->request->super_globals_disabled(), 'Superglobals were not disabled');
+
+ $this->request->enable_super_globals();
+
+ $this->assertFalse($this->request->super_globals_disabled(), 'Superglobals were not enabled');
+
+ $this->assertEquals(1, $_POST['test'], 'Checking $_POST after enable_super_globals');
+ $this->assertEquals(2, $_GET['test'], 'Checking $_GET after enable_super_globals');
+ $this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE after enable_super_globals');
+ $this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST after enable_super_globals');
+ $this->assertEquals(256, $_FILES['test']['size']);
+
+ $_POST['x'] = 2;
+ $this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']');
+ }
+
+ public function test_server()
+ {
+ $this->assertEquals('example.com', $this->request->server('HTTP_HOST'));
+ }
+
+ public function test_server_escaping()
+ {
+ $this->type_cast_helper
+ ->expects($this->once())
+ ->method('recursive_set_var')
+ ->with(
+ $this->anything(),
+ '',
+ true
+ );
+
+ $this->request->server('HTTP_SOMEVAR');
+ }
+
+ public function test_header()
+ {
+ $this->assertEquals('application/json', $this->request->header('Accept'));
+ }
+
+ public function test_header_escaping()
+ {
+ $this->type_cast_helper
+ ->expects($this->once())
+ ->method('recursive_set_var')
+ ->with(
+ $this->anything(),
+ '',
+ true
+ );
+
+ $this->request->header('SOMEVAR');
+ }
+
+ public function test_file()
+ {
+ $file = $this->request->file('test');
+ $this->assertEquals('file', $file['name']);
+ $this->assertEquals('tmp', $file['tmp_name']);
+ $this->assertEquals(256, $file['size']);
+ $this->assertEquals('application/octet-stream', $file['type']);
+ $this->assertEquals(UPLOAD_ERR_OK, $file['error']);
+ }
+
+ public function test_file_not_exists()
+ {
+ $file = $this->request->file('404');
+ $this->assertTrue(is_array($file));
+ $this->assertTrue(empty($file));
+ }
+
+ /**
+ * Checks that directly accessing $_POST will trigger
+ * an error.
+ */
+ public function test_disable_post_super_global()
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $_POST['test'] = 3;
+ }
+
+ public function test_is_set_post()
+ {
+ $this->assertTrue($this->request->is_set_post('test'));
+ $this->assertFalse($this->request->is_set_post('unset'));
+ }
+
+ public function test_is_ajax_without_ajax()
+ {
+ $this->assertFalse($this->request->is_ajax());
+ }
+
+ public function test_is_ajax_with_ajax()
+ {
+ $this->request->enable_super_globals();
+ $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
+ $this->request = new \phpbb\request\request($this->type_cast_helper);
+
+ $this->assertTrue($this->request->is_ajax());
+ }
+
+ public function data_is_secure()
+ {
+ return array(
+ array(
+ array(
+ 'HTTPS' => 'on',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => '1',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'yes',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 1,
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'off',
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTPS' => '0',
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTPS' => 0,
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTPS' => '',
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'off',
+ 'HTTP_X_FORWARDED_PROTO' => 'https',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'on',
+ 'HTTP_X_FORWARDED_PROTO' => 'http',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'off',
+ 'HTTP_X_FORWARDED_PROTO' => 'http',
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTP_X_FORWARDED_PROTO' => 'http',
+ ),
+ false,
+ ),
+ array(
+ array(
+ 'HTTP_X_FORWARDED_PROTO' => 'https',
+ ),
+ true,
+ ),
+ array(
+ array(
+ 'HTTPS' => 'on',
+ 'HTTP_X_FORWARDED_PROTO' => 'http',
+ ),
+ true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_is_secure
+ */
+ public function test_is_secure($server_data, $expected)
+ {
+ $this->assertFalse($this->request->is_secure());
+
+ $this->request->enable_super_globals();
+ $_SERVER = $server_data;
+ $this->request = new \phpbb\request\request($this->type_cast_helper);
+
+ $this->assertSame($expected, $this->request->is_secure());
+ }
+
+ public function test_variable_names()
+ {
+ $expected = array('test', 'unset');
+ $result = $this->request->variable_names();
+ $this->assertEquals($expected, $result);
+ }
+
+ /**
+ * Makes sure super globals work properly after these tests
+ */
+ protected function tearDown()
+ {
+ $this->request->enable_super_globals();
+ }
+}
diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php
index 0c07fe11a3..67712eb6c8 100644
--- a/tests/request/request_var_test.php
+++ b/tests/request/request_var_test.php
@@ -1,18 +1,31 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/utf/utf_tools.php';
-class phpbb_request_request_var_test extends phpbb_test_case
+class phpbb_request_var_test extends phpbb_test_case
{
/**
+ * Makes sure request_var has its standard behaviour.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ request_var(false, false, false, false, false);
+ }
+
+ /**
* @dataProvider request_variables
*/
public function test_post($variable_value, $default, $multibyte, $expected)
@@ -73,7 +86,48 @@ class phpbb_request_request_var_test extends phpbb_test_case
unset($_GET[$var], $_POST[$var], $_REQUEST[$var], $_COOKIE[$var]);
}
- static public function request_variables()
+ /**
+ * @dataProvider deep_access
+ * Only possible with 3.1.x (later)
+ */
+ public function test_deep_multi_dim_array_access($path, $default, $expected)
+ {
+ $this->unset_variables('var');
+
+ // cannot set $_REQUEST directly because in \phpbb\request\request implementation
+ // $_REQUEST = $_POST + $_GET
+ $_POST['var'] = array(
+ 0 => array(
+ 'b' => array(
+ true => array(
+ 5 => 'c',
+ 6 => 'd',
+ ),
+ ),
+ ),
+ 2 => array(
+ 3 => array(
+ false => 5,
+ ),
+ ),
+ );
+
+ $result = request_var($path, $default);
+ $this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
+ }
+
+ public function deep_access()
+ {
+ return array(
+ // array(path, default, expected result)
+ array(array('var', 0, 'b', true, 5), '', 'c'),
+ array(array('var', 0, 'b', true, 6), '', 'd'),
+ array(array('var', 2, 3, false), 0, 5),
+ array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
+ );
+ }
+
+ public function request_variables()
{
return array(
// strings
@@ -173,6 +227,50 @@ class phpbb_request_request_var_test extends phpbb_test_case
'abc' => array()
)
),
+ array(
+ // input:
+ array(
+ 0 => array(0 => array(3, '4', 'ab'), 1 => array()),
+ 1 => array(array(3, 4)),
+ ),
+ // default:
+ array(0 => array(0 => array(0))),
+ false,
+ // expected:
+ array(
+ 0 => array(0 => array(3, 4, 0), 1 => array()),
+ 1 => array(array(3, 4))
+ )
+ ),
+ array(
+ // input:
+ array(
+ 'ü' => array(array('c' => 'd')),
+ 'ä' => array(4 => array('a' => 2, 'ö' => 3)),
+ ),
+ // default:
+ array('' => array(0 => array('' => 0))),
+ false,
+ // expected:
+ array(
+ '??' => array(4 => array('a' => 2, '??' => 3)),
+ )
+ ),
+ array(
+ // input:
+ array(
+ 'ü' => array(array('c' => 'd')),
+ 'ä' => array(4 => array('a' => 2, 'ö' => 3)),
+ ),
+ // default:
+ array('' => array(0 => array('' => 0))),
+ true,
+ // expected:
+ array(
+ 'ü' => array(array('c' => 0)),
+ 'ä' => array(4 => array('a' => 2, 'ö' => 3)),
+ )
+ ),
);
}
diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php
new file mode 100644
index 0000000000..d6ee1dc728
--- /dev/null
+++ b/tests/request/type_cast_helper_test.php
@@ -0,0 +1,74 @@
+<?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_type_cast_helper_test extends phpbb_test_case
+{
+ private $type_cast_helper;
+
+ protected function setUp()
+ {
+ $this->type_cast_helper = new \phpbb\request\type_cast_helper();
+ }
+
+ public function test_addslashes_recursively()
+ {
+ $data = array('some"string' => array('that"' => 'really"', 'needs"' => '"escaping'));
+ $expected = array('some\\"string' => array('that\\"' => 'really\\"', 'needs\\"' => '\\"escaping'));
+
+ $this->type_cast_helper->addslashes_recursively($data);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function test_simple_recursive_set_var()
+ {
+ $data = 'eviL<3';
+ $expected = 'eviL&lt;3';
+
+ $this->type_cast_helper->recursive_set_var($data, '', true);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function test_nested_recursive_set_var()
+ {
+ $data = array('eviL<3');
+ $expected = array('eviL&lt;3');
+
+ $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function test_simple_untrimmed_recursive_set_var()
+ {
+ $data = " eviL<3\t\t";
+ $expected = " eviL&lt;3\t\t";
+
+ $this->type_cast_helper->recursive_set_var($data, '', true, false);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function test_nested_untrimmed_recursive_set_var()
+ {
+ $data = array(" eviL<3\t\t");
+ $expected = array(" eviL&lt;3\t\t");
+
+ $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false);
+
+ $this->assertEquals($expected, $data);
+ }
+}
diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php
new file mode 100644
index 0000000000..0bb4549832
--- /dev/null
+++ b/tests/search/common_test_case.php
@@ -0,0 +1,208 @@
+<?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__) . '/../test_framework/phpbb_search_test_case.php';
+
+abstract class phpbb_search_common_test_case extends phpbb_search_test_case
+{
+ public function keywords()
+ {
+ return array(
+ // keywords
+ // terms
+ // ok
+ // split words
+ // common words
+ array(
+ 'fooo',
+ 'all',
+ true,
+ array('fooo'),
+ array(),
+ ),
+ array(
+ 'fooo baar',
+ 'all',
+ true,
+ array('fooo', 'baar'),
+ array(),
+ ),
+ // leading, trailing and multiple spaces
+ array(
+ ' fooo baar ',
+ 'all',
+ true,
+ array('fooo', 'baar'),
+ array(),
+ ),
+ // words too short
+ array(
+ 'f',
+ 'all',
+ false,
+ null,
+ // short words count as "common" words
+ array('f'),
+ ),
+ array(
+ 'f o o',
+ 'all',
+ false,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
+ 'f -o -o',
+ 'all',
+ false,
+ null,
+ array('f', '-o', '-o'),
+ ),
+ array(
+ 'fooo -baar',
+ 'all',
+ true,
+ array('-baar', 'fooo'),
+ array(),
+ ),
+ // all negative
+ array(
+ '-fooo',
+ 'all',
+ true,
+ array('-fooo'),
+ array(),
+ ),
+ array(
+ '-fooo -baar',
+ 'all',
+ true,
+ array('-fooo', '-baar'),
+ array(),
+ ),
+ array(
+ 'fooo -fooo',
+ 'all',
+ true,
+ array('fooo', '-fooo'),
+ array(),
+ ),
+ array(
+ 'fooo fooo-',
+ 'all',
+ true,
+ array('fooo', 'fooo'),
+ array(),
+ ),
+ array(
+ '-fooo fooo',
+ 'all',
+ true,
+ array('-fooo', 'fooo'),
+ array(),
+ ),
+ array(
+ 'fooo- fooo',
+ 'all',
+ true,
+ array('fooo', 'fooo'),
+ array(),
+ ),
+ array(
+ 'fooo-baar fooo',
+ 'all',
+ true,
+ array('fooo', 'baar', 'fooo'),
+ array(),
+ ),
+ array(
+ 'fooo-baar -fooo',
+ 'all',
+ true,
+ array('fooo', 'baar', '-fooo'),
+ array(),
+ ),
+ array(
+ 'fooo-baar fooo-',
+ 'all',
+ true,
+ array('fooo', 'baar', 'fooo'),
+ array(),
+ ),
+ array(
+ 'fooo-baar baar',
+ 'all',
+ true,
+ array('fooo', 'baar', 'baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar -baar',
+ 'all',
+ true,
+ array('fooo', 'baar', '-baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar baar-',
+ 'all',
+ true,
+ array('fooo', 'baar', 'baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar fooo-baar',
+ 'all',
+ true,
+ array('fooo', 'baar', 'fooo', 'baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar -fooo-baar',
+ 'all',
+ true,
+ array('fooo', 'baar', '-fooo', 'baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar fooo-baar-',
+ 'all',
+ true,
+ array('fooo', 'baar', 'fooo', 'baar'),
+ array(),
+ ),
+ array(
+ 'fooo-baar-baaz',
+ 'all',
+ true,
+ array('fooo', 'baar', 'baaz'),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider keywords
+ */
+ public function test_split_keywords($keywords, $terms, $ok, $split_words, $common)
+ {
+ $rv = $this->search->split_keywords($keywords, $terms);
+ $this->assertEquals($ok, $rv);
+ if ($ok)
+ {
+ // only check criteria if the search is going to be performed
+ $this->assert_array_content_equals($split_words, $this->search->get_split_words());
+ }
+ $this->assert_array_content_equals($common, $this->search->get_common_words());
+ }
+}
diff --git a/tests/search/fixtures/posts.xml b/tests/search/fixtures/posts.xml
new file mode 100644
index 0000000000..16232b8f39
--- /dev/null
+++ b/tests/search/fixtures/posts.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_posts">
+ <column>post_username</column>
+ <column>post_subject</column>
+ <column>post_text</column>
+ <row>
+ <value>foo</value>
+ <value>foo</value>
+ <value>foo</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>bar</value>
+ <value>bar</value>
+ </row>
+ <row>
+ <value>commonword</value>
+ <value>commonword</value>
+ <value>commonword</value>
+ </row>
+ <row>
+ <value>baaz</value>
+ <value>baaz</value>
+ <value>baaz</value>
+ </row>
+ </table>
+ <table name="phpbb_search_wordlist">
+ <column>word_id</column>
+ <column>word_text</column>
+ <column>word_common</column>
+ <row>
+ <value>1</value>
+ <value>foo</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>bar</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>commonword</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>baaz</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php
new file mode 100644
index 0000000000..3a791f5e81
--- /dev/null
+++ b/tests/search/mysql_test.php
@@ -0,0 +1,45 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_search_mysql_test extends phpbb_search_common_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_mock_cache();
+
+ // set config values
+ $config['fulltext_mysql_min_word_len'] = 4;
+ $config['fulltext_mysql_max_word_len'] = 254;
+
+ $this->db = $this->new_dbal();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $error = null;
+ $class = self::get_search_wrapper('\phpbb\search\fulltext_mysql');
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ }
+}
diff --git a/tests/search/native_test.php b/tests/search/native_test.php
new file mode 100644
index 0000000000..29d0d0a8d3
--- /dev/null
+++ b/tests/search/native_test.php
@@ -0,0 +1,262 @@
+<?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__) . '/../test_framework/phpbb_search_test_case.php';
+
+class phpbb_search_native_test extends phpbb_search_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_mock_cache();
+
+ $this->db = $this->new_dbal();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $error = null;
+ $class = self::get_search_wrapper('\phpbb\search\fulltext_native');
+ $config['fulltext_native_min_chars'] = 2;
+ $config['fulltext_native_max_chars'] = 14;
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ }
+
+ public function keywords()
+ {
+ return array(
+ // keywords
+ // terms
+ // ok
+ // must contain ids
+ // must not contain ids
+ // common words
+ array(
+ 'foo',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array(),
+ ),
+ array(
+ 'baaz*',
+ 'all',
+ true,
+ array('\'baaz%\''),
+ array(),
+ array(),
+ ),
+ array(
+ 'ba*az',
+ 'all',
+ true,
+ array('\'ba%az\''),
+ array(),
+ array(),
+ ),
+ array(
+ 'ba*z',
+ 'all',
+ true,
+ array('\'ba%z\''),
+ array(),
+ array(),
+ ),
+ array(
+ 'baa* baaz*',
+ 'all',
+ true,
+ array('\'baa%\'', '\'baaz%\''),
+ array(),
+ array(),
+ ),
+ array(
+ 'ba*z baa*',
+ 'all',
+ true,
+ array('\'ba%z\'', '\'baa%\''),
+ array(),
+ array(),
+ ),
+ array(
+ 'baaz* commonword',
+ 'all',
+ true,
+ array('\'baaz%\''),
+ array(),
+ array('commonword'),
+ ),
+ array(
+ 'foo bar',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ // leading, trailing and multiple spaces
+ array(
+ ' foo bar ',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ // words too short
+ array(
+ 'f',
+ 'all',
+ false,
+ null,
+ null,
+ // short words count as "common" words
+ array('f'),
+ ),
+ array(
+ 'f o o',
+ 'all',
+ false,
+ null,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
+ 'f -o -o',
+ 'all',
+ false,
+ null,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
+ 'foo -bar',
+ 'all',
+ true,
+ array(1),
+ array(2),
+ array(),
+ ),
+ // all negative
+ array(
+ '-foo',
+ 'all',
+ true,
+ array(),
+ array(1),
+ array(),
+ ),
+ array(
+ '-foo -bar',
+ 'all',
+ true,
+ array(),
+ array(1, 2),
+ array(),
+ ),
+ array(
+ 'foo -foo',
+ 'all',
+ true,
+ array(1),
+ array(1),
+ array(),
+ ),
+ array(
+ '-foo foo',
+ 'all',
+ true,
+ array(1),
+ array(1),
+ array(),
+ ),
+ // some creative edge cases
+ array(
+ 'foo foo-',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array(),
+ ),
+ array(
+ 'foo- foo',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array(),
+ ),
+ array(
+ 'foo-bar',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ array(
+ 'foo-bar-foo',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ // all common
+ array(
+ 'commonword',
+ 'all',
+ false,
+ null,
+ null,
+ array('commonword'),
+ ),
+ // some common
+ array(
+ 'commonword foo',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array('commonword'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider keywords
+ */
+ public function test_split_keywords($keywords, $terms, $ok, $must_contain, $must_not_contain, $common)
+ {
+ $rv = $this->search->split_keywords($keywords, $terms);
+ $this->assertEquals($ok, $rv);
+ if ($ok)
+ {
+ // only check criteria if the search is going to be performed
+ $this->assert_array_content_equals($must_contain, $this->search->get_must_contain_ids());
+ $this->assert_array_content_equals($must_not_contain, $this->search->get_must_not_contain_ids());
+ }
+ $this->assert_array_content_equals($common, $this->search->get_common_words());
+ }
+}
diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php
new file mode 100644
index 0000000000..97cca0e70c
--- /dev/null
+++ b/tests/search/postgres_test.php
@@ -0,0 +1,45 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_search_postgres_test extends phpbb_search_common_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_mock_cache();
+
+ // set config values
+ $config['fulltext_postgres_min_word_len'] = 4;
+ $config['fulltext_postgres_max_word_len'] = 254;
+
+ $this->db = $this->new_dbal();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $error = null;
+ $class = self::get_search_wrapper('\phpbb\search\fulltext_postgres');
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ }
+}
diff --git a/tests/security/base.php b/tests/security/base.php
index 2658798237..330408b448 100644
--- a/tests/security/base.php
+++ b/tests/security/base.php
@@ -1,33 +1,40 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
abstract class phpbb_security_test_base extends phpbb_test_case
{
+ protected $server = array();
+
/**
* Set up the required user object and server variables for the suites
*/
protected function setUp()
{
- global $user, $phpbb_root_path;
+ global $user, $phpbb_root_path, $phpEx, $request, $symfony_request, $phpbb_filesystem;
// Put this into a global function being run by every test to init a proper user session
- $_SERVER['HTTP_HOST'] = 'localhost';
- $_SERVER['SERVER_NAME'] = 'localhost';
- $_SERVER['SERVER_ADDR'] = '127.0.0.1';
- $_SERVER['SERVER_PORT'] = 80;
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
- $_SERVER['QUERY_STRING'] = '';
- $_SERVER['REQUEST_URI'] = '/tests/';
- $_SERVER['SCRIPT_NAME'] = '/tests/index.php';
- $_SERVER['PHP_SELF'] = '/tests/index.php';
- $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
+ $this->server['HTTP_HOST'] = 'localhost';
+ $this->server['SERVER_NAME'] = 'localhost';
+ $this->server['SERVER_ADDR'] = '127.0.0.1';
+ $this->server['SERVER_PORT'] = 80;
+ $this->server['REMOTE_ADDR'] = '127.0.0.1';
+ $this->server['QUERY_STRING'] = '';
+ $this->server['REQUEST_URI'] = '/tests/';
+ $this->server['SCRIPT_NAME'] = '/tests/index.php';
+ $this->server['SCRIPT_FILENAME'] = '/var/www/tests/index.php';
+ $this->server['PHP_SELF'] = '/tests/index.php';
+ $this->server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
+ $this->server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
/*
[HTTP_ACCEPT_ENCODING] => gzip,deflate
@@ -36,14 +43,19 @@ abstract class phpbb_security_test_base extends phpbb_test_case
[SCRIPT_FILENAME] => /var/www/tests/index.php
*/
+ $request = new phpbb_mock_request(array(), array(), array(), $this->server);
+ $symfony_request = new \phpbb\symfony_request($request);
+
+ $phpbb_filesystem = new \phpbb\filesystem();
+
// Set no user and trick a bit to circumvent errors
- $user = new user();
+ $user = new \phpbb\user('\phpbb\datetime');
$user->lang = true;
- $user->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
- $user->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : '';
- $user->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
- $user->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
- $user->page = session::extract_current_page($phpbb_root_path);
+ $user->browser = $this->server['HTTP_USER_AGENT'];
+ $user->referer = '';
+ $user->forwarded_for = '';
+ $user->host = $this->server['HTTP_HOST'];
+ $user->page = \phpbb\session::extract_current_page($phpbb_root_path);
}
protected function tearDown()
diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php
index 0f5128884b..767b901a43 100644
--- a/tests/security/extract_current_page_test.php
+++ b/tests/security/extract_current_page_test.php
@@ -1,36 +1,45 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/base.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
class phpbb_security_extract_current_page_test extends phpbb_security_test_base
{
- static public function security_variables()
+ public function security_variables()
{
return array(
- array('http://localhost/phpBB/index.php', 'mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'),
- array('http://localhost/phpBB/index.php', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'),
+ array('mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'),
+ array('mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'),
+ array('mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'),
);
}
/**
* @dataProvider security_variables
*/
- public function test_query_string_php_self($url, $query_string, $expected)
+ public function test_query_string_php_self($query_string, $expected)
{
- $_SERVER['PHP_SELF'] = $url;
- $_SERVER['QUERY_STRING'] = $query_string;
+ global $symfony_request, $request;
+
+ $this->server['REQUEST_URI'] = '';
+ $this->server['QUERY_STRING'] = $query_string;
+
+ $request = new phpbb_mock_request(array(), array(), array(), $this->server);
+ $symfony_request = new \phpbb\symfony_request($request);
- $result = session::extract_current_page('./');
+ $result = \phpbb\session::extract_current_page('./');
$label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.';
$this->assertEquals($expected, $result['query_string'], $label);
@@ -39,15 +48,18 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base
/**
* @dataProvider security_variables
*/
- public function test_query_string_request_uri($url, $query_string, $expected)
+ public function test_query_string_request_uri($query_string, $expected)
{
- $_SERVER['REQUEST_URI'] = $url . '?' . $query_string;
- $_SERVER['QUERY_STRING'] = $query_string;
+ global $symfony_request, $request;
- $result = session::extract_current_page('./');
+ $this->server['QUERY_STRING'] = $query_string;
+
+ $request = new phpbb_mock_request(array(), array(), array(), $this->server);
+ $symfony_request = new \phpbb\symfony_request($request);
+
+ $result = \phpbb\session::extract_current_page('./');
$label = 'Running extract_current_page on ' . $query_string . ' with REQUEST_URI filled.';
$this->assertEquals($expected, $result['query_string'], $label);
}
}
-
diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php
index e226365ef3..0494c55c6d 100644
--- a/tests/security/hash_test.php
+++ b/tests/security/hash_test.php
@@ -1,16 +1,45 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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_compatibility.php';
class phpbb_security_hash_test extends phpbb_test_case
{
+ public function setUp()
+ {
+ global $phpbb_container;
+
+ $config = new \phpbb\config\config(array());
+ $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $driver_helper = new \phpbb\passwords\driver\helper($config);
+ $passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
+ );
+
+ $passwords_helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
+
+ $phpbb_container
+ ->expects($this->any())
+ ->method('get')
+ ->with('passwords.manager')
+ ->will($this->returnValue($passwords_manager));
+ }
+
public function test_check_hash_with_phpass()
{
$this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php
index 9a24ba5d65..a88fc63858 100644
--- a/tests/security/redirect_test.php
+++ b/tests/security/redirect_test.php
@@ -1,65 +1,126 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/base.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
class phpbb_security_redirect_test extends phpbb_security_test_base
{
- static public function provider()
+ protected $path_helper;
+
+ public function provider()
{
// array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
return array(
- array('data://x', 'Tried to redirect to potentially insecure url.', false),
- array('bad://localhost/phpBB/index.php', 'Tried to redirect to potentially insecure url.', false),
- array('http://www.otherdomain.com/somescript.php', 'Tried to redirect to potentially insecure url.', false),
- array("http://localhost/phpBB/memberlist.php\n\rConnection: close", 'Tried to redirect to potentially insecure url.', false),
- array('javascript:test', false, 'http://localhost/phpBB/../javascript:test'),
- array('http://localhost/phpBB/index.php;url=', 'Tried to redirect to potentially insecure url.', false),
- array('https://foobar.com\@http://localhost/phpBB', 'Tried to redirect to potentially insecure url.', false),
- array('https://foobar.com\@localhost/troll/http://localhost/', 'Tried to redirect to potentially insecure url.', false),
- array('http://localhost.foobar.com\@localhost/troll/http://localhost/', 'Tried to redirect to potentially insecure url.', false),
- array('http://localhost/phpBB', false, 'http://localhost/phpBB'),
- array('http://localhost/phpBB/', false, 'http://localhost/phpBB/'),
+ array('data://x', false, 'INSECURE_REDIRECT', false),
+ array('bad://localhost/phpBB/index.php', false, 'INSECURE_REDIRECT', false),
+ array('http://www.otherdomain.com/somescript.php', false, 'INSECURE_REDIRECT', false),
+ array("http://localhost/phpBB/memberlist.php\n\rConnection: close", false, 'INSECURE_REDIRECT', false),
+ array('javascript:test', false, false, 'http://localhost/phpBB/javascript:test'),
+ array('http://localhost/phpBB/index.php;url=', false, 'INSECURE_REDIRECT', false),
+ array('http://localhost/phpBB/app.php/foobar', false, false, 'http://localhost/phpBB/app.php/foobar'),
+ array('./app.php/foobar', false, false, 'http://localhost/phpBB/app.php/foobar'),
+ array('app.php/foobar', false, false, 'http://localhost/phpBB/app.php/foobar'),
+ array('./../app.php/foobar', false, false, 'http://localhost/app.php/foobar'),
+ array('./../app.php/foobar', true, false, 'http://localhost/app.php/foobar'),
+ array('./../app.php/foo/bar', false, false, 'http://localhost/app.php/foo/bar'),
+ array('./../app.php/foo/bar', true, false, 'http://localhost/app.php/foo/bar'),
+ array('./../foo/bar', false, false, 'http://localhost/foo/bar'),
+ array('./../foo/bar', true, false, 'http://localhost/foo/bar'),
+ array('app.php/', false, false, 'http://localhost/phpBB/app.php/'),
+ array('app.php/a', false, false, 'http://localhost/phpBB/app.php/a'),
+ array('app.php/a/b', false, false, 'http://localhost/phpBB/app.php/a/b'),
+ array('./app.php/', false, false, 'http://localhost/phpBB/app.php/'),
+ array('foobar', false, false, 'http://localhost/phpBB/foobar'),
+ array('./foobar', false, false, 'http://localhost/phpBB/foobar'),
+ array('foo/bar', false, false, 'http://localhost/phpBB/foo/bar'),
+ array('./foo/bar', false, false, 'http://localhost/phpBB/foo/bar'),
+ array('./../index.php', false, false, 'http://localhost/index.php'),
+ array('./../index.php', true, false, 'http://localhost/index.php'),
+ array('../index.php', false, false, 'http://localhost/index.php'),
+ array('../index.php', true, false, 'http://localhost/index.php'),
+ array('./index.php', false, false, 'http://localhost/phpBB/index.php'),
+ array('https://foobar.com\@http://localhost/phpBB', false, 'INSECURE_REDIRECT', false),
+ array('https://foobar.com\@localhost/troll/http://localhost/', false, 'INSECURE_REDIRECT', false),
+ array('http://localhost.foobar.com\@localhost/troll/http://localhost/', false, 'INSECURE_REDIRECT', false),
+ array('http://localhost/phpBB', false, false, 'http://localhost/phpBB'),
+ array('http://localhost/phpBB/', false, false, 'http://localhost/phpBB/'),
);
}
+ protected function get_path_helper()
+ {
+ if (!($this->path_helper instanceof \phpbb\path_helper))
+ {
+ $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'
+ );
+ }
+ return $this->path_helper;
+ }
+
protected function setUp()
{
+ global $phpbb_dispatcher;
+
parent::setUp();
-
+
$GLOBALS['config'] = array(
'force_server_vars' => '0',
);
+
+ $this->path_helper = $this->get_path_helper();
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
}
/**
* @dataProvider provider
*/
- public function test_redirect($test, $expected_error, $expected_result)
+ public function test_redirect($test, $disable_cd_check, $expected_error, $expected_result)
{
- global $user;
+ global $user, $phpbb_root_path, $phpbb_path_helper;
+
+ $phpbb_path_helper = $this->path_helper;
+
+ $temp_phpbb_root_path = $phpbb_root_path;
+ $temp_page_dir = $user->page['page_dir'];
+ // We need to hack phpbb_root_path and the user's page_dir here
+ // so it matches the actual fileinfo of the testing script.
+ // Otherwise the paths are returned incorrectly.
+ $phpbb_root_path = '';
+ $user->page['page_dir'] = '';
if ($expected_error !== false)
{
- $this->setExpectedTriggerError(E_USER_ERROR, $expected_error);
+ $this->setExpectedTriggerError(E_USER_ERROR, $user->lang[$expected_error]);
}
- $result = redirect($test, true);
+ $result = redirect($test, true, $disable_cd_check);
// only verify result if we did not expect an error
if ($expected_error === false)
{
$this->assertEquals($expected_result, $result);
}
+ $phpbb_root_path = $temp_phpbb_root_path;
+ $user->page['page_dir'] = $temp_page_dir;
}
}
-
diff --git a/tests/security/trailing_path_test.php b/tests/security/trailing_path_test.php
deleted file mode 100644
index 9d586e74ef..0000000000
--- a/tests/security/trailing_path_test.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-/**
- *
- * @package testing
- * @copyright (c) 2011 phpBB Group
- * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
- *
- */
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/startup.php';
-
-class phpbb_security_trailing_path_test extends phpbb_test_case
-{
- public function data_has_trailing_path()
- {
- return array(
- array(false, '', '', ''),
- array(true, '/', '', ''),
- array(true, '/foo', '', ''),
- array(true, '', '/foo', ''),
- array(true, '/foo', '/foo', ''),
- array(false, '', '', '/'),
- array(false, '', '', '/?/x.php/'),
- array(false, '', '', '/index.php'),
- array(false, '', '', '/dir.phpisfunny/foo.php'),
- array(true, '', '', '/index.php/foo.php'),
- array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5'),
- array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5/'),
- array(false, '', '', '/phpBB/viewtopic.php?f=3&amp;t=5/foo'),
- array(true, '/foo', '/foo', '/phpBB/viewtopic.php?f=3&amp;t=5/foo'),
- array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5/'),
- array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5'),
- array(false, '', '', '/projects/php.bb/phpBB/viewtopic.php?f=3&amp;t=5/foo.php/'),
- array(false, '', '', '/projects/php.bb/phpBB/index.php'),
- array(true, '', '', '/projects/php.bb/phpBB/index.php/'),
- array(true, '', '', '/phpBB/index.php/?foo/a'),
- array(true, '', '', '/projects/php.bb/phpBB/index.php/?a=5'),
- array(false, '', '', '/projects/php.bb/phpBB/index.php?/a=5'),
- array(false, '', '/phpBB/index.php', '/phpBB/index.php', '/phpBB/index.php'),
- array(true, '', '/phpBB/index.php', '/phpBB/index.php'),
- array(true, '', '/phpBB/index.php/', '/phpBB/index.php/', '/phpBB/index.php'),
- array(true, '', '/phpBB/index.php/', '/phpBB/index.php/'),
- );
- }
-
- /**
- * @dataProvider data_has_trailing_path
- */
- public function test_has_trailing_path($expected, $path_info, $orig_path_info, $request_uri, $script_name = '')
- {
- global $phpEx;
-
- $_SERVER['PATH_INFO'] = $path_info;
- $_SERVER['ORIG_PATH_INFO'] = $orig_path_info;
- $_SERVER['REQUEST_URI'] = $request_uri;
- $_SERVER['SCRIPT_NAME'] = $script_name;
-
- $this->assertSame($expected, phpbb_has_trailing_path($phpEx));
- }
-}
diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php
index ce7bf71215..2a1d94514f 100644
--- a/tests/session/append_sid_test.php
+++ b/tests/session/append_sid_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -45,6 +49,10 @@ class phpbb_session_append_sid_test extends phpbb_test_case
*/
public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
{
+ global $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
}
}
+
diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php
new file mode 100644
index 0000000000..561b7faf49
--- /dev/null
+++ b/tests/session/check_ban_test.php
@@ -0,0 +1,82 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_check_ban_test extends phpbb_session_test_case
+{
+ protected $user_id = 4;
+ protected $key_id = 4;
+ protected $session;
+ protected $backup_cache;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_banlist.xml');
+ }
+
+ static function check_banned_data()
+ {
+ return array(
+ array('All false values, should not be banned',
+ false, false, false, false, /* should be banned? -> */ false),
+ array('Matching values in the database, should be banned',
+ 4, '127.0.0.1', 'bar@example.org', true, /* should be banned? -> */ true),
+ array('IP Banned, should be banned',
+ false, '127.1.1.1', false, false, /* should be banned? -> */ true),
+ );
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+ // Get session here so that config is mocked correctly
+ $this->session = $this->session_factory->get_session($this->db);
+ global $cache, $config, $phpbb_root_path, $phpEx;
+ $this->backup_cache = $cache;
+ // Change the global cache object for this test because
+ // the mock cache object does not hit the database as is needed
+ // for this test.
+ $cache = new \phpbb\cache\service(
+ new \phpbb\cache\driver\file(),
+ $config,
+ $this->db,
+ $phpbb_root_path,
+ $phpEx
+ );
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+ // Set cache back to what it was before the test changed it
+ global $cache;
+ $cache = $this->backup_cache;
+ }
+
+ /** @dataProvider check_banned_data */
+ public function test_check_is_banned($test_msg, $user_id, $user_ips, $user_email, $return, $should_be_banned)
+ {
+ try
+ {
+ $is_banned = $this->session->check_ban($user_id, $user_ips, $user_email, $return);
+ }
+ catch (PHPUnit_Framework_Error_Notice $e)
+ {
+ // User error was triggered, user must have been banned
+ $is_banned = true;
+ }
+
+ $this->assertEquals($should_be_banned, $is_banned, $test_msg);
+ }
+}
diff --git a/tests/session/check_isvalid_test.php b/tests/session/check_isvalid_test.php
new file mode 100644
index 0000000000..90554bfe5f
--- /dev/null
+++ b/tests/session/check_isvalid_test.php
@@ -0,0 +1,65 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_check_isvalid_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
+ }
+
+ protected function access_with($session_id, $user_id, $user_agent, $ip)
+ {
+ $this->session_factory->merge_test_data($session_id, $user_id, $user_agent, $ip);
+
+ $session = $this->session_factory->get_session($this->db);
+ $session->page = array('page' => 'page', 'forum' => 0);
+
+ $session->session_begin();
+ $this->session_factory->check($this);
+ return $session;
+ }
+
+ public function test_session_valid_session_exists()
+ {
+ $session = $this->access_with('bar_session000000000000000000000', '4', 'user agent', '127.0.0.1');
+ $session->check_cookies($this, array());
+
+ $this->check_sessions_equals(array(
+ array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ 'If a request comes with a valid session id with matching user agent and IP, no new session should be created.'
+ );
+ }
+
+ public function test_session_invalid_make_new_annon_session()
+ {
+ $session = $this->access_with('anon_session00000000000000000000', '4', 'user agent', '127.0.0.1');
+ $session->check_cookies($this, array(
+ 'u' => array('1', null),
+ 'k' => array(null, null),
+ 'sid' => array($session->session_id, null),
+ ));
+
+ $this->check_sessions_equals(array(
+ array('session_id' => $session->session_id, 'session_user_id' => 1), // use generated SID
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ 'If a request comes with a valid session id and IP but different user id and user agent,
+ a new anonymous session is created and the session matching the supplied session id is deleted.'
+ );
+ }
+}
diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php
deleted file mode 100644
index c4f7f8d75b..0000000000
--- a/tests/session/continue_test.php
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../mock/cache.php';
-require_once dirname(__FILE__) . '/testable_factory.php';
-
-class phpbb_session_continue_test extends phpbb_database_test_case
-{
- public function getDataSet()
- {
- return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
- }
-
- static public function session_begin_attempts()
- {
- // The session_id field is defined as CHAR(32) in the database schema.
- // Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes.
- // Thus we fill those strings up with zeroes until they have a string length of 32.
-
- return array(
- array(
- 'bar_session000000000000000000000', '4', 'user agent', '127.0.0.1',
- array(
- array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
- array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
- ),
- array(),
- 'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
- ),
- array(
- 'anon_session00000000000000000000', '4', 'user agent', '127.0.0.1',
- array(
- array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
- array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
- ),
- array(
- 'u' => array('1', null),
- 'k' => array(null, null),
- 'sid' => array('__new_session_id__', null),
- ),
- 'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
- ),
- );
- }
-
- /**
- * @dataProvider session_begin_attempts
- */
- public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message)
- {
- $db = $this->new_dbal();
- $session_factory = new phpbb_session_testable_factory;
- $session_factory->set_cookies(array(
- '_sid' => $session_id,
- '_u' => $user_id,
- ));
- $session_factory->merge_config_data(array(
- 'session_length' => time(), // need to do this to allow sessions started at time 0
- ));
- $session_factory->merge_server_data(array(
- 'HTTP_USER_AGENT' => $user_agent,
- 'REMOTE_ADDR' => $ip,
- ));
-
- $session = $session_factory->get_session($db);
- $session->page = array('page' => 'page', 'forum' => 0);
-
- $session->session_begin();
-
- $sql = 'SELECT session_id, session_user_id
- FROM phpbb_sessions
- ORDER BY session_user_id';
-
- $expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
- $expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
-
- $this->assertSqlResultEquals(
- $expected_sessions,
- $sql,
- $message
- );
-
- $session->check_cookies($this, $expected_cookies);
-
- $session_factory->check($this);
- }
-
- /**
- * Replaces recursively the value __new_session_id__ with the given session
- * id.
- *
- * @param array $array An array of data
- * @param string $session_id The new session id to use instead of the
- * placeholder.
- * @return array The input array with all occurances of __new_session_id__
- * replaced.
- */
- public function replace_session($array, $session_id)
- {
- foreach ($array as $key => &$value)
- {
- if ($value === '__new_session_id__')
- {
- $value = $session_id;
- }
-
- if (is_array($value))
- {
- $value = $this->replace_session($value, $session_id);
- }
- }
-
- return $array;
- }
-}
diff --git a/tests/session/create_test.php b/tests/session/create_test.php
new file mode 100644
index 0000000000..105c76eb7f
--- /dev/null
+++ b/tests/session/create_test.php
@@ -0,0 +1,47 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_create_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
+ }
+
+ static function bot($bot_agent, $user_id, $bot_ip)
+ {
+ return array(array(
+ 'bot_agent' => $bot_agent,
+ 'user_id' => $user_id,
+ 'bot_ip' => $bot_ip,
+ ));
+ }
+
+ function test_bot_session()
+ {
+ $output = $this->session_facade->session_create(
+ false,
+ false,
+ false,
+ false,
+ array(),
+ 'user agent',
+ '127.0.0.1',
+ self::bot('user agent', 13, '127.0.0.1'),
+ ''
+ );
+ $this->assertEquals(true, $output->data['is_bot'], 'should be a bot');
+ }
+}
diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php
deleted file mode 100644
index bef52c6554..0000000000
--- a/tests/session/creation_test.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../mock/cache.php';
-require_once dirname(__FILE__) . '/testable_factory.php';
-
-class phpbb_session_creation_test extends phpbb_database_test_case
-{
- public function getDataSet()
- {
- return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml');
- }
-
- // also see security/extract_current_page.php
-
- public function test_login_session_create()
- {
- $db = $this->new_dbal();
- $session_factory = new phpbb_session_testable_factory;
-
- $session = $session_factory->get_session($db);
- $session->page = array('page' => 'page', 'forum' => 0);
-
- $session->session_create(3);
-
- $sql = 'SELECT session_user_id
- FROM phpbb_sessions';
-
- $this->assertSqlResultEquals(
- array(array('session_user_id' => 3)),
- $sql,
- 'Check if exactly one session for user id 3 was created'
- );
-
- $one_year_in_seconds = 365 * 24 * 60 * 60;
- $cookie_expire = $session->time_now + $one_year_in_seconds;
-
- $session->check_cookies($this, array(
- 'u' => array(null, $cookie_expire),
- 'k' => array(null, $cookie_expire),
- 'sid' => array($session->session_id, $cookie_expire),
- ));
-
- global $SID, $_SID;
- $this->assertEquals($session->session_id, $_SID);
- $this->assertEquals('?sid=' . $session->session_id, $SID);
-
- $session_factory->check($this);
- }
-}
-
diff --git a/tests/session/extract_hostname_test.php b/tests/session/extract_hostname_test.php
new file mode 100644
index 0000000000..3a9d498007
--- /dev/null
+++ b/tests/session/extract_hostname_test.php
@@ -0,0 +1,55 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_extract_hostname_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
+ }
+
+ static public function extract_current_hostname_data()
+ {
+ return array (
+ // [Input] $host, $server_name_config, $cookie_domain_config, [Expected] $output
+ // If host is ip use that
+ // ipv4
+ array('127.0.0.1', 'skipped.org', 'skipped.org', '127.0.0.1'),
+ // ipv6
+ array('::1', 'skipped.org', 'skipped.org', ':'),
+ array('2002::3235:51f9', 'skipped.org', 'skipped.org', '2002::3235'),
+ // If no host but server name matches cookie_domain use that
+ array('', 'example.org', 'example.org', 'example.org'),
+ // If there is a host uri use that
+ array('example.org', false, false, 'example.org'),
+ // 'best approach' guessing
+ array('', 'example.org', false, 'example.org'),
+ array('', false, '127.0.0.1', '127.0.0.1'),
+ array('', false, false, php_uname('n')),
+ );
+ }
+
+ /** @dataProvider extract_current_hostname_data */
+ function test_extract_current_hostname($host, $server_name_config, $cookie_domain_config, $expected)
+ {
+ $output = $this->session_facade->extract_current_hostname(
+ $host,
+ $server_name_config,
+ $cookie_domain_config
+ );
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/session/extract_page_test.php b/tests/session/extract_page_test.php
new file mode 100644
index 0000000000..f0d1cdb60e
--- /dev/null
+++ b/tests/session/extract_page_test.php
@@ -0,0 +1,172 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_session_extract_page_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
+ }
+
+ static public function extract_current_page_data()
+ {
+ return array(
+ array(
+ './',
+ '/phpBB/index.php',
+ '',
+ '/phpBB/',
+ '/',
+ array(
+ 'page_name' => 'index.php',
+ 'page_dir' => '',
+ 'query_string' => '',
+ 'script_path' => '/phpBB/',
+ 'root_script_path' => '/phpBB/',
+ 'page' => 'index.php',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './',
+ '/phpBB/ucp.php',
+ 'mode=login',
+ '/phpBB/',
+ '/',
+ array(
+ 'page_name' => 'ucp.php',
+ 'page_dir' => '',
+ 'query_string' => 'mode=login',
+ 'script_path' => '/phpBB/',
+ 'root_script_path' => '/phpBB/',
+ 'page' => 'ucp.php?mode=login',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './',
+ '/phpBB/ucp.php',
+ 'mode=register',
+ '/phpBB/',
+ '/',
+ array(
+ 'page_name' => 'ucp.php',
+ 'page_dir' => '',
+ 'query_string' => 'mode=register',
+ 'script_path' => '/phpBB/',
+ 'root_script_path' => '/phpBB/',
+ 'page' => 'ucp.php?mode=register',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './',
+ '/phpBB/ucp.php',
+ 'mode=register',
+ '/phpBB/',
+ '/',
+ array(
+ 'page_name' => 'ucp.php',
+ 'page_dir' => '',
+ 'query_string' => 'mode=register',
+ 'script_path' => '/phpBB/',
+ 'root_script_path' => '/phpBB/',
+ 'page' => 'ucp.php?mode=register',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './../',
+ '/phpBB/adm/index.php',
+ 'sid=e7215d958cdd41a6fc13509bebe53e42',
+ '/phpBB/adm/',
+ '/',
+ array(
+ 'page_name' => 'index.php',
+ //'page_dir' => 'adm',
+ // ^-- Ignored because .. returns different directory in live vs testing
+ 'query_string' => '',
+ 'script_path' => '/phpBB/adm/',
+ //'root_script_path' => '/phpBB/adm/',
+ //'page' => 'adm/index.php',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './',
+ '/phpBB/adm/app.php',
+ 'page=1&test=2',
+ '/phpBB/adm/',
+ '/foo/bar',
+ array(
+ 'page_name' => 'app.php/foo/bar',
+ //'page_dir' => '',
+ 'query_string' => 'page=1&test=2',
+ 'script_path' => '/phpBB/adm/',
+ //'root_script_path' => '/phpBB/adm/',
+ //'page' => 'app.php/foo/bar?page=1&test=2',
+ 'forum' => 0,
+ ),
+ ),
+ array(
+ './../phpBB/',
+ '/test/test.php',
+ 'page=1&test=2',
+ '/test/',
+ '',
+ array(
+ 'page_name' => 'test.php',
+ //'page_dir' => '',
+ 'query_string' => 'page=1&test=2',
+ 'script_path' => '/test/',
+ //'root_script_path' => '../phpBB/',
+ //'page' => '../test/test.php/foo/bar?page=1&test=2',
+ 'forum' => 0,
+ ),
+ ),
+ );
+ }
+
+ /** @dataProvider extract_current_page_data */
+ function test_extract_current_page($root_path, $getScriptName, $getQueryString, $getBasePath, $getPathInfo, $expected)
+ {
+ global $symfony_request, $request, $phpbb_filesystem;
+
+ $phpbb_filesystem = new \phpbb\filesystem();
+
+ $server['HTTP_HOST'] = 'localhost';
+ $server['SERVER_NAME'] = 'localhost';
+ $server['SERVER_ADDR'] = '127.0.0.1';
+ $server['SERVER_PORT'] = 80;
+ $server['REMOTE_ADDR'] = '127.0.0.1';
+ $server['QUERY_STRING'] = $getQueryString;
+ $server['REQUEST_URI'] = $getScriptName . $getPathInfo . ($getQueryString === '' ? '' : '?' . $getQueryString);
+ $server['SCRIPT_NAME'] = $getScriptName;
+ $server['SCRIPT_FILENAME'] = '/var/www/' . $getScriptName;
+ $server['PHP_SELF'] = $getScriptName;
+ $server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
+ $server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
+
+ $request = new phpbb_mock_request(array(), array(), array(), $server);
+ $symfony_request = new \phpbb\symfony_request($request);
+
+ $output = \phpbb\session::extract_current_page($root_path);
+
+ // This compares the result of the output.
+ // Any keys that are not in the expected array are overwritten by the output (aka not checked).
+ $this->assert_array_content_equals(array_merge($output, $expected), $output);
+ }
+}
diff --git a/tests/session/fixtures/sessions_banlist.xml b/tests/session/fixtures/sessions_banlist.xml
new file mode 100644
index 0000000000..e720e35f0a
--- /dev/null
+++ b/tests/session/fixtures/sessions_banlist.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>anonymous</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ <column>session_admin</column>
+ <row>
+ <value>bar_session000000000000000000000</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_banlist">
+ <column>ban_id</column>
+ <column>ban_userid</column>
+ <column>ban_ip</column>
+ <column>ban_email</column>
+ <column>ban_start</column>
+ <column>ban_end</column>
+ <column>ban_exclude</column>
+ <column>ban_reason</column>
+ <column>ban_give_reason</column>
+ <row>
+ <value>2</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>bar@example.org</value>
+ <value>1111</value>
+ <value>0</value>
+ <value>0</value>
+ <value>HAHAHA</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>0</value>
+ <value>127.1.1.1</value>
+ <value></value>
+ <value>1111</value>
+ <value>0</value>
+ <value>0</value>
+ <value>HAHAHA</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/session/fixtures/sessions_empty.xml b/tests/session/fixtures/sessions_empty.xml
index c592e0a6c8..068951dc4c 100644
--- a/tests/session/fixtures/sessions_empty.xml
+++ b/tests/session/fixtures/sessions_empty.xml
@@ -5,31 +5,23 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>anonymous</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
<value>foo</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>4</value>
<value>bar</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
<table name="phpbb_sessions">
diff --git a/tests/session/fixtures/sessions_full.xml b/tests/session/fixtures/sessions_full.xml
index 509687f4d2..4fb6b9dfd4 100644
--- a/tests/session/fixtures/sessions_full.xml
+++ b/tests/session/fixtures/sessions_full.xml
@@ -5,31 +5,23 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>anonymous</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
<value>foo</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>4</value>
<value>bar</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
<table name="phpbb_sessions">
@@ -37,17 +29,20 @@
<column>session_user_id</column>
<column>session_ip</column>
<column>session_browser</column>
+ <column>session_admin</column>
<row>
<value>anon_session00000000000000000000</value>
<value>1</value>
<value>127.0.0.1</value>
<value>anonymous user agent</value>
+ <value>0</value>
</row>
<row>
<value>bar_session000000000000000000000</value>
<value>4</value>
<value>127.0.0.1</value>
<value>user agent</value>
+ <value>1</value>
</row>
</table>
</dataset>
diff --git a/tests/session/fixtures/sessions_garbage.xml b/tests/session/fixtures/sessions_garbage.xml
new file mode 100644
index 0000000000..5eace839d0
--- /dev/null
+++ b/tests/session/fixtures/sessions_garbage.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ <column>session_admin</column>
+ <row>
+ <value>anon_session00000000000000000000</value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ <value>anonymous user agent</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>bar_session000000000000000000000</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_login_attempts">
+ <column>attempt_ip</column>
+ <column>attempt_browser</column>
+ <column>attempt_forwarded_for</column>
+ <column>attempt_time</column>
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <row>
+ <value>127.0.0.1</value>
+ <value>browser</value>
+ <value></value>
+ <value>0001</value>
+ <value>4</value>
+ <value>bar</value>
+ <value>bar</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/session/fixtures/sessions_key.xml b/tests/session/fixtures/sessions_key.xml
new file mode 100644
index 0000000000..245f89a604
--- /dev/null
+++ b/tests/session/fixtures/sessions_key.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_sessions_keys">
+ <column>key_id</column>
+ <column>user_id</column>
+ <column>last_ip</column>
+ <column>last_login</column>
+ <row>
+ <value>a87ff679a2f3e71d9181a67b7542122c</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ <row>
+ <value>bar_session000000000000000000000</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/session/garbage_collection_test.php b/tests/session/garbage_collection_test.php
new file mode 100644
index 0000000000..3fad81c68b
--- /dev/null
+++ b/tests/session/garbage_collection_test.php
@@ -0,0 +1,71 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_session_garbage_collection_test extends phpbb_session_test_case
+{
+ public $session;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_garbage.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->session = $this->session_factory->get_session($this->db);
+
+ global $phpbb_container;
+
+ $plugins = new \phpbb\di\service_collection($phpbb_container);
+ $plugins->add('core.captcha.plugins.nogd');
+ $phpbb_container->set(
+ 'captcha.factory',
+ new \phpbb\captcha\factory($phpbb_container, $plugins)
+ );
+ $phpbb_container->set(
+ 'core.captcha.plugins.nogd',
+ new \phpbb\captcha\plugins\nogd()
+ );
+ }
+
+ public function test_cleanup_all()
+ {
+ $this->check_sessions_equals(
+ array(
+ array(
+ 'session_id' => 'anon_session00000000000000000000',
+ 'session_user_id' => 1,
+ ),
+ array(
+ 'session_id' => 'bar_session000000000000000000000',
+ 'session_user_id' => 4,
+ ),
+ ),
+ 'Before test, should have some sessions.'
+ );
+ // Set session length so it clears all
+ global $config;
+ $config['session_length'] = 0;
+ // There is an error unless the captcha plugin is set
+ $config['captcha_plugin'] = 'core.captcha.plugins.nogd';
+ $this->session->session_gc();
+ $this->check_sessions_equals(
+ array(),
+ 'After setting session time to 0, should remove all.'
+ );
+ }
+}
diff --git a/tests/session/session_key_test.php b/tests/session/session_key_test.php
new file mode 100644
index 0000000000..bf3dfcaa3c
--- /dev/null
+++ b/tests/session/session_key_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.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_login_keys_test extends phpbb_session_test_case
+{
+ protected $user_id = 4;
+ protected $key_id = 4;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_key.xml');
+ }
+
+ public function test_set_key_manually()
+ {
+ // With AutoLogin setup
+ $this->session_factory->merge_config_data(array('allow_autologin' => true));
+ $session = $this->session_factory->get_session($this->db);
+
+ // Using a user_id and key that is already in the database
+ $session->cookie_data['u'] = $this->user_id;
+ $session->cookie_data['k'] = $this->key_id;
+
+ // Try to access session with the session key
+ $session->session_create(false, false, false);
+ $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in by the session key');
+ }
+
+ public function test_reset_keys()
+ {
+ // With AutoLogin setup
+ $this->session_factory->merge_config_data(array('allow_autologin' => true));
+ $session = $this->session_factory->get_session($this->db);
+
+ // Reset of the keys for this user
+ $session->reset_login_keys($this->user_id);
+
+ // Using a user_id and key that was in the database (before reset)
+ $session->cookie_data['u'] = $this->user_id;
+ $session->cookie_data['k'] = $this->key_id;
+
+ // Try to access session with the session key
+ $session->session_create(false, false, $this->user_id);
+ $this->assertNotEquals($this->user_id, $session->data['user_id'], 'User is not logged in because the session key is invalid');
+
+ $session->session_create($this->user_id, false, false);
+ $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in because we create a new session');
+ }
+}
diff --git a/tests/session/testable_facade.php b/tests/session/testable_facade.php
new file mode 100644
index 0000000000..05858c8a63
--- /dev/null
+++ b/tests/session/testable_facade.php
@@ -0,0 +1,130 @@
+<?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__) . '/testable_factory.php';
+require_once dirname(__FILE__) . '/../../phpBB/phpbb/session.php';
+
+/**
+ * This class exists to expose session.php's functions in a more testable way.
+ *
+ * Since many functions in session.php have global variables inside the function,
+ * this exposes those functions through a testable facade that uses
+ * testable_factory's mock global variables to modify global variables used in
+ * the functions.
+ *
+ * This is using the facade pattern to provide a testable "front" to the
+ * functions in sessions.php.
+ *
+ */
+class phpbb_session_testable_facade
+{
+ protected $db;
+ protected $session_factory;
+
+ function __construct($db, $session_factory)
+ {
+ $this->db = $db;
+ $this->session_factory = $session_factory;
+ }
+
+ function extract_current_hostname(
+ $host,
+ $server_name_config,
+ $cookie_domain_config
+ )
+ {
+ $session = $this->session_factory->get_session($this->db);
+ global $config, $request;
+ $config['server_name'] = $server_name_config;
+ $config['cookie_domain'] = $cookie_domain_config;
+ $request->overwrite('SERVER_NAME', $host, \phpbb\request\request_interface::SERVER);
+ $request->overwrite('Host', $host, \phpbb\request\request_interface::SERVER);
+ // Note: There is a php_uname function used as a fallthrough
+ // that this function doesn't override
+ return $session->extract_current_hostname();
+ }
+
+ /**
+ *
+ * This function has a lot of dependencies, so instead of naming them all,
+ * just ask for overrides
+ *
+ * @param update_session_page Boolean of whether to set page of the session
+ * @param config_overrides An array of overrides for the global config object
+ * @param request_overrides An array of overrides for the global request object
+ * @return boolean False if the user is identified, otherwise true.
+ */
+ function session_begin(
+ $update_session_page = true,
+ $config_overrides = array(),
+ $request_overrides = array(),
+ $cookies_overrides = array()
+ )
+ {
+ $this->session_factory->merge_config_data($config_overrides);
+ $this->session_factory->merge_server_data($request_overrides);
+ $this->session_factory->set_cookies($cookies_overrides);
+ $session = $this->session_factory->get_session($this->db);
+ $session->session_begin($update_session_page);
+ return $session;
+ }
+
+ function session_create(
+ $user_id = false,
+ $set_admin = false,
+ $persist_login = false,
+ $viewonline = true,
+ array $config_overrides = array(),
+ $user_agent = 'user agent',
+ $ip_address = '127.0.0.1',
+ array $bot_overrides = array(),
+ $uri_sid = ""
+ )
+ {
+ $this->session_factory->merge_config_data($config_overrides);
+ // Bots
+ $this->session_factory->merge_cache_data(array('_bots' => $bot_overrides));
+ global $request;
+ $session = $this->session_factory->get_session($this->db);
+ $session->browser = $user_agent;
+ $session->ip = $ip_address;
+ // Uri sid
+ if ($uri_sid)
+ {
+ $_GET['sid'] = $uri_sid;
+ }
+ $session->session_create($user_id, $set_admin, $persist_login, $viewonline);
+ return $session;
+ }
+
+ function validate_referer(
+ $check_script_path,
+ $referer,
+ $host,
+ $force_server_vars,
+ $server_port,
+ $server_name,
+ $root_script_path
+ )
+ {
+ $session = $this->session_factory->get_session($this->db);
+ global $config, $request;
+ $session->referer = $referer;
+ $session->page['root_script_path'] = $root_script_path;
+ $session->host = $host;
+ $config['force_server_vars'] = $force_server_vars;
+ $config['server_name'] = $server_name;
+ $request->overwrite('SERVER_PORT', $server_port, \phpbb\request\request_interface::SERVER);
+ return $session->validate_referer($check_script_path);
+ }
+}
diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php
index 00f79738ef..3e25286480 100644
--- a/tests/session/testable_factory.php
+++ b/tests/session/testable_factory.php
@@ -1,13 +1,18 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/../mock/session_testable.php';
+require_once dirname(__FILE__) . '/../mock/container_builder.php';
+require_once dirname(__FILE__) . '/../mock/auth_provider.php';
/**
* This class exists to setup an instance of phpbb's session class for testing.
@@ -18,12 +23,14 @@ require_once dirname(__FILE__) . '/../mock/session_testable.php';
*/
class phpbb_session_testable_factory
{
+ protected $container;
protected $config_data;
protected $cache_data;
protected $cookies;
protected $config;
protected $cache;
+ protected $request;
/**
* Initialises the factory with a set of default config and cache values.
@@ -60,22 +67,41 @@ class phpbb_session_testable_factory
/**
* Retrieve the configured session class instance
*
- * @param dbal $dbal The database connection to use for session data
+ * @param \phpbb\db\driver\driver_interface $dbal The database connection to use for session data
* @return phpbb_mock_session_testable A session instance
*/
- public function get_session(dbal $dbal)
+ public function get_session(\phpbb\db\driver\driver_interface $dbal)
{
// set up all the global variables used by session
- global $SID, $_SID, $db, $config, $cache;
+ global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container;
+
+ $request = $this->request = new phpbb_mock_request(
+ array(),
+ array(),
+ $this->cookies,
+ $this->server_data
+ );
+ request_var(null, null, null, null, $request);
+
+ $config = $this->config = new \phpbb\config\config($this->get_config_data());
+ set_config(null, null, null, $config);
- $config = $this->config = $this->get_config_data();
$db = $dbal;
$cache = $this->cache = new phpbb_mock_cache($this->get_cache_data());
$SID = $_SID = null;
- $_COOKIE = $this->cookies;
- $_SERVER = $this->server_data;
+ $phpbb_container = $this->container = new phpbb_mock_container_builder();
+ $phpbb_container->set(
+ 'auth.provider.db',
+ new phpbb_mock_auth_provider()
+ );
+ $provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
+ $provider_collection->add('auth.provider.db');
+ $phpbb_container->set(
+ 'auth.provider_collection',
+ $provider_collection
+ );
$session = new phpbb_mock_session_testable;
return $session;
@@ -159,6 +185,32 @@ class phpbb_session_testable_factory
}
/**
+ * Set cookies, merge config and server data in one step.
+ *
+ * New values overwrite old ones.
+ *
+ * @param $session_id
+ * @param $user_id
+ * @param $user_agent
+ * @param $ip
+ * @param int $time
+ */
+ public function merge_test_data($session_id, $user_id, $user_agent, $ip, $time = 0)
+ {
+ $this->set_cookies(array(
+ '_sid' => $session_id,
+ '_u' => $user_id,
+ ));
+ $this->merge_config_data(array(
+ 'session_length' => time() + $time, // need to do this to allow sessions started at time 0
+ ));
+ $this->merge_server_data(array(
+ 'HTTP_USER_AGENT' => $user_agent,
+ 'REMOTE_ADDR' => $ip,
+ ));
+ }
+
+ /**
* Retrieve all server variables to be passed to the session.
*
* @return array Server variables
diff --git a/tests/session/unset_admin_test.php b/tests/session/unset_admin_test.php
new file mode 100644
index 0000000000..9633d77be6
--- /dev/null
+++ b/tests/session/unset_admin_test.php
@@ -0,0 +1,52 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_unset_admin_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_full.xml');
+ }
+
+ function get_test_session()
+ {
+ return $this->session_facade->session_begin(
+ true,
+ // Config
+ array(
+ 'session_length' => time(), // need to do this to allow sessions started at time 0
+ ),
+ // Server
+ array(
+ 'HTTP_USER_AGENT' => "user agent",
+ 'REMOTE_ADDR' => "127.0.0.1",
+ ),
+ // Cookies
+ array(
+ '_sid' => 'bar_session000000000000000000000',
+ '_u' => 4,
+ )
+ );
+ }
+
+ public function test_unset_admin()
+ {
+ $session = $this->get_test_session();
+ $this->assertEquals(1, $session->data['session_admin'], 'should be an admin before test starts');
+ $session->unset_admin();
+ $session = $this->get_test_session();
+ $this->assertEquals(0, $session->data['session_admin'], 'should be not be an admin after unset_admin');
+ }
+}
diff --git a/tests/session/validate_referrer_test.php b/tests/session/validate_referrer_test.php
new file mode 100644
index 0000000000..7690a89018
--- /dev/null
+++ b/tests/session/validate_referrer_test.php
@@ -0,0 +1,74 @@
+<?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__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_validate_referrer_test extends phpbb_session_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
+ }
+
+ static function referrer_inputs()
+ {
+ $ex = "example.org";
+ $alt = "example.com";
+ return array(
+ // checkpath referrer host forcevars port servername rootpath pass?
+ // 0 Referrer or host wasn't collected, therefore should validate
+ array(false, '', $ex, false, 80, $ex, '', true),
+ array(false, $ex, '', false, 80, $ex, '', true),
+ // 2 Referrer doesn't match host or server_name
+ array(false, $alt, $ex, false, 80, $ex, '', false),
+ // 3 Everything should check out
+ array(false, $ex, $ex, false, 80, $ex, '', true),
+ // 4 Check Script Path
+ array(true, $ex, $ex, false, 80, $ex, '', true),
+ array(true, "$ex/foo", $ex, false, 80, $ex, "/foo", true),
+ array(true, "$ex/bar", $ex, false, 80, $ex, "/foo", false),
+ // 7 Port (This is not checked unless path is checked)
+ array(true, "$ex:80/foo", "$ex:80", false, 80, "$ex:80", "/foo", true),
+ array(true, "$ex:80/bar", "$ex:80", false, 80, "$ex:80", "/foo", false),
+ array(true, "$ex:79/foo", "$ex:81", false, 81, "$ex:81", "/foo", false),
+ );
+ }
+
+ /** @dataProvider referrer_inputs */
+ function test_referrer_inputs(
+ $check_script_path,
+ $referrer,
+ $host,
+ $force_server_vars,
+ $server_port,
+ $server_name,
+ $root_script_path,
+ $pass_or_fail
+ )
+ {
+ // Referrer needs http:// because it's going to get stripped in function.
+ $referrer = $referrer ? 'http://' . $referrer : '';
+ $this->assertEquals(
+ $pass_or_fail,
+ $this->session_facade->validate_referer(
+ $check_script_path,
+ $referrer,
+ $host,
+ $force_server_vars,
+ $server_port,
+ $server_name,
+ $root_script_path
+ ),
+ "referrer should" . ($pass_or_fail ? '' : "n't") . " be validated");
+ }
+}
diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/event/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/event/test.html
new file mode 100644
index 0000000000..3eb906a09e
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/event/test.html
@@ -0,0 +1 @@
+Kappa test event in all
diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/event/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/event/test.html
new file mode 100644
index 0000000000..3b65d80a6d
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/event/test.html
@@ -0,0 +1 @@
+Kappa test event in silver
diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/event/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/event/test.html
new file mode 100644
index 0000000000..26826d59e3
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/event/test.html
@@ -0,0 +1 @@
+Kappa test event in silver_inherit
diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/event/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/event/test.html
new file mode 100644
index 0000000000..003d193dc3
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/event/test.html
@@ -0,0 +1 @@
+Omega test event in all
diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/test.html
new file mode 100644
index 0000000000..6bf06f5457
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/test.html
@@ -0,0 +1 @@
+Omega test event in silver
diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/two.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/two.html
new file mode 100644
index 0000000000..7f8058f4e4
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/event/two.html
@@ -0,0 +1 @@
+two in silver in omega
diff --git a/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/event/test.html b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/event/test.html
new file mode 100644
index 0000000000..5fc7e5ac12
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/event/test.html
@@ -0,0 +1 @@
+Zeta test event in all
diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html
new file mode 100644
index 0000000000..4d78dddb12
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html
@@ -0,0 +1 @@
+<!-- EVENT test -->
diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html
new file mode 100644
index 0000000000..fe46be3782
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html
@@ -0,0 +1 @@
+<!-- EVENT two -->
diff --git a/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html
new file mode 100644
index 0000000000..4d78dddb12
--- /dev/null
+++ b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html
@@ -0,0 +1 @@
+<!-- EVENT test -->
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/event_variable_spacing.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/event_variable_spacing.html
new file mode 100644
index 0000000000..028f8aa0d1
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/event_variable_spacing.html
@@ -0,0 +1,6 @@
+|{VARIABLE}|
+{VARIABLE}|{VARIABLE}|
+
+|{VARIABLE}
+
+<div class="{VARIABLE}">test</div>
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_loop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_loop.html
new file mode 100644
index 0000000000..235e129f85
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_loop.html
@@ -0,0 +1 @@
+{event_loop.S_ROW_COUNT}<!-- IF not event_loop.S_LAST_ROW -->|<!-- ENDIF -->
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
new file mode 100644
index 0000000000..98fa1770ba
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
@@ -0,0 +1,2 @@
+[{event_loop.S_ROW_COUNT}<!-- BEGIN event_loop.subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
+<!-- END event_loop.subloop -->]
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/universal.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/universal.html
new file mode 100644
index 0000000000..f2c5762ade
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/universal.html
@@ -0,0 +1 @@
+Universal in trivial extension.
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/event/simple.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/event/simple.html
new file mode 100644
index 0000000000..fe32a1ed3f
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/event/simple.html
@@ -0,0 +1 @@
+Simple in trivial extension.
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html
new file mode 100644
index 0000000000..c70d8f86d7
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html
@@ -0,0 +1,3 @@
+<!-- BEGIN event_loop -->
+event_loop<!-- EVENT test_event_loop -->
+<!-- END event_loop -->
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html
new file mode 100644
index 0000000000..604c1acdce
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html
@@ -0,0 +1 @@
+<!-- EVENT simple -->
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html
new file mode 100644
index 0000000000..233b32a4c7
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html
@@ -0,0 +1,3 @@
+<!-- BEGIN event_loop -->
+event_loop<!-- EVENT test_event_subloop -->
+<!-- END event_loop -->
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html
new file mode 100644
index 0000000000..15425cacc3
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html
@@ -0,0 +1 @@
+<!-- EVENT universal -->
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html
new file mode 100644
index 0000000000..49d8a6b873
--- /dev/null
+++ b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html
@@ -0,0 +1 @@
+<!-- EVENT event_variable_spacing -->
diff --git a/tests/template/ext/include/css/styles/all/theme/child_only.css b/tests/template/ext/include/css/styles/all/theme/child_only.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/ext/include/css/styles/all/theme/child_only.css
diff --git a/tests/template/ext/include/css/styles/all/theme/test.css b/tests/template/ext/include/css/styles/all/theme/test.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/ext/include/css/styles/all/theme/test.css
diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php
new file mode 100644
index 0000000000..fdddbef4f2
--- /dev/null
+++ b/tests/template/includephp_test.php
@@ -0,0 +1,60 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_includephp_test extends phpbb_template_template_test_case
+{
+ public function test_includephp_relative()
+ {
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");
+
+ $this->template->set_filenames(array('test' => 'includephp_relative.html'));
+ $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+
+ public function test_includephp_variables()
+ {
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php");
+
+ $this->template->set_filenames(array('test' => 'includephp_variables.html'));
+ $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+
+ public function test_includephp_absolute()
+ {
+ global $phpbb_root_path;
+
+ $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc';
+ $this->assertTrue(phpbb_is_absolute($path_to_php));
+ $template_text = "Path is absolute.\n<!-- INCLUDEPHP $path_to_php -->";
+
+ $cache_dir = $phpbb_root_path . 'cache/';
+ $fp = fopen($cache_dir . 'includephp_absolute.html', 'w');
+ fputs($fp, $template_text);
+ fclose($fp);
+
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $this->template->set_custom_style('tests', $cache_dir);
+
+ $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");
+
+ $this->template->set_filenames(array('test' => 'includephp_absolute.html'));
+ $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+}
diff --git a/tests/template/parent_templates/parent_and_child.html b/tests/template/parent_templates/parent_and_child.html
new file mode 100644
index 0000000000..71984b48ad
--- /dev/null
+++ b/tests/template/parent_templates/parent_and_child.html
@@ -0,0 +1 @@
+Parent template.
diff --git a/tests/template/parent_templates/parent_and_child.js b/tests/template/parent_templates/parent_and_child.js
new file mode 100644
index 0000000000..6d9bb163bf
--- /dev/null
+++ b/tests/template/parent_templates/parent_and_child.js
@@ -0,0 +1 @@
+// JavaScript file in a parent style.
diff --git a/tests/template/parent_templates/parent_only.css b/tests/template/parent_templates/parent_only.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/parent_templates/parent_only.css
diff --git a/tests/template/parent_templates/parent_only.html b/tests/template/parent_templates/parent_only.html
new file mode 100644
index 0000000000..8cfb90eca2
--- /dev/null
+++ b/tests/template/parent_templates/parent_only.html
@@ -0,0 +1 @@
+Only in parent.
diff --git a/tests/template/parent_templates/parent_only.js b/tests/template/parent_templates/parent_only.js
new file mode 100644
index 0000000000..9c3007d83f
--- /dev/null
+++ b/tests/template/parent_templates/parent_only.js
@@ -0,0 +1 @@
+// JavaScript file only in parent style.
diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php
new file mode 100644
index 0000000000..08ffb0f7dc
--- /dev/null
+++ b/tests/template/subdir/includephp_from_subdir_test.php
@@ -0,0 +1,31 @@
+<?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__) . '/../template_test_case.php';
+
+class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_template_test_case
+{
+ // Exact copy of test_includephp_relatve from ../includephp_test.php.
+ // Verifies that relative php inclusion works when including script
+ // (and thus current working directory) is in a subdirectory of
+ // board root.
+ public function test_includephp_relative()
+ {
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");
+
+ $this->template->set_filenames(array('test' => 'includephp_relative.html'));
+ $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+}
diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php
new file mode 100644
index 0000000000..b4ad84e9c3
--- /dev/null
+++ b/tests/template/template_allfolder_test.php
@@ -0,0 +1,59 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_allfolder_test extends phpbb_template_template_test_case
+{
+ public function test_allfolder()
+ {
+ $this->setup_engine_for_allfolder();
+
+ $this->run_template('foobar_body.html', array(), array(), array(), "All folder");
+ }
+
+ protected function setup_engine_for_allfolder(array $new_config = array())
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $defaults = $this->config_defaults();
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+ $this->user = new \phpbb\user('\phpbb\datetime');
+
+ $path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'vendor4/bar' => array(
+ 'ext_name' => 'vendor4/bar',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/vendor4/bar/',
+ ),
+ )
+ );
+
+ $this->template_path = $this->test_path . '/templates';
+ $this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template';
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context(), $this->extension_manager);
+ $this->template->set_custom_style('all', array($this->template_path, $this->ext_template_path));
+ }
+}
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
new file mode 100644
index 0000000000..c415c969fe
--- /dev/null
+++ b/tests/template/template_events_test.php
@@ -0,0 +1,153 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_template_events_test extends phpbb_template_template_test_case
+{
+ public function template_data()
+ {
+ return array(
+ /*
+ array(
+ '', // Description
+ '', // dataset
+ array(), // style names
+ '', // file
+ array(), // vars
+ array(), // block vars
+ array(), // destroy
+ '', // expected result
+ ),
+ */
+ array(
+ 'Simple template event',
+ 'ext_trivial',
+ array(),
+ 'event_simple.html',
+ array(),
+ array(),
+ array(),
+ "Simple in trivial extension.",
+ ),
+ array(
+ 'Universal template event ("all" style)',
+ 'ext_trivial',
+ array(),
+ 'event_universal.html',
+ array(),
+ array(),
+ array(),
+ "Universal in trivial extension.",
+ ),
+ array(
+ 'Template event with inheritance - parent',
+ 'event_inheritance',
+ array('silver'),
+ 'event_test.html',
+ array(),
+ array(),
+ array(),
+'Kappa test event in silver
+Omega test event in silver
+Zeta test event in all',
+ ),
+ array(
+ 'Template event with inheritance - child',
+ 'event_inheritance',
+ array('silver_inherit', 'silver'),
+ 'event_test.html',
+ array(),
+ array(),
+ array(),
+'Kappa test event in silver_inherit
+Omega test event in silver
+Zeta test event in all',
+ ),
+ array(
+ 'Definition in parent style',
+ 'event_inheritance',
+ array('silver_inherit', 'silver'),
+ 'event_two.html',
+ array(),
+ array(),
+ array(),
+'two in silver in omega',
+ ),
+ array(
+ 'EVENT in loop',
+ 'ext_trivial',
+ array('silver'),
+ 'event_loop.html',
+ array(),
+ array('event_loop' => array(array(), array(), array())),
+ array(),
+ 'event_loop0|event_loop1|event_loop2',
+ ),
+ array(
+ 'EVENT with subloop in loop',
+ 'ext_trivial',
+ array('silver'),
+ 'event_subloop.html',
+ array(),
+ array(
+ 'event_loop' => array(array()),
+ 'event_loop.subloop' => array(array()),
+ ),
+ array(),
+ 'event_loop[0[subloop:0]]',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider template_data
+ */
+ public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected, $incomplete_message = '')
+ {
+ if ($incomplete_message)
+ {
+ $this->markTestIncomplete($incomplete_message);
+ }
+
+ // Reset the engine state
+ $this->setup_engine_for_events($dataset, $style_names);
+
+ // Run test
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected);
+ }
+
+ protected function setup_engine_for_events($dataset, $style_names, array $new_config = array())
+ {
+ global $phpbb_root_path, $phpEx, $user;
+
+ $defaults = $this->config_defaults();
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+
+ $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template";
+ $this->extension_manager = new phpbb_mock_filesystem_extension_manager(
+ dirname(__FILE__) . "/datasets/$dataset/"
+ );
+ $path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, new \phpbb\template\context, $this->extension_manager);
+ $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
+ }
+}
diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php
new file mode 100644
index 0000000000..b025cd21d5
--- /dev/null
+++ b/tests/template/template_includecss_test.php
@@ -0,0 +1,97 @@
+<?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__) . '/template_test_case_with_tree.php';
+
+class phpbb_template_template_includecss_test extends phpbb_template_template_test_case_with_tree
+{
+ protected function setup_engine(array $new_config = array())
+ {
+ global $phpbb_root_path, $phpEx, $user;
+
+ $defaults = $this->config_defaults();
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+
+ $this->phpbb_path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->template_path = $this->test_path . '/templates';
+ $this->parent_template_path = $this->test_path . '/parent_templates';
+ $this->template = new phpbb\template\twig\twig(
+ $this->phpbb_path_helper,
+ $config,
+ $user,
+ new phpbb\template\context(),
+ new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'include/css' => array(
+ 'ext_name' => 'include/css',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/include/css/',
+ ),
+ )
+ )
+ );
+ $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
+ }
+
+ public function template_data()
+ {
+ return array(
+ /*
+ array(
+ // vars
+ // expected
+ ),
+ */
+ array(
+ array('TEST' => 1),
+ '<link href="tests/template/templates/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen" />',
+ ),
+ array(
+ array('TEST' => 2),
+ '<link href="tests/template/parent_templates/parent_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen" />',
+ ),
+ array(
+ array('TEST' => 3),
+ '<link href="tests/template/ext/include/css/styles/all/theme/test.css?assets_version=1" rel="stylesheet" type="text/css" media="screen" />',
+ ),
+ array(
+ array('TEST' => 4),
+ '<link href="tests/template/ext/include/css/styles/all/theme/child_only.css?assets_version=1" rel="stylesheet" type="text/css" media="screen" />',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider template_data
+ */
+ public function test_includecss_compilation($vars, $expected)
+ {
+ // Reset the engine state
+ $this->setup_engine(array('assets_version' => 1));
+
+ $this->template->assign_vars($vars);
+
+ // Run test
+ $this->run_template('includecss.html', array(), array(), array(), $expected);
+ }
+}
diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php
new file mode 100644
index 0000000000..232f551b4a
--- /dev/null
+++ b/tests/template/template_includejs_test.php
@@ -0,0 +1,109 @@
+<?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__) . '/template_test_case_with_tree.php';
+
+class phpbb_template_template_includejs_test extends phpbb_template_template_test_case_with_tree
+{
+ public function template_data()
+ {
+ $this->setup_engine();
+
+ return array(
+ /*
+ array(
+ // vars
+ // expected
+ ),
+ */
+ array(
+ array('TEST' => 1),
+ '<script type="text/javascript" src="tests/template/templates/parent_and_child.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 2),
+ '<script type="text/javascript" src="tests/template/templates/parent_and_child.js?assets_version=0"></script>',
+ ),
+ array(
+ array('TEST' => 3),
+ '<script type="text/javascript" src="tests/template/templates/parent_and_child.js?test=1&assets_version=0"></script>',
+ ),
+ array(
+ array('TEST' => 4),
+ '<script type="text/javascript" src="tests/template/templates/parent_and_child.js?test=1&amp;assets_version=0"></script>',
+ ),
+ array(
+ array('TEST' => 6),
+ '<script type="text/javascript" src="tests/template/parent_templates/parent_only.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 7),
+ '<script type="text/javascript" src="tests/template/templates/child_only.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 8),
+ '<script type="text/javascript" src="tests/template/templates/subdir/parent_only.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 9),
+ '<script type="text/javascript" src="tests/template/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 10),
+ '<script type="text/javascript" src="tests/template/templates/subdir/parent_only.js?assets_version=1"></script>',
+ ),
+ array(
+ array('TEST' => 11),
+ '<script type="text/javascript" src="tests/template/templates/child_only.js?test1=1&amp;test2=2&amp;assets_version=1#test3"></script>',
+ ),
+ array(
+ array('TEST' => 12),
+ '<script type="text/javascript" src="tests/template/parent_templates/parent_only.js?test1=1&amp;test2=2&amp;assets_version=1#test3"></script>',
+ ),
+ array(
+ array('TEST' => 14),
+ '<script type="text/javascript" src="tests/template/parent_templates/parent_only.js?test1=&quot;&amp;assets_version=1#test3"></script>',
+ ),
+ array(
+ array('TEST' => 15),
+ '<script type="text/javascript" src="http://phpbb.com/b.js?c=d#f"></script>',
+ ),
+ array(
+ array('TEST' => 16),
+ '<script type="text/javascript" src="http://phpbb.com/b.js?c=d&assets_version=2#f"></script>',
+ ),
+ array(
+ array('TEST' => 17),
+ '<script type="text/javascript" src="//phpbb.com/b.js"></script>',
+ ),
+ array(
+ array('TEST' => 18),
+ '<script type="text/javascript" src="tests/template/templates/parent_and_child.js?test=1&test2=0&amp;assets_version=1"></script>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider template_data
+ */
+ public function test_includejs_compilation($vars, $expected)
+ {
+ // Reset the engine state
+ $this->setup_engine(array('assets_version' => 1));
+
+ $this->template->assign_vars($vars);
+
+ // Run test
+ $this->run_template('includejs.html', array_merge(array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), $vars), array(), array(), $expected);
+ }
+}
diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php
new file mode 100644
index 0000000000..4d918b3167
--- /dev/null
+++ b/tests/template/template_inheritance_test.php
@@ -0,0 +1,59 @@
+<?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__) . '/template_test_case_with_tree.php';
+
+class phpbb_template_template_inheritance_test extends phpbb_template_template_test_case_with_tree
+{
+ /**
+ * @todo put test data into templates/xyz.test
+ */
+ public function template_data()
+ {
+ return array(
+ // First element of the array is test name - keep them distinct
+ array(
+ 'simple inheritance - only parent template exists',
+ 'parent_only.html',
+ array(),
+ array(),
+ array(),
+ "Only in parent.",
+ ),
+ array(
+ 'simple inheritance - only child template exists',
+ 'child_only.html',
+ array(),
+ array(),
+ array(),
+ "Only in child.",
+ ),
+ array(
+ 'simple inheritance - both parent and child templates exist',
+ 'parent_and_child.html',
+ array(),
+ array(),
+ array(),
+ "Child template.",
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider template_data
+ */
+ public function test_template($name, $file, array $vars, array $block_vars, array $destroy, $expected)
+ {
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected);
+ }
+}
diff --git a/tests/template/template_parser_test.php b/tests/template/template_parser_test.php
new file mode 100644
index 0000000000..d32fe78391
--- /dev/null
+++ b/tests/template/template_parser_test.php
@@ -0,0 +1,33 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_template_parser_test extends phpbb_template_template_test_case
+{
+ public function test_set_filenames()
+ {
+ $this->template->set_filenames(array(
+ 'basic' => 'basic.html',
+ ));
+
+ $this->assertEquals("passpasspass<!-- DUMMY var -->", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic')));
+
+ $this->template->set_filenames(array(
+ 'basic' => 'if.html',
+ ));
+
+ $this->assertEquals("03!false", str_replace(array("\n", "\r", "\t"), '', $this->template->assign_display('basic')));
+ }
+}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 94ec2ab8a7..69546cc227 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -1,111 +1,25 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/template.php';
+require_once dirname(__FILE__) . '/template_test_case.php';
-class phpbb_template_template_test extends phpbb_test_case
+class phpbb_template_template_test extends phpbb_template_template_test_case
{
- private $template;
- private $template_path;
-
- // Keep the contents of the cache for debugging?
- const PRESERVE_CACHE = true;
-
- private function display($handle)
- {
- // allow the templates to throw notices
- $error_level = error_reporting();
- error_reporting($error_level & ~E_NOTICE);
-
- ob_start();
-
- try
- {
- $this->assertTrue($this->template->display($handle, false));
- }
- catch (Exception $exception)
- {
- // reset the error level even when an error occurred
- // PHPUnit turns trigger_error into exceptions as well
- error_reporting($error_level);
- ob_end_clean();
- throw $exception;
- }
-
- $result = self::trim_template_result(ob_get_clean());
-
- // reset error level
- error_reporting($error_level);
- return $result;
- }
-
- private static function trim_template_result($result)
- {
- return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result)))));
- }
-
- private function setup_engine()
- {
- $this->template_path = dirname(__FILE__) . '/templates';
- $this->template = new template();
- $this->template->set_custom_template($this->template_path, 'tests');
- }
-
- protected function setUp()
- {
- // Test the engine can be used
- $this->setup_engine();
-
- $template_cache_dir = dirname($this->template->cachepath);
- if (!is_writable($template_cache_dir))
- {
- $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable.");
- }
-
- $file_array = scandir($template_cache_dir);
- $file_prefix = basename($this->template->cachepath);
- foreach ($file_array as $file)
- {
- if (strpos($file, $file_prefix) === 0)
- {
- unlink($template_cache_dir . '/' . $file);
- }
- }
-
- $GLOBALS['config'] = array(
- 'load_tplcompile' => true,
- 'tpl_allow_php' => false,
- );
- }
-
- protected function tearDown()
- {
- if (is_object($this->template))
- {
- $template_cache_dir = dirname($this->template->cachepath);
- $file_array = scandir($template_cache_dir);
- $file_prefix = basename($this->template->cachepath);
- foreach ($file_array as $file)
- {
- if (strpos($file, $file_prefix) === 0)
- {
- unlink($template_cache_dir . '/' . $file);
- }
- }
- }
- }
-
/**
* @todo put test data into templates/xyz.test
*/
- static public function template_data()
+ public function template_data()
{
return array(
/*
@@ -122,7 +36,7 @@ class phpbb_template_template_test extends phpbb_test_case
array(),
array(),
array(),
- "pass\npass\n<!-- DUMMY var -->",
+ "pass\npass\npass\n<!-- DUMMY var -->",
),
array(
'variable.html',
@@ -136,28 +50,56 @@ class phpbb_template_template_test extends phpbb_test_case
array(),
array(),
array(),
- '0',
+ '03!false',
),
array(
'if.html',
array('S_VALUE' => true),
array(),
array(),
- "1\n0",
+ '1!false',
),
array(
'if.html',
array('S_VALUE' => true, 'S_OTHER_VALUE' => true),
array(),
array(),
- '1',
+ '1!false',
+ ),
+ array(
+ 'if.html',
+ array('S_OTHER_OTHER_VALUE' => true),
+ array(),
+ array(),
+ '|S_OTHER_OTHER_VALUE|!false',
),
array(
'if.html',
array('S_VALUE' => false, 'S_OTHER_VALUE' => true),
array(),
array(),
- '2',
+ '2!false',
+ ),
+ array(
+ 'if.html',
+ array('S_TEST' => false),
+ array(),
+ array(),
+ '03false',
+ ),
+ array(
+ 'if.html',
+ array('S_TEST' => 0),
+ array(),
+ array(),
+ '03!false',
+ ),
+ array(
+ 'if.html',
+ array('VALUE_TEST' => 'value'),
+ array(),
+ array(),
+ '03!falsevalue',
),
array(
'loop.html',
@@ -169,65 +111,88 @@ class phpbb_template_template_test extends phpbb_test_case
array(
'loop.html',
array(),
- array('loop' => array(array())),
+ array('test_loop' => array(array())),
array(),
"loop\nloop",
),
array(
'loop.html',
array(),
- array('loop' => array(array(), array()), 'loop.block' => array(array())),
+ array('test_loop' => array(array(), array()), 'test_loop.block' => array(array())),
array(),
"loop\nloop\nloop\nloop",
),
array(
'loop.html',
array(),
- array('loop' => array(array(), array()), 'loop.block' => array(array()), 'block' => array(array(), array())),
+ array('test_loop' => array(array(), array()), 'test_loop.block' => array(array()), 'block' => array(array(), array())),
array(),
"loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1",
),
array(
'loop_vars.html',
array(),
- array('loop' => array(array('VARIABLE' => 'x'))),
+ array('test_loop' => array(array('VARIABLE' => 'x'))),
array(),
- "first\n0\nx\nset\nlast",
- ),/* no nested top level loops
+ "first\n0 - a\nx - b\nset\nlast",
+ ),
array(
'loop_vars.html',
array(),
- array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
+ array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
array(),
- "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast",
+ "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast",
),
array(
'loop_vars.html',
array(),
- array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
+ array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
array(),
- "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast\n0\n\n1\nlast inner\ninner loop",
- ),*/
+ "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner",
+ ),
array(
'loop_advanced.html',
array(),
- array('loop' => array(array(), array(), array(), array(), array(), array(), array())),
+ array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())),
array(),
"101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561",
),
array(
+ 'loop_nested2.html',
+ array(),
+ array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())),
+ array(),
+ "o0o1m01m11",
+ ),
+ array(
'define.html',
array(),
- array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
+ array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
array(),
- "xyz\nabc",
+ "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n((\$VALUE == 'abc'))\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]|foobar|false",
+ ),
+ array(
+ 'define_advanced.html',
+ array(),
+ array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
+ array(),
+ "abc\nzxc\ncde\nbcd",
),
array(
'expressions.html',
array(),
array(),
array(),
- trim(str_repeat("pass", 39)),
+ trim(str_repeat("pass\n", 10) . "\n"
+ . str_repeat("pass\n", 4) . "\n"
+ . str_repeat("pass\n", 2) . "\n"
+ . str_repeat("pass\n", 6) . "\n"
+ . str_repeat("pass\n", 2) . "\n"
+ . str_repeat("pass\n", 6) . "\n"
+ . str_repeat("pass\n", 2) . "\n"
+ . str_repeat("pass\n", 2) . "\n"
+ . str_repeat("pass\n", 3) . "\n"
+ . str_repeat("pass\n", 2) . "\n"),
),
array(
'php.html',
@@ -251,10 +216,31 @@ class phpbb_template_template_test extends phpbb_test_case
'value',
),
array(
+ 'include_loop.html',
+ array(),
+ array('test_loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'test_loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))),
+ array(),
+ "1\n_1\n_02\n_3",
+ ),
+ array(
+ 'include_variable.html',
+ array('FILE' => 'variable.html', 'VARIABLE' => 'value'),
+ array(),
+ array(),
+ 'value',
+ ),
+ array(
+ 'include_variables.html',
+ array('SUBDIR' => 'subdir', 'VARIABLE' => 'value'),
+ array(),
+ array(),
+ 'value',
+ ),
+ array(
'loop_vars.html',
array(),
- array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
- array('loop'),
+ array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
+ array('test_loop'),
'',
),
array(
@@ -262,12 +248,12 @@ class phpbb_template_template_test extends phpbb_test_case
array('VARIABLE' => 'variable.html'),
array(),
array(),
- 'variable.html',
+ "variable.html\nvariable.html\nvariable.html",
),
array(
'include_loop_define.html',
array('VARIABLE' => 'value'),
- array('loop' => array(array('NESTED_FILE' => 'variable.html'))),
+ array('test_loop' => array(array('NESTED_FILE' => 'variable.html'))),
array(),
'value',
),
@@ -275,30 +261,103 @@ class phpbb_template_template_test extends phpbb_test_case
array(
'loop_vars.html',
array(),
- array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
- array('loop.inner'),
+ array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())),
+ array('test_loop.inner'),
"first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast",
),*/
array(
- 'lang.html',
+ // Just like a regular loop but the name begins
+ // with an underscore
+ 'loop_underscore.html',
array(),
array(),
array(),
- "{ VARIABLE }\n{ VARIABLE }",
+ "noloop\nnoloop",
),
array(
'lang.html',
- array('L_VARIABLE' => "Value'"),
array(),
array(),
- "Value'\nValue\'",
+ array(),
+ "VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE",
),
array(
'lang.html',
- array('LA_VARIABLE' => "Value'"),
array(),
array(),
- "{ VARIABLE }\nValue'",
+ array(),
+ "Value'\n1 O'Clock\nValue\'\n1 O\'Clock",
+ array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
+ ),
+ array(
+ 'loop_nested_multilevel_ref.html',
+ array(),
+ array(),
+ array(),
+ "top-level content",
+ ),
+ array(
+ 'loop_nested_multilevel_ref.html',
+ array(),
+ array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),
+ array(),
+ "top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz",
+ ),
+ array(
+ 'loop_nested_deep_multilevel_ref.html',
+ array(),
+ array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),
+ array(),
+ "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz",
+ ),
+ array(
+ 'loop_size.html',
+ array(),
+ array('test_loop' => array(array()), 'empty_loop' => array()),
+ array(),
+ "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop",
+ ),
+ array(
+ 'loop_include.html',
+ array(),
+ array('test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1'))),
+ array(),
+ "barbarbar1bar1",
+ ),
+ array(
+ 'loop_nested_include.html',
+ array(),
+ array(
+ 'test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1')),
+ 'test_loop.inner' => array(array('myinner' => 'works')),
+ ),
+ array(),
+ "[bar|[bar|]][bar1|[bar1|[bar1|works]]]",
+ array(),
+ ),
+ /* Does not pass with the current implementation.
+ array(
+ 'loop_reuse.html',
+ array(),
+ array('one' => array(array('VAR' => 'a'), array('VAR' => 'b')), 'one.one' => array(array('VAR' => 'c'), array('VAR' => 'd'))),
+ array(),
+ // Not entirely sure what should be outputted but the current output of "a" is most certainly wrong
+ "a\nb\nc\nd",
+ ),
+ */
+ array(
+ 'twig.html',
+ array('VARIABLE' => 'FOObar',),
+ array(),
+ array(),
+ "13FOOBAR|foobar",
+ ),
+ array(
+ 'if_nested_tags.html',
+ array('S_VALUE' => true,),
+ array(),
+ array(),
+ 'inner_value',
),
);
}
@@ -310,149 +369,101 @@ class phpbb_template_template_test extends phpbb_test_case
$this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
- $expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path . '/../') . '/templates/' . $filename);
- $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
+ $this->setExpectedException('Twig_Error_Loader');
$this->display('test');
}
- public function test_empty_file()
- {
- $expecting = 'template->set_filenames: Empty filename specified for test';
-
- $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
- $this->template->set_filenames(array('test' => ''));
- }
public function test_invalid_handle()
{
- $expecting = 'template->_tpl_load(): No file specified for handle test';
- $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
+ $this->setExpectedException('Twig_Error_Loader');
$this->display('test');
}
- private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
+ /**
+ * @dataProvider template_data
+ */
+ public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array(), $incomplete_message = '')
{
- $this->template->set_filenames(array('test' => $file));
- $this->template->assign_vars($vars);
-
- foreach ($block_vars as $block => $loops)
+ if ($incomplete_message)
{
- foreach ($loops as $_vars)
- {
- $this->template->assign_block_vars($block, $_vars);
- }
+ $this->markTestIncomplete($incomplete_message);
}
- foreach ($destroy as $block)
- {
- $this->template->destroy_block_vars($block);
- }
-
- try
- {
- $this->assertEquals($expected, $this->display('test'), "Testing $file");
- $this->assertFileExists($cache_file);
- }
- catch (ErrorException $e)
- {
- if (file_exists($cache_file))
- {
- copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
- }
-
- throw $e;
- }
-
- // For debugging
- if (self::PRESERVE_CACHE)
- {
- copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
- }
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected, $lang_vars);
}
- /**
- * @dataProvider template_data
- */
- public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
+ public function test_assign_display()
{
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
-
- $this->assertFileNotExists($cache_file);
+ $this->run_template('basic.html', array(), array(), array(), "pass\npass\npass\n<!-- DUMMY var -->");
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
+ $this->template->set_filenames(array(
+ 'test' => 'basic.html',
+ 'container' => 'variable.html',
+ ));
- // Reset the engine state
- $this->setup_engine();
+ $this->template->assign_display('test', 'VARIABLE', false);
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
+ $this->assertEquals("pass\npass\npass\n<!-- DUMMY var -->", $this->display('container'), "Testing assign_display($file)");
}
- /**
- * @dataProvider template_data
- */
- public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected)
+ public function test_append_var_without_assign_var()
{
$this->template->set_filenames(array(
- 'test' => $file,
- 'container' => 'variable.html',
+ 'append_var' => 'variable.html'
));
- $this->template->assign_vars($vars);
- foreach ($block_vars as $block => $loops)
- {
- foreach ($loops as $_vars)
- {
- $this->template->assign_block_vars($block, $_vars);
- }
- }
+ $items = array('This ', 'is ', 'a ', 'test');
+ $expecting = implode('', $items);
- foreach ($destroy as $block)
+ foreach ($items as $word)
{
- $this->template->destroy_block_vars($block);
+ $this->template->append_var('VARIABLE', $word);
}
- $error_level = error_reporting();
- error_reporting($error_level & ~E_NOTICE);
-
- $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)");
-
- $this->template->assign_display('test', 'VARIABLE', false);
-
- error_reporting($error_level);
-
- $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)");
+ $this->assertEquals($expecting, $this->display('append_var'));
}
- public function test_php()
+ public function test_append_var_with_assign_var()
{
- $GLOBALS['config']['tpl_allow_php'] = true;
-
- $cache_file = $this->template->cachepath . 'php.html.php';
+ $this->template->set_filenames(array(
+ 'append_var' => 'variable.html'
+ ));
- $this->assertFileNotExists($cache_file);
+ $start = 'This ';
+ $items = array('is ', 'a ', 'test');
+ $expecting = $start . implode('', $items);
- $this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
+ $this->template->assign_var('VARIABLE', $start);
+ foreach ($items as $word)
+ {
+ $this->template->append_var('VARIABLE', $word);
+ }
- $GLOBALS['config']['tpl_allow_php'] = false;
+ $this->assertEquals($expecting, $this->display('append_var'));
}
- public function test_includephp()
+ public function test_php()
{
- $GLOBALS['config']['tpl_allow_php'] = true;
+ global $phpbb_root_path;
+
+ $template_text = '<!-- PHP -->echo "test";<!-- ENDPHP -->';
- $cache_file = $this->template->cachepath . 'includephp.html.php';
+ $cache_dir = $phpbb_root_path . 'cache/';
+ $fp = fopen($cache_dir . 'php.html', 'w');
+ fputs($fp, $template_text);
+ fclose($fp);
- $this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file);
+ $this->setup_engine(array('tpl_allow_php' => true));
- $this->template->set_filenames(array('test' => 'includephp.html'));
- $this->assertEquals('testing included php', $this->display('test'), "Testing INCLUDEPHP");
+ $this->template->set_custom_style('tests', $cache_dir);
- $GLOBALS['config']['tpl_allow_php'] = false;
+ $this->run_template('php.html', array(), array(), array(), 'test');
}
- static public function alter_block_array_data()
+ public function alter_block_array_data()
{
return array(
array(
@@ -517,22 +528,139 @@ EOT
),
array(
'outer',
+ array('VARIABLE' => 'changed'),
+ 0,
+ 'change',
+ <<<EOT
+outer - 0 - changed
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+EOT
+,
+ 'Test changing at 0 on top level block',
+ ),
+ array(
+ 'outer',
+ array('VARIABLE' => 'changed'),
+ array('S_ROW_NUM' => 2),
+ 'change',
+ <<<EOT
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2 - changed
+middle - 0
+middle - 1
+EOT
+,
+ 'Test changing at KEY on top level block',
+ ),
+ array(
+ 'outer.middle',
+ array('VARIABLE' => 'before'),
+ false,
+ 'insert',
+ <<<EOT
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0 - before
+middle - 1
+middle - 2
+EOT
+,
+ 'Test inserting before on middle level block',
+ ),
+ array(
+ 'outer.middle',
+ array('VARIABLE' => 'after'),
+ true,
+ 'insert',
+ <<<EOT
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+middle - 2 - after
+EOT
+,
+ 'Test inserting after on middle level block',
+ ),
+ array(
+ 'outer[1].middle',
array('VARIABLE' => 'pos #1'),
+ 1,
+ 'insert',
+ <<<EOT
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1 - pos #1
+middle - 2
+outer - 2
+middle - 0
+middle - 1
+EOT
+,
+ 'Test inserting at 1 on middle level block',
+ ),
+ array(
+ 'outer[].middle',
+ array('VARIABLE' => 'changed'),
0,
'change',
<<<EOT
-outer - 0 - pos #1
+outer - 0
middle - 0
middle - 1
outer - 1
middle - 0
middle - 1
outer - 2
+middle - 0 - changed
+middle - 1
+EOT
+,
+ 'Test changing at beginning of last top level block',
+ ),
+ array(
+ 'outer.middle',
+ array('VARIABLE' => 'changed'),
+ array('S_ROW_NUM' => 1),
+ 'change',
+ <<<EOT
+outer - 0
middle - 0
middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1 - changed
EOT
,
- 'Test inserting at 1 on top level block',
+ 'Test changing at beginning of last top level block',
),
);
}
@@ -555,10 +683,129 @@ EOT
$this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer.middle', array());
- $this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
+ $this->assertEquals("outer - 0middle - 0middle - 1outer - 1middle - 0middle - 1outer - 2middle - 0middle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
- $this->assertEquals($expect, $this->display('test'), $description);
+ $this->assertEquals(str_replace(array("\n", "\r", "\t"), '', $expect), str_replace(array("\n", "\r", "\t"), '', $this->display('test')), $description);
}
-}
+ public function test_more_alter_block_array()
+ {
+ $this->template->set_filenames(array('test' => 'loop_nested.html'));
+
+ $this->template->assign_var('TEST_MORE', true);
+
+ // @todo Change this
+ $this->template->assign_block_vars('outer', array());
+ $this->template->assign_block_vars('outer.middle', array());
+ $this->template->assign_block_vars('outer', array());
+ $this->template->assign_block_vars('outer.middle', array());
+ $this->template->assign_block_vars('outer.middle', array());
+ $this->template->assign_block_vars('outer', array());
+ $this->template->assign_block_vars('outer.middle', array());
+ $this->template->assign_block_vars('outer.middle', array());
+ $this->template->assign_block_vars('outer.middle', array());
+
+ $expect = 'outer - 0[outer|3]middle - 0[middle|1]outer - 1[outer|3]middle - 0[middle|2]middle - 1[middle|2]outer - 2[outer|3]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification');
+
+ $this->template->alter_block_array('outer', array());
+
+ $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion');
+
+ $this->template->alter_block_array('outer', array('VARIABLE' => 'test'), 2, 'change');
+
+ $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification');
+
+ $this->template->alter_block_array('outer.middle', array());
+
+ $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2[middle|4]middle - 3[middle|4]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion at middle level');
+
+ $this->template->alter_block_array('outer.middle', array('VARIABLE' => 'test'), 2, 'change');
+
+ $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2 - test[middle|4]middle - 3[middle|4]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification at middle level');
+ }
+
+ public function test_find_key_index()
+ {
+ $this->template->set_filenames(array('test' => 'loop_nested.html'));
+
+ $this->template->assign_var('TEST_MORE', true);
+
+ // @todo Change this
+ $this->template->assign_block_vars('outer', array('VARIABLE' => 'zero'));
+ $this->template->assign_block_vars('outer', array('VARIABLE' => 'one'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '1A'));
+ $this->template->assign_block_vars('outer', array('VARIABLE' => 'two'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2A'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2B'));
+ $this->template->assign_block_vars('outer', array('VARIABLE' => 'three'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3A'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3B'));
+ $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3C'));
+
+ $expect = 'outer - 0 - zero[outer|4]outer - 1 - one[outer|4]middle - 0 - 1A[middle|1]outer - 2 - two[outer|4]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 3 - three[outer|4]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]';
+ $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification');
+
+ $this->template->find_key_index('outer', false);
+
+ $this->assertEquals(0, $this->template->find_key_index('outer', false), 'Find index at the beginning of outer loop');
+ $this->assertEquals(1, $this->template->find_key_index('outer', 1), 'Find index by index in outer loop');
+ $this->assertEquals(2, $this->template->find_key_index('outer', array('VARIABLE' => 'two')), 'Find index by key in outer loop');
+ $this->assertEquals(3, $this->template->find_key_index('outer', true), 'Find index at the end of outer loop');
+ $this->assertEquals(false, $this->template->find_key_index('outer', 7), 'Find index out of bounds of outer loop');
+
+ $this->assertEquals(false, $this->template->find_key_index('outer[0].middle', false), 'Find index at the beginning of middle loop, no middle block');
+ $this->assertEquals(false, $this->template->find_key_index('outer[1].middle', 1), 'Find index by index in inner loop, out of bounds');
+ $this->assertEquals(1, $this->template->find_key_index('outer[2].middle', array('VARIABLE' => '2B')), 'Find index by key in middle loop');
+ $this->assertEquals(2, $this->template->find_key_index('outer.middle', true), 'Find index at the end of middle loop');
+
+ $this->assertEquals(false, $this->template->find_key_index('outer.wrong', true), 'Wrong middle block name');
+ $this->assertEquals(false, $this->template->find_key_index('wrong.middle', false), 'Wrong outer block name');
+ }
+ public function assign_block_vars_array_data()
+ {
+ return array(
+ array(
+ array(
+ 'outer' => array(
+ array('VARIABLE' => 'Test assigning block vars array loop 0:'),
+ array('VARIABLE' => 'Test assigning block vars array loop 1:'),
+ ),
+ 'outer.middle' => array(
+ array('VARIABLE' => '1st iteration',),
+ array('VARIABLE' => '2nd iteration',),
+ array('VARIABLE' => '3rd iteration',),
+ ),
+ )
+ )
+ );
+ }
+
+ /**
+ * @dataProvider assign_block_vars_array_data
+ */
+ public function test_assign_block_vars_array($block_data)
+ {
+ $this->template->set_filenames(array('test' => 'loop_nested.html'));
+
+ foreach ($block_data as $blockname => $block_vars_array)
+ {
+ $this->template->assign_block_vars_array($blockname, $block_vars_array);
+ }
+
+ $this->assertEquals("outer - 0 - Test assigning block vars array loop 0:outer - 1 - Test assigning block vars array loop 1:middle - 0 - 1st iterationmiddle - 1 - 2nd iterationmiddle - 2 - 3rd iteration", $this->display('test'), 'Ensuring assigning block vars array to template is working correctly');
+ }
+
+ /**
+ * @expectedException Twig_Error_Syntax
+ */
+ public function test_define_error()
+ {
+ $this->run_template('define_error.html', array(), array(), array(), '');
+ }
+}
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
new file mode 100644
index 0000000000..1250397401
--- /dev/null
+++ b/tests/template/template_test_case.php
@@ -0,0 +1,132 @@
+<?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_template_template_test_case extends phpbb_test_case
+{
+ protected $template;
+ protected $template_path;
+ protected $user;
+
+ protected $test_path = 'tests/template';
+
+ // Keep the contents of the cache for debugging?
+ const PRESERVE_CACHE = true;
+
+ protected function display($handle)
+ {
+ ob_start();
+
+ try
+ {
+ $this->template->display($handle, false);
+ }
+ catch (Exception $exception)
+ {
+ // reset output buffering even when an error occurred
+ // PHPUnit turns trigger_error into exceptions as well
+ ob_end_clean();
+ throw $exception;
+ }
+
+ $result = self::trim_template_result(ob_get_clean());
+
+ return $result;
+ }
+
+ protected static function trim_template_result($result)
+ {
+ return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result)))));
+ }
+
+ protected function config_defaults()
+ {
+ $defaults = array(
+ 'load_tplcompile' => true,
+ 'tpl_allow_php' => false,
+ );
+ return $defaults;
+ }
+
+ protected function setup_engine(array $new_config = array())
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $defaults = $this->config_defaults();
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+ $this->user = new \phpbb\user('\phpbb\datetime');
+
+ $path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->template_path = $this->test_path . '/templates';
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context());
+ $this->template->set_custom_style('tests', $this->template_path);
+ }
+
+ protected function setUp()
+ {
+ // Test the engine can be used
+ $this->setup_engine();
+
+ $this->template->clear_cache();
+ }
+
+ protected function tearDown()
+ {
+ if ($this->template)
+ {
+ $this->template->clear_cache();
+ }
+ }
+
+ protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())
+ {
+ $this->template->set_filenames(array('test' => $file));
+ $this->template->assign_vars($vars);
+
+ foreach ($block_vars as $block => $loops)
+ {
+ foreach ($loops as $_vars)
+ {
+ $this->template->assign_block_vars($block, $_vars);
+ }
+ }
+
+ foreach ($destroy as $block)
+ {
+ $this->template->destroy_block_vars($block);
+ }
+
+ // Previous functionality was $cachefile (string), which was removed, check to prevent errors
+ if (is_array($lang_vars))
+ {
+ foreach ($lang_vars as $name => $value)
+ {
+ $this->user->lang[$name] = $value;
+ }
+ }
+
+ $expected = str_replace(array("\n", "\r", "\t"), '', $expected);
+ $output = str_replace(array("\n", "\r", "\t"), '', $this->display('test'));
+ $this->assertEquals($expected, $output, "Testing $file");
+ }
+}
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
new file mode 100644
index 0000000000..68ecc4b706
--- /dev/null
+++ b/tests/template/template_test_case_with_tree.php
@@ -0,0 +1,40 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_template_test_case_with_tree extends phpbb_template_template_test_case
+{
+ protected function setup_engine(array $new_config = array())
+ {
+ global $phpbb_root_path, $phpEx, $user;
+
+ $defaults = $this->config_defaults();
+ $config = new \phpbb\config\config(array_merge($defaults, $new_config));
+
+ $this->phpbb_path_helper = new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->template_path = $this->test_path . '/templates';
+ $this->parent_template_path = $this->test_path . '/parent_templates';
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, new phpbb\template\context());
+ $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
+ }
+}
diff --git a/tests/template/templates/basic.html b/tests/template/templates/basic.html
index c1dd690260..e5c6f280fb 100644
--- a/tests/template/templates/basic.html
+++ b/tests/template/templates/basic.html
@@ -16,5 +16,8 @@ fail
<!-- BEGINELSE -->
pass
<!-- END empty -->
+<!-- IF not S_EMPTY -->
+pass
+<!-- ENDIF -->
<!-- DUMMY var -->
diff --git a/tests/template/templates/child_only.css b/tests/template/templates/child_only.css
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/child_only.css
diff --git a/tests/template/templates/child_only.html b/tests/template/templates/child_only.html
new file mode 100644
index 0000000000..6121fef5c5
--- /dev/null
+++ b/tests/template/templates/child_only.html
@@ -0,0 +1 @@
+Only in child.
diff --git a/tests/template/templates/child_only.js b/tests/template/templates/child_only.js
new file mode 100644
index 0000000000..542b26526c
--- /dev/null
+++ b/tests/template/templates/child_only.js
@@ -0,0 +1 @@
+// JavaScript file only in a child style.
diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html
index 82237d21a3..276d2ebb99 100644
--- a/tests/template/templates/define.html
+++ b/tests/template/templates/define.html
@@ -2,7 +2,36 @@
{$VALUE}
<!-- DEFINE $VALUE = 'abc' -->
{$VALUE}
+<!-- IF $VALUE != 'abc' -->
+$VALUE != 'abc'
+<!-- ELSEIF $VALUE == 'abc' -->
+$VALUE == 'abc'
+<!-- ENDIF -->
+<!-- IF ($VALUE == 'abc') -->
+($VALUE == 'abc')
+<!-- ENDIF -->
+<!-- IF (($VALUE == 'abc')) -->
+(($VALUE == 'abc'))
+<!-- ENDIF -->
+<!-- IF !$DOESNT_EXIST -->
+!$DOESNT_EXIST
+<!-- ENDIF -->
+<!-- IF (!$DOESNT_EXIST) -->
+(!$DOESNT_EXIST)
+<!-- ENDIF -->
+<!-- INCLUDE define_include.html -->
+{$INCLUDED_VALUE}
+{$VALUE}
<!-- UNDEFINE $VALUE -->
{$VALUE}
-<!-- DEFINE $VALUE -->
-
+<!-- DEFINE $VALUE = 'test!@#$%^&*()_-=+{}[]:;",<.>/?' -->
+{$VALUE}
+<!-- DEFINE $VALUE = '' -->
+[{$VALUE}]
+<!-- DEFINE $TEST -->foobar<!-- ENDDEFINE -->|{$TEST}|
+<!-- DEFINE $VAR = false -->
+<!-- IF $VAR -->
+true
+<!-- ELSE -->
+false
+<!-- ENDIF -->
diff --git a/tests/template/templates/define_advanced.html b/tests/template/templates/define_advanced.html
new file mode 100644
index 0000000000..83467a5b4b
--- /dev/null
+++ b/tests/template/templates/define_advanced.html
@@ -0,0 +1,12 @@
+<!-- DEFINE $VALUE -->
+abc
+<!-- ENDDEFINE -->
+{$VALUE}
+<!-- DEFINE $VALUE1 -->
+bcd
+<!-- ENDDEFINE -->
+<!-- DEFINE $VALUE2 -->
+cde
+<!-- ENDDEFINE -->
+<!-- INCLUDE define_include2.html -->
+{$INCLUDED_VALUE3}
diff --git a/tests/template/templates/define_error.html b/tests/template/templates/define_error.html
new file mode 100644
index 0000000000..72ab1ba033
--- /dev/null
+++ b/tests/template/templates/define_error.html
@@ -0,0 +1,2 @@
+<!-- DEFINE $VAR = foo -->
+{$VAR}
diff --git a/tests/template/templates/define_include.html b/tests/template/templates/define_include.html
new file mode 100644
index 0000000000..9c470c296a
--- /dev/null
+++ b/tests/template/templates/define_include.html
@@ -0,0 +1,3 @@
+{$VALUE}
+<!-- DEFINE $INCLUDED_VALUE = 'bar' -->
+{$INCLUDED_VALUE}
diff --git a/tests/template/templates/define_include2.html b/tests/template/templates/define_include2.html
new file mode 100644
index 0000000000..874f3e1852
--- /dev/null
+++ b/tests/template/templates/define_include2.html
@@ -0,0 +1,11 @@
+<!-- DEFINE $INCLUDED_VALUE1 -->
+zxc
+<!-- ENDDEFINE -->
+<!-- DEFINE $INCLUDED_VALUE2 -->
+qwe
+<!-- ENDDEFINE -->
+{$INCLUDED_VALUE1}
+<!-- DEFINE $INCLUDED_VALUE3 -->
+{$VALUE2}
+{$VALUE1}
+<!-- ENDDEFINE -->
diff --git a/tests/template/templates/events.html b/tests/template/templates/events.html
new file mode 100644
index 0000000000..c44a7469e7
--- /dev/null
+++ b/tests/template/templates/events.html
@@ -0,0 +1,4 @@
+<!-- EVENT child_only -->
+<!-- EVENT parent_only -->
+<!-- EVENT parent_and_child -->
+<!-- EVENT random_event -->
diff --git a/tests/template/templates/expressions.html b/tests/template/templates/expressions.html
index c40d967dab..e1283f165f 100644
--- a/tests/template/templates/expressions.html
+++ b/tests/template/templates/expressions.html
@@ -1,86 +1,57 @@
<!-- IF 10 is even -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 is even -->fail<!-- ELSE -->pass<!-- ENDIF -->
-
<!-- IF not 390 is even -->fail<!-- ELSE -->pass<!-- ENDIF -->
-
<!-- IF 9 is odd -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 32 is odd -->fail<!-- ELSE -->pass<!-- ENDIF -->
-
<!-- IF 32 is div by 16 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 10 is not even -->fail<!-- ELSE -->pass<!-- ENDIF -->
-
<!-- IF 24 == 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 24 eq 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF ((((((24 == 24)))))) -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 24 != 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 24 <> 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 24 ne 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 24 neq 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 10 lt 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 10 < 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 10 le 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 10 lte 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 10 <= 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 20 le 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 20 lte 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 20 <= 20 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 9 gt 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 > 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 9 >= 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 gte 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 ge 1 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 >= 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 gte 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 9 ge 9 -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF true && (10 > 4) -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF true and (10 > 4) -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF false || true -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF false or true -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF !false -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF not false -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF not not not false -->pass<!-- ELSE -->fail<!-- ENDIF -->
<!-- IF 6 % 4 == 2 -->pass<!-- ELSE -->fail<!-- ENDIF -->
-
<!-- IF 24 mod 12 == 0 -->pass<!-- ELSE -->fail<!-- ENDIF -->
diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html
index c502e52f51..71312f994c 100644
--- a/tests/template/templates/if.html
+++ b/tests/template/templates/if.html
@@ -2,10 +2,24 @@
1
<!-- ELSEIF S_OTHER_VALUE -->
2
+<!-- ELSE IF S_OTHER_OTHER_VALUE -->
+|S_OTHER_OTHER_VALUE|
<!-- ELSE -->
-0
+03
<!-- ENDIF -->
-<!-- IF (S_VALUE > S_OTHER_VALUE) -->
-0
+<!-- IF S_VALUE and S_OTHER_VALUE and (S_VALUE > S_OTHER_VALUE) -->
+04
+<!-- ENDIF -->
+
+<!-- IF S_TEST === false -->
+false
+<!-- ENDIF -->
+
+<!-- IF S_TEST !== false -->
+!false
+<!-- ENDIF -->
+
+<!-- IF VALUE_TEST is defined -->
+{VALUE_TEST}
<!-- ENDIF -->
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/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html
index aff9b574c2..6052657c97 100644
--- a/tests/template/templates/include_define_variable.html
+++ b/tests/template/templates/include_define_variable.html
@@ -1,2 +1,8 @@
<!-- DEFINE $DEF = '{VARIABLE}' -->
<!-- INCLUDE {$DEF} -->
+
+<!-- DEFINE $DEF_WITH_UNDERSCORES = '{VARIABLE}' -->
+<!-- INCLUDE {$DEF_WITH_UNDERSCORES} -->
+
+<!-- DEFINE $DEF123 = '{VARIABLE}' -->
+<!-- INCLUDE {$DEF123} -->
diff --git a/tests/template/templates/include_loop.html b/tests/template/templates/include_loop.html
new file mode 100644
index 0000000000..5cad34b363
--- /dev/null
+++ b/tests/template/templates/include_loop.html
@@ -0,0 +1,4 @@
+<!-- BEGIN test_loop -->
+<!-- INCLUDE {test_loop.NESTED_FILE} -->
+<!-- BEGIN inner -->_<!-- INCLUDE {test_loop.inner.NESTED_FILE} --><!-- END inner -->
+<!-- END test_loop -->
diff --git a/tests/template/templates/include_loop1.html b/tests/template/templates/include_loop1.html
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/tests/template/templates/include_loop1.html
@@ -0,0 +1 @@
+1
diff --git a/tests/template/templates/include_loop2.html b/tests/template/templates/include_loop2.html
new file mode 100644
index 0000000000..9e22bcb8e3
--- /dev/null
+++ b/tests/template/templates/include_loop2.html
@@ -0,0 +1 @@
+02
diff --git a/tests/template/templates/include_loop3.html b/tests/template/templates/include_loop3.html
new file mode 100644
index 0000000000..00750edc07
--- /dev/null
+++ b/tests/template/templates/include_loop3.html
@@ -0,0 +1 @@
+3
diff --git a/tests/template/templates/include_loop_define.html b/tests/template/templates/include_loop_define.html
index f539b21396..4bab09422e 100644
--- a/tests/template/templates/include_loop_define.html
+++ b/tests/template/templates/include_loop_define.html
@@ -1,4 +1,4 @@
-<!-- BEGIN loop -->
-<!-- DEFINE $DEF = '{loop.NESTED_FILE}' -->
+<!-- BEGIN test_loop -->
+<!-- DEFINE $DEF = '{test_loop.NESTED_FILE}' -->
<!-- INCLUDE {$DEF} -->
-<!-- END loop -->
+<!-- END test_loop -->
diff --git a/tests/template/templates/include_variable.html b/tests/template/templates/include_variable.html
new file mode 100644
index 0000000000..b907e0b44f
--- /dev/null
+++ b/tests/template/templates/include_variable.html
@@ -0,0 +1 @@
+<!-- INCLUDE {FILE} -->
diff --git a/tests/template/templates/include_variables.html b/tests/template/templates/include_variables.html
new file mode 100644
index 0000000000..8371a061b5
--- /dev/null
+++ b/tests/template/templates/include_variables.html
@@ -0,0 +1 @@
+<!-- INCLUDE {SUBDIR}/variable.html -->
diff --git a/tests/template/templates/includecss.html b/tests/template/templates/includecss.html
new file mode 100644
index 0000000000..23e3c426d7
--- /dev/null
+++ b/tests/template/templates/includecss.html
@@ -0,0 +1,10 @@
+<!-- IF TEST === 1 -->
+ <!-- INCLUDECSS child_only.css -->
+<!-- ELSEIF TEST === 2 -->
+ <!-- INCLUDECSS parent_only.css -->
+<!-- ELSEIF TEST === 3 -->
+ <!-- INCLUDECSS @include_css/test.css -->
+<!-- ELSEIF TEST === 4 -->
+ <!-- INCLUDECSS @include_css/child_only.css -->
+<!-- ENDIF -->
+{$STYLESHEETS}
diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html
new file mode 100644
index 0000000000..0bcdf1a815
--- /dev/null
+++ b/tests/template/templates/includejs.html
@@ -0,0 +1,36 @@
+<!-- IF TEST === 1 -->
+ <!-- INCLUDEJS parent_and_child.js -->
+<!-- ELSEIF TEST === 2 -->
+ <!-- INCLUDEJS parent_and_child.js?assets_version=0 -->
+<!-- ELSEIF TEST === 3 -->
+ <!-- INCLUDEJS parent_and_child.js?test=1&assets_version=0 -->
+<!-- ELSEIF TEST === 4 -->
+ <!-- INCLUDEJS parent_and_child.js?test=1&amp;assets_version=0 -->
+<!-- ELSEIF TEST === 6 -->
+ <!-- INCLUDEJS {PARENT} -->
+<!-- ELSEIF TEST === 7 -->
+ <!-- DEFINE $TEST = 'child_only.js' -->
+ <!-- INCLUDEJS {$TEST} -->
+<!-- ELSEIF TEST === 8 -->
+ <!-- INCLUDEJS subdir/{PARENT} -->
+<!-- ELSEIF TEST === 9 -->
+ <!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} -->
+<!-- ELSEIF TEST === 10 -->
+ <!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} -->
+<!-- ELSEIF TEST === 11 -->
+ <!-- DEFINE $TEST = 'child_only.js?test1=1&amp;test2=2#test3' -->
+ <!-- INCLUDEJS {$TEST} -->
+<!-- ELSEIF TEST === 12 -->
+ <!-- INCLUDEJS parent_only.js?test1=1&amp;test2=2#test3 -->
+<!-- ELSEIF TEST === 14 -->
+ <!-- INCLUDEJS parent_only.js?test1=&quot;#test3 -->
+<!-- ELSEIF TEST === 15 -->
+ <!-- INCLUDEJS http://phpbb.com/b.js?c=d#f -->
+<!-- ELSEIF TEST === 16 -->
+ <!-- INCLUDEJS http://phpbb.com/b.js?c=d&assets_version=2#f -->
+<!-- ELSEIF TEST === 17 -->
+ <!-- INCLUDEJS //phpbb.com/b.js -->
+<!-- ELSEIF TEST === 18 -->
+ <!-- INCLUDEJS parent_and_child.js?test=1&test2=0 -->
+<!-- ENDIF -->
+{$SCRIPTS}
diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp_relative.html
index 70ebdac0d0..297c9efcb0 100644
--- a/tests/template/templates/includephp.html
+++ b/tests/template/templates/includephp_relative.html
@@ -1 +1,2 @@
+Path is relative to board root.
<!-- INCLUDEPHP ../tests/template/templates/_dummy_include.php.inc -->
diff --git a/tests/template/templates/includephp_variables.html b/tests/template/templates/includephp_variables.html
new file mode 100644
index 0000000000..6106efc86a
--- /dev/null
+++ b/tests/template/templates/includephp_variables.html
@@ -0,0 +1,2 @@
+Path includes variables.
+<!-- INCLUDEPHP ../tests/template/{TEMPLATES}/_dummy_include.php.inc -->
diff --git a/tests/template/templates/invalid/endif_without_if.html b/tests/template/templates/invalid/endif_without_if.html
new file mode 100644
index 0000000000..e371ffd150
--- /dev/null
+++ b/tests/template/templates/invalid/endif_without_if.html
@@ -0,0 +1 @@
+<!-- ENDIF -->
diff --git a/tests/template/templates/invalid/output/endif_without_if.html b/tests/template/templates/invalid/output/endif_without_if.html
new file mode 100644
index 0000000000..5f2239c964
--- /dev/null
+++ b/tests/template/templates/invalid/output/endif_without_if.html
@@ -0,0 +1 @@
+Parse error (fatal, destroys php runtime).
diff --git a/tests/template/templates/invalid/output/include_nonexistent_file.html b/tests/template/templates/invalid/output/include_nonexistent_file.html
new file mode 100644
index 0000000000..8a118d2713
--- /dev/null
+++ b/tests/template/templates/invalid/output/include_nonexistent_file.html
@@ -0,0 +1 @@
+style resource locator: File for handle nonexistent.html does not exist. Could not find:
diff --git a/tests/template/templates/invalid/output/unknown_tag.html b/tests/template/templates/invalid/output/unknown_tag.html
new file mode 100644
index 0000000000..1489e5e31a
--- /dev/null
+++ b/tests/template/templates/invalid/output/unknown_tag.html
@@ -0,0 +1 @@
+<!-- UNKNOWNTAG variable.html -->
diff --git a/tests/template/templates/lang.html b/tests/template/templates/lang.html
index 2b5ea1cafe..3eecc298cb 100644
--- a/tests/template/templates/lang.html
+++ b/tests/template/templates/lang.html
@@ -1,3 +1,5 @@
{L_VARIABLE}
+{L_1_VARIABLE}
{LA_VARIABLE}
+{LA_1_VARIABLE}
diff --git a/tests/template/templates/loop.html b/tests/template/templates/loop.html
index de1a10004d..f541e934df 100644
--- a/tests/template/templates/loop.html
+++ b/tests/template/templates/loop.html
@@ -1,21 +1,21 @@
-<!-- BEGIN loop -->
+<!-- BEGIN test_loop -->
loop
<!-- BEGINELSE -->
noloop
-<!-- END loop -->
+<!-- END test_loop -->
-<!-- IF .loop -->
+<!-- IF .test_loop -->
loop
<!-- ELSE -->
noloop
<!-- ENDIF -->
-<!-- IF .loop == 2 -->
+<!-- IF .test_loop == 2 -->
loop
<!-- ENDIF -->
-<!-- BEGIN loop -->
+<!-- BEGIN test_loop -->
<!-- BEGIN !block -->
-loop#{loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT}
+loop#{test_loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT}
<!-- END !block -->
-<!-- END loop -->
+<!-- END test_loop -->
diff --git a/tests/template/templates/loop_advanced.html b/tests/template/templates/loop_advanced.html
index c75fe55f03..1f56686eaa 100644
--- a/tests/template/templates/loop_advanced.html
+++ b/tests/template/templates/loop_advanced.html
@@ -1,19 +1,19 @@
-<!-- BEGIN loop -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(0) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(0) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(0,-1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(0,-1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(1,1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(1,1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(0,1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(0,1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(2,4) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(2,4) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(0,-7) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(0,-7) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(-2,6) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(-2,6) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
x
-<!-- BEGIN loop(-2,-1) -->{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW}<!-- END loop -->
+<!-- BEGIN test_loop(-2,-1) -->{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW}<!-- END test_loop -->
diff --git a/tests/template/templates/loop_expressions.html b/tests/template/templates/loop_expressions.html
new file mode 100644
index 0000000000..6bff53f388
--- /dev/null
+++ b/tests/template/templates/loop_expressions.html
@@ -0,0 +1,11 @@
+<!-- BEGIN loop -->
+
+<!-- IF loop.S_ROW_NUM is even by 4 -->on<!-- ELSE -->off<!-- ENDIF -->
+
+<!-- END loop -->
+
+<!-- BEGIN loop -->
+
+<!-- IF loop.S_ROW_NUM is odd by 3 -->on<!-- ELSE -->off<!-- ENDIF -->
+
+<!-- END loop -->
diff --git a/tests/template/templates/loop_include.html b/tests/template/templates/loop_include.html
new file mode 100644
index 0000000000..7bbdfc4248
--- /dev/null
+++ b/tests/template/templates/loop_include.html
@@ -0,0 +1,4 @@
+<!-- BEGIN test_loop -->
+{test_loop.foo}
+ <!-- INCLUDE loop_include1.html -->
+<!-- END test_loop -->
diff --git a/tests/template/templates/loop_include1.html b/tests/template/templates/loop_include1.html
new file mode 100644
index 0000000000..851f6e6e75
--- /dev/null
+++ b/tests/template/templates/loop_include1.html
@@ -0,0 +1 @@
+{test_loop.foo}
diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html
index 9b251cd453..cf099ecc15 100644
--- a/tests/template/templates/loop_nested.html
+++ b/tests/template/templates/loop_nested.html
@@ -1,8 +1,6 @@
<!-- BEGIN outer -->
- outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
-
- <!-- BEGIN middle -->
- middle - {middle.S_ROW_COUNT}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
-
- <!-- END middle -->
+outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF --><!-- IF TEST_MORE -->[{outer.S_BLOCK_NAME}|{outer.S_NUM_ROWS}]<!-- ENDIF -->
+<!-- BEGIN middle -->
+middle - {outer.middle.S_ROW_COUNT}<!-- IF outer.middle.VARIABLE --> - {outer.middle.VARIABLE}<!-- ENDIF --><!-- IF TEST_MORE -->[{outer.middle.S_BLOCK_NAME}|{outer.middle.S_NUM_ROWS}]<!-- ENDIF -->
+<!-- END middle -->
<!-- END outer -->
diff --git a/tests/template/templates/loop_nested2.html b/tests/template/templates/loop_nested2.html
new file mode 100644
index 0000000000..3eeeb5e36a
--- /dev/null
+++ b/tests/template/templates/loop_nested2.html
@@ -0,0 +1,6 @@
+<!-- BEGIN outer -->
+o{outer.S_ROW_COUNT}
+<!-- BEGIN middle -->
+m{outer.middle.S_ROW_COUNT}{outer.S_ROW_COUNT}
+<!-- END middle -->
+<!-- END outer -->
diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref.html b/tests/template/templates/loop_nested_deep_multilevel_ref.html
new file mode 100644
index 0000000000..bcc2a7c07b
--- /dev/null
+++ b/tests/template/templates/loop_nested_deep_multilevel_ref.html
@@ -0,0 +1,13 @@
+top-level content
+<!-- BEGIN outer -->
+ outer
+ <!-- BEGIN middle -->
+ {outer.middle.S_BLOCK_NAME}
+ <!-- BEGIN inner -->
+ inner {inner.VARIABLE}
+ <!-- IF outer.middle.inner.S_FIRST_ROW -->
+ first row of {outer.middle.inner.S_NUM_ROWS} in {middle.inner.S_BLOCK_NAME}
+ <!-- ENDIF -->
+ <!-- END inner -->
+ <!-- END middle -->
+<!-- END outer -->
diff --git a/tests/template/templates/loop_nested_include.html b/tests/template/templates/loop_nested_include.html
new file mode 100644
index 0000000000..eaad46cc5b
--- /dev/null
+++ b/tests/template/templates/loop_nested_include.html
@@ -0,0 +1,4 @@
+<!-- BEGIN test_loop -->
+[{test_loop.foo}
+ |<!-- INCLUDE loop_nested_include1.html -->]
+<!-- END test_loop -->
diff --git a/tests/template/templates/loop_nested_include1.html b/tests/template/templates/loop_nested_include1.html
new file mode 100644
index 0000000000..88efffc99c
--- /dev/null
+++ b/tests/template/templates/loop_nested_include1.html
@@ -0,0 +1,5 @@
+[{test_loop.foo}|
+<!-- BEGIN test_loop.inner -->
+[{test_loop.foo}|
+{test_loop.inner.myinner}]
+<!-- END test_loop.inner -->]
diff --git a/tests/template/templates/loop_nested_multilevel_ref.html b/tests/template/templates/loop_nested_multilevel_ref.html
new file mode 100644
index 0000000000..f2f1c746ed
--- /dev/null
+++ b/tests/template/templates/loop_nested_multilevel_ref.html
@@ -0,0 +1,10 @@
+top-level content
+<!-- BEGIN outer -->
+ outer {outer.VARIABLE}
+ <!-- BEGIN inner -->
+ inner {inner.VARIABLE}
+ <!-- IF outer.inner.S_FIRST_ROW -->
+ first row
+ <!-- ENDIF -->
+ <!-- END inner -->
+<!-- END outer -->
diff --git a/tests/template/templates/loop_reuse.html b/tests/template/templates/loop_reuse.html
new file mode 100644
index 0000000000..bd0354ae6f
--- /dev/null
+++ b/tests/template/templates/loop_reuse.html
@@ -0,0 +1,6 @@
+<!-- BEGIN one -->
+ {one.VAR}
+ <!-- BEGIN one -->
+ {one.one.VAR}
+ <!-- END one -->
+<!-- END one -->
diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html
new file mode 100644
index 0000000000..2b1fcd2dd4
--- /dev/null
+++ b/tests/template/templates/loop_size.html
@@ -0,0 +1,39 @@
+<!-- IF .nonexistent_loop -->
+ nonexistent
+<!-- ENDIF -->
+
+<!-- IF .nonexistent_loop == 0 -->
+ nonexistent = 0
+<!-- ENDIF -->
+
+<!-- IF ! .nonexistent_loop -->
+ ! nonexistent
+<!-- ENDIF -->
+
+<!-- IF .empty_loop -->
+ empty
+<!-- ENDIF -->
+
+<!-- IF .empty_loop == 0 -->
+ empty = 0
+<!-- ENDIF -->
+
+<!-- IF ! .empty_loop -->
+ ! empty
+<!-- ENDIF -->
+
+<!-- IF .test_loop -->
+ loop
+<!-- ENDIF -->
+
+<!-- IF .test_loop == 0 -->
+ loop = 0
+<!-- ENDIF -->
+
+<!-- IF ! .test_loop -->
+ ! loop
+<!-- ENDIF -->
+
+<!-- BEGIN test_loop -->
+ in loop
+<!-- END test_loop -->
diff --git a/tests/template/templates/loop_underscore.html b/tests/template/templates/loop_underscore.html
new file mode 100644
index 0000000000..4001007868
--- /dev/null
+++ b/tests/template/templates/loop_underscore.html
@@ -0,0 +1,21 @@
+<!-- BEGIN _underscore_loop -->
+loop
+<!-- BEGINELSE -->
+noloop
+<!-- END _underscore_loop -->
+
+<!-- IF ._underscore_loop -->
+loop
+<!-- ELSE -->
+noloop
+<!-- ENDIF -->
+
+<!-- IF ._underscore_loop == 2 -->
+loop
+<!-- ENDIF -->
+
+<!-- BEGIN _underscore_loop -->
+<!-- BEGIN !block -->
+loop#{loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT}
+<!-- END !block -->
+<!-- END _underscore_loop -->
diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html
index 4f02fd2e6c..70a3eb2cec 100644
--- a/tests/template/templates/loop_vars.html
+++ b/tests/template/templates/loop_vars.html
@@ -1,21 +1,13 @@
-<!-- BEGIN loop -->
-<!-- IF loop.S_FIRST_ROW -->first<!-- ENDIF -->
-
-{loop.S_ROW_COUNT}
-
-{loop.VARIABLE}
-
-<!-- IF loop.VARIABLE -->set<!-- ENDIF -->
-
-<!-- IF loop.S_LAST_ROW -->
+<!-- BEGIN test_loop -->
+<!-- IF test_loop.S_FIRST_ROW -->first<!-- ENDIF -->
+{test_loop.S_ROW_NUM} - a
+{test_loop.VARIABLE} - b
+<!-- IF test_loop.VARIABLE -->set<!-- ENDIF -->
+<!-- IF test_loop.S_LAST_ROW -->
last
<!-- ENDIF -->
<!-- BEGIN inner -->
-
-{inner.S_ROW_COUNT}
-
-<!-- IF inner.S_LAST_ROW and inner.S_ROW_COUNT and inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
-
+{test_loop.inner.S_ROW_NUM} - c
+<!-- IF test_loop.inner.S_LAST_ROW and test_loop.inner.S_ROW_COUNT and test_loop.inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
<!-- END inner -->
-<!-- END loop -->
-<!-- IF .loop.inner -->inner loop<!-- ENDIF -->
+<!-- END test_loop -->
diff --git a/tests/template/templates/parent_and_child.html b/tests/template/templates/parent_and_child.html
new file mode 100644
index 0000000000..16223d91e7
--- /dev/null
+++ b/tests/template/templates/parent_and_child.html
@@ -0,0 +1 @@
+Child template.
diff --git a/tests/template/templates/parent_and_child.js b/tests/template/templates/parent_and_child.js
new file mode 100644
index 0000000000..d544d94d83
--- /dev/null
+++ b/tests/template/templates/parent_and_child.js
@@ -0,0 +1 @@
+// JavaScript file in a child style.
diff --git a/tests/template/templates/subdir/parent_only.js b/tests/template/templates/subdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/parent_only.js
diff --git a/tests/template/templates/subdir/subsubdir/parent_only.js b/tests/template/templates/subdir/subsubdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/subsubdir/parent_only.js
diff --git a/tests/template/templates/subdir/variable.html b/tests/template/templates/subdir/variable.html
new file mode 100644
index 0000000000..f68f91597c
--- /dev/null
+++ b/tests/template/templates/subdir/variable.html
@@ -0,0 +1 @@
+{VARIABLE}
diff --git a/tests/template/templates/trivial.html b/tests/template/templates/trivial.html
new file mode 100644
index 0000000000..3a1c1c5324
--- /dev/null
+++ b/tests/template/templates/trivial.html
@@ -0,0 +1 @@
+This is a trivial template.
diff --git a/tests/template/templates/twig.html b/tests/template/templates/twig.html
new file mode 100644
index 0000000000..17b94ad8d4
--- /dev/null
+++ b/tests/template/templates/twig.html
@@ -0,0 +1,6 @@
+<!-- EXTENDS "twig_parent.html" -->
+
+<!-- BLOCK overwritten -->
+3{VARIABLE|upper}|{VARIABLE|lower}
+<!-- ENDBLOCK -->
+
diff --git a/tests/template/templates/twig_parent.html b/tests/template/templates/twig_parent.html
new file mode 100644
index 0000000000..e9863221e1
--- /dev/null
+++ b/tests/template/templates/twig_parent.html
@@ -0,0 +1,7 @@
+<!-- BLOCK notoverwritten -->
+1
+<!-- ENDBLOCK -->
+
+<!-- BLOCK overwritten -->
+2
+<!-- ENDBLOCK -->
diff --git a/tests/template/templates/variable_spacing.html b/tests/template/templates/variable_spacing.html
new file mode 100644
index 0000000000..028f8aa0d1
--- /dev/null
+++ b/tests/template/templates/variable_spacing.html
@@ -0,0 +1,6 @@
+|{VARIABLE}|
+{VARIABLE}|{VARIABLE}|
+
+|{VARIABLE}
+
+<div class="{VARIABLE}">test</div>
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 ec59fa3886..db31edc984 100644
--- a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
+++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -21,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 28d3a716f0..fc1a3632f4 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -17,6 +21,12 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
protected $fixture_xml_data;
+ static protected $schema_file;
+
+ static protected $phpbb_schema_copy;
+
+ static protected $install_schema_file;
+
public function __construct($name = NULL, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
@@ -34,6 +44,58 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$this->db_connections = array();
}
+ /**
+ * @return array List of extensions that should be set up
+ */
+ static protected function setup_extensions()
+ {
+ return array();
+ }
+
+ static public function setUpBeforeClass()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $setup_extensions = static::setup_extensions();
+
+ $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
+ $finder->core_path('phpbb/db/migration/data/');
+ if (!empty($setup_extensions))
+ {
+ $finder->set_extensions($setup_extensions)
+ ->extension_directory('/migrations');
+ }
+ $classes = $finder->get_classes();
+
+ $schema_sha1 = sha1(serialize($classes));
+ self::$schema_file = __DIR__ . '/../tmp/' . $schema_sha1 . '.json';
+ self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
+
+ if (!file_exists(self::$schema_file))
+ {
+
+ global $table_prefix;
+
+ $db = new \phpbb\db\driver\sqlite();
+ $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
+ file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));
+ }
+
+ copy(self::$schema_file, self::$install_schema_file);
+
+ parent::setUpBeforeClass();
+ }
+
+ static public function tearDownAfterClass()
+ {
+ if (file_exists(self::$install_schema_file))
+ {
+ unlink(self::$install_schema_file);
+ }
+
+ parent::tearDownAfterClass();
+ }
+
protected function tearDown()
{
parent::tearDown();
@@ -79,25 +141,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'] == '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;
}
@@ -138,7 +182,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
if (!self::$already_connected)
{
- $manager->load_schema();
+ $manager->load_schema($this->new_dbal());
self::$already_connected = true;
}
@@ -147,13 +191,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
public function new_dbal()
{
- global $phpbb_root_path, $phpEx;
-
$config = $this->get_database_config();
- require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
- $dbal = 'dbal_' . $config['dbms'];
- $db = new $dbal();
+ $db = new $config['dbms']();
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
$this->db_connections[] = $db;
@@ -182,16 +222,19 @@ 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)
+ public function assert_array_content_equals($one, $two)
{
- return $matches[1] . strtoupper($matches[2]) . $matches[3];
+ // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important
+ // but one array_diff is not enough!
+ if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one)))
+ {
+ // get a nice error message
+ $this->assertEquals($one, $two);
+ }
+ else
+ {
+ // increase assertion count
+ $this->assertTrue(true);
+ }
}
}
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index 30f1fa6589..3b5bab749e 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -12,8 +16,11 @@ require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.ph
class phpbb_database_test_connection_manager
{
+ /** @var array */
private $config;
+ /** @var array */
private $dbms;
+ /** @var \PDO */
private $pdo;
/**
@@ -50,6 +57,7 @@ class phpbb_database_test_connection_manager
switch ($this->dbms['PDO'])
{
case 'sqlite2':
+ case 'sqlite': // SQLite3 driver
$dsn .= $this->config['dbhost'];
break;
@@ -77,11 +85,18 @@ class phpbb_database_test_connection_manager
break;
default:
- $dsn .= 'host=' . $this->config['dbhost'];
-
- if ($this->config['dbport'])
+ if (!empty($this->config['dbport']) && !is_numeric($this->config['dbport']) && $this->dbms['PDO'] != 'pgsql')
{
- $dsn .= ';port=' . $this->config['dbport'];
+ $dsn .= 'unix_socket=' . $this->config['dbport'];
+ }
+ else
+ {
+ $dsn .= 'host=' . $this->config['dbhost'];
+
+ if ($this->config['dbport'])
+ {
+ $dsn .= ';port=' . $this->config['dbport'];
+ }
}
if ($use_db)
@@ -108,7 +123,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'] == 'mssql' || $this->config['dbms'] == 'firebird'))
+ if (!empty($this->config['custom_dsn']) && $this->config['dbms'] == 'phpbb\db\driver\mssql')
{
$dsn = 'odbc:' . $this->config['custom_dsn'];
}
@@ -117,19 +132,11 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
- case 'mssql':
- case 'mssql_odbc':
+ case 'phpbb\db\driver\mssql':
+ case 'phpbb\db\driver\mssql_odbc':
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break;
- case '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;
@@ -138,15 +145,15 @@ class phpbb_database_test_connection_manager
catch (PDOException $e)
{
$cleaned_dsn = str_replace($this->config['dbpasswd'], '*password*', $dsn);
- throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");
+ throw new Exception("Unable to connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");
}
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
switch ($this->config['dbms'])
{
- case 'mysql':
- case 'mysqli':
+ case 'phpbb\db\driver\mysql':
+ case 'phpbb\db\driver\mysqli':
$this->pdo->exec('SET NAMES utf8');
/*
@@ -169,12 +176,12 @@ class phpbb_database_test_connection_manager
/**
* Load the phpBB database schema into the database
*/
- public function load_schema()
+ public function load_schema($db)
{
$this->ensure_connected(__METHOD__);
$directory = dirname(__FILE__) . '/../../phpBB/install/schemas/';
- $this->load_schema_from_file($directory);
+ $this->load_schema_from_file($directory, $db);
}
/**
@@ -187,8 +194,8 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
- case 'sqlite':
- case 'firebird':
+ case 'phpbb\db\driver\sqlite':
+ case 'phpbb\db\driver\sqlite3':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -198,7 +205,7 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
- case 'oracle':
+ case 'phpbb\db\driver\oracle':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -208,7 +215,7 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
- case 'postgres':
+ case 'phpbb\db\driver\postgres':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -258,39 +265,38 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
- case 'mysql':
- case 'mysql4':
- case 'mysqli':
+ case 'phpbb\db\driver\mysql':
+ case 'phpbb\db\driver\mysqli':
$sql = 'SHOW TABLES';
break;
- case 'sqlite':
+ case 'phpbb\db\driver\sqlite':
$sql = 'SELECT name
FROM sqlite_master
WHERE type = "table"';
break;
- case 'mssql':
- case 'mssql_odbc':
- case 'mssqlnative':
+ case 'phpbb\db\driver\sqlite3':
+ $sql = 'SELECT name
+ FROM sqlite_master
+ WHERE type = "table"
+ AND name <> "sqlite_sequence"';
+ break;
+
+ case 'phpbb\db\driver\mssql':
+ case 'phpbb\db\driver\mssql_odbc':
+ case 'phpbb\db\driver\mssqlnative':
$sql = "SELECT name
FROM sysobjects
WHERE type='U'";
break;
- case 'postgres':
+ case 'phpbb\db\driver\postgres':
$sql = 'SELECT relname
FROM pg_stat_user_tables';
break;
- case 'firebird':
- $sql = 'SELECT rdb$relation_name
- FROM rdb$relations
- WHERE rdb$view_source is null
- AND rdb$system_flag = 0';
- break;
-
- case 'oracle':
+ case 'phpbb\db\driver\oracle':
$sql = 'SELECT table_name
FROM USER_TABLES';
break;
@@ -322,11 +328,11 @@ class phpbb_database_test_connection_manager
* Compile the correct schema filename (as per create_schema_files) and
* load it into the database.
*/
- protected function load_schema_from_file($directory)
+ protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db)
{
$schema = $this->dbms['SCHEMA'];
- if ($this->config['dbms'] == 'mysql')
+ if ($this->config['dbms'] == 'phpbb\db\driver\mysql')
{
$sth = $this->pdo->query('SELECT VERSION() AS version');
$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -343,14 +349,61 @@ 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)
+ // Ok we have the db info go ahead and work on building the table
+ if (file_exists($directory . 'schema.json'))
{
- $this->pdo->exec($query);
+ $db_table_schema = file_get_contents($directory . 'schema.json');
+ $db_table_schema = json_decode($db_table_schema, true);
+ }
+ else
+ {
+ global $phpbb_root_path, $phpEx, $table_prefix;
+
+ $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
+ $classes = $finder->core_path('phpbb/db/migration/data/')
+ ->get_classes();
+
+ $db = new \phpbb\db\driver\sqlite();
+ $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
+ $db_table_schema = $schema_generator->get_schema();
+ }
+
+ $db_tools = new \phpbb\db\tools($db, true);
+ foreach ($db_table_schema as $table_name => $table_data)
+ {
+ $queries = $db_tools->sql_create_table(
+ $table_name,
+ $table_data
+ );
+
+ foreach ($queries as $query)
+ {
+ if ($query === 'begin')
+ {
+ $this->pdo->beginTransaction();
+ }
+ else if ($query === 'commit')
+ {
+ $this->pdo->commit();
+ }
+ else
+ {
+ $this->pdo->exec($query);
+ }
+ }
}
}
@@ -360,51 +413,51 @@ class phpbb_database_test_connection_manager
protected function get_dbms_data($dbms)
{
$available_dbms = array(
- 'firebird' => array(
- 'SCHEMA' => 'firebird',
- 'DELIM' => ';;',
- 'PDO' => 'firebird',
- ),
- 'mysqli' => array(
+ 'phpbb\db\driver\mysqli' => array(
'SCHEMA' => 'mysql_41',
'DELIM' => ';',
'PDO' => 'mysql',
),
- 'mysql' => array(
+ 'phpbb\db\driver\mysql' => array(
'SCHEMA' => 'mysql',
'DELIM' => ';',
'PDO' => 'mysql',
),
- 'mssql' => array(
+ 'phpbb\db\driver\mssql' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
),
- 'mssql_odbc'=> array(
+ 'phpbb\db\driver\mssql_odbc'=> array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
),
- 'mssqlnative' => array(
+ 'phpbb\db\driver\mssqlnative' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'sqlsrv',
),
- 'oracle' => array(
+ 'phpbb\db\driver\oracle' => array(
'SCHEMA' => 'oracle',
'DELIM' => '/',
'PDO' => 'oci',
),
- 'postgres' => array(
+ 'phpbb\db\driver\postgres' => array(
'SCHEMA' => 'postgres',
'DELIM' => ';',
'PDO' => 'pgsql',
),
- 'sqlite' => array(
+ 'phpbb\db\driver\sqlite' => array(
'SCHEMA' => 'sqlite',
'DELIM' => ';',
'PDO' => 'sqlite2',
),
+ 'phpbb\db\driver\sqlite3' => array(
+ 'SCHEMA' => 'sqlite',
+ 'DELIM' => ';',
+ 'PDO' => 'sqlite',
+ ),
);
if (isset($available_dbms[$dbms]))
@@ -429,19 +482,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
- case '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 'oracle':
+ case 'phpbb\db\driver\oracle':
$sql = 'SELECT sequence_name
FROM USER_SEQUENCES';
$result = $this->pdo->query($sql);
@@ -452,7 +493,7 @@ class phpbb_database_test_connection_manager
}
break;
- case 'postgres':
+ case 'phpbb\db\driver\postgres':
$sql = 'SELECT sequence_name
FROM information_schema.sequences';
$result = $this->pdo->query($sql);
@@ -510,7 +551,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
- case 'oracle':
+ case 'phpbb\db\driver\oracle':
// Get all of the information about the sequences
$sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value
FROM USER_TRIGGERS t
@@ -545,14 +586,14 @@ class phpbb_database_test_connection_manager
* Since we have no objects attached to our sequencers (triggers aren't attached), this works fine.
*/
$queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME'];
- $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']}
- MINVALUE {$row['MIN_VALUE']}
- INCREMENT BY {$row['INCREMENT_BY']}
+ $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']}
+ MINVALUE {$row['MIN_VALUE']}
+ INCREMENT BY {$row['INCREMENT_BY']}
START WITH $max_val";
}
break;
- case 'postgres':
+ case 'phpbb\db\driver\postgres':
// Get the sequences attached to the tables
$sql = 'SELECT column_name, table_name FROM information_schema.columns
WHERE table_name IN (' . implode(', ', $table_names) . ")
@@ -592,6 +633,14 @@ class phpbb_database_test_connection_manager
$queries[] = 'SELECT ' . implode(', ', $setval_queries);
}
break;
+
+ case 'phpbb\db\driver\sqlite3':
+ /**
+ * Just delete all of the sequences. When an insertion occurs, the sequence will be automatically
+ * re-created from the key with the AUTOINCREMENT attribute
+ */
+ $queries[] = 'DELETE FROM sqlite_sequence';
+ break;
}
foreach ($queries as $query)
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 9b64600c7d..8107e45dc7 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -1,16 +1,18 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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 Symfony\Component\BrowserKit\CookieJar;
require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
-require_once __DIR__ . '/../../phpBB/includes/acm/acm_file.php';
-require_once __DIR__ . '/../../phpBB/includes/cache.php';
class phpbb_functional_test_case extends phpbb_test_case
{
@@ -20,6 +22,7 @@ class phpbb_functional_test_case extends phpbb_test_case
protected $cache = null;
protected $db = null;
+ protected $extension_manager = null;
/**
* Session ID for current test's session (each test makes its own)
@@ -35,6 +38,7 @@ class phpbb_functional_test_case extends phpbb_test_case
static protected $config = array();
static protected $already_installed = false;
+ static protected $last_post_timestamp = 0;
static public function setUpBeforeClass()
{
@@ -43,6 +47,12 @@ 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'];
+ // 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
+ // installed, and also before each test case is run.
+ self::$config['table_prefix'] = 'phpbb_';
+
if (!isset(self::$config['phpbb_functional_url']))
{
self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
@@ -55,6 +65,14 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
+ /**
+ * @return array List of extensions that should be set up
+ */
+ static protected function setup_extensions()
+ {
+ return array();
+ }
+
public function setUp()
{
parent::setUp();
@@ -71,7 +89,36 @@ class phpbb_functional_test_case extends phpbb_test_case
// that were added in other tests are gone
$this->lang = array();
$this->add_lang('common');
- $this->purge_cache();
+
+ $db = $this->get_db();
+
+ foreach (static::setup_extensions() as $extension)
+ {
+ $this->purge_cache();
+
+ $sql = 'SELECT ext_active
+ FROM ' . EXT_TABLE . "
+ WHERE ext_name = '" . $db->sql_escape($extension). "'";
+ $result = $db->sql_query($sql);
+ $status = (bool) $db->sql_fetchfield('ext_active');
+ $db->sql_freeresult($result);
+
+ if (!$status)
+ {
+ $this->install_ext($extension);
+ }
+ }
+ }
+
+ 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();
+ }
}
/**
@@ -132,18 +179,23 @@ class phpbb_functional_test_case extends phpbb_test_case
{
}
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_test_case' => array('config', 'already_installed'),
+ );
+ }
+
protected function get_db()
{
global $phpbb_root_path, $phpEx;
// so we don't reopen an open connection
- if (!($this->db instanceof dbal))
+ if (!($this->db instanceof \phpbb\db\driver\driver_interface))
{
- if (!class_exists('dbal_' . self::$config['dbms']))
- {
- include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
- }
- $sql_db = 'dbal_' . self::$config['dbms'];
- $this->db = new $sql_db();
+ $dbms = self::$config['dbms'];
+ $this->db = new $dbms();
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
}
return $this->db;
@@ -153,7 +205,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
if (!$this->cache)
{
- $this->cache = new cache();
+ $this->cache = new \phpbb\cache\driver\file;
}
return $this->cache;
@@ -168,20 +220,50 @@ class phpbb_functional_test_case extends phpbb_test_case
$cache->load();
}
- public function __construct($name = NULL, array $data = array(), $dataName = '')
+ protected function get_extension_manager()
{
- parent::__construct($name, $data, $dataName);
+ global $phpbb_root_path, $phpEx;
- $this->backupStaticAttributesBlacklist += array(
- 'phpbb_functional_test_case' => array('config', 'already_installed'),
+ $config = new \phpbb\config\config(array());
+ $db = $this->get_db();
+ $db_tools = new \phpbb\db\tools($db);
+
+ $container = new phpbb_mock_container_builder();
+ $migrator = new \phpbb\db\migrator(
+ $container,
+ $config,
+ $db,
+ $db_tools,
+ self::$config['table_prefix'] . 'migrations',
+ $phpbb_root_path,
+ $phpEx,
+ self::$config['table_prefix'],
+ array(),
+ new \phpbb\db\migration\helper()
);
+ $container->set('migrator', $migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
+ $user = new \phpbb\user('\phpbb\datetime');
+
+ $extension_manager = new \phpbb\extension\manager(
+ $container,
+ $db,
+ $config,
+ new phpbb\filesystem(),
+ $user,
+ self::$config['table_prefix'] . 'ext',
+ dirname(__FILE__) . '/',
+ $phpEx,
+ $this->get_cache_driver()
+ );
+
+ return $extension_manager;
}
static protected function install_board()
{
global $phpbb_root_path, $phpEx;
- self::$config['table_prefix'] = 'phpbb_';
self::recreate_database(self::$config);
$config_file = $phpbb_root_path . "config.$phpEx";
@@ -216,7 +298,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$parseURL = parse_url(self::$config['phpbb_functional_url']);
- $crawler = self::request('GET', 'install/index.php?mode=install');
+ $crawler = self::request('GET', 'install/index.php?mode=install&language=en');
self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
@@ -230,7 +312,7 @@ class phpbb_functional_test_case extends phpbb_test_case
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']),
+ 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']),
'dbhost' => self::$config['dbhost'],
'dbport' => self::$config['dbport'],
'dbname' => self::$config['dbname'],
@@ -252,8 +334,7 @@ class phpbb_functional_test_case extends phpbb_test_case
'admin_name' => 'admin',
'admin_pass1' => 'adminadmin',
'admin_pass2' => 'adminadmin',
- 'board_email1' => 'nobody@example.com',
- 'board_email2' => 'nobody@example.com',
+ 'board_email' => 'nobody@example.com',
));
// install/index.php?mode=install&sub=administrator
@@ -265,7 +346,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// 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'], array(), true, true);
+ $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)
{
@@ -317,6 +398,36 @@ class phpbb_functional_test_case extends phpbb_test_case
copy($config_file, $config_file_test);
}
+ public function install_ext($extension)
+ {
+ $this->login();
+ $this->admin_login();
+
+ $ext_path = str_replace('/', '%2F', $extension);
+
+ $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid);
+ $this->assertGreaterThan(0, $crawler->filter('.submit-buttons')->count());
+
+ $form = $crawler->selectButton('Enable')->form();
+ $crawler = self::submit($form);
+ $this->add_lang('acp/extensions');
+
+ $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]');
+
+ // Wait for extension to be fully enabled
+ while (sizeof($meta_refresh))
+ {
+ preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match);
+ $url = $match[1];
+ $crawler = self::request('POST', $url);
+ $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]');
+ }
+
+ $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text());
+
+ $this->logout();
+ }
+
static private function recreate_database($config)
{
$db_conn_mgr = new phpbb_database_test_connection_manager($config);
@@ -336,51 +447,67 @@ class phpbb_functional_test_case extends phpbb_test_case
global $phpbb_root_path;
$db = $this->get_db();
- $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array(
- 'style_id' => $style_id,
- 'style_name' => $style_path,
- 'style_copyright' => '',
- 'style_active' => 1,
- 'template_id' => $style_id,
- 'theme_id' => $style_id,
- 'imageset_id' => $style_id,
- ));
- $db->sql_query($sql);
-
- $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array(
- 'imageset_id' => $style_id,
- 'imageset_name' => $style_path,
- 'imageset_copyright' => '',
- 'imageset_path' => $style_path,
- ));
- $db->sql_query($sql);
-
- $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array(
- 'template_id' => $style_id,
- 'template_name' => $style_path,
- 'template_copyright' => '',
- 'template_path' => $style_path,
- 'bbcode_bitfield' => 'kNg=',
- 'template_inherits_id' => $parent_style_id,
- 'template_inherit_path' => $parent_style_path,
- ));
- $db->sql_query($sql);
-
- $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array(
- 'theme_id' => $style_id,
- 'theme_name' => $style_path,
- 'theme_copyright' => '',
- 'theme_path' => $style_path,
- 'theme_storedb' => 0,
- 'theme_mtime' => 0,
- 'theme_data' => '',
- ));
- $db->sql_query($sql);
-
- if ($style_path != 'prosilver' && $style_path != 'subsilver2')
+ if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<'))
+ {
+ $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array(
+ 'style_id' => $style_id,
+ 'style_name' => $style_path,
+ 'style_copyright' => '',
+ 'style_active' => 1,
+ 'template_id' => $style_id,
+ 'theme_id' => $style_id,
+ 'imageset_id' => $style_id,
+ ));
+ $db->sql_query($sql);
+
+ $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array(
+ 'imageset_id' => $style_id,
+ 'imageset_name' => $style_path,
+ 'imageset_copyright' => '',
+ 'imageset_path' => $style_path,
+ ));
+ $db->sql_query($sql);
+
+ $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array(
+ 'template_id' => $style_id,
+ 'template_name' => $style_path,
+ 'template_copyright' => '',
+ 'template_path' => $style_path,
+ 'bbcode_bitfield' => 'kNg=',
+ 'template_inherits_id' => $parent_style_id,
+ 'template_inherit_path' => $parent_style_path,
+ ));
+ $db->sql_query($sql);
+
+ $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array(
+ 'theme_id' => $style_id,
+ 'theme_name' => $style_path,
+ 'theme_copyright' => '',
+ 'theme_path' => $style_path,
+ 'theme_storedb' => 0,
+ 'theme_mtime' => 0,
+ 'theme_data' => '',
+ ));
+ $db->sql_query($sql);
+
+ if ($style_path != 'prosilver' && $style_path != 'subsilver2')
+ {
+ @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777);
+ @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777);
+ }
+ }
+ else
{
- @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777);
- @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777);
+ $db->sql_multi_insert(STYLES_TABLE, array(array(
+ 'style_id' => $style_id,
+ 'style_name' => $style_path,
+ 'style_copyright' => '',
+ 'style_active' => 1,
+ 'style_path' => $style_path,
+ 'bbcode_bitfield' => 'kNg=',
+ 'style_parent_id' => $parent_style_id,
+ 'style_parent_tree' => $parent_style_path,
+ )));
}
}
@@ -396,14 +523,17 @@ class phpbb_functional_test_case extends phpbb_test_case
$db = $this->get_db();
$db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id);
- $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id);
- $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id);
- $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id);
-
- if ($style_path != 'prosilver' && $style_path != 'subsilver2')
+ if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<'))
{
- @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template');
- @rmdir($phpbb_root_path . 'styles/' . $style_path);
+ $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id);
+ $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id);
+ $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id);
+
+ if ($style_path != 'prosilver' && $style_path != 'subsilver2')
+ {
+ @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template');
+ @rmdir($phpbb_root_path . 'styles/' . $style_path);
+ }
}
}
@@ -418,10 +548,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// Required by unique_id
global $config;
- if (!is_array($config))
- {
- $config = array();
- }
+ $config = new \phpbb\config\config(array());
/*
* Add required config entries to the config array to prevent
@@ -436,7 +563,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$config['rand_seed_last_update'] = time() + 600;
// Required by user_add
- global $db, $cache;
+ global $db, $cache, $phpbb_dispatcher, $phpbb_container;
$db = $this->get_db();
if (!function_exists('phpbb_mock_null_cache'))
{
@@ -444,6 +571,12 @@ class phpbb_functional_test_case extends phpbb_test_case
}
$cache = new phpbb_mock_null_cache;
+ $cache_driver = new \phpbb\cache\driver\null();
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_container->set('cache.driver', $cache_driver);
+ $phpbb_notifications = new phpbb_mock_notification_manager();
+ $phpbb_container->set('notification_manager', $phpbb_notifications);
+
if (!function_exists('utf_clean_string'))
{
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
@@ -452,6 +585,10 @@ class phpbb_functional_test_case extends phpbb_test_case
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}
+ set_config(null, null, null, $config);
+ set_config_count(null, null, null, $config);
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $passwords_manager = $this->get_passwords_manager();
$user_row = array(
'username' => $username,
@@ -459,13 +596,94 @@ class phpbb_functional_test_case extends phpbb_test_case
'user_email' => 'nobody@example.com',
'user_type' => 0,
'user_lang' => 'en',
- 'user_timezone' => 0,
- 'user_dateformat' => '',
- 'user_password' => phpbb_hash($username . $username),
+ 'user_timezone' => 'UTC',
+ 'user_dateformat' => 'r',
+ 'user_password' => $passwords_manager->hash($username . $username),
);
return user_add($user_row);
}
+ protected function remove_user_group($group_name, $usernames)
+ {
+ global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx;
+
+ $config = new \phpbb\config\config(array());
+ $config['coppa_enable'] = 0;
+
+ $db = $this->get_db();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+ $cache = new phpbb_mock_null_cache;
+
+ $cache_driver = new \phpbb\cache\driver\null();
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_container->set('cache.driver', $cache_driver);
+ $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
+
+ if (!function_exists('utf_clean_string'))
+ {
+ require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
+ }
+ if (!function_exists('group_user_del'))
+ {
+ require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
+ }
+
+ $sql = 'SELECT group_id
+ FROM ' . GROUPS_TABLE . "
+ WHERE group_name = '" . $db->sql_escape($group_name) . "'";
+ $result = $db->sql_query($sql);
+ $group_id = (int) $db->sql_fetchfield('group_id');
+ $db->sql_freeresult($result);
+
+ return group_user_del($group_id, false, $usernames, $group_name);
+ }
+
+ protected function add_user_group($group_name, $usernames, $default = false, $leader = false)
+ {
+ global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx;
+
+ $config = new \phpbb\config\config(array());
+ $config['coppa_enable'] = 0;
+
+ $db = $this->get_db();
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $auth = $this->getMock('\phpbb\auth\auth');
+
+ $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
+ $cache = new phpbb_mock_null_cache;
+
+ $cache_driver = new \phpbb\cache\driver\null();
+ $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $phpbb_container
+ ->expects($this->any())
+ ->method('get')
+ ->with('cache.driver')
+ ->will($this->returnValue($cache_driver));
+
+ if (!function_exists('utf_clean_string'))
+ {
+ require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
+ }
+ if (!function_exists('group_user_del'))
+ {
+ require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
+ }
+
+ $sql = 'SELECT group_id
+ FROM ' . GROUPS_TABLE . "
+ WHERE group_name = '" . $db->sql_escape($group_name) . "'";
+ $result = $db->sql_query($sql);
+ $group_id = (int) $db->sql_fetchfield('group_id');
+ $db->sql_freeresult($result);
+
+ return group_user_add($group_id, false, $usernames, $group_name, $default, $leader);
+ }
+
protected function login($username = 'admin')
{
$this->add_lang('ucp');
@@ -475,7 +693,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$form = $crawler->selectButton($this->lang('LOGIN'))->form();
$crawler = self::submit($form, array('username' => $username, 'password' => $username . $username));
- $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
+ $this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text());
$cookies = self::$cookieJar->all();
@@ -489,6 +707,16 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
+ protected function logout()
+ {
+ $this->add_lang('ucp');
+
+ $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
+ $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
+ unset($this->sid);
+
+ }
+
/**
* Login to the ACP
* You must run login() before calling this.
@@ -514,7 +742,7 @@ class phpbb_functional_test_case extends phpbb_test_case
if (strpos($field, 'password_') === 0)
{
$crawler = self::submit($form, array('username' => $username, $field => $username . $username));
- $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text());
+ $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
$cookies = self::$cookieJar->all();
@@ -554,6 +782,30 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->lang = array_merge($this->lang, $lang);
}
+ protected function add_lang_ext($ext_name, $lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang_ext($ext_name, $file);
+ }
+
+ return;
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/ext/{$ext_name}/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
protected function lang()
{
$args = func_get_args();
@@ -570,6 +822,30 @@ class phpbb_functional_test_case extends phpbb_test_case
}
/**
+ * assertContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ /**
+ * assertNotContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertNotContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertNotContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ /*
* Perform some basic assertions for the page
*
* Checks for debug/error output before the actual page content and the status code
@@ -579,15 +855,36 @@ class phpbb_functional_test_case extends phpbb_test_case
*/
static public function assert_response_html($status_code = 200)
{
+ // Any output before the doc type means there was an error
+ $content = self::$client->getResponse()->getContent();
+ self::assertNotContains('[phpBB Debug]', $content);
+ self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
+
if ($status_code !== false)
{
self::assert_response_status_code($status_code);
}
+ }
- // Any output before the doc type means there was an error
+ /*
+ * Perform some basic assertions for an xml page
+ *
+ * Checks for debug/error output before the actual page content and the status code
+ *
+ * @param mixed $status_code Expected status code, false to disable check
+ * @return null
+ */
+ static public function assert_response_xml($status_code = 200)
+ {
+ // Any output before the xml opening means there was an error
$content = self::$client->getResponse()->getContent();
self::assertNotContains('[phpBB Debug]', $content);
- self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
+ self::assertStringStartsWith('<?xml', trim($content), 'Output found before XML specification.');
+
+ if ($status_code !== false)
+ {
+ self::assert_response_status_code($status_code);
+ }
}
/**
@@ -604,6 +901,86 @@ class phpbb_functional_test_case extends phpbb_test_case
self::assertEquals($status_code, self::$client->getResponse()->getStatus(), 'HTTP status code does not match');
}
+ public function assert_filter($crawler, $expr, $msg = null)
+ {
+ $nodes = $crawler->filter($expr);
+ if ($msg)
+ {
+ $msg .= "\n";
+ }
+ else
+ {
+ $msg = '';
+ }
+ $msg .= "`$expr` not found in DOM.";
+ $this->assertGreaterThan(0, count($nodes), $msg);
+ return $nodes;
+ }
+
+ /**
+ * Asserts that exactly one checkbox with name $name exists within the scope
+ * of $crawler and that the checkbox is checked.
+ *
+ * @param Symfony\Component\DomCrawler\Crawler $crawler
+ * @param string $name
+ * @param string $message
+ *
+ * @return null
+ */
+ public function assert_checkbox_is_checked($crawler, $name, $message = '')
+ {
+ $this->assertSame(
+ 'checked',
+ $this->assert_find_one_checkbox($crawler, $name)->attr('checked'),
+ $message ?: "Failed asserting that checkbox $name is checked."
+ );
+ }
+
+ /**
+ * Asserts that exactly one checkbox with name $name exists within the scope
+ * of $crawler and that the checkbox is unchecked.
+ *
+ * @param Symfony\Component\DomCrawler\Crawler $crawler
+ * @param string $name
+ * @param string $message
+ *
+ * @return null
+ */
+ public function assert_checkbox_is_unchecked($crawler, $name, $message = '')
+ {
+ $this->assertSame(
+ '',
+ $this->assert_find_one_checkbox($crawler, $name)->attr('checked'),
+ $message ?: "Failed asserting that checkbox $name is unchecked."
+ );
+ }
+
+ /**
+ * Searches for an input element of type checkbox with the name $name using
+ * $crawler. Contains an assertion that only one such checkbox exists within
+ * the scope of $crawler.
+ *
+ * @param Symfony\Component\DomCrawler\Crawler $crawler
+ * @param string $name
+ * @param string $message
+ *
+ * @return Symfony\Component\DomCrawler\Crawler
+ */
+ public function assert_find_one_checkbox($crawler, $name, $message = '')
+ {
+ $query = sprintf('//input[@type="checkbox" and @name="%s"]', $name);
+ $result = $crawler->filterXPath($query);
+
+ $this->assertEquals(
+ 1,
+ sizeof($result),
+ $message ?: 'Failed asserting that exactly one checkbox with name' .
+ " $name exists in crawler scope."
+ );
+
+ return $result;
+ }
+
/**
* Creates a topic
*
@@ -613,9 +990,10 @@ class phpbb_functional_test_case extends phpbb_test_case
* @param string $subject
* @param string $message
* @param array $additional_form_data Any additional form data to be sent in the request
- * @return array post_id, topic_id
+ * @param string $expected Lang var of expected message after posting
+ * @return array|null post_id, topic_id if message is empty
*/
- public function create_topic($forum_id, $subject, $message, $additional_form_data = array())
+ public function create_topic($forum_id, $subject, $message, $additional_form_data = array(), $expected = '')
{
$posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}";
@@ -625,7 +1003,7 @@ class phpbb_functional_test_case extends phpbb_test_case
'post' => true,
), $additional_form_data);
- return self::submit_post($posting_url, 'POST_TOPIC', $form_data);
+ return self::submit_post($posting_url, 'POST_TOPIC', $form_data, $expected);
}
/**
@@ -638,9 +1016,10 @@ class phpbb_functional_test_case extends phpbb_test_case
* @param string $subject
* @param string $message
* @param array $additional_form_data Any additional form data to be sent in the request
- * @return array post_id, topic_id
+ * @param string $expected Lang var of expected message after posting
+ * @return array|null post_id, topic_id if message is empty
*/
- public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array())
+ public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array(), $expected = '')
{
$posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}";
@@ -650,7 +1029,7 @@ class phpbb_functional_test_case extends phpbb_test_case
'post' => true,
), $additional_form_data);
- return self::submit_post($posting_url, 'POST_REPLY', $form_data);
+ return self::submit_post($posting_url, 'POST_REPLY', $form_data, $expected);
}
/**
@@ -659,16 +1038,29 @@ class phpbb_functional_test_case extends phpbb_test_case
* @param string $posting_url
* @param string $posting_contains
* @param array $form_data
- * @return array post_id, topic_id
+ * @param string $expected Lang var of expected message after posting
+ * @return array|null post_id, topic_id if message is empty
*/
- protected function submit_post($posting_url, $posting_contains, $form_data)
+ protected function submit_post($posting_url, $posting_contains, $form_data, $expected = '')
{
$this->add_lang('posting');
$crawler = $this->submit_message($posting_url, $posting_contains, $form_data);
- $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
- $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
+ 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'),
@@ -722,10 +1114,33 @@ class phpbb_functional_test_case extends phpbb_test_case
*/
protected function submit_message($posting_url, $posting_contains, $form_data)
{
+ if (time() == self::$last_post_timestamp)
+ {
+ // Travis is too fast, so we have to wait to not mix up the post/topic order
+ sleep(1);
+ }
+ self::$last_post_timestamp = time();
$crawler = self::request('GET', $posting_url);
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
+ if (!empty($form_data['upload_files']))
+ {
+ for ($i = 0; $i < $form_data['upload_files']; $i++)
+ {
+ $file = array(
+ 'tmp_name' => __DIR__ . '/../functional/fixtures/files/valid.jpg',
+ 'name' => 'valid.jpg',
+ 'type' => 'image/jpeg',
+ 'size' => filesize(__DIR__ . '/../functional/fixtures/files/valid.jpg'),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = self::$client->request('POST', $posting_url, array('add_file' => $this->lang('ADD_FILE')), array('fileupload' => $file));
+ }
+ unset($form_data['upload_files']);
+ }
+
$hidden_fields = array(
$crawler->filter('[type="hidden"]')->each(function ($node, $i) {
return array('name' => $node->attr('name'), 'value' => $node->attr('value'));
@@ -751,6 +1166,48 @@ class phpbb_functional_test_case extends phpbb_test_case
}
/**
+ * Deletes a topic
+ *
+ * Be sure to login before creating
+ *
+ * @param int $topic_id
+ * @return null
+ */
+ public function delete_topic($topic_id)
+ {
+ $this->add_lang('posting');
+ $crawler = $this->get_quickmod_page($topic_id, 'DELETE_TOPIC');
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $form['delete_permanent'] = 1;
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+ }
+
+ /**
+ * Deletes a post
+ *
+ * Be sure to login before creating
+ *
+ * @param int $forum_id
+ * @param int $topic_id
+ * @return null
+ */
+ public function delete_post($forum_id, $post_id)
+ {
+ $this->add_lang('posting');
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$forum_id}&p={$post_id}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $form['delete_permanent'] = 1;
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+ }
+
+ /**
* Returns the requested parameter from a URL
*
* @param string $url
@@ -785,4 +1242,50 @@ class phpbb_functional_test_case extends phpbb_test_case
}
return null;
}
+
+ /**
+ * Return a passwords manager instance
+ *
+ * @return phpbb\passwords\manager
+ */
+ public function get_passwords_manager()
+ {
+ // Prepare dependencies for manager and driver
+ $config = new \phpbb\config\config(array());
+ $driver_helper = new \phpbb\passwords\driver\helper($config);
+
+ $passwords_drivers = array(
+ 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper),
+ 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper),
+ 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper),
+ 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper),
+ );
+
+ $passwords_helper = new \phpbb\passwords\helper;
+ // Set up passwords manager
+ $manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
+
+ 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_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php
new file mode 100644
index 0000000000..b37ed1d039
--- /dev/null
+++ b/tests/test_framework/phpbb_search_test_case.php
@@ -0,0 +1,33 @@
+<?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.
+*
+*/
+
+abstract class phpbb_search_test_case extends phpbb_database_test_case
+{
+ static protected function get_search_wrapper($class)
+ {
+ $wrapped = str_replace('\\', '_', $class) . '_wrapper';
+ if (!class_exists($wrapped))
+ {
+ $code = "
+class $wrapped extends $class
+{
+ public function get_must_contain_ids() { return \$this->must_contain_ids; }
+ public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; }
+ public function get_split_words() { return \$this->split_words; }
+}
+ ";
+ eval($code);
+ }
+ return $wrapped;
+ }
+}
diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php
new file mode 100644
index 0000000000..1bf0277fe0
--- /dev/null
+++ b/tests/test_framework/phpbb_session_test_case.php
@@ -0,0 +1,60 @@
+<?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__) . '/../session/testable_factory.php';
+require_once dirname(__FILE__) . '/../session/testable_facade.php';
+
+abstract class phpbb_session_test_case extends phpbb_database_test_case
+{
+ /** @var phpbb_session_testable_factory */
+ protected $session_factory;
+
+ /** @var phpbb_session_testable_facade */
+ protected $session_facade;
+
+ /** @var \phpbb\db\driver\driver_interface */
+ protected $db;
+
+ function setUp()
+ {
+ parent::setUp();
+
+ global $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $request, $phpbb_root_path, $phpEx;
+ $symfony_request = new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ );
+ $phpbb_filesystem = new \phpbb\filesystem();
+ $phpbb_path_helper = new \phpbb\path_helper(
+ $symfony_request,
+ $phpbb_filesystem,
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ );
+
+ $this->session_factory = new phpbb_session_testable_factory;
+ $this->db = $this->new_dbal();
+ $this->session_facade =
+ new phpbb_session_testable_facade($this->db, $this->session_factory);
+ }
+
+ protected function check_sessions_equals($expected_sessions, $message)
+ {
+ $sql = 'SELECT session_id, session_user_id
+ FROM phpbb_sessions
+ ORDER BY session_user_id';
+
+ $this->assertSqlResultEquals($expected_sessions, $sql, $message);
+ }
+}
diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php
index 8b16f02638..01d26fb67d 100644
--- a/tests/test_framework/phpbb_test_case.php
+++ b/tests/test_framework/phpbb_test_case.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -22,7 +26,7 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase
'PHP_Token_Stream' => array('customTokens'),
'PHP_Token_Stream_CachingFactory' => array('cache'),
- 'phpbb_database_test_case' => array('already_connected'),
+ 'phpbb_database_test_case' => array('already_connected', 'last_post_timestamp'),
);
}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 29adfc6817..dee70ad016 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -18,6 +22,56 @@ class phpbb_test_case_helpers
$this->test_case = $test_case;
}
+ /**
+ * This should only be called once before the tests are run.
+ * This is used to copy the fixtures to the phpBB install
+ */
+ public function copy_ext_fixtures($fixtures_dir, $fixtures)
+ {
+ global $phpbb_root_path;
+
+ if (file_exists($phpbb_root_path . 'ext/'))
+ {
+ // First, move any extensions setup on the board to a temp directory
+ $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/');
+
+ // Then empty the ext/ directory on the board (for accurate test cases)
+ $this->empty_dir($phpbb_root_path . 'ext/');
+ }
+
+ // Copy our ext/ files from the test case to the board
+ foreach ($fixtures as $fixture)
+ {
+ $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture);
+ }
+ }
+
+ /**
+ * This should only be called once after the tests are run.
+ * This is used to remove the fixtures from the phpBB install
+ */
+ public function restore_original_ext_dir()
+ {
+ global $phpbb_root_path;
+
+ // Remove all of the files we copied from test ext -> board ext
+ $this->empty_dir($phpbb_root_path . 'ext/');
+
+ // Copy back the board installed extensions from the temp directory
+ if (file_exists($phpbb_root_path . 'store/temp_ext/'))
+ {
+ $this->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/');
+
+ // Remove all of the files we copied from board ext -> temp_ext
+ $this->empty_dir($phpbb_root_path . 'store/temp_ext/');
+ }
+
+ if (file_exists($phpbb_root_path . 'store/temp_ext/'))
+ {
+ $this->empty_dir($phpbb_root_path . 'store/temp_ext/');
+ }
+ }
+
public function setExpectedTriggerError($errno, $message = '')
{
$exceptionName = '';
@@ -42,14 +96,34 @@ class phpbb_test_case_helpers
$this->test_case->setExpectedException($exceptionName, (string) $message, $errno);
}
+ public function makedirs($path)
+ {
+ // PHP bug #55124 (fixed in 5.4.0)
+ $path = str_replace('/./', '/', $path);
+
+ mkdir($path, 0777, true);
+ }
+
static public function get_test_config()
{
$config = array();
- if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
+
+ if (extension_loaded('sqlite3'))
{
$config = array_merge($config, array(
- 'dbms' => 'sqlite',
+ 'dbms' => 'phpbb\db\driver\sqlite3',
+ 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite3', // filename
+ 'dbport' => '',
+ 'dbname' => '',
+ 'dbuser' => '',
+ 'dbpasswd' => '',
+ ));
+ }
+ else if (extension_loaded('sqlite'))
+ {
+ $config = array_merge($config, array(
+ 'dbms' => 'phpbb\db\driver\sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '',
'dbname' => '',
@@ -68,12 +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);
+ $config_php_file->set_config_file($test_config);
+ extract($config_php_file->get_all());
$config = array_merge($config, array(
- 'dbms' => $dbms,
+ 'dbms' => $config_php_file->convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
@@ -86,12 +163,26 @@ class phpbb_test_case_helpers
{
$config['phpbb_functional_url'] = $phpbb_functional_url;
}
+
+ if (isset($phpbb_redis_host))
+ {
+ $config['redis_host'] = $phpbb_redis_host;
+ }
+ if (isset($phpbb_redis_port))
+ {
+ $config['redis_port'] = $phpbb_redis_port;
+ }
+
+ if (isset($fulltext_sphinx_id))
+ {
+ $config['fulltext_sphinx_id'] = $fulltext_sphinx_id;
+ }
}
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
$config = array_merge($config, array(
- 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_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'] : '',
@@ -108,6 +199,103 @@ class phpbb_test_case_helpers
));
}
+ if (isset($_SERVER['PHPBB_TEST_REDIS_HOST']))
+ {
+ $config['redis_host'] = $_SERVER['PHPBB_TEST_REDIS_HOST'];
+ }
+
+ if (isset($_SERVER['PHPBB_TEST_REDIS_PORT']))
+ {
+ $config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT'];
+ }
+
return $config;
}
+
+ /**
+ * Recursive directory copying function
+ *
+ * @param string $source
+ * @param string $dest
+ * @return array list of files copied
+ */
+ public function copy_dir($source, $dest)
+ {
+ $source = (substr($source, -1) == '/') ? $source : $source . '/';
+ $dest = (substr($dest, -1) == '/') ? $dest : $dest . '/';
+
+ $copied_files = array();
+
+ if (!is_dir($dest))
+ {
+ $this->makedirs($dest);
+ }
+
+ $files = scandir($source);
+ foreach ($files as $file)
+ {
+ if ($file == '.' || $file == '..')
+ {
+ continue;
+ }
+
+ if (is_dir($source . $file))
+ {
+ $created_dir = false;
+ if (!is_dir($dest . $file))
+ {
+ $created_dir = true;
+ $this->makedirs($dest . $file);
+ }
+
+ $copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file));
+
+ if ($created_dir)
+ {
+ $copied_files[] = $dest . $file;
+ }
+ }
+ else
+ {
+ if (!file_exists($dest . $file))
+ {
+ copy($source . $file, $dest . $file);
+
+ $copied_files[] = $dest . $file;
+ }
+ }
+ }
+
+ return $copied_files;
+ }
+
+ /**
+ * Empty directory (remove any subdirectories/files below)
+ *
+ * @param array $file_list
+ */
+ public function empty_dir($path)
+ {
+ $path = (substr($path, -1) == '/') ? $path : $path . '/';
+
+ $files = scandir($path);
+ foreach ($files as $file)
+ {
+ if ($file == '.' || $file == '..')
+ {
+ continue;
+ }
+
+ if (is_dir($path . $file))
+ {
+ $this->empty_dir($path . $file);
+
+ rmdir($path . $file);
+ }
+ else
+ {
+ unlink($path . $file);
+ }
+ }
+ }
}
diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php
new file mode 100644
index 0000000000..e8b230ecbe
--- /dev/null
+++ b/tests/test_framework/phpbb_ui_test_case.php
@@ -0,0 +1,571 @@
+<?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 Facebook\WebDriver\WebDriverBy;
+use Facebook\WebDriver\Exception\WebDriverCurlException;
+use Facebook\WebDriver\Remote\RemoteWebDriver;
+use Facebook\WebDriver\Remote\DesiredCapabilities;
+
+require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
+
+class phpbb_ui_test_case extends phpbb_test_case
+{
+ static protected $host = '127.0.0.1';
+ static protected $port = 8910;
+
+ /**
+ * @var RemoteWebDriver
+ */
+ static protected $webDriver;
+
+ static protected $config;
+ static protected $root_url;
+ static protected $already_installed = false;
+ static protected $install_success = false;
+
+ protected $cache = null;
+ protected $db = null;
+ protected $extension_manager = null;
+
+ /**
+ * Session ID for current test's session (each test makes its own)
+ * @var string
+ */
+ protected $sid;
+
+ /**
+ * Language array used by phpBB
+ * @var array
+ */
+ protected $lang = array();
+
+ static public function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ if (version_compare(PHP_VERSION, '5.3.19', '<'))
+ {
+ self::markTestSkipped('UI test case requires at least PHP 5.3.19.');
+ }
+ else if (!class_exists('\Facebook\WebDriver\Remote\RemoteWebDriver'))
+ {
+ self::markTestSkipped(
+ 'Could not find RemoteWebDriver class. ' .
+ 'Run "php ../composer.phar install" from the tests folder.'
+ );
+ }
+
+ self::$config = phpbb_test_case_helpers::get_test_config();
+ self::$root_url = self::$config['phpbb_functional_url'];
+
+ // 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
+ // installed, and also before each test case is run.
+ self::$config['table_prefix'] = 'phpbb_';
+
+ if (!isset(self::$config['phpbb_functional_url']))
+ {
+ self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
+ }
+
+ if (!self::$webDriver)
+ {
+ try {
+ $capabilities = DesiredCapabilities::firefox();
+ self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities);
+ } catch (WebDriverCurlException $e) {
+ self::markTestSkipped('PhantomJS webserver is not running.');
+ }
+ }
+
+ if (!self::$already_installed)
+ {
+ self::install_board();
+ self::$already_installed = true;
+ }
+ }
+
+ /**
+ * @return array List of extensions that should be set up
+ */
+ static protected function setup_extensions()
+ {
+ return array();
+ }
+
+ public function setUp()
+ {
+ if (!self::$install_success)
+ {
+ $this->fail('Installing phpBB has failed.');
+ }
+
+ // Clear the language array so that things
+ // that were added in other tests are gone
+ $this->lang = array();
+ $this->add_lang('common');
+
+ $db = $this->get_db();
+
+ foreach (static::setup_extensions() as $extension)
+ {
+ $this->purge_cache();
+
+ $sql = 'SELECT ext_active
+ FROM ' . EXT_TABLE . "
+ WHERE ext_name = '" . $db->sql_escape($extension). "'";
+ $result = $db->sql_query($sql);
+ $status = (bool) $db->sql_fetchfield('ext_active');
+ $db->sql_freeresult($result);
+
+ if (!$status)
+ {
+ $this->install_ext($extension);
+ }
+ }
+ }
+
+ 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();
+ }
+ }
+
+ static public function visit($path)
+ {
+ self::$webDriver->get(self::$root_url . $path);
+ }
+
+ static protected function recreate_database($config)
+ {
+ $db_conn_mgr = new phpbb_database_test_connection_manager($config);
+ $db_conn_mgr->recreate_db();
+ }
+
+ static public function find_element($type, $value)
+ {
+ return self::$webDriver->findElement(WebDriverBy::$type($value));
+ }
+
+ static public function submit($type = 'id', $value = 'submit')
+ {
+ $element = self::find_element($type, $value);
+ $element->click();
+ }
+
+ static protected function install_board()
+ {
+ global $phpbb_root_path, $phpEx, $db;
+
+ 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);
+ }
+ }
+
+ $parseURL = parse_url(self::$config['phpbb_functional_url']);
+
+ self::visit('install/index.php?mode=install&language=en');
+ self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText());
+
+ // install/index.php?mode=install&sub=requirements
+ self::submit();
+ self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText());
+
+ // install/index.php?mode=install&sub=database
+ self::submit();
+ self::assertContains('Database configuration', self::find_element('id', 'main')->getText());
+
+ self::find_element('id','dbms')->sendKeys(str_replace('phpbb\db\driver\\', '', self::$config['dbms']));
+ self::find_element('id','dbhost')->sendKeys(self::$config['dbhost']);
+ self::find_element('id','dbport')->sendKeys(self::$config['dbport']);
+ self::find_element('id','dbname')->sendKeys(self::$config['dbname']);
+ self::find_element('id','dbuser')->sendKeys(self::$config['dbuser']);
+ self::find_element('id','dbpasswd')->sendKeys(self::$config['dbpasswd']);
+
+ // Need to clear default phpbb_ prefix
+ self::find_element('id','table_prefix')->clear();
+ self::find_element('id','table_prefix')->sendKeys(self::$config['table_prefix']);
+
+ // install/index.php?mode=install&sub=database
+ self::submit();
+ self::assertContains('Successful connection', self::find_element('id','main')->getText());
+
+ // install/index.php?mode=install&sub=administrator
+ self::submit();
+ self::assertContains('Administrator configuration', self::find_element('id','main')->getText());
+
+ self::find_element('id','admin_name')->sendKeys('admin');
+ self::find_element('id','admin_pass1')->sendKeys('adminadmin');
+ self::find_element('id','admin_pass2')->sendKeys('adminadmin');
+ self::find_element('id','board_email')->sendKeys('nobody@example.com');
+
+ // install/index.php?mode=install&sub=administrator
+ self::submit();
+ self::assertContains('Tests passed', self::find_element('id','main')->getText());
+
+ // install/index.php?mode=install&sub=config_file
+ self::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(self::find_element('id','main')->getText(), 'The configuration file has been written') === false)
+ {
+ self::submit('id', 'dldone');
+ }
+ self::assertContains('The configuration file has been written', self::find_element('id','main')->getText());
+
+ // install/index.php?mode=install&sub=advanced
+ self::submit();
+ self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id','main')->getText());
+
+ self::find_element('id','smtp_delivery')->sendKeys('1');
+ self::find_element('id','smtp_host')->sendKeys('nxdomain.phpbb.com');
+ self::find_element('id','smtp_user')->sendKeys('nxuser');
+ self::find_element('id','smtp_pass')->sendKeys('nxpass');
+ self::find_element('id','server_protocol')->sendKeys($parseURL['scheme'] . '://');
+ self::find_element('id','server_name')->sendKeys('localhost');
+ self::find_element('id','server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80);
+ self::find_element('id','script_path')->sendKeys($parseURL['path']);
+
+ // install/index.php?mode=install&sub=create_table
+ self::submit();
+ self::assertContains('The database tables used by phpBB', self::find_element('id','main')->getText());
+ self::assertContains('have been created and populated with some initial data.', self::find_element('id','main')->getText());
+
+ // install/index.php?mode=install&sub=final
+ self::submit();
+ self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText());
+
+ copy($config_file, $config_file_test);
+
+ self::$install_success = true;
+ }
+
+ public function install_ext($extension)
+ {
+ $this->login();
+ $this->admin_login();
+
+ $ext_path = str_replace('/', '%2F', $extension);
+
+ $this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid);
+ $this->assertNotEmpty(count(self::find_element('cssSelector', '.submit-buttons')));
+
+ self::find_element('cssSelector', "input[value='Enable']")->submit();
+ $this->add_lang('acp/extensions');
+
+ try
+ {
+ $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]');
+
+ // Wait for extension to be fully enabled
+ while (sizeof($meta_refresh))
+ {
+ preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match);
+ self::$webDriver->execute(array('method' => 'post', 'url' => $match[1]));
+ $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]');
+ }
+ }
+ catch (\Facebook\WebDriver\Exception\NoSuchElementException $e)
+ {
+ // Probably no refresh triggered
+ }
+
+ $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText());
+
+ $this->logout();
+ }
+
+ protected function get_cache_driver()
+ {
+ if (!$this->cache)
+ {
+ $this->cache = new \phpbb\cache\driver\file;
+ }
+
+ return $this->cache;
+ }
+
+ protected function purge_cache()
+ {
+ $cache = $this->get_cache_driver();
+
+ $cache->purge();
+ $cache->unload();
+ $cache->load();
+ }
+
+ protected function get_extension_manager()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $config = new \phpbb\config\config(array());
+ $db = $this->get_db();
+ $db_tools = new \phpbb\db\tools($db);
+
+ $container = new phpbb_mock_container_builder();
+ $migrator = new \phpbb\db\migrator(
+ $container,
+ $config,
+ $db,
+ $db_tools,
+ self::$config['table_prefix'] . 'migrations',
+ $phpbb_root_path,
+ $phpEx,
+ self::$config['table_prefix'],
+ array(),
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
+ $user = new \phpbb\user('\phpbb\datetime');
+
+ $extension_manager = new \phpbb\extension\manager(
+ $container,
+ $db,
+ $config,
+ new phpbb\filesystem(),
+ $user,
+ self::$config['table_prefix'] . 'ext',
+ dirname(__FILE__) . '/',
+ $phpEx,
+ $this->get_cache_driver()
+ );
+
+ return $extension_manager;
+ }
+
+ protected function get_db()
+ {
+ // so we don't reopen an open connection
+ if (!($this->db instanceof \phpbb\db\driver\driver_interface))
+ {
+ $dbms = self::$config['dbms'];
+ /** @var \phpbb\db\driver\driver_interface $db */
+ $db = new $dbms();
+ $db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
+ $this->db = $db;
+ }
+ return $this->db;
+ }
+
+ protected function logout()
+ {
+ $this->add_lang('ucp');
+
+ if (empty($this->sid))
+ {
+ return;
+ }
+
+ $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout');
+ $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource());
+ unset($this->sid);
+
+ }
+
+ /**
+ * Login to the ACP
+ * You must run login() before calling this.
+ */
+ protected function admin_login($username = 'admin')
+ {
+ $this->add_lang('acp/common');
+
+ // Requires login first!
+ if (empty($this->sid))
+ {
+ $this->fail('$this->sid is empty. Make sure you call login() before admin_login()');
+ return;
+ }
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ $this->visit('adm/index.php?sid=' . $this->sid);
+ $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource());
+
+ self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username);
+ self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username);
+ self::find_element('cssSelector', 'input[name=login]')->click();
+ $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText());
+
+ $cookies = self::$webDriver->manage()->getCookies();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie)
+ {
+ if (substr($cookie['name'], -4) == '_sid')
+ {
+ $this->sid = $cookie['value'];
+
+ break;
+ }
+ }
+
+ $this->assertNotEmpty($this->sid);
+ }
+
+ protected function add_lang($lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang($file);
+ }
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
+ protected function add_lang_ext($ext_name, $lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang_ext($ext_name, $file);
+ }
+
+ return;
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/ext/{$ext_name}/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
+ protected function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ if (empty($this->lang[$key]))
+ {
+ throw new RuntimeException('Language key "' . $key . '" could not be found.');
+ }
+
+ $args[0] = $this->lang[$key];
+
+ return call_user_func_array('sprintf', $args);
+ }
+
+ /**
+ * assertContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ /**
+ * assertNotContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertNotContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertNotContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ protected function login($username = 'admin')
+ {
+ $this->add_lang('ucp');
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ $this->visit('ucp.php');
+ $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource());
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ self::find_element('cssSelector', 'input[name=username]')->sendKeys($username);
+ self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username);
+ self::find_element('cssSelector', 'input[name=login]')->click();
+ $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText());
+
+ $cookies = self::$webDriver->manage()->getCookies();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie)
+ {
+ if (substr($cookie['name'], -4) == '_sid')
+ {
+ $this->sid = $cookie['value'];
+ }
+ }
+
+ $this->assertNotEmpty($this->sid);
+ }
+
+ /**
+ * Take screenshot. Can be used for debug purposes.
+ *
+ * @throws Exception When screenshot can't be created
+ */
+ public function take_screenshot()
+ {
+ // Change the Path to your own settings
+ $screenshot = time() . ".png";
+
+ self::$webDriver->takeScreenshot($screenshot);
+ }
+}
diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php
index f0e13638a5..983a5ba2d3 100644
--- a/tests/text_processing/censor_text_test.php
+++ b/tests/text_processing/censor_text_test.php
@@ -1,16 +1,18 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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__) . '/../mock/user.php';
-require_once dirname(__FILE__) . '/../mock/cache.php';
class phpbb_text_processing_censor_text_test extends phpbb_test_case
{
@@ -19,7 +21,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case
global $cache, $user;
$cache = new phpbb_mock_cache;
$user = new phpbb_mock_user;
-
+
$user->optionset('viewcensors', false);
return array(
@@ -61,7 +63,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case
array('badword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'),
array('badword1 badword2 badword3 badword4d', 'replacement1 replacement2 replacement3 badword4d'),
array('abadword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'),
-
+
array("new\nline\ntest", "new\nline\ntest"),
array("tab\ttest\t", "tab\ttest\t"),
array('öäü', 'öäü'),
diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php
index a157fe7d9a..057416da33 100644
--- a/tests/text_processing/generate_text_for_display_test.php
+++ b/tests/text_processing/generate_text_for_display_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -16,7 +20,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
{
public function setUp()
{
- global $cache, $user;
+ global $cache, $user, $phpbb_dispatcher;
parent::setUp();
@@ -24,6 +28,8 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
$user = new phpbb_mock_user;
$user->optionset('viewcensors', false);
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
}
public function test_empty_string()
diff --git a/tests/text_processing/make_clickable_test.php b/tests/text_processing/make_clickable_test.php
index db0812319d..95e304dd97 100644
--- a/tests/text_processing/make_clickable_test.php
+++ b/tests/text_processing/make_clickable_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -12,7 +16,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
class phpbb_text_processing_make_clickable_test extends phpbb_test_case
{
- static public function make_clickable_data()
+ public function make_clickable_data()
{
// value => whether it should work
$prefix_texts = array(
@@ -100,5 +104,50 @@ class phpbb_text_processing_make_clickable_test extends phpbb_test_case
$this->assertEquals($expected, $result, $label);
}
+ public function make_clickable_mixed_serverurl_data()
+ {
+ $urls = array(
+ 'http://thisdomain.org' => array('tag' => 'm', 'url' => false, 'text' => false),
+ 'http://thisdomain.org/' => array('tag' => 'm', 'url' => false, 'text' => false),
+ 'http://thisdomain.org/1' => array('tag' => 'm', 'url' => false, 'text' => false),
+ 'http://thisdomain.org/path/some?query=abc#test' => array('tag' => 'm', 'url' => false, 'text' => false),
+
+ 'https://www.phpbb.com' => array('tag' => 'm', 'url' => false, 'text' => false),
+ 'https://www.phpbb.com/' => array('tag' => 'm', 'url' => false, 'text' => false),
+ 'https://www.phpbb.com/1' => array('tag' => 'l', 'url' => false, 'text' => '1'),
+ 'https://www.phpbb.com/path/some?query=abc#test' => array('tag' => 'l', 'url' => false, 'text' => 'path/some?query=abc#test'),
+ );
+
+ $test_data = array();
+
+ // run the test for each combination
+ foreach ($urls as $url => $url_type)
+ {
+ // false means it's the same as the url, less typing
+ $url_type['url'] = ($url_type['url']) ? $url_type['url'] : $url;
+ $url_type['text'] = ($url_type['text']) ? $url_type['text'] : $url;
+
+ $class = ($url_type['tag'] === 'l') ? 'postlink-local' : 'postlink';
+
+ // replace the url with the desired output format
+ $output = '<!-- ' . $url_type['tag'] . ' --><a class="' . $class . '" href="' . $url_type['url'] . '">' . $url_type['text'] . '</a><!-- ' . $url_type['tag'] . ' -->';
+
+ $test_data[] = array($url, $output);
+ }
+
+ return $test_data;
+ }
+
+ /**
+ * @dataProvider make_clickable_mixed_serverurl_data
+ */
+ public function test_make_clickable_mixed_serverurl($input, $expected)
+ {
+ $result = make_clickable($input, 'https://www.phpbb.com');
+
+ $label = 'Making text clickable: ' . $input;
+ $this->assertEquals($expected, $result, $label);
+ }
+
}
diff --git a/tests/tree/fixtures/phpbb_forums.xml b/tests/tree/fixtures/phpbb_forums.xml
new file mode 100644
index 0000000000..8f133078a9
--- /dev/null
+++ b/tests/tree/fixtures/phpbb_forums.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_forums">
+ <column>forum_id</column>
+ <column>parent_id</column>
+ <column>left_id</column>
+ <column>right_id</column>
+ <column>forum_parents</column>
+ <column>forum_name</column>
+ <column>forum_desc</column>
+ <column>forum_rules</column>
+ </table>
+</dataset>
diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php
new file mode 100644
index 0000000000..c56be1f81e
--- /dev/null
+++ b/tests/tree/nestedset_forum_base.php
@@ -0,0 +1,121 @@
+<?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_tests_tree_nestedset_forum_base extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/phpbb_forums.xml');
+ }
+
+ protected $forum_data = array(
+ // \__/
+ 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ 2 => array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ 3 => array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ // \ /
+ // \/
+ 4 => array('forum_id' => 4, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+ 5 => array('forum_id' => 5, 'parent_id' => 4, 'user_id' => 0, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ 6 => array('forum_id' => 6, 'parent_id' => 5, 'user_id' => 0, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+
+ // \_ _/
+ // \/
+ 7 => array('forum_id' => 7, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ 8 => array('forum_id' => 8, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ 9 => array('forum_id' => 9, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+
+ // Non-existent forums
+ 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'),
+ 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'),
+ );
+
+ protected $set,
+ $config,
+ $lock,
+ $db;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+
+ global $config;
+
+ $config = $this->config = new \phpbb\config\config(array('nestedset_forum_lock' => 0));
+ set_config(null, null, null, $this->config);
+
+ $this->lock = new \phpbb\lock\db('nestedset_forum_lock', $this->config, $this->db);
+ $this->set = new \phpbb\tree\nestedset_forum($this->db, $this->lock, 'phpbb_forums');
+
+ $this->set_up_forums();
+ }
+
+ protected function set_up_forums()
+ {
+ static $forums;
+
+ if (empty($forums))
+ {
+ $this->create_forum('Parent with two flat children');
+ $this->create_forum('Flat child #1', 1);
+ $this->create_forum('Flat child #2', 1);
+
+ $this->create_forum('Parent with two nested children');
+ $this->create_forum('Nested child #1', 4);
+ $this->create_forum('Nested child #2', 5);
+
+ $this->create_forum('Parent with flat and nested children');
+ $this->create_forum('Mixed child #1', 7);
+ $this->create_forum('Mixed child #2', 7);
+ $this->create_forum('Nested child #1 of Mixed child #2', 9);
+ $this->create_forum('Mixed child #3', 7);
+
+ // Updating forum_parents column here so it's not empty
+ // This is required, so we can see whether the methods
+ // correctly clear the values.
+ $sql = "UPDATE phpbb_forums
+ SET forum_parents = 'a:0:{}'";
+ $this->db->sql_query($sql);
+
+ // Copy the forums into a static array, so we can reuse the list later
+ $sql = 'SELECT *
+ FROM phpbb_forums';
+ $result = $this->db->sql_query($sql);
+ $forums = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+ }
+ else
+ {
+ $buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_forums');
+ $buffer->insert_all($forums);
+ $buffer->flush();
+
+ $this->database_synchronisation(array(
+ 'phpbb_forums' => array('forum_id'),
+ ));
+ }
+ }
+
+ protected function create_forum($name, $parent_id = 0)
+ {
+ $forum = $this->set->insert(array('forum_name' => $name, 'forum_desc' => '', 'forum_rules' => ''));
+ $this->set->change_parent($forum['forum_id'], $parent_id);
+ }
+}
diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php
new file mode 100644
index 0000000000..48fbabdb8c
--- /dev/null
+++ b/tests/tree/nestedset_forum_get_data_test.php
@@ -0,0 +1,139 @@
+<?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__) . '/nestedset_forum_base.php';
+
+class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_nestedset_forum_base
+{
+ public function get_path_and_subtree_data_data()
+ {
+ return array(
+ array(1, true, true, array(1, 2, 3)),
+ array(1, true, false, array(2, 3)),
+ array(1, false, true, array(3, 2, 1)),
+ array(1, false, false, array(3, 2)),
+
+ array(2, true, true, array(1, 2)),
+ array(2, true, false, array(1)),
+ array(2, false, true, array(2, 1)),
+ array(2, false, false, array(1)),
+
+ array(5, true, true, array(4, 5, 6)),
+ array(5, true, false, array(4, 6)),
+ array(5, false, true, array(6, 5, 4)),
+ array(5, false, false, array(6, 4)),
+ );
+ }
+
+ /**
+ * @dataProvider get_path_and_subtree_data_data
+ */
+ public function test_get_path_and_subtree_data($forum_id, $order_asc, $include_item, $expected)
+ {
+ $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_asc, $include_item)));
+ }
+
+ public function get_path_data_data()
+ {
+ return array(
+ array(1, true, true, array(1)),
+ array(1, true, false, array()),
+ array(1, false, true, array(1)),
+ array(1, false, false, array()),
+
+ array(2, true, true, array(1, 2)),
+ array(2, true, false, array(1)),
+ array(2, false, true, array(2, 1)),
+ array(2, false, false, array(1)),
+
+ array(5, true, true, array(4, 5)),
+ array(5, true, false, array(4)),
+ array(5, false, true, array(5, 4)),
+ array(5, false, false, array(4)),
+ );
+ }
+
+ /**
+ * @dataProvider get_path_data_data
+ */
+ public function test_get_path_data($forum_id, $order_asc, $include_item, $expected)
+ {
+ $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_asc, $include_item)));
+ }
+
+ public function get_subtree_data_data()
+ {
+ return array(
+ array(1, true, true, array(1, 2, 3)),
+ array(1, true, false, array(2, 3)),
+ array(1, false, true, array(3, 2, 1)),
+ array(1, false, false, array(3, 2)),
+
+ array(2, true, true, array(2)),
+ array(2, true, false, array()),
+ array(2, false, true, array(2)),
+ array(2, false, false, array()),
+
+ array(5, true, true, array(5, 6)),
+ array(5, true, false, array(6)),
+ array(5, false, true, array(6, 5)),
+ array(5, false, false, array(6)),
+ );
+ }
+
+ /**
+ * @dataProvider get_subtree_data_data
+ */
+ public function test_get_subtree_data($forum_id, $order_asc, $include_item, $expected)
+ {
+ $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_asc, $include_item)));
+ }
+
+ public function get_path_basic_data_data()
+ {
+ return array(
+ array(1, '', array()),
+ array(1, serialize(array()), array()),
+ array(2, '', array(1)),
+ array(2, serialize(array(1 => array())), array(1)),
+ array(10, '', array(7, 9)),
+ array(10, serialize(array(7 => array(), 9 => array())), array(7, 9)),
+ );
+ }
+
+ /**
+ * @dataProvider get_path_basic_data_data
+ */
+ public function test_get_path_basic_data($forum_id, $forum_parents, $expected)
+ {
+ $forum_data = $this->forum_data[$forum_id];
+ $forum_data['forum_parents'] = $forum_parents;
+ $this->assertEquals($expected, array_keys($this->set->get_path_basic_data($forum_data)));
+ }
+
+ public function get_all_tree_data_data()
+ {
+ return array(
+ array(true, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)),
+ array(false, array(11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)),
+ );
+ }
+
+ /**
+ * @dataProvider get_all_tree_data_data
+ */
+ public function test_get_all_tree_data($order_asc, $expected)
+ {
+ $this->assertEquals($expected, array_keys($this->set->get_all_tree_data($order_asc)));
+ }
+}
diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php
new file mode 100644
index 0000000000..6393752010
--- /dev/null
+++ b/tests/tree/nestedset_forum_insert_delete_test.php
@@ -0,0 +1,124 @@
+<?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__) . '/nestedset_forum_base.php';
+
+class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_nestedset_forum_base
+{
+ public function delete_data()
+ {
+ return array(
+ array(1, array(1, 2, 3), array(
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ )),
+ array(2, array(2), array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider delete_data
+ */
+ public function test_delete($forum_id, $expected_deleted, $expected)
+ {
+ $this->assertEquals($expected_deleted, $this->set->delete($forum_id));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function delete_throws_data()
+ {
+ return array(
+ array('Not an item', 0),
+ array('Item does not exist', 200),
+ );
+ }
+
+ /**
+ * @dataProvider delete_throws_data
+ *
+ * @expectedException OutOfBoundsException
+ * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM
+ */
+ public function test_delete_throws($explain, $forum_id)
+ {
+ $this->set->delete($forum_id);
+ }
+
+ public function insert_data()
+ {
+ return array(
+ array(array(
+ 'forum_desc' => '',
+ 'forum_rules' => '',
+ 'forum_id' => 12,
+ 'parent_id' => 0,
+ 'left_id' => 23,
+ 'right_id' => 24,
+ 'forum_parents' => '',
+ ), array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+
+ array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider insert_data
+ */
+ public function test_insert($expected_data, $expected)
+ {
+ $this->assertEquals($expected_data, $this->set->insert(array(
+ 'forum_desc' => '',
+ 'forum_rules' => '',
+ )));
+
+ $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC');
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php
new file mode 100644
index 0000000000..108faf5b71
--- /dev/null
+++ b/tests/tree/nestedset_forum_move_test.php
@@ -0,0 +1,573 @@
+<?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__) . '/nestedset_forum_base.php';
+
+class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nestedset_forum_base
+{
+ public function move_data()
+ {
+ return array(
+ array('Move first item up',
+ 1, 1, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move last item down',
+ 7, -1, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move first item down',
+ 1, -1, true, array(
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move second item up',
+ 4, 1, true, array(
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move last item up',
+ 7, 1, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20),
+ )),
+ array('Move last item up by 2',
+ 7, 2, true, array(
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20),
+ )),
+ array('Move last item up by 100',
+ 7, 100, true, array(
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_data
+ */
+ public function test_move($explain, $forum_id, $delta, $expected_moved, $expected)
+ {
+ $this->assertEquals($expected_moved, $this->set->move($forum_id, $delta));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function move_down_data()
+ {
+ return array(
+ array('Move last item down',
+ 7, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move first item down',
+ 1, true, array(
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_down_data
+ */
+ public function test_move_down($explain, $forum_id, $expected_moved, $expected)
+ {
+ $this->assertEquals($expected_moved, $this->set->move_down($forum_id));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function move_up_data()
+ {
+ return array(
+ array('Move first item up',
+ 1, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ array('Move second item up',
+ 4, true, array(
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4),
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11),
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_up_data
+ */
+ public function test_move_up($explain, $forum_id, $expected_moved, $expected)
+ {
+ $this->assertEquals($expected_moved, $this->set->move_up($forum_id));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function move_children_data()
+ {
+ return array(
+ array('Item has no children',
+ 2, 1, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move to same parent',
+ 4, 4, false, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move single child up',
+ 5, 1, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move nested children up',
+ 4, 1, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move single child down',
+ 5, 7, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
+
+ )),
+ array('Move nested children down',
+ 4, 7, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''),
+ )),
+ array('Move single child to parent 0',
+ 5, 0, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''),
+ )),
+ array('Move nested children to parent 0',
+ 4, 0, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_children_data
+ */
+ public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected)
+ {
+ $this->assertEquals($expected_moved, $this->set->move_children($forum_id, $target_id));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function move_children_throws_item_data()
+ {
+ return array(
+ array('Item 0 does not exist', 0, 5),
+ array('Item does not exist', 200, 5),
+ );
+ }
+
+ /**
+ * @dataProvider move_children_throws_item_data
+ *
+ * @expectedException OutOfBoundsException
+ * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM
+ */
+ public function test_move_children_throws_item($explain, $forum_id, $target_id)
+ {
+ $this->set->move_children($forum_id, $target_id);
+ }
+
+ public function move_children_throws_parent_data()
+ {
+ return array(
+ array('New parent is child', 4, 5),
+ array('New parent is child 2', 7, 9),
+ array('New parent does not exist', 1, 200),
+ );
+ }
+
+ /**
+ * @dataProvider move_children_throws_parent_data
+ *
+ * @expectedException OutOfBoundsException
+ * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT
+ */
+ public function test_move_children_throws_parent($explain, $forum_id, $target_id)
+ {
+ $this->set->move_children($forum_id, $target_id);
+ }
+
+ public function change_parent_data()
+ {
+ return array(
+ array('Move single child up',
+ 6, 1, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move nested children up',
+ 5, 1, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'),
+ )),
+ array('Move single child down',
+ 6, 7, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
+ )),
+ array('Move nested children down',
+ 5, 7, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''),
+ )),
+ array('Move single child to parent 0',
+ 6, 0, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''),
+ )),
+ array('Move nested children to parent 0',
+ 5, 0, true, array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'),
+
+ array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider change_parent_data
+ */
+ public function test_change_parent($explain, $forum_id, $target_id, $expected_moved, $expected)
+ {
+ $this->assertEquals($expected_moved, $this->set->change_parent($forum_id, $target_id));
+
+ $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC");
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function change_parent_throws_item_data()
+ {
+ return array(
+ array('Item 0 does not exist', 0, 5),
+ array('Item does not exist', 200, 5),
+ );
+ }
+
+ /**
+ * @dataProvider change_parent_throws_item_data
+ *
+ * @expectedException OutOfBoundsException
+ * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM
+ */
+ public function test_change_parent_throws_item($explain, $forum_id, $target_id)
+ {
+ $this->set->change_parent($forum_id, $target_id);
+ }
+
+ public function change_parent_throws_parent_data()
+ {
+ return array(
+ array('New parent is child', 4, 5),
+ array('New parent is child 2', 7, 9),
+ array('New parent does not exist', 1, 200),
+ );
+ }
+
+ /**
+ * @dataProvider change_parent_throws_parent_data
+ *
+ * @expectedException OutOfBoundsException
+ * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT
+ */
+ public function test_change_parent_throws_parent($explain, $forum_id, $target_id)
+ {
+ $this->set->change_parent($forum_id, $target_id);
+ }
+}
diff --git a/tests/tree/nestedset_forum_regenerate_test.php b/tests/tree/nestedset_forum_regenerate_test.php
new file mode 100644
index 0000000000..914cc5f749
--- /dev/null
+++ b/tests/tree/nestedset_forum_regenerate_test.php
@@ -0,0 +1,76 @@
+<?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__) . '/nestedset_forum_base.php';
+
+class phpbb_tests_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base
+{
+ protected $fixed_set = array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
+ );
+
+ public function regenerate_left_right_ids_data()
+ {
+ return array(
+ array('UPDATE phpbb_forums
+ SET left_id = 0,
+ right_id = 0', false),
+ array('UPDATE phpbb_forums
+ SET left_id = 28,
+ right_id = 28
+ WHERE left_id > 12', false),
+ array('UPDATE phpbb_forums
+ SET left_id = left_id * 2,
+ right_id = right_id * 2', false),
+ array('UPDATE phpbb_forums
+ SET left_id = left_id * 2,
+ right_id = right_id * 2
+ WHERE left_id > 12', false),
+ array('UPDATE phpbb_forums
+ SET left_id = left_id - 4,
+ right_id = right_id * 4
+ WHERE left_id > 4', false),
+ array('UPDATE phpbb_forums
+ SET left_id = 0,
+ right_id = 0
+ WHERE left_id > 12', true),
+ );
+ }
+
+ /**
+ * @dataProvider regenerate_left_right_ids_data
+ */
+ public function test_regenerate_left_right_ids($breaking_query, $reset_ids)
+ {
+ $result = $this->db->sql_query($breaking_query);
+
+ $this->assertEquals(23, $this->set->regenerate_left_right_ids(1, 0, $reset_ids));
+
+ $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC');
+ $this->assertEquals($this->fixed_set, $this->db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php
new file mode 100644
index 0000000000..7ccdc0a9b5
--- /dev/null
+++ b/tests/tree/nestedset_forum_test.php
@@ -0,0 +1,120 @@
+<?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__) . '/nestedset_forum_base.php';
+
+class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_forum_base
+{
+ public function forum_constructor_data()
+ {
+ return array(
+ array(array(
+ array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6),
+ array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3),
+ array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5),
+
+ array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12),
+ array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11),
+ array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10),
+
+ array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22),
+ array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15),
+ array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19),
+ array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18),
+ array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider forum_constructor_data
+ */
+ public function test_forum_constructor($expected)
+ {
+ $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id
+ FROM phpbb_forums
+ ORDER BY left_id, forum_id ASC');
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+
+ public function get_sql_where_data()
+ {
+ return array(
+ array('SELECT forum_id
+ FROM phpbb_forums
+ %s
+ ORDER BY forum_id ASC',
+ 'WHERE', '', array(
+ array('forum_id' => 1),
+ array('forum_id' => 2),
+ array('forum_id' => 3),
+
+ array('forum_id' => 4),
+ array('forum_id' => 5),
+ array('forum_id' => 6),
+
+ array('forum_id' => 7),
+ array('forum_id' => 8),
+ array('forum_id' => 9),
+ array('forum_id' => 10),
+ array('forum_id' => 11),
+ )),
+ array('SELECT f.forum_id
+ FROM phpbb_forums f
+ %s
+ ORDER BY f.forum_id ASC',
+ 'WHERE', 'f.', array(
+ array('forum_id' => 1),
+ array('forum_id' => 2),
+ array('forum_id' => 3),
+
+ array('forum_id' => 4),
+ array('forum_id' => 5),
+ array('forum_id' => 6),
+
+ array('forum_id' => 7),
+ array('forum_id' => 8),
+ array('forum_id' => 9),
+ array('forum_id' => 10),
+ array('forum_id' => 11),
+ )),
+ array('SELECT forum_id
+ FROM phpbb_forums
+ WHERE forum_id < 4 %s
+ ORDER BY forum_id ASC',
+ 'AND', '', array(
+ array('forum_id' => 1),
+ array('forum_id' => 2),
+ array('forum_id' => 3),
+ )),
+ array('SELECT f.forum_id
+ FROM phpbb_forums f
+ WHERE f.forum_id < 4 %s
+ ORDER BY f.forum_id ASC',
+ 'AND', 'f.', array(
+ array('forum_id' => 1),
+ array('forum_id' => 2),
+ array('forum_id' => 3),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider get_sql_where_data
+ */
+ public function test_get_sql_where($sql_query, $operator, $column_prefix, $expected)
+ {
+ $result = $this->db->sql_query(sprintf($sql_query, $this->set->get_sql_where($operator, $column_prefix)));
+ $this->assertEquals($expected, $this->db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/ui/quick_links_test.php b/tests/ui/quick_links_test.php
new file mode 100644
index 0000000000..5bddb44a8b
--- /dev/null
+++ b/tests/ui/quick_links_test.php
@@ -0,0 +1,27 @@
+<?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 ui
+*/
+class quick_links_test extends phpbb_ui_test_case
+{
+
+ public function test_quick_links()
+ {
+ $this->visit('index.php');
+ $this->assertEmpty(self::find_element('className', 'dropdown')->getText());
+ self::find_element('className', 'dropdown-toggle')->click();
+ $this->assertNotNull(self::find_element('className', 'dropdown')->getText());
+ }
+}
diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php
new file mode 100644
index 0000000000..ed28bcb38f
--- /dev/null
+++ b/tests/upload/filespec_test.php
@@ -0,0 +1,338 @@
+<?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 __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+
+class phpbb_filespec_test extends phpbb_test_case
+{
+ const TEST_COUNT = 100;
+ const PREFIX = 'phpbb_';
+ const MAX_STR_LEN = 50;
+ const UPLOAD_MAX_FILESIZE = 1000;
+
+ private $config;
+ public $path;
+
+ protected function setUp()
+ {
+ // Global $config required by unique_id
+ // Global $user required by filespec::additional_checks and
+ // filespec::move_file
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+ // This config value is normally pulled from the database which is set
+ // to this value at install time.
+ // See: phpBB/install/schemas/schema_data.sql
+ $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title';
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->config = &$config;
+ $this->path = __DIR__ . '/fixture/';
+
+ // Create copies of the files for use in testing move_file
+ $iterator = new DirectoryIterator($this->path);
+ foreach ($iterator as $fileinfo)
+ {
+ if ($fileinfo->isDot() || $fileinfo->isDir())
+ {
+ continue;
+ }
+
+ copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy');
+ if ($fileinfo->getFilename() === 'txt')
+ {
+ 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())
+ {
+ // Initialise a blank filespec object for use with trivial methods
+ $upload_ary = array(
+ 'name' => '',
+ 'type' => '',
+ 'size' => '',
+ 'tmp_name' => '',
+ 'error' => '',
+ );
+
+ return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser);
+ }
+
+ protected function tearDown()
+ {
+ global $user;
+ $this->config = array();
+ $user = null;
+
+ $iterator = new DirectoryIterator($this->path . 'copies');
+ foreach ($iterator as $fileinfo)
+ {
+ $name = $fileinfo->getFilename();
+ if ($name[0] !== '.')
+ {
+ unlink($fileinfo->getPathname());
+ }
+ }
+ }
+
+ public function additional_checks_variables()
+ {
+ // False here just indicates the file is too large and fails the
+ // filespec::additional_checks method because of it. All other code
+ // paths in that method are covered elsewhere.
+ return array(
+ array('gif', true),
+ array('jpg', false),
+ array('png', true),
+ array('tif', false),
+ array('txt', false),
+ );
+ }
+
+ /**
+ * @dataProvider additional_checks_variables
+ */
+ public function test_additional_checks($filename, $expected)
+ {
+ $upload = new phpbb_mock_fileupload();
+ $filespec = $this->get_filespec();
+ $filespec->upload = $upload;
+ $filespec->file_moved = true;
+ $filespec->filesize = $filespec->get_filesize($this->path . $filename);
+
+ $this->assertEquals($expected, $filespec->additional_checks());
+ }
+
+ public function check_content_variables()
+ {
+ // False here indicates that a file is non-binary and contains
+ // disallowed content that makes IE report the mimetype incorrectly.
+ return array(
+ array('gif', true),
+ array('jpg', true),
+ array('png', true),
+ array('tif', true),
+ array('txt', false),
+ );
+ }
+
+ /**
+ * @dataProvider check_content_variables
+ */
+ public function test_check_content($filename, $expected)
+ {
+ $disallowed_content = explode('|', $this->config['mime_triggers']);
+ $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename));
+ $this->assertEquals($expected, $filespec->check_content($disallowed_content));
+ // All files should pass if $disallowed_content is empty
+ $this->assertEquals(true, $filespec->check_content(array()));
+ }
+
+ public function clean_filename_variables()
+ {
+ $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8);
+ return array(
+ array($chunks[0] . $chunks[7]),
+ array($chunks[1] . $chunks[8]),
+ array($chunks[2] . $chunks[9]),
+ array($chunks[3] . $chunks[4]),
+ array($chunks[5] . $chunks[6]),
+ );
+ }
+
+ /**
+ * @dataProvider clean_filename_variables
+ */
+ public function test_clean_filename_real($filename)
+ {
+ $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
+ $filespec = $this->get_filespec(array('name' => $filename));
+ $filespec->clean_filename('real', self::PREFIX);
+ $name = $filespec->realname;
+
+ $this->assertEquals(0, preg_match('/%(\w{2})/', $name));
+ foreach ($bad_chars as $char)
+ {
+ $this->assertFalse(strpos($name, $char));
+ }
+ }
+
+ public function test_clean_filename_unique()
+ {
+ $filenames = array();
+ for ($tests = 0; $tests < self::TEST_COUNT; $tests++)
+ {
+ $filespec = $this->get_filespec();
+ $filespec->clean_filename('unique', self::PREFIX);
+ $name = $filespec->realname;
+
+ $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
+ $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
+ $this->assertFalse(isset($filenames[$name]));
+ $filenames[$name] = true;
+ }
+ }
+
+ public function get_extension_variables()
+ {
+ return array(
+ array('file.png', 'png'),
+ array('file.phpbb.gif', 'gif'),
+ array('file..', ''),
+ array('.file..jpg.webp', 'webp'),
+ array('/test.com/file', ''),
+ array('/test.com/file.gif', 'gif'),
+ );
+ }
+
+ /**
+ * @dataProvider get_extension_variables
+ */
+ public function test_get_extension($filename, $expected)
+ {
+ $this->assertEquals($expected, filespec::get_extension($filename));
+ }
+
+ public function is_image_variables()
+ {
+ 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', false),
+ array('gif', 'application/octetstream', false),
+ array('png', 'application/mime', false),
+ );
+ }
+
+ /**
+ * @dataProvider is_image_variables
+ */
+ public function test_is_image($filename, $mimetype, $expected)
+ {
+ $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
+ $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)
+ {
+ if (!class_exists('finfo') && strtolower(substr(PHP_OS, 0, 3)) === 'win')
+ {
+ $this->markTestSkipped('Unable to test mimetype guessing without fileinfo support on Windows');
+ }
+
+ $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(
+ array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true),
+ array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false),
+ array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true),
+ array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true),
+ array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true),
+ array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true),
+ );
+ }
+
+ /**
+ * @dataProvider move_file_variables
+ */
+ public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected)
+ {
+ // Global $phpbb_root_path and $phpEx are required by phpbb_chmod
+ global $phpbb_root_path, $phpEx;
+ $phpbb_root_path = '';
+ $phpEx = 'php';
+
+ $upload = new phpbb_mock_fileupload();
+ $upload->max_filesize = self::UPLOAD_MAX_FILESIZE;
+
+ $filespec = $this->get_filespec(array(
+ 'tmp_name' => $this->path . 'copies/' . $tmp_name,
+ 'name' => $realname,
+ 'type' => $mime_type,
+ ));
+ $filespec->extension = $extension;
+ $filespec->upload = $upload;
+ $filespec->local = true;
+
+ $this->assertEquals($expected, $filespec->move_file($this->path . 'copies'));
+ $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/' . $realname));
+ if ($error)
+ {
+ $this->assertEquals($error, $filespec->error[0]);
+ }
+
+ $phpEx = '';
+ }
+
+ /**
+ * @dataProvider clean_filename_variables
+ */
+ public function test_uploadname($filename)
+ {
+ $type_cast_helper = new \phpbb\request\type_cast_helper();
+
+ $upload_name = '';
+ $type_cast_helper->set_var($upload_name, $filename, 'string', true, true);
+ $filespec = $this->get_filespec(array('name'=> $upload_name));
+
+ $this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->uploadname);
+ }
+}
diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php
new file mode 100644
index 0000000000..fcfb84125d
--- /dev/null
+++ b/tests/upload/fileupload_test.php
@@ -0,0 +1,149 @@
+<?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 __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+require_once __DIR__ . '/../mock/filespec.php';
+
+class phpbb_fileupload_test extends phpbb_test_case
+{
+ private $path;
+
+ protected function setUp()
+ {
+ // Global $config required by unique_id
+ // Global $user required by several functions dealing with translations
+ // Global $request required by form_upload, local_upload and is_valid
+ global $config, $user, $request;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $request = new phpbb_mock_request();
+
+ $this->path = __DIR__ . '/fixture/';
+ }
+
+ private function gen_valid_filespec()
+ {
+ $filespec = new phpbb_mock_filespec();
+ $filespec->filesize = 1;
+ $filespec->extension = 'jpg';
+ $filespec->realname = 'valid';
+ $filespec->width = 2;
+ $filespec->height = 2;
+
+ return $filespec;
+ }
+
+ protected function tearDown()
+ {
+ // Clear globals
+ global $config, $user;
+ $config = array();
+ $user = null;
+ }
+
+ public function test_common_checks_invalid_extension()
+ {
+ $upload = new fileupload('', array('png'), 100);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]);
+ }
+
+ public function test_common_checks_invalid_filename()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->realname = 'invalid?';
+ $upload->common_checks($file);
+ $this->assertEquals('INVALID_FILENAME', $file->error[0]);
+ }
+
+ public function test_common_checks_too_large()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->filesize = 1000;
+ $upload->common_checks($file);
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+
+ public function test_common_checks_valid_file()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals(0, sizeof($file->error));
+ }
+
+ public function test_local_upload()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+
+ copy($this->path . 'jpg', $this->path . 'jpg.jpg');
+ $file = $upload->local_upload($this->path . 'jpg.jpg');
+ $this->assertEquals(0, sizeof($file->error));
+ unlink($this->path . 'jpg.jpg');
+ }
+
+ public function test_move_existent_file()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+
+ copy($this->path . 'jpg', $this->path . 'jpg.jpg');
+ $file = $upload->local_upload($this->path . 'jpg.jpg');
+ $this->assertEquals(0, sizeof($file->error));
+ $this->assertFalse($file->move_file('../tests/upload/fixture'));
+ $this->assertFalse($file->file_moved);
+ $this->assertEquals(1, sizeof($file->error));
+ }
+
+ public function test_move_existent_file_overwrite()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+
+ copy($this->path . 'jpg', $this->path . 'jpg.jpg');
+ copy($this->path . 'jpg', $this->path . 'copies/jpg.jpg');
+ $file = $upload->local_upload($this->path . 'jpg.jpg');
+ $this->assertEquals(0, sizeof($file->error));
+ $file->move_file('../tests/upload/fixture/copies', true);
+ $this->assertEquals(0, sizeof($file->error));
+ unlink($this->path . 'copies/jpg.jpg');
+ }
+
+ public function test_valid_dimensions()
+ {
+ $upload = new fileupload('', false, false, 1, 1, 100, 100);
+
+ $file1 = $this->gen_valid_filespec();
+ $file2 = $this->gen_valid_filespec();
+ $file2->height = 101;
+ $file3 = $this->gen_valid_filespec();
+ $file3->width = 0;
+
+ $this->assertTrue($upload->valid_dimensions($file1));
+ $this->assertFalse($upload->valid_dimensions($file2));
+ $this->assertFalse($upload->valid_dimensions($file3));
+ }
+}
diff --git a/tests/upload/fixture/copies/.gitkeep b/tests/upload/fixture/copies/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/upload/fixture/copies/.gitkeep
diff --git a/tests/upload/fixture/gif b/tests/upload/fixture/gif
new file mode 100644
index 0000000000..b636f4b8df
--- /dev/null
+++ b/tests/upload/fixture/gif
Binary files differ
diff --git a/tests/upload/fixture/jpg b/tests/upload/fixture/jpg
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/upload/fixture/jpg
Binary files differ
diff --git a/tests/upload/fixture/png b/tests/upload/fixture/png
new file mode 100644
index 0000000000..5514ad40e9
--- /dev/null
+++ b/tests/upload/fixture/png
Binary files differ
diff --git a/tests/upload/fixture/tif b/tests/upload/fixture/tif
new file mode 100644
index 0000000000..248b50f9cb
--- /dev/null
+++ b/tests/upload/fixture/tif
Binary files differ
diff --git a/tests/upload/fixture/txt b/tests/upload/fixture/txt
new file mode 100644
index 0000000000..a78c858f5c
--- /dev/null
+++ b/tests/upload/fixture/txt
@@ -0,0 +1,2 @@
+<HTML>mime trigger</HTML>
+The HTML tags should remain uppercase so that case-insensitivity can be checked.
diff --git a/tests/user/fixtures/user_loader.xml b/tests/user/fixtures/user_loader.xml
new file mode 100644
index 0000000000..f676f468a6
--- /dev/null
+++ b/tests/user/fixtures/user_loader.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_permissions</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value></value>
+ <value>Guest</value>
+ <value>guest</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value></value>
+ <value>Admin</value>
+ <value>admin</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value></value>
+ <value>Test</value>
+ <value>test</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php
index d33f430955..bb11bb63cb 100644
--- a/tests/user/lang_test.php
+++ b/tests/user/lang_test.php
@@ -1,19 +1,23 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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/session.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_user_lang_test extends phpbb_test_case
{
public function test_user_lang_sprintf()
{
- $user = new user;
+ $user = new \phpbb\user('\phpbb\datetime');
$user->lang = array(
'FOO' => 'BAR',
'BARZ' => 'PENG',
@@ -26,6 +30,26 @@ class phpbb_user_lang_test extends phpbb_test_case
1 => '1 post', // 1
2 => '%d posts', // 2+
),
+ 'ARRY_NO_ZERO' => array(
+ 1 => '1 post', // 1
+ 2 => '%d posts', // 0, 2+
+ ),
+ 'ARRY_MISSING' => array(
+ 1 => '%d post', // 1
+ //Missing second plural
+ ),
+ 'ARRY_FLOAT' => array(
+ 1 => '1 post', // 1.x
+ 2 => '%1$.1f posts', // 0.x, 2+.x
+ ),
+ 'ARRY_EMPTY' => array(
+ ),
+ 'dateformat' => array(
+ 'AGO' => array(
+ 1 => '%d second',
+ 2 => '%d seconds',
+ ),
+ ),
);
// No param
@@ -51,8 +75,45 @@ class phpbb_user_lang_test extends phpbb_test_case
$this->assertEquals($user->lang('ARRY', 2), '2 posts');
$this->assertEquals($user->lang('ARRY', 123), '123 posts');
- // Bug PHPBB3-9949
+ // Empty array returns the language key
+ $this->assertEquals($user->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY');
+
+ // No 0 key defined
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts');
+
+ // Array with missing keys
+ $this->assertEquals($user->lang('ARRY_MISSING', 2), '2 post');
+
+ // Floats as array key
+ $this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts');
+
+ // Use sub key, if first paramenter is an array
+ $this->assertEquals($user->lang(array('dateformat', 'AGO'), 2), '2 seconds');
+
+ // ticket PHPBB3-9949 - use first int to determinate the plural-form to use
$this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');
+
+ // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array(
+ 'PLURAL_RULE' => 13,
+ 'ARRY' => array(
+ 0 => '%d is 0', // 0
+ 1 => '%d is 1', // 1
+ 2 => '%d ends with 01-10', // ending with 01-10
+ 3 => '%d ends with 11-19', // ending with 11-19
+ 4 => '%d is part of the last rule', // everything else
+ ),
+ );
+ $this->assertEquals($user->lang('ARRY', 0), '0 is 0');
+ $this->assertEquals($user->lang('ARRY', 1), '1 is 1');
+ $this->assertEquals($user->lang('ARRY', 103), '103 ends with 01-10');
+ $this->assertEquals($user->lang('ARRY', 15), '15 ends with 11-19');
+ $this->assertEquals($user->lang('ARRY', 300), '300 is part of the last rule');
}
}
diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php
new file mode 100644
index 0000000000..8d1f43707b
--- /dev/null
+++ b/tests/user/user_loader_test.php
@@ -0,0 +1,67 @@
+<?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.
+*
+*/
+
+include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
+
+class phpbb_user_loader_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $user_loader;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->user_loader = new \phpbb\user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users');
+ }
+
+ public function test_load_get()
+ {
+ $this->user_loader->load_users(array(2));
+
+ $user = $this->user_loader->get_user(1);
+ $this->assertEquals(1, $user['user_id']);
+ $this->assertEquals('Guest', $user['username']);
+
+ $user = $this->user_loader->get_user(2);
+ $this->assertEquals(2, $user['user_id']);
+ $this->assertEquals('Admin', $user['username']);
+ }
+
+ public function test_load_get_unloaded()
+ {
+ $this->user_loader->load_users(array(2));
+
+ $user = $this->user_loader->get_user(3);
+ $this->assertEquals(1, $user['user_id']);
+ $this->assertEquals('Guest', $user['username']);
+
+ $user = $this->user_loader->get_user(3, true);
+ $this->assertEquals(3, $user['user_id']);
+ $this->assertEquals('Test', $user['username']);
+ }
+
+ public function test_load_user_by_username()
+ {
+ $user_id = $this->user_loader->load_user_by_username('Test');
+ $user = $this->user_loader->get_user($user_id);
+ $this->assertEquals(3, $user['user_id']);
+ $this->assertEquals('Test', $user['username']);
+ }
+}
diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php
index 92230cfcc9..50eafda859 100644
--- a/tests/utf/normalizer_test.php
+++ b/tests/utf/normalizer_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/utf/utf8_clean_string_test.php b/tests/utf/utf8_clean_string_test.php
index 5ebf6409af..2bb65387e0 100644
--- a/tests/utf/utf8_clean_string_test.php
+++ b/tests/utf/utf8_clean_string_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -11,7 +15,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_utf_utf8_clean_string_test extends phpbb_test_case
{
- static public function cleanable_strings()
+ public function cleanable_strings()
{
return array(
array('MiXed CaSe', 'mixed case', 'Checking case folding'),
diff --git a/tests/utf/utf8_wordwrap_test.php b/tests/utf/utf8_wordwrap_test.php
index 39fdf73308..ab053e2911 100644
--- a/tests/utf/utf8_wordwrap_test.php
+++ b/tests/utf/utf8_wordwrap_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php
new file mode 100644
index 0000000000..cfc87183cf
--- /dev/null
+++ b/tests/version/version_fetch_test.php
@@ -0,0 +1,63 @@
+<?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 slow
+*/
+class phpbb_version_helper_fetch_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
+
+ $this->cache = $this->getMockBuilder('\phpbb\cache\service')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->version_helper = new \phpbb\version_helper(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => '3.1.0',
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime')
+ );
+ }
+
+ public function test_version_phpbb_com()
+ {
+ global $phpbb_root_path, $phpEx;
+ include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
+
+ if (!phpbb_checkdnsrr('version.phpbb.com', 'A'))
+ {
+ $this->markTestSkipped(sprintf(
+ 'Could not find a DNS record for hostname %s. ' .
+ 'Assuming network is down.',
+ 'version.phpbb.com'
+ ));
+ }
+
+ $this->version_helper->get_versions();
+
+ // get_versions checks to make sure we got a valid versions file or
+ // throws an exception if we did not. We don't need to test anything
+ // here, but adding an assertion so we do not get a warning about no
+ // assertions in this test
+ $this->assertSame(true, true);
+ }
+}
diff --git a/tests/version/version_helper_remote_test.php b/tests/version/version_helper_remote_test.php
new file mode 100644
index 0000000000..b2d497b72a
--- /dev/null
+++ b/tests/version/version_helper_remote_test.php
@@ -0,0 +1,216 @@
+<?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 version_helper_remote_test extends \phpbb_test_case
+{
+ protected $file_downloader;
+ protected $cache;
+ protected $version_helper;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
+
+ $config = new \phpbb\config\config(array(
+ 'version' => '3.1.0',
+ ));
+ $container = new \phpbb_mock_container_builder();
+ $db = new \phpbb\db\driver\factory($container);
+ $this->cache = $this->getMock('\phpbb\cache\service', array('get'), array(new \phpbb\cache\driver\null(), $config, $db, '../../', 'php'));
+ $this->cache->expects($this->any())
+ ->method('get')
+ ->with($this->anything())
+ ->will($this->returnValue(false));
+ $this->file_downloader = new phpbb_mock_file_downloader();
+
+ $this->user = new \phpbb\user('\phpbb\datetime');
+ $this->user->add_lang('acp/common');
+ $this->version_helper = new \phpbb\version_helper(
+ $this->cache,
+ $config,
+ $this->file_downloader,
+ $this->user
+ );
+ }
+
+ public function provider_get_versions()
+ {
+ return array(
+ array('', false, '', 'VERSIONCHECK_FAIL'),
+ array('foobar', false, '', 'VERSIONCHECK_FAIL'),
+ array('{
+ "stable": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false
+ }
+ }
+}', true, array (
+ 'stable' => array (
+ '1.0' => array (
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
+ ),
+ ),
+ 'unstable' => array (
+ '1.0' => array (
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
+ ),
+ ),
+ )),
+ array('{
+ "foobar": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false
+ }
+ }
+}', false, '', 'VERSIONCHECK_FAIL'),
+ array('{
+ "stable": {
+ "1.0": {
+ "current": "1.0.1<script>alert(\'foo\');</script>",
+ "download": "https://www.phpbb.com/customise/db/download/104136<script>alert(\'foo\');</script>",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/<script>alert(\'foo\');</script>",
+ "eol": "<script>alert(\'foo\');</script>",
+ "security": "<script>alert(\'foo\');</script>"
+ }
+ }
+}', false, null, 'VERSIONCHECK_INVALID_VERSION'),
+ array('{
+ "unstable": {
+ "1.0": {
+ "current": "1.0.1<script>alert(\'foo\');</script>",
+ "download": "https://www.phpbb.com/customise/db/download/104136<script>alert(\'foo\');</script>",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/<script>alert(\'foo\');</script>",
+ "eol": "<script>alert(\'foo\');</script>",
+ "security": "<script>alert(\'foo\');</script>"
+ }
+ }
+}', false, null, 'VERSIONCHECK_INVALID_VERSION'),
+ array('{
+ "unstable": {
+ "1.0<script>alert(\'foo\');</script>": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": "",
+ "security": ""
+ }
+ }
+}', false, array('stable' => array(), 'unstable' => array()), 'VERSIONCHECK_INVALID_VERSION'),
+ array('{
+ "\"\n<script>alert(\'foo\');</script>\n": "test",
+ "stable": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false
+ }
+ }
+}', true, array (
+ 'stable' => array (
+ '1.0' => array (
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
+ ),
+ ),
+ 'unstable' => array (
+ '1.0' => array (
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'eol' => NULL,
+ 'security' => false,
+ ),
+ ),
+ )),
+ array('{
+ "unstable": {
+ "1.0": {
+ "current": "1.0.1",
+ "download": "https://www.phpbb.com/customise/db/download/104136",
+ "announcement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false,
+ "foobar": "<script>alert(\'test\');<script>"
+ }
+ }
+}', true, array('stable' => array(), 'unstable' => array('1.0' => array(
+ 'current' => '1.0.1',
+ 'download' => 'https://www.phpbb.com/customise/db/download/104136',
+ 'announcement' => 'https://www.phpbb.com/customise/db/extension/boardrules/',
+ 'security' => false,
+ ))), 'VERSIONCHECK_INVALID_ENTRY'),
+ array('{
+ "unstable": {
+ "1.0": {
+ "current<script>alert(\'foo\');</script>": "1.0.1",
+ "download2": "https://www.phpbb.com/customise/db/download/104136",
+ "bannouncement": "https://www.phpbb.com/customise/db/extension/boardrules/",
+ "eol": null,
+ "security": false,
+ "foobar": "<script>alert(\'test\');<script>"
+ }
+ }
+}', true, array('stable' => array(), 'unstable' => array('1.0' => array(
+ 'security' => false,
+ ))), 'VERSIONCHECK_INVALID_ENTRY'),
+ );
+ }
+
+ /**
+ * @dataProvider provider_get_versions
+ */
+ public function test_get_versions($input, $valid_data, $expected_return = '', $expected_exception = '')
+ {
+ $this->file_downloader->set($input);
+
+ if (!$valid_data)
+ {
+ try {
+ $return = $this->version_helper->get_versions();
+ } catch (\RuntimeException $e) {
+ $this->assertEquals((string)$e->getMessage(), $this->user->lang($expected_exception));
+ }
+ }
+ else
+ {
+ $return = $this->version_helper->get_versions();
+ }
+
+ $this->assertEquals($expected_return, $return);
+ }
+}
diff --git a/tests/version/version_test.php b/tests/version/version_test.php
new file mode 100644
index 0000000000..0ed0fcb589
--- /dev/null
+++ b/tests/version/version_test.php
@@ -0,0 +1,827 @@
+<?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_version_helper_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ global $phpbb_root_path, $phpEx;
+
+ include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
+
+ $this->cache = $this->getMockBuilder('\phpbb\cache\service')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->version_helper = new \phpbb\version_helper(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => '3.1.0',
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime')
+ );
+ }
+
+ public function is_stable_data()
+ {
+ return array(
+ array(
+ '3.0.0-a1',
+ false,
+ ),
+ array(
+ '3.0.0-b1',
+ false,
+ ),
+ array(
+ '3.0.0-rc1',
+ false,
+ ),
+ array(
+ '3.0.0-RC1',
+ false,
+ ),
+ array(
+ '3.0.0',
+ true,
+ ),
+ array(
+ '3.0.0-pl1',
+ true,
+ ),
+ array(
+ '3.0.0.1-pl1',
+ true,
+ ),
+ array(
+ '3.1-dev',
+ false,
+ ),
+ array(
+ 'foobar',
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider is_stable_data
+ */
+ public function test_is_stable($version, $expected)
+ {
+ $this->assertSame($expected, $this->version_helper->is_stable($version));
+ }
+
+ public function get_suggested_updates_data()
+ {
+ return array(
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ ),
+ array(
+ '1.0.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ ),
+ array(
+ '1.0.1-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1-a2',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0',
+ ),
+ ),
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1-a2',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0',
+ ),
+ ),
+ ),
+ array(
+ '1.1.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ ),
+ array(
+ '1.1.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '1.1.0-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0-a2',
+ ),
+ ),
+ array(
+ '1.1' => array(
+ 'current' => '1.1.0-a2',
+ ),
+ ),
+ ),
+ array(
+ '1.1.0',
+ array(),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_suggested_updates_data
+ */
+ public function test_get_suggested_updates($current_version, $versions, $expected)
+ {
+ $version_helper = $this
+ ->getMockBuilder('\phpbb\version_helper')
+ ->setMethods(array(
+ 'get_versions_matching_stability',
+ ))
+ ->setConstructorArgs(array(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => $current_version,
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime'),
+ ))
+ ->getMock()
+ ;
+
+ $version_helper->expects($this->any())
+ ->method('get_versions_matching_stability')
+ ->will($this->returnValue($versions));
+
+ $this->assertSame($expected, $version_helper->get_suggested_updates());
+ }
+
+ public function get_latest_on_current_branch_data()
+ {
+ return array(
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ '1.0.1',
+ ),
+ array(
+ '1.0.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ '1.0.1',
+ ),
+ array(
+ '1.0.1-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1-a2',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0',
+ ),
+ ),
+ '1.0.1-a2',
+ ),
+ array(
+ '1.1.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ '1.1.1',
+ ),
+ array(
+ '1.1.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ '1.1.1',
+ ),
+ array(
+ '1.1.0-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0-a2',
+ ),
+ ),
+ '1.1.0-a2',
+ ),
+ array(
+ '1.1.0',
+ array(),
+ null,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_latest_on_current_branch_data
+ */
+ public function test_get_latest_on_current_branch($current_version, $versions, $expected)
+ {
+ $version_helper = $this
+ ->getMockBuilder('\phpbb\version_helper')
+ ->setMethods(array(
+ 'get_versions_matching_stability',
+ ))
+ ->setConstructorArgs(array(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => $current_version,
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime'),
+ ))
+ ->getMock()
+ ;
+
+ $version_helper->expects($this->any())
+ ->method('get_versions_matching_stability')
+ ->will($this->returnValue($versions));
+
+ $this->assertSame($expected, $version_helper->get_latest_on_current_branch());
+ }
+
+ public function get_update_on_branch_data()
+ {
+ return array(
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ '1.0.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '1.0.1-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1-a2',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1-a2',
+ ),
+ ),
+ array(
+ '1.1.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '1.1.1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '1.1.0-a1',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.0-a2',
+ ),
+ ),
+ array(
+ 'current' => '1.1.0-a2',
+ ),
+ ),
+ array(
+ '1.1.0',
+ array(),
+ array(),
+ ),
+ // Latest safe release is 1.0.1
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ 'security' => '1.0.1',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ 'security' => '1.0.1',
+ ),
+ ),
+ // Latest safe release is 1.0.0
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ 'security' => '1.0.0',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ 'security' => '1.0.0',
+ ),
+ ),
+ // Latest safe release is 1.1.0
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ 'security' => '1.1.0',
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ // Latest 1.0 release is EOL
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ 'eol' => true,
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ // All are EOL -- somewhat undefined behavior
+ array(
+ '1.0.0',
+ array(
+ '1.0' => array(
+ 'current' => '1.0.1',
+ 'eol' => true,
+ ),
+ '1.1' => array(
+ 'current' => '1.1.1',
+ 'eol' => true,
+ ),
+ ),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_update_on_branch_data
+ */
+ public function test_get_update_on_branch($current_version, $versions, $expected)
+ {
+ $version_helper = $this
+ ->getMockBuilder('\phpbb\version_helper')
+ ->setMethods(array(
+ 'get_versions_matching_stability',
+ ))
+ ->setConstructorArgs(array(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => $current_version,
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime'),
+ ))
+ ->getMock()
+ ;
+
+ $version_helper->expects($this->any())
+ ->method('get_versions_matching_stability')
+ ->will($this->returnValue($versions));
+
+ $this->assertSame($expected, $version_helper->get_update_on_branch());
+ }
+
+ public function get_ext_update_on_branch_data()
+ {
+ return array(
+ // Single branch, check version for current branch
+ array(
+ '3.1.0',
+ '1.0.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ '3.1.0',
+ '1.0.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '3.2.0',
+ '1.0.0',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.2.0',
+ '1.1.1',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ // Single branch, check for newest version when branches don't match up
+ array(
+ '3.1.0',
+ '1.0.0',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.1.0',
+ '1.1.1',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '3.2.0',
+ '1.0.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ '3.2.0',
+ '1.0.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '3.3.0',
+ '1.0.0',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.3.0',
+ '1.1.1',
+ array(
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ // Multiple branches, check version for current branch
+ array(
+ '3.1.0',
+ '1.0.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.0.1',
+ ),
+ ),
+ array(
+ '3.1.0',
+ '1.0.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '3.1.0',
+ '1.1.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ array(
+ '3.2.0',
+ '1.0.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.2.0',
+ '1.0.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.2.0',
+ '1.1.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ // Multiple branches, check for newest version when branches don't match up
+ array(
+ '3.3.0',
+ '1.0.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.3.0',
+ '1.0.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.3.0',
+ '1.1.0',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(
+ '3.3.0',
+ '1.1.1',
+ array(
+ '3.1' => array(
+ 'current' => '1.0.1',
+ ),
+ '3.2' => array(
+ 'current' => '1.1.1',
+ ),
+ ),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_ext_update_on_branch_data
+ */
+ public function test_get_ext_update_on_branch($phpbb_version, $ext_version, $versions, $expected)
+ {
+ $version_helper = $this
+ ->getMockBuilder('\phpbb\version_helper')
+ ->setMethods(array(
+ 'get_versions_matching_stability',
+ ))
+ ->setConstructorArgs(array(
+ $this->cache,
+ new \phpbb\config\config(array(
+ 'version' => $phpbb_version,
+ )),
+ new \phpbb\file_downloader(),
+ new \phpbb\user('\phpbb\datetime'),
+ ))
+ ->getMock()
+ ;
+
+ $version_helper->expects($this->any())
+ ->method('get_versions_matching_stability')
+ ->will($this->returnValue($versions));
+
+ $version_helper->set_current_version($ext_version);
+
+ $this->assertSame($expected, $version_helper->get_ext_update_on_branch());
+ }
+}
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]);
+ }
+}
diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php
index a838cfdba9..2e55a78d21 100644
--- a/tests/wrapper/gmgetdate_test.php
+++ b/tests/wrapper/gmgetdate_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
@@ -11,26 +15,28 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_wrapper_gmgetdate_test extends phpbb_test_case
{
- public function test_gmgetdate()
+ public static function phpbb_gmgetdate_data()
{
- $this->run_gmgetdate_assertion();
- $this->run_test_with_timezone('UTC');
- $this->run_test_with_timezone('Europe/Berlin');
- $this->run_test_with_timezone('America/Los_Angeles');
- $this->run_test_with_timezone('Antarctica/South_Pole');
+ return array(
+ array(''),
+ array('UTC'),
+ array('Europe/Berlin'),
+ array('America/Los_Angeles'),
+ array('Antarctica/South_Pole'),
+ );
}
- protected function run_test_with_timezone($timezone_identifier)
+ /**
+ * @dataProvider phpbb_gmgetdate_data
+ */
+ public function test_phpbb_gmgetdate($timezone_identifier)
{
- $current_timezone = date_default_timezone_get();
-
- date_default_timezone_set($timezone_identifier);
- $this->run_gmgetdate_assertion();
- date_default_timezone_set($current_timezone);
- }
+ if ($timezone_identifier)
+ {
+ $current_timezone = date_default_timezone_get();
+ date_default_timezone_set($timezone_identifier);
+ }
- protected function run_gmgetdate_assertion()
- {
$expected = time();
$date_array = phpbb_gmgetdate($expected);
@@ -44,6 +50,22 @@ class phpbb_wrapper_gmgetdate_test extends phpbb_test_case
$date_array['year']
);
- $this->assertEquals($expected, $actual);
+ // Calling second-granularity time functions twice isn't guaranteed to
+ // give the same results. As long as they're in the right order, allow
+ // a 1 second difference.
+ $this->assertGreaterThanOrEqual(
+ $expected, $actual,
+ 'Expected second time to be after (or equal to) the previous one'
+ );
+ $this->assertLessThanOrEqual(
+ 1,
+ abs($actual - $expected),
+ "Expected $actual to be within 1 second of $expected."
+ );
+
+ if (isset($current_timezone))
+ {
+ date_default_timezone_set($current_timezone);
+ }
}
}
diff --git a/tests/wrapper/mt_rand_test.php b/tests/wrapper/mt_rand_test.php
index eba0bf2faa..d190182286 100644
--- a/tests/wrapper/mt_rand_test.php
+++ b/tests/wrapper/mt_rand_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/
diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php
new file mode 100644
index 0000000000..f218ff6d03
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_fake.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_php_ini_fake extends \phpbb\php\ini
+{
+ function get($varname)
+ {
+ return $varname;
+ }
+}
diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php
new file mode 100644
index 0000000000..27c2487f0a
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_test.php
@@ -0,0 +1,90 @@
+<?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_php_ini_fake.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case
+{
+ protected $php_ini;
+
+ public function setUp()
+ {
+ $this->php_ini = new phpbb_php_ini_fake;
+ }
+
+ public function test_get_string()
+ {
+ $this->assertSame(false, $this->php_ini->get_string(false));
+ $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb '));
+ }
+
+ public function test_get_bool()
+ {
+ $this->assertSame(true, $this->php_ini->get_bool('ON'));
+ $this->assertSame(true, $this->php_ini->get_bool('on'));
+ $this->assertSame(true, $this->php_ini->get_bool('1'));
+
+ $this->assertSame(false, $this->php_ini->get_bool('OFF'));
+ $this->assertSame(false, $this->php_ini->get_bool('off'));
+ $this->assertSame(false, $this->php_ini->get_bool('0'));
+ $this->assertSame(false, $this->php_ini->get_bool(''));
+ }
+
+ public function test_get_int()
+ {
+ $this->assertSame(1234, $this->php_ini->get_int('1234'));
+ $this->assertSame(-12345, $this->php_ini->get_int('-12345'));
+ $this->assertSame(false, $this->php_ini->get_int('phpBB'));
+ }
+
+ public function test_get_float()
+ {
+ $this->assertSame(1234.0, $this->php_ini->get_float('1234'));
+ $this->assertSame(-12345.0, $this->php_ini->get_float('-12345'));
+ $this->assertSame(false, $this->php_ini->get_float('phpBB'));
+ }
+
+ public function test_get_bytes_invalid()
+ {
+ $this->assertSame(false, $this->php_ini->get_bytes(false));
+ $this->assertSame(false, $this->php_ini->get_bytes('phpBB'));
+ $this->assertSame(false, $this->php_ini->get_bytes('k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('M'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-M'));
+ }
+
+ /**
+ * @dataProvider get_bytes_data
+ */
+ public function test_get_bytes($expected, $value)
+ {
+ $actual = $this->php_ini->get_bytes($value);
+
+ $this->assertTrue(is_float($actual) || is_int($actual));
+ $this->assertEquals($expected, $actual);
+ }
+
+ static public function get_bytes_data()
+ {
+ return array(
+ array(32 * pow(2, 20), '32m'),
+ array(- 32 * pow(2, 20), '-32m'),
+ array(8 * pow(2, 30), '8G'),
+ array(- 8 * pow(2, 30), '-8G'),
+ array(1234, '1234'),
+ array(-12345, '-12345'),
+ );
+ }
+}
diff --git a/tests/wrapper/version_compare_test.php b/tests/wrapper/version_compare_test.php
index 8b42eb4bee..93d9e0117d 100644
--- a/tests/wrapper/version_compare_test.php
+++ b/tests/wrapper/version_compare_test.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* 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.
*
*/