diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 79128293e2..25851d738e 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -525,6 +525,7 @@ $lang = array_merge($lang, array( 'NO_EMAIL_SUBJECT' => 'No email subject specified.', 'NO_FORUM' => 'The forum you selected does not exist.', 'NO_FORUMS' => 'This board has no forums.', + 'NO_GENERATOR_CLASS' => 'No generator class given.', 'NO_GROUP' => 'The requested usergroup does not exist.', 'NO_GROUP_MEMBERS' => 'This group currently has no members.', 'NO_IPS_DEFINED' => 'No IP addresses or hostnames defined', diff --git a/phpBB/phpbb/captcha/plugins/incomplete.php b/phpBB/phpbb/captcha/plugins/incomplete.php index 5c2b7f9a66..37301c45f5 100644 --- a/phpBB/phpbb/captcha/plugins/incomplete.php +++ b/phpBB/phpbb/captcha/plugins/incomplete.php @@ -14,6 +14,7 @@ namespace phpbb\captcha\plugins; use phpbb\config\config; +use phpbb\exception\runtime_exception; use phpbb\template\template; class incomplete extends captcha_abstract @@ -39,12 +40,14 @@ class incomplete extends captcha_abstract } /** - * Dummy implementation + * Dummy implementation, not supported by this captcha * + * @throws runtime_exception * @return void */ - public function get_generator_class() + public function get_generator_class(): void { + throw new runtime_exception('NO_GENERATOR_CLASS'); } /** @@ -65,6 +68,7 @@ class incomplete extends captcha_abstract */ public function init($type) { + $this->type = (int) $type; } /** diff --git a/phpBB/phpbb/captcha/plugins/recaptcha.php b/phpBB/phpbb/captcha/plugins/recaptcha.php index 399eb34b6b..ef30baaa9b 100644 --- a/phpBB/phpbb/captcha/plugins/recaptcha.php +++ b/phpBB/phpbb/captcha/plugins/recaptcha.php @@ -13,6 +13,8 @@ namespace phpbb\captcha\plugins; +use phpbb\exception\runtime_exception; + class recaptcha extends captcha_abstract { private $response; @@ -55,10 +57,11 @@ class recaptcha extends captcha_abstract /** * This function is implemented because required by the upper class, but is never used for reCaptcha. + * @throws runtime_exception */ function get_generator_class() { - throw new \Exception('No generator class given.'); + throw new runtime_exception('NO_GENERATOR_CLASS'); } function acp_page($id, $module) diff --git a/phpBB/phpbb/captcha/plugins/recaptcha_v3.php b/phpBB/phpbb/captcha/plugins/recaptcha_v3.php index 02dacb4b51..67035ab1c6 100644 --- a/phpBB/phpbb/captcha/plugins/recaptcha_v3.php +++ b/phpBB/phpbb/captcha/plugins/recaptcha_v3.php @@ -13,6 +13,8 @@ namespace phpbb\captcha\plugins; +use phpbb\exception\runtime_exception; + /** * Google reCAPTCHA v3 plugin. */ @@ -86,12 +88,12 @@ class recaptcha_v3 extends captcha_abstract * * Not needed by this CAPTCHA plugin. * - * @throws \Exception + * @throws runtime_exception * @return void */ public function get_generator_class() { - throw new \Exception('No generator class given.'); + throw new runtime_exception('NO_GENERATOR_CLASS'); } /** diff --git a/tests/captcha/incomplete_test.php b/tests/captcha/incomplete_test.php new file mode 100644 index 0000000000..88b6825fa9 --- /dev/null +++ b/tests/captcha/incomplete_test.php @@ -0,0 +1,86 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +use phpbb\captcha\plugins\incomplete; +use phpbb\config\config; +use phpbb\template\template; + +class phpbb_captcha_incomplete_test extends phpbb_test_case +{ + protected config $config; + + protected template $template; + + + /** @var incomplete */ + protected incomplete $incomplete_captcha; + + protected array $assigned_vars = []; + + public function assign_vars(array $vars): void + { + $this->assigned_vars = array_merge($this->assigned_vars, $vars); + } + + protected function setUp(): void + { + global $phpbb_root_path, $phpEx; + + $this->config = new config([]); + $this->template = $this->getMockBuilder('\phpbb\template\twig\twig') + ->setMethods(['assign_vars']) + ->disableOriginalConstructor() + ->getMock(); + $this->template->method('assign_vars') + ->willReturnCallback([$this, 'assign_vars']); + + $this->incomplete_captcha = new incomplete( + $this->config, + $this->template, + $phpbb_root_path, + $phpEx + ); + } + + public function test_miscellaneous_incomplete(): void + { + $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->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(); + } + + public function test_get_tempate(): void + { + $this->incomplete_captcha->init(CONFIRM_REG); + $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->assertSame('captcha_incomplete.html', $this->incomplete_captcha->get_template()); + $this->assertEquals('POST_CONFIRM_INCOMPLETE', $this->assigned_vars['CONFIRM_LANG']); + } +}