diff --git a/phpBB/config/default/container/services_captcha.yml b/phpBB/config/default/container/services_captcha.yml index d4f1ad863a..ea41fefe80 100644 --- a/phpBB/config/default/container/services_captcha.yml +++ b/phpBB/config/default/container/services_captcha.yml @@ -19,7 +19,11 @@ services: shared: false arguments: - '@config' + - '@dbal.conn' + - '@language' + - '@request' - '@template' + - '@user' - '%core.root_path%' - '%core.php_ext%' calls: diff --git a/phpBB/phpbb/captcha/plugins/base.php b/phpBB/phpbb/captcha/plugins/base.php index 1b02d63166..a30e679731 100644 --- a/phpBB/phpbb/captcha/plugins/base.php +++ b/phpBB/phpbb/captcha/plugins/base.php @@ -246,4 +246,11 @@ abstract class base implements plugin_interface } $this->db->sql_freeresult($result); } + + /** + * {@inheritDoc} + */ + public function acp_page(mixed $id, mixed $module): void + { + } } diff --git a/phpBB/phpbb/captcha/plugins/incomplete.php b/phpBB/phpbb/captcha/plugins/incomplete.php index ec3376c0a5..07998a7125 100644 --- a/phpBB/phpbb/captcha/plugins/incomplete.php +++ b/phpBB/phpbb/captcha/plugins/incomplete.php @@ -14,25 +14,34 @@ namespace phpbb\captcha\plugins; use phpbb\config\config; -use phpbb\exception\runtime_exception; +use phpbb\db\driver\driver_interface; +use phpbb\language\language; +use phpbb\request\request_interface; use phpbb\template\template; +use phpbb\user; -class incomplete extends captcha_abstract +class incomplete extends base { /** * Constructor for incomplete captcha * * @param config $config + * @param driver_interface $db + * @param language $language + * @param request_interface $request * @param template $template + * @param user $user * @param string $phpbb_root_path * @param string $phpEx */ - public function __construct(protected config $config, protected template $template, - protected string $phpbb_root_path, protected string $phpEx) - {} + public function __construct(config $config, driver_interface $db, language $language, request_interface $request, + protected template $template, user $user, protected string $phpbb_root_path, protected string $phpEx) + { + parent::__construct($config, $db, $language, $request, $user); + } /** - * @return bool True if captcha is available, false if not + * {@inheritDoc} */ public function is_available(): bool { @@ -40,70 +49,45 @@ class incomplete extends captcha_abstract } /** - * Dummy implementation, not supported by this captcha - * - * @throws runtime_exception - * @return void + * {@inheritDoc} */ - public function get_generator_class(): void + public function has_config(): bool { - throw new runtime_exception('NO_GENERATOR_CLASS'); + return false; } /** - * Get CAPTCHA name language variable - * - * @return string Language variable + * {@inheritDoc} */ - public static function get_name(): string + public function get_name(): string { return 'CAPTCHA_INCOMPLETE'; } /** - * Init CAPTCHA - * - * @param int $type CAPTCHA type - * @return void + * {@inheritDoc} */ - public function init($type) + public function set_name(string $name): void { } /** - * Execute demo - * - * @return void + * {@inheritDoc} */ - public function execute_demo() + public function init(confirm_type $type): void { } /** - * Execute CAPTCHA - * - * @return void + * {@inheritDoc} */ - public function execute() - { - } - - /** - * Get template data for demo - * - * @param int|string $id ACP module ID - * - * @return string Demo template file name - */ - public function get_demo_template($id): string + public function get_demo_template(): string { return ''; } /** - * Get template data for CAPTCHA - * - * @return string CAPTCHA template file name + * {@inheritDoc} */ public function get_template(): string { @@ -118,9 +102,7 @@ class incomplete extends captcha_abstract } /** - * Validate CAPTCHA - * - * @return false Incomplete CAPTCHA will never validate + * {@inheritDoc} */ public function validate(): bool { @@ -128,12 +110,26 @@ class incomplete extends captcha_abstract } /** - * Check whether CAPTCHA is solved - * - * @return false Incomplete CAPTCHA will never be solved + * {@inheritDoc} + */ + public function get_error(): string + { + return ''; + } + + /** + * {@inheritDoc} */ public function is_solved(): bool { return false; } + + /** + * {@inheritDoc} + */ + public function get_attempt_count(): int + { + return 0; + } } diff --git a/phpBB/phpbb/captcha/plugins/legacy_wrapper.php b/phpBB/phpbb/captcha/plugins/legacy_wrapper.php index 600683194d..aaabddb48b 100644 --- a/phpBB/phpbb/captcha/plugins/legacy_wrapper.php +++ b/phpBB/phpbb/captcha/plugins/legacy_wrapper.php @@ -211,7 +211,7 @@ class legacy_wrapper implements plugin_interface /** * {@inheritDoc} */ - public function acp_page($id, $module): void + public function acp_page(mixed $id, mixed $module): void { if (method_exists($this->legacy_captcha, 'acp_page')) { diff --git a/phpBB/phpbb/captcha/plugins/plugin_interface.php b/phpBB/phpbb/captcha/plugins/plugin_interface.php index f9dd9c6402..41483e45a5 100644 --- a/phpBB/phpbb/captcha/plugins/plugin_interface.php +++ b/phpBB/phpbb/captcha/plugins/plugin_interface.php @@ -122,5 +122,5 @@ interface plugin_interface * @param mixed $module ACP module name * @return void */ - public function acp_page($id, $module): void; + public function acp_page(mixed $id, mixed $module): void; } diff --git a/phpBB/phpbb/captcha/plugins/turnstile.php b/phpBB/phpbb/captcha/plugins/turnstile.php index edd6832159..afd7a363b2 100644 --- a/phpBB/phpbb/captcha/plugins/turnstile.php +++ b/phpBB/phpbb/captcha/plugins/turnstile.php @@ -229,7 +229,7 @@ class turnstile extends base /** * {@inheritDoc} */ - public function acp_page($id, $module): void + public function acp_page(mixed $id, mixed $module): void { $captcha_vars = [ 'captcha_turnstile_sitekey' => 'CAPTCHA_TURNSTILE_SITEKEY', diff --git a/tests/captcha/incomplete_test.php b/tests/captcha/incomplete_test.php index c1da2b6c48..4c5e7c6b27 100644 --- a/tests/captcha/incomplete_test.php +++ b/tests/captcha/incomplete_test.php @@ -11,11 +11,15 @@ * */ +use phpbb\captcha\plugins\confirm_type; use phpbb\captcha\plugins\incomplete; use phpbb\config\config; +use phpbb\language\language; +use phpbb\request\request; use phpbb\template\template; +use phpbb\user; -class phpbb_captcha_incomplete_test extends phpbb_test_case +class phpbb_captcha_incomplete_test extends phpbb_database_test_case { protected config $config; @@ -32,21 +36,34 @@ class phpbb_captcha_incomplete_test extends phpbb_test_case $this->assigned_vars = array_merge($this->assigned_vars, $vars); } + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/../fixtures/empty.xml'); + } + protected function setUp(): void { global $phpbb_root_path, $phpEx; $this->config = new config([]); $this->template = $this->getMockBuilder('\phpbb\template\twig\twig') - ->setMethods(['assign_vars']) + ->onlyMethods(['assign_vars']) ->disableOriginalConstructor() ->getMock(); $this->template->method('assign_vars') ->willReturnCallback([$this, 'assign_vars']); + $db = $this->new_dbal(); + $language = $this->createMock(language::class); + $request = $this->createMock(request::class); + $user = $this->createMock(user::class); $this->incomplete_captcha = new incomplete( $this->config, + $db, + $language, + $request, $this->template, + $user, $phpbb_root_path, $phpEx ); @@ -57,29 +74,25 @@ class phpbb_captcha_incomplete_test extends phpbb_test_case $this->assertTrue($this->incomplete_captcha->is_available()); $this->assertFalse($this->incomplete_captcha->is_solved()); $this->assertFalse($this->incomplete_captcha->validate()); - $this->assertSame('CAPTCHA_INCOMPLETE', incomplete::get_name()); - $this->incomplete_captcha->init(0); - $this->incomplete_captcha->execute(); - $this->incomplete_captcha->execute_demo(); + $this->assertFalse($this->incomplete_captcha->has_config()); + $this->incomplete_captcha->set_name('foo'); + $this->assertSame('CAPTCHA_INCOMPLETE', $this->incomplete_captcha->get_name()); + $this->incomplete_captcha->init(confirm_type::UNDEFINED); $this->assertEmpty($this->assigned_vars); $this->assertEmpty($this->incomplete_captcha->get_demo_template(0)); - } - - public function test_get_generator_class(): void - { - $this->expectException(\phpbb\exception\runtime_exception::class); - $this->incomplete_captcha->get_generator_class(); + $this->assertEmpty($this->incomplete_captcha->get_error()); + $this->assertSame(0, $this->incomplete_captcha->get_attempt_count()); } public function test_get_tempate(): void { - $this->incomplete_captcha->init(CONFIRM_REG); + $this->incomplete_captcha->init(confirm_type::REGISTRATION); $this->assertSame('captcha_incomplete.html', $this->incomplete_captcha->get_template()); $this->assertEquals('CONFIRM_INCOMPLETE', $this->assigned_vars['CONFIRM_LANG']); $this->assigned_vars = []; - $this->incomplete_captcha->init(CONFIRM_POST); + $this->incomplete_captcha->init(confirm_type::POST); $this->assertSame('captcha_incomplete.html', $this->incomplete_captcha->get_template()); $this->assertEquals('CONFIRM_INCOMPLETE', $this->assigned_vars['CONFIRM_LANG']); }