Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
36 / 36
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_textreparser_base_test
100.00% covered (success)
100.00%
36 / 36
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 setUp
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_reparser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_rows
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 test_reparse_empty
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 test_reparse_case_insensitive
100.00% covered (success)
100.00%
10 / 10
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
14require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php';
15
16class phpbb_textreparser_base_test extends phpbb_database_test_case
17{
18    protected $db;
19
20    protected function setUp(): void
21    {
22        global $config;
23        if (!isset($config))
24        {
25            $config = new \phpbb\config\config(array());
26        }
27        $this->get_test_case_helpers()->set_s9e_services();
28        $this->db = $this->new_dbal();
29        parent::setUp();
30    }
31
32    public function getDataSet()
33    {
34        return $this->createXMLDataSet(__DIR__ . '/fixtures/base.xml');
35    }
36
37    protected function get_reparser()
38    {
39        return new \phpbb\textreparser\plugins\post_text($this->db, POSTS_TABLE);
40    }
41
42    protected function get_rows(array $ids)
43    {
44        $sql = 'SELECT post_id AS id, post_text AS text
45            FROM ' . POSTS_TABLE . '
46            WHERE ' . $this->db->sql_in_set('post_id', $ids) . '
47            ORDER BY id';
48        $result = $this->db->sql_query($sql);
49        $rows = $this->db->sql_fetchrowset($result);
50        $this->db->sql_freeresult($result);
51
52        return $rows;
53    }
54
55    public function test_reparse_empty()
56    {
57        $this->get_reparser()->reparse_range(1, 1);
58
59        $this->assertEquals(
60            array(
61                array(
62                    'id'   => 1,
63                    'text' => '<t></t>'
64                )
65            ),
66            $this->get_rows(array(1))
67        );
68    }
69
70    public function test_reparse_case_insensitive()
71    {
72        $this->get_reparser()->reparse_range(2, 2);
73
74        $this->assertEquals(
75            [
76                [
77                    'id'   => '2',
78                    'text' => '<r><IMG src="img.png"><s>[IMG]</s>img.png<e>[/IMG]</e></IMG></r>'
79                ]
80            ],
81            $this->get_rows([2])
82        );
83    }
84}