Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
30 / 50
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
mention_helper_test
60.00% covered (warning)
60.00%
30 / 50
66.67% covered (warning)
66.67%
4 / 6
8.30
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%
26 / 26
100.00% covered (success)
100.00%
1 / 1
1
 inject_metadata_data
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_inject_metadata
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_mentioned_user_ids_data
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_mentioned_user_ids
100.00% covered (success)
100.00%
1 / 1
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 Symfony\Component\DependencyInjection\ContainerBuilder;
15
16class mention_helper_test extends phpbb_database_test_case
17{
18    protected $db, $container, $user, $auth;
19
20    /**
21     * @var \phpbb\textformatter\s9e\mention_helper
22     */
23    protected $mention_helper;
24
25    public function getDataSet()
26    {
27        return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/mention.xml');
28    }
29
30    public function setUp(): void
31    {
32        parent::setUp();
33
34        global $auth, $db, $cache, $phpbb_container, $phpEx, $phpbb_root_path;
35
36        // Disable caching for this test class
37        $cache = null;
38
39        // Database
40        $this->db = $this->new_dbal();
41        $db = $this->db;
42
43        // Auth
44        $auth = $this->createMock('\phpbb\auth\auth');
45        $auth->expects($this->any())
46             ->method('acl_gets')
47             ->with('a_group', 'a_groupadd', 'a_groupdel')
48             ->willReturn(false)
49        ;
50
51        // Language
52        $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
53
54        // User
55        $user = $this->createMock('\phpbb\user');
56        $user->ip = '';
57        $user->data = array(
58            'user_id'       => 2,
59            'username'      => 'myself',
60            'is_registered' => true,
61            'user_colour'   => '',
62        );
63
64        // Container
65        $phpbb_container = new phpbb_mock_container_builder();
66
67        $phpbb_container->set('dbal.conn', $db);
68        $phpbb_container->set('auth', $auth);
69        $phpbb_container->set('user', $user);
70
71        $this->get_test_case_helpers()->set_s9e_services($phpbb_container);
72
73        $this->mention_helper = $phpbb_container->get('text_formatter.s9e.mention_helper');
74    }
75
76    public static function inject_metadata_data()
77    {
78        return [
79            [
80                '<r><MENTION user_id="3"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION></r>',
81                'mode=viewprofile&amp;u=3',
82            ],
83            [
84                '<r><MENTION group_id="3"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
85                'mode=group&amp;g=3',
86            ],
87        ];
88    }
89
90    /**
91     * @dataProvider inject_metadata_data
92     */
93    public function test_inject_metadata($incoming_xml, $expected_profile_substring)
94    {
95        $result = $this->mention_helper->inject_metadata($incoming_xml);
96        $this->assertStringContainsString($expected_profile_substring, $result);
97    }
98
99    public static function get_mentioned_user_ids_data()
100    {
101        return [
102            [
103                '<r><MENTION user_id="3"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION><MENTION user_id="4"><s>[mention=u:4]</s>test<e>[/mention]</e></MENTION><MENTION user_id="5"><s>[mention=u:5]</s>test<e>[/mention]</e></MENTION></r>',
104                [3, 4, 5],
105            ],
106            [
107                '<r><MENTION group_id="1"><s>[mention=g:1]</s>test<e>[/mention]</e></MENTION><MENTION group_id="2"><s>[mention=g:2]</s>test<e>[/mention]</e></MENTION><MENTION group_id="3"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>',
108                [4, 2, 6],
109            ],
110        ];
111    }
112
113    /**
114     * @dataProvider get_mentioned_user_ids_data
115     */
116    public function test_get_mentioned_user_ids($incoming_xml, $expected_result)
117    {
118        $this->assertEqualsCanonicalizing($expected_result, $this->mention_helper->get_mentioned_user_ids($incoming_xml));
119    }
120}