mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/17414] Change incomplete CAPTCHA to extend new base class
PHPBB-17414
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user