Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
41.46% covered (danger)
41.46%
17 / 41
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_captcha_qa_test
41.46% covered (danger)
41.46%
17 / 41
83.33% covered (warning)
83.33%
5 / 6
13.22
0.00% covered (danger)
0.00%
0 / 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%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_is_installed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_set_get_name
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 data_acp_get_question_input
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
2
 test_acp_get_question_input
100.00% covered (success)
100.00%
3 / 3
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
14class phpbb_captcha_qa_test extends \phpbb_database_test_case
15{
16    protected $request;
17
18    /** @var \phpbb\captcha\plugins\qa */
19    protected $qa;
20
21    public function getDataSet()
22    {
23        return $this->createXMLDataSet(__DIR__ . '/../fixtures/empty.xml');
24    }
25
26    protected function setUp(): void
27    {
28        global $db, $request, $phpbb_container;
29
30        $db = $this->new_dbal();
31        $db_doctrine = $this->new_doctrine_dbal();
32
33        parent::setUp();
34
35        $request = new \phpbb_mock_request();
36        $phpbb_container = new \phpbb_mock_container_builder();
37        $factory = new \phpbb\db\tools\factory();
38        $phpbb_container->set('dbal.tools', $factory->get($db_doctrine));
39        $this->qa = new \phpbb\captcha\plugins\qa('phpbb_captcha_questions', 'phpbb_captcha_answers', 'phpbb_qa_confirm');
40    }
41
42    public function test_is_installed()
43    {
44        $this->assertTrue($this->qa->is_installed());
45    }
46
47    public function test_set_get_name()
48    {
49        $this->assertNull($this->qa->get_service_name());
50        $this->qa->set_name('foobar');
51        $this->assertSame('foobar', $this->qa->get_service_name());
52    }
53
54    public static function data_acp_get_question_input()
55    {
56        return array(
57            array("foobar\ntest\nyes", array(
58                'question_text'    => '',
59                'strict'    => false,
60                'lang_iso'    => '',
61                'answers'    => array('foobar', 'test', 'yes')
62            )),
63            array("foobar\ntest\n \nyes", array(
64                'question_text'    => '',
65                'strict'    => false,
66                'lang_iso'    => '',
67                'answers'    => array(
68                    0 => 'foobar',
69                    1 => 'test',
70                    3 => 'yes',
71                )
72            )),
73            array('', array(
74                'question_text'    => '',
75                'strict'    => false,
76                'lang_iso'    => '',
77                'answers'    => '',
78            )),
79        );
80    }
81
82    /**
83     * @dataProvider data_acp_get_question_input
84     */
85    public function test_acp_get_question_input($value, $expected)
86    {
87        global $request;
88        $request->overwrite('answers', $value);
89
90        $this->assertEquals($expected, $this->qa->acp_get_question_input());
91    }
92}