Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
22 / 44
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_textreparser_post_text_test
50.00% covered (danger)
50.00%
22 / 44
75.00% covered (warning)
75.00%
3 / 4
8.12
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
 get_reparser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data_reparse_url
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
2
 test_reparse_url
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
2
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*/
13include_once __DIR__ . '/test_row_based_plugin.php';
14
15class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_based_plugin
16{
17    public function getDataSet()
18    {
19        return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml');
20    }
21
22    protected function get_reparser()
23    {
24        return new \phpbb\textreparser\plugins\post_text($this->db, POSTS_TABLE);
25    }
26
27    public static function data_reparse_url(): array
28    {
29        return [
30            [ // Reparse the same
31                '<r><URL url="https://www.example.com">https://www.example.com</URL> and some more text test included</r>',
32                '<r><URL url="https://www.example.com">https://www.example.com</URL> and some more text test included</r>',
33            ],
34            [ // Reparse without magic URL, shouldn't change
35                'https://www.example.com and some more text test included',
36                '<t>https://www.example.com and some more text test included</t>',
37            ],
38            [ // Reparse new format without magic URL, shouldn't change
39                '<t>https://www.example.com and some more text test included</t>',
40                '<t>https://www.example.com and some more text test included</t>',
41            ],
42            [ // Reparse with magic URL, should update to text formatter format
43                'Foo is <!-- m --><a class="postlink" href="https://symfony.com/doc/current/service_container.html">https://symfony.com/doc/current/service_container.html</a><!-- m --> good',
44                '<r>Foo is <URL url="https://symfony.com/doc/current/service_container.html">https://symfony.com/doc/current/service_container.html</URL> good</r>',
45            ],
46            [ // Reparse new format with magic URL, shouldn't change
47                '<r>Foo is <URL url="https://symfony.com/doc/current/service_container.html">https://symfony.com/doc/current/service_container.html</URL> good</r>',
48                '<r>Foo is <URL url="https://symfony.com/doc/current/service_container.html">https://symfony.com/doc/current/service_container.html</URL> good</r>',
49            ]
50        ];
51    }
52
53    /**
54     * @dataProvider data_reparse_url
55     */
56    public function test_reparse_url(string $input_text, string $expected_text)
57    {
58        foreach ([true, false] as $enable_magic_url)
59        {
60            $record = [
61                'enable_bbcode'            => true,
62                'enable_smilies'        => true,
63                'enable_magic_url'        => $enable_magic_url,
64                'post_text'                    => $input_text,
65                'bbcode_uid'            => '',
66            ];
67
68            $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $record);
69            $this->db->sql_query($sql);
70
71            $record['id'] = $this->db->sql_last_inserted_id();
72            $record['text'] = $record['post_text'];
73
74            // Call reparse_record via reflection
75            $reparser = $this->get_reparser();
76            $reparser_reflection = new \ReflectionMethod($reparser, 'reparse_record');
77            $reparser_reflection->invoke($reparser, $record);
78
79            // Retrieve reparsed post text and compare with expectec
80            $sql = 'SELECT post_id, post_text FROM ' . POSTS_TABLE . ' WHERE post_id = ' . (int) $record['id'];
81            $result = $this->db->sql_query($sql);
82            $actual_text = $this->db->sql_fetchfield('post_text');
83            $this->db->sql_freeresult($result);
84
85            $this->assertSame($expected_text, $actual_text);
86        }
87    }
88}