diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0397672..ef4213d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,7 @@ jobs: call-tests: name: Extension tests - uses: phpbb-extensions/test-framework/.github/workflows/tests.yml@3.3.x + uses: phpbb-extensions/test-framework/.github/workflows/tests.yml@master with: EXTNAME: phpbb/consentmanager CODECOV: 1 diff --git a/config/services.yml b/config/services.yml index 3101f21..9bb35fb 100644 --- a/config/services.yml +++ b/config/services.yml @@ -28,7 +28,6 @@ services: - '@dispatcher' - '@template.twig.environment' - '@path_helper' - - '@filesystem' - '@request' phpbb.consentmanager.log_manager: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 574c6b9..572dd6a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,13 @@ - - + backupStaticProperties="false"> ./tests @@ -20,15 +17,16 @@ ./tests/functional/ - - - + + ./ - - ./language/ - ./migrations/ - ./tests/ - - - + + + ./language/ + ./migrations/ + ./tests/ + + diff --git a/service/consent_manager.php b/service/consent_manager.php index f181242..9123674 100644 --- a/service/consent_manager.php +++ b/service/consent_manager.php @@ -13,7 +13,6 @@ use phpbb\config\config; use phpbb\config\db_text; use phpbb\event\dispatcher_interface; -use phpbb\filesystem\filesystem; use phpbb\language\language; use phpbb\path_helper; use phpbb\request\request_interface; @@ -50,9 +49,6 @@ class consent_manager implements consent_manager_interface /** @var path_helper */ protected $path_helper; - /** @var filesystem */ - protected $filesystem; - /** @var request_interface */ protected $request; @@ -91,10 +87,9 @@ class consent_manager implements consent_manager_interface * @param dispatcher_interface $dispatcher Event dispatcher * @param environment $twig_environment Twig environment * @param path_helper $path_helper Path helper - * @param filesystem $filesystem Filesystem helper * @param request_interface $request Request service */ - public function __construct(consent_cache $consent_cache, translation_manager $translation_manager, config $config, db_text $config_text, language $language, dispatcher_interface $dispatcher, environment $twig_environment, path_helper $path_helper, filesystem $filesystem, request_interface $request) + public function __construct(consent_cache $consent_cache, translation_manager $translation_manager, config $config, db_text $config_text, language $language, dispatcher_interface $dispatcher, environment $twig_environment, path_helper $path_helper, request_interface $request) { $this->consent_cache = $consent_cache; $this->translation_manager = $translation_manager; @@ -104,7 +99,6 @@ public function __construct(consent_cache $consent_cache, translation_manager $t $this->dispatcher = $dispatcher; $this->twig_environment = $twig_environment; $this->path_helper = $path_helper; - $this->filesystem = $filesystem; $this->request = $request; } @@ -1014,7 +1008,7 @@ protected function resolve_local_asset_source($asset_path) return $this->local_asset_sources[$asset_path]; } - $template_asset = new asset($asset_path, $this->path_helper, $this->filesystem); + $template_asset = new asset($asset_path, $this->path_helper); if (!$this->is_valid_local_asset_path($asset_path) || !$template_asset->is_relative()) { return $this->local_asset_sources[$asset_path] = ''; diff --git a/styles/all/template/event/overall_footer_right_side_prepend.html b/styles/all/template/event/overall_footer_right_side_prepend.html new file mode 100644 index 0000000..5fc8316 --- /dev/null +++ b/styles/all/template/event/overall_footer_right_side_prepend.html @@ -0,0 +1,7 @@ +{% if S_CONSENTMANAGER_ENABLED %} + +{% endif %} diff --git a/tests/acp/acp_module_test.php b/tests/acp/acp_module_test.php index 7fde982..c4b210a 100644 --- a/tests/acp/acp_module_test.php +++ b/tests/acp/acp_module_test.php @@ -100,7 +100,7 @@ public function test_module_info() ], $this->module_manager->get_module_infos('acp', 'consentmanager_module')); } - public function module_auth_test_data() + public static function module_auth_test_data() { return [ // module_auth, expected result @@ -150,11 +150,10 @@ public function test_main_module_banner_mode() protected function expect_controller_method($method) { - $args = ['phpbb.consentmanager.controller.acp']; $this->container ->expects(self::once()) ->method('get') - ->with(...$args) + ->with('phpbb.consentmanager.controller.acp') ->willReturn($this->acp_controller); $this->acp_controller diff --git a/tests/controller/acp_controller_test.php b/tests/controller/acp_controller_test.php index 38a29a0..cfae56b 100644 --- a/tests/controller/acp_controller_test.php +++ b/tests/controller/acp_controller_test.php @@ -248,7 +248,7 @@ public function test_handle_consent_text_uses_sanitized_multibyte_request_variab $request = $this->getMockBuilder('\phpbb\request\request') ->disableOriginalConstructor() - ->setMethods(['is_set_post', 'variable', 'raw_variable']) + ->onlyMethods(['is_set_post', 'variable', 'raw_variable']) ->getMock(); $request->method('is_set_post') ->willReturnCallback(static function ($name) { @@ -341,7 +341,7 @@ public function test_handle_invalid_form_key($action, $manager_method, $log_acti $this->create_controller($this->create_request_mock([$action => 1]))->handle(); } - public function handle_invalid_form_key_data() + public static function handle_invalid_form_key_data() { return [ 'submit' => ['submit', 'save_settings'], @@ -386,7 +386,7 @@ public function test_handle_logs_invalid_form_key_before_processing(array $reque $this->create_controller($this->create_request_mock($request_values), self::EXPORT_URL)->handle_logs(); } - public function handle_logs_invalid_form_key_data() + public static function handle_logs_invalid_form_key_data() { return [ 'download csv' => [ @@ -464,7 +464,7 @@ public function test_handle_logs_delete_requests_confirmation_with_current_filte ], $expected_token_fields), self::$confirm_hidden_fields); } - public function handle_logs_delete_confirmation_data() + public static function handle_logs_delete_confirmation_data() { return [ 'with current csrf tokens' => [ @@ -561,7 +561,7 @@ public function test_handle_logs_invalid_filters_show_error($action, array $requ $this->create_controller($this->create_request_mock($request_values), self::EXPORT_URL)->handle_logs(); } - public function handle_logs_invalid_filter_data() + public static function handle_logs_invalid_filter_data() { $cases = [ 'invalid date from' => [ @@ -755,7 +755,7 @@ public function test_handle_logs_unknown_username_shows_error($action) ]), self::EXPORT_URL)->handle_logs(); } - public function handle_logs_unknown_username_data() + public static function handle_logs_unknown_username_data() { return [ 'download csv' => ['download_csv'], @@ -767,7 +767,7 @@ protected function create_request_mock(array $values = [], array $raw_values = [ { $request = $this->getMockBuilder('\phpbb\request\request') ->disableOriginalConstructor() - ->setMethods(['is_set_post', 'variable', 'raw_variable']) + ->onlyMethods(['is_set_post', 'variable', 'raw_variable']) ->getMock(); $request->method('is_set_post') diff --git a/tests/controller/log_controller_test.php b/tests/controller/log_controller_test.php index e798a9d..fc2f45b 100644 --- a/tests/controller/log_controller_test.php +++ b/tests/controller/log_controller_test.php @@ -104,7 +104,7 @@ public function test_log_persists_valid_submission() ), json_decode($response->getContent(), true)); } - public function invalid_submission_data() + public static function invalid_submission_data() { return array( 'invalid hash' => array('invalid_hash', 403), diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 38aebe5..561d504 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -82,7 +82,7 @@ public function test_configure_iframe_renderer_delegates_to_media_manager() ])); } - public function inject_frontend_assigns_template_payload_data() + public static function inject_frontend_assigns_template_payload_data() { return [ 'front end' => [true], @@ -145,24 +145,35 @@ public function test_inject_frontend_assigns_template_payload($invoke) ]); $template->expects($invoke ? self::exactly(2) : self::never()) ->method('assign_block_vars') - ->withConsecutive( - ['CONSENTMANAGER_CATEGORIES', [ - 'ID' => 'necessary', - 'LABEL' => 'Necessary', - 'DESCRIPTION' => 'Required cookies.', - 'REQUIRED' => true, - 'services' => [ - [ - 'LABEL' => 'Cookie baker', - 'DESCRIPTION' => 'Delicious cookies', + ->willReturnCallback(function() use ($invoke) { + static $call = 0; + $args = func_get_args(); + if ($call === 0) + { + self::assertSame('CONSENTMANAGER_CATEGORIES', $args[0]); + self::assertSame([ + 'ID' => 'necessary', + 'LABEL' => 'Necessary', + 'DESCRIPTION' => 'Required cookies.', + 'REQUIRED' => true, + 'services' => [ + [ + 'LABEL' => 'Cookie baker', + 'DESCRIPTION' => 'Delicious cookies', + ], ], - ], - ]], - ['CONSENTMANAGER_CATEGORIES.CONSENTMANAGER_SERVICES', [ - 'LABEL' => 'Cookie baker', - 'DESCRIPTION' => 'Delicious cookies', - ]] - ); + ], $args[1]); + } + else + { + self::assertSame('CONSENTMANAGER_CATEGORIES.CONSENTMANAGER_SERVICES', $args[0]); + self::assertSame([ + 'LABEL' => 'Cookie baker', + 'DESCRIPTION' => 'Delicious cookies', + ], $args[1]); + } + $call++; + }); $listener = new class($helper, $this->language, $consent_manager, $template, $this->media_manager, $invoke) extends \phpbb\consentmanager\event\listener { /** @var bool */ diff --git a/tests/functional/frontend_test.php b/tests/functional/frontend_test.php index cdb10e7..30973d7 100644 --- a/tests/functional/frontend_test.php +++ b/tests/functional/frontend_test.php @@ -81,7 +81,7 @@ public function test_log_endpoint_rejects_invalid_json_payload() '{invalid' ); - $this->assertSame(400, self::$client->getResponse()->getStatus()); + $this->assertSame(400, self::$client->getResponse()->getStatusCode()); $this->assertSame(array( 'success' => false, 'error' => 'invalid_payload', @@ -93,7 +93,7 @@ public function test_log_endpoint_persists_valid_anonymous_submission() $payload = $this->fetch_frontend_payload(); $response = $this->post_log_request($payload, array('analytics', 'analytics', 'unknown')); - $this->assertSame(200, self::$client->getResponse()->getStatus()); + $this->assertSame(200, self::$client->getResponse()->getStatusCode()); $this->assertSame(array('necessary', 'analytics'), $response['categories']); $this->assertSame($payload['version'], $response['version']); @@ -114,7 +114,7 @@ public function test_log_endpoint_persists_valid_authenticated_submission() $payload = $this->fetch_frontend_payload(); $response = $this->post_log_request($payload, array('analytics', 'analytics', 'unknown')); - $this->assertSame(200, self::$client->getResponse()->getStatus()); + $this->assertSame(200, self::$client->getResponse()->getStatusCode()); $this->assertSame(array('necessary', 'analytics'), $response['categories']); $this->assertSame($payload['version'], $response['version']); @@ -134,7 +134,7 @@ public function test_log_endpoint_rejects_stale_version() $payload = $this->fetch_frontend_payload(); $response = $this->post_log_request($payload, array('analytics'), $payload['version'] + 1); - $this->assertSame(409, self::$client->getResponse()->getStatus()); + $this->assertSame(409, self::$client->getResponse()->getStatusCode()); $this->assertSame('version_mismatch', $response['error']); } diff --git a/tests/service/acp_manager_test.php b/tests/service/acp_manager_test.php index 9859cc8..b37136b 100644 --- a/tests/service/acp_manager_test.php +++ b/tests/service/acp_manager_test.php @@ -61,7 +61,7 @@ public function test_log_admin_action_delegates_to_phpbb_log($log_action) { $log = $this->getMockBuilder('\phpbb\log\log') ->disableOriginalConstructor() - ->setMethods(array('add')) + ->onlyMethods(array('add')) ->getMock(); $log->expects(self::once()) ->method('add') @@ -70,7 +70,7 @@ public function test_log_admin_action_delegates_to_phpbb_log($log_action) $this->create_manager(7, 'admin-session', $log)->log_admin_action($log_action); } - public function log_admin_action_data() + public static function log_admin_action_data() { return [ ['LOG_CONSENTMANAGER_UPDATED'], @@ -334,7 +334,7 @@ public function test_save_settings_rejects_invalid_integrations($json) self::assertSame([$this->language->lang('ACP_CONSENTMANAGER_INVALID_INTEGRATIONS')], $errors); } - public function invalid_integrations_data() + public static function invalid_integrations_data() { return [ 'malformed json' => ['{not json'], @@ -370,7 +370,7 @@ public function test_save_settings_rejects_invalid_array_integrations($integrati self::assertSame($expected_errors, $errors); } - public function invalid_array_integrations_data() + public static function invalid_array_integrations_data() { return [ 'invalid entry' => [ @@ -511,10 +511,10 @@ public function test_stream_logs_csv_row_format_is_correct() self::assertCount(4, $row); // anonymized_id: 64-char hex - self::assertRegExp('/^[0-9a-f]{64}$/', $row[0]); + self::assertMatchesRegularExpression('/^[0-9a-f]{64}$/', $row[0]); // timestamp: ISO 8601 UTC - self::assertRegExp('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/', $row[1]); + self::assertMatchesRegularExpression('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/', $row[1]); // consent_version self::assertSame('3', $row[2]); @@ -794,10 +794,7 @@ protected function get_language_messages(array $message_specs) protected function invoke_method($object, $method_name, array $arguments = []) { - $method = new \ReflectionMethod($object, $method_name); - $method->setAccessible(true); - - return $method->invokeArgs($object, $arguments); + return (new \ReflectionMethod($object, $method_name))->invokeArgs($object, $arguments); } protected function create_log_manager($user_id, $session_id) diff --git a/tests/service/consent_manager_test.php b/tests/service/consent_manager_test.php index b282ff5..334ef03 100644 --- a/tests/service/consent_manager_test.php +++ b/tests/service/consent_manager_test.php @@ -15,9 +15,6 @@ class consent_manager_test extends \phpbb_test_case /** @var \phpbb\language\language */ protected $language; - /** @var \phpbb\filesystem\filesystem */ - protected $filesystem; - /** @var \phpbb\path_helper */ protected $path_helper; @@ -41,8 +38,6 @@ protected function setUp(): void $this->language->add_lang('common', 'phpbb/consentmanager'); $this->language->add_lang('acp_consentmanager', 'phpbb/consentmanager'); - $this->filesystem = new \phpbb\filesystem\filesystem(); - $request = new \phpbb_mock_request(array(), array(), array(), array( 'HTTP_HOST' => 'example.com', 'REQUEST_URI' => '/index.php', @@ -51,7 +46,6 @@ protected function setUp(): void $symfony_request = new \phpbb\symfony_request($request); $this->path_helper = new \phpbb\path_helper( $symfony_request, - $this->filesystem, $request, $phpbb_root_path, $phpEx @@ -133,7 +127,7 @@ public function test_get_configured_integrations_uses_persistent_cache() $cached_manager = $this->getMockBuilder('\phpbb\consentmanager\service\consent_manager') ->setConstructorArgs($this->get_manager_constructor_args([], $config_text, new \phpbb_mock_event_dispatcher(), null, null, $this->language, $consent_cache)) - ->setMethods(['normalize_integrations']) + ->onlyMethods(['normalize_integrations']) ->getMock(); $cached_manager->expects(self::never()) ->method('normalize_integrations'); @@ -154,7 +148,7 @@ public function test_get_configured_integrations_reloads_after_persistent_cache_ $refreshed_manager = $this->getMockBuilder('\phpbb\consentmanager\service\consent_manager') ->setConstructorArgs($this->get_manager_constructor_args([], $config_text, new \phpbb_mock_event_dispatcher(), null, null, $this->language, $consent_cache)) - ->setMethods(['normalize_integrations']) + ->onlyMethods(['normalize_integrations']) ->getMock(); $normalize_args = [$this->get_submitted_integrations_json(), self::anything()]; $refreshed_manager->expects(self::once()) @@ -190,7 +184,7 @@ public function test_get_configured_integrations_cache_ignores_asset_version_cha $cached_manager = $this->getMockBuilder('\phpbb\consentmanager\service\consent_manager') ->setConstructorArgs($this->get_manager_constructor_args(['assets_version' => 99], $config_text, new \phpbb_mock_event_dispatcher(), null, null, $this->language, $consent_cache)) - ->setMethods(['normalize_integrations']) + ->onlyMethods(['normalize_integrations']) ->getMock(); $cached_manager->expects(self::never()) ->method('normalize_integrations'); @@ -256,7 +250,7 @@ public function test_register_rejects_invalid_definitions($id, array $definition self::assertSame(array(), $manager->get_services()); } - public function invalid_registration_data() + public static function invalid_registration_data() { return array( 'invalid id' => array('bad id', array( @@ -281,7 +275,7 @@ public function test_register_discards_invalid_script_sources(array $definition) self::assertSame(array(), $this->get_service('vendor.bundle', $manager)['scripts']); } - public function invalid_script_source_data() + public static function invalid_script_source_data() { return array( 'multiple sources' => array(array( @@ -844,7 +838,7 @@ public function test_normalize_integrations_handles_edge_cases($input, array $ex self::assertSame($this->get_language_messages($expected_error_specs), $errors); } - public function normalize_integrations_edge_case_data() + public static function normalize_integrations_edge_case_data() { return array( 'empty string' => array( @@ -999,7 +993,7 @@ public function test_has_server_consent_rejects_invalid_cookie_state($cookie_val self::assertFalse($manager->has_server_consent($category)); } - public function invalid_server_consent_cookie_data() + public static function invalid_server_consent_cookie_data() { return [ 'stale version' => [ @@ -1039,7 +1033,7 @@ public function test_register_resolves_template_assets_via_twig_lookup() { $twig_environment = $this->getMockBuilder('\phpbb\template\twig\environment') ->disableOriginalConstructor() - ->setMethods(array('get_phpbb_root_path', 'findTemplate')) + ->onlyMethods(array('get_phpbb_root_path', 'findTemplate')) ->getMock(); $twig_environment->method('get_phpbb_root_path') ->willReturn($this->phpbb_root_path); @@ -1064,7 +1058,7 @@ public function test_register_discards_missing_template_assets() { $twig_environment = $this->getMockBuilder('\phpbb\template\twig\environment') ->disableOriginalConstructor() - ->setMethods(array('get_phpbb_root_path', 'findTemplate')) + ->onlyMethods(array('get_phpbb_root_path', 'findTemplate')) ->getMock(); $twig_environment->method('get_phpbb_root_path') ->willReturn($this->phpbb_root_path); @@ -1087,7 +1081,7 @@ protected function create_twig_environment_mock($template_path, $result, $invoca { $twig_environment = $this->getMockBuilder('\phpbb\template\twig\environment') ->disableOriginalConstructor() - ->setMethods(array('get_phpbb_root_path', 'getNamespaceLookUpOrder', 'findTemplate')) + ->onlyMethods(array('get_phpbb_root_path', 'getNamespaceLookUpOrder', 'findTemplate')) ->getMock(); $twig_environment->method('get_phpbb_root_path') ->willReturn($this->phpbb_root_path); @@ -1143,7 +1137,7 @@ protected function get_manager_constructor_args(array $config_values = array(), { $twig_environment = $this->getMockBuilder('\phpbb\template\twig\environment') ->disableOriginalConstructor() - ->setMethods(array('get_phpbb_root_path', 'getNamespaceLookUpOrder', 'findTemplate')) + ->onlyMethods(array('get_phpbb_root_path', 'getNamespaceLookUpOrder', 'findTemplate')) ->getMock(); $twig_environment->method('get_phpbb_root_path') ->willReturn($this->phpbb_root_path); @@ -1182,7 +1176,6 @@ protected function get_manager_constructor_args(array $config_values = array(), $dispatcher, $twig_environment, $this->path_helper, - $this->filesystem, $request, ]; } diff --git a/tests/service/media_manager_test.php b/tests/service/media_manager_test.php index f19c57a..ab6ddf8 100644 --- a/tests/service/media_manager_test.php +++ b/tests/service/media_manager_test.php @@ -204,7 +204,7 @@ public function test_build_iframe_placeholder_template_edge_cases($template, $re } } - public function build_iframe_placeholder_template_data() + public static function build_iframe_placeholder_template_data() { return [ 'no runtime iframes' => [ @@ -261,10 +261,7 @@ public function test_rewrite_iframe_node_rewrites_static_and_xsl_src_and_onload_ protected function invoke_method($object, $method_name, array $arguments = []) { - $method = new \ReflectionMethod($object, $method_name); - $method->setAccessible(true); - - return $method->invokeArgs($object, $arguments); + return (new \ReflectionMethod($object, $method_name))->invokeArgs($object, $arguments); } protected function build_strip_internal_s9e_fixture() @@ -295,7 +292,7 @@ protected function create_renderer_mock($parameter_name, $parameter_value) $renderer = $this->getMockBuilder('\phpbb\textformatter\s9e\renderer') ->disableOriginalConstructor() - ->setMethods(['get_renderer']) + ->onlyMethods(['get_renderer']) ->getMock(); $renderer->expects(self::once()) ->method('get_renderer') diff --git a/tests/service/translation_manager_test.php b/tests/service/translation_manager_test.php index 867569d..eb483be 100644 --- a/tests/service/translation_manager_test.php +++ b/tests/service/translation_manager_test.php @@ -52,7 +52,6 @@ protected function setUp(): void $this->insert_language('de', 'German'); $config = new \phpbb\config\config(['allow_nocensors' => false]); - set_config(null, null, null, $config); $cache = new \phpbb_mock_cache(); $phpbb_container = new \phpbb_mock_container_builder(); diff --git a/tests/system/ext_test.php b/tests/system/ext_test.php index 769da44..3fe5d53 100644 --- a/tests/system/ext_test.php +++ b/tests/system/ext_test.php @@ -29,7 +29,7 @@ protected function setUp(): void parent::setUp(); $this->container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')->disableOriginalConstructor()->getMock(); - $this->extension_finder = $this->getMockBuilder('\phpbb\finder')->disableOriginalConstructor()->getMock(); + $this->extension_finder = $this->getMockBuilder('\phpbb\finder\finder')->disableOriginalConstructor()->getMock(); $this->migrator = $this->getMockBuilder('\phpbb\db\migrator')->disableOriginalConstructor()->getMock(); } @@ -60,7 +60,7 @@ public function test_ext_returns_localized_error_when_not_enableable() $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $extension_manager = $this->getMockBuilder('\phpbb\extension\manager') ->disableOriginalConstructor() - ->setMethods(['get_extension_path']) + ->onlyMethods(['get_extension_path']) ->getMock(); $extension_manager_args = ['phpbb/consentmanager', true]; $extension_manager->method('get_extension_path')