mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/12960] Add tests for incomplete captcha
PHPBB3-12960
This commit is contained in:
parent
7da461eac4
commit
d1e2e39469
5 changed files with 101 additions and 5 deletions
|
@ -525,6 +525,7 @@ $lang = array_merge($lang, array(
|
||||||
'NO_EMAIL_SUBJECT' => 'No email subject specified.',
|
'NO_EMAIL_SUBJECT' => 'No email subject specified.',
|
||||||
'NO_FORUM' => 'The forum you selected does not exist.',
|
'NO_FORUM' => 'The forum you selected does not exist.',
|
||||||
'NO_FORUMS' => 'This board has no forums.',
|
'NO_FORUMS' => 'This board has no forums.',
|
||||||
|
'NO_GENERATOR_CLASS' => 'No generator class given.',
|
||||||
'NO_GROUP' => 'The requested usergroup does not exist.',
|
'NO_GROUP' => 'The requested usergroup does not exist.',
|
||||||
'NO_GROUP_MEMBERS' => 'This group currently has no members.',
|
'NO_GROUP_MEMBERS' => 'This group currently has no members.',
|
||||||
'NO_IPS_DEFINED' => 'No IP addresses or hostnames defined',
|
'NO_IPS_DEFINED' => 'No IP addresses or hostnames defined',
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
namespace phpbb\captcha\plugins;
|
namespace phpbb\captcha\plugins;
|
||||||
|
|
||||||
use phpbb\config\config;
|
use phpbb\config\config;
|
||||||
|
use phpbb\exception\runtime_exception;
|
||||||
use phpbb\template\template;
|
use phpbb\template\template;
|
||||||
|
|
||||||
class incomplete extends captcha_abstract
|
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
|
* @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)
|
public function init($type)
|
||||||
{
|
{
|
||||||
|
$this->type = (int) $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace phpbb\captcha\plugins;
|
namespace phpbb\captcha\plugins;
|
||||||
|
|
||||||
|
use phpbb\exception\runtime_exception;
|
||||||
|
|
||||||
class recaptcha extends captcha_abstract
|
class recaptcha extends captcha_abstract
|
||||||
{
|
{
|
||||||
private $response;
|
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.
|
* This function is implemented because required by the upper class, but is never used for reCaptcha.
|
||||||
|
* @throws runtime_exception
|
||||||
*/
|
*/
|
||||||
function get_generator_class()
|
function get_generator_class()
|
||||||
{
|
{
|
||||||
throw new \Exception('No generator class given.');
|
throw new runtime_exception('NO_GENERATOR_CLASS');
|
||||||
}
|
}
|
||||||
|
|
||||||
function acp_page($id, $module)
|
function acp_page($id, $module)
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace phpbb\captcha\plugins;
|
namespace phpbb\captcha\plugins;
|
||||||
|
|
||||||
|
use phpbb\exception\runtime_exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Google reCAPTCHA v3 plugin.
|
* Google reCAPTCHA v3 plugin.
|
||||||
*/
|
*/
|
||||||
|
@ -86,12 +88,12 @@ class recaptcha_v3 extends captcha_abstract
|
||||||
*
|
*
|
||||||
* Not needed by this CAPTCHA plugin.
|
* Not needed by this CAPTCHA plugin.
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws runtime_exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function get_generator_class()
|
public function get_generator_class()
|
||||||
{
|
{
|
||||||
throw new \Exception('No generator class given.');
|
throw new runtime_exception('NO_GENERATOR_CLASS');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
86
tests/captcha/incomplete_test.php
Normal file
86
tests/captcha/incomplete_test.php
Normal file
|
@ -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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue