Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_captcha_incomplete_test
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 assign_vars
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUp
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
1 / 1
1
 test_miscellaneous_incomplete
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 test_get_tempate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14use phpbb\captcha\plugins\confirm_type;
15use phpbb\captcha\plugins\incomplete;
16use phpbb\config\config;
17use phpbb\language\language;
18use phpbb\request\request;
19use phpbb\template\template;
20use phpbb\user;
21
22class phpbb_captcha_incomplete_test extends phpbb_database_test_case
23{
24    protected config $config;
25
26    protected template $template;
27
28
29    /** @var incomplete */
30    protected incomplete $incomplete_captcha;
31
32    protected array $assigned_vars = [];
33
34    public function assign_vars(array $vars): void
35    {
36        $this->assigned_vars = array_merge($this->assigned_vars, $vars);
37    }
38
39    public function getDataSet()
40    {
41        return $this->createXMLDataSet(__DIR__ . '/../fixtures/empty.xml');
42    }
43
44    protected function setUp(): void
45    {
46        global $phpbb_root_path, $phpEx;
47
48        $this->config = new config([]);
49        $this->template = $this->getMockBuilder('\phpbb\template\twig\twig')
50            ->onlyMethods(['assign_vars'])
51            ->disableOriginalConstructor()
52            ->getMock();
53        $this->template->method('assign_vars')
54            ->willReturnCallback([$this, 'assign_vars']);
55        $db = $this->new_dbal();
56        $language = $this->createMock(language::class);
57        $request = $this->createMock(request::class);
58        $user = $this->createMock(user::class);
59
60        $this->incomplete_captcha = new incomplete(
61            $this->config,
62            $db,
63            $language,
64            $request,
65            $this->template,
66            $user,
67            $phpbb_root_path,
68            $phpEx
69        );
70    }
71
72    public function test_miscellaneous_incomplete(): void
73    {
74        $this->assertTrue($this->incomplete_captcha->is_available());
75        $this->assertFalse($this->incomplete_captcha->is_solved());
76        $this->assertFalse($this->incomplete_captcha->validate());
77        $this->assertFalse($this->incomplete_captcha->has_config());
78        $this->incomplete_captcha->set_name('foo');
79        $this->assertSame('CAPTCHA_INCOMPLETE', $this->incomplete_captcha->get_name());
80        $this->incomplete_captcha->init(confirm_type::UNDEFINED);
81        $this->assertEmpty($this->assigned_vars);
82        $this->assertEmpty($this->incomplete_captcha->get_demo_template(0));
83        $this->assertEmpty($this->incomplete_captcha->get_error());
84        $this->assertSame(0, $this->incomplete_captcha->get_attempt_count());
85    }
86
87    public function test_get_tempate(): void
88    {
89        $this->incomplete_captcha->init(confirm_type::REGISTRATION);
90        $this->assertSame('captcha_incomplete.html', $this->incomplete_captcha->get_template());
91        $this->assertEquals('CONFIRM_INCOMPLETE', $this->assigned_vars['CONFIRM_LANG']);
92
93        $this->assigned_vars = [];
94
95        $this->incomplete_captcha->init(confirm_type::POST);
96        $this->assertSame('captcha_incomplete.html', $this->incomplete_captcha->get_template());
97        $this->assertEquals('CONFIRM_INCOMPLETE', $this->assigned_vars['CONFIRM_LANG']);
98    }
99}