Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
62.26% |
33 / 53 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| mention_helper_test | |
62.26% |
33 / 53 |
|
66.67% |
4 / 6 |
7.93 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
1 | |||
| inject_metadata_data | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| test_inject_metadata | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| get_mentioned_user_ids_data | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_mentioned_user_ids | |
100.00% |
1 / 1 |
|
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 | |
| 14 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 15 | |
| 16 | class 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', array(), array( |
| 56 | $lang, |
| 57 | '\phpbb\datetime' |
| 58 | )); |
| 59 | $user->ip = ''; |
| 60 | $user->data = array( |
| 61 | 'user_id' => 2, |
| 62 | 'username' => 'myself', |
| 63 | 'is_registered' => true, |
| 64 | 'user_colour' => '', |
| 65 | ); |
| 66 | |
| 67 | // Container |
| 68 | $phpbb_container = new phpbb_mock_container_builder(); |
| 69 | |
| 70 | $phpbb_container->set('dbal.conn', $db); |
| 71 | $phpbb_container->set('auth', $auth); |
| 72 | $phpbb_container->set('user', $user); |
| 73 | |
| 74 | $this->get_test_case_helpers()->set_s9e_services($phpbb_container); |
| 75 | |
| 76 | $this->mention_helper = $phpbb_container->get('text_formatter.s9e.mention_helper'); |
| 77 | } |
| 78 | |
| 79 | public static function inject_metadata_data() |
| 80 | { |
| 81 | return [ |
| 82 | [ |
| 83 | '<r><MENTION user_id="3"><s>[mention=u:3]</s>test<e>[/mention]</e></MENTION></r>', |
| 84 | 'mode=viewprofile&u=3', |
| 85 | ], |
| 86 | [ |
| 87 | '<r><MENTION group_id="3"><s>[mention=g:3]</s>test<e>[/mention]</e></MENTION></r>', |
| 88 | 'mode=group&g=3', |
| 89 | ], |
| 90 | ]; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @dataProvider inject_metadata_data |
| 95 | */ |
| 96 | public function test_inject_metadata($incoming_xml, $expected_profile_substring) |
| 97 | { |
| 98 | $result = $this->mention_helper->inject_metadata($incoming_xml); |
| 99 | $this->assertStringContainsString($expected_profile_substring, $result); |
| 100 | } |
| 101 | |
| 102 | public static function get_mentioned_user_ids_data() |
| 103 | { |
| 104 | return [ |
| 105 | [ |
| 106 | '<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>', |
| 107 | [3, 4, 5], |
| 108 | ], |
| 109 | [ |
| 110 | '<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>', |
| 111 | [4, 2, 6], |
| 112 | ], |
| 113 | ]; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @dataProvider get_mentioned_user_ids_data |
| 118 | */ |
| 119 | public function test_get_mentioned_user_ids($incoming_xml, $expected_result) |
| 120 | { |
| 121 | $this->assertEqualsCanonicalizing($expected_result, $this->mention_helper->get_mentioned_user_ids($incoming_xml)); |
| 122 | } |
| 123 | } |