Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.20% covered (danger)
40.20%
41 / 102
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_notification_user_list_trim_test
40.20% covered (danger)
40.20%
41 / 102
75.00% covered (warning)
75.00%
3 / 4
7.42
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%
37 / 37
100.00% covered (success)
100.00%
1 / 1
1
 user_list_trim_data
0.00% covered (danger)
0.00%
0 / 61
0.00% covered (danger)
0.00%
0 / 1
2
 test_user_list_trim
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_notification_user_list_trim_test extends phpbb_database_test_case
15{
16    protected $notification;
17
18    public function getDataSet()
19    {
20        return $this->createXMLDataSet(__DIR__ . '/fixtures/user_list_trim.xml');
21    }
22
23    protected function setUp(): void
24    {
25        global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $user, $cache, $auth;
26
27        parent::setUp();
28
29        $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
30        $db = $this->new_dbal();
31
32        $config = new \phpbb\config\config(array());
33
34        $cache = new \phpbb\cache\service(
35            new \phpbb\cache\driver\dummy(),
36            $config,
37            $db,
38            $phpbb_dispatcher,
39            $phpbb_root_path,
40            $phpEx
41        );
42
43        $auth = $this->createMock('\phpbb\auth\auth');
44        $auth->expects($this->any())
45            ->method('acl_get')
46            ->with($this->stringContains('_'),
47                $this->anything())
48            ->will($this->returnValueMap(array(
49                array('u_viewprofile', 1, false),
50            )));
51
52        $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
53        $lang = new \phpbb\language\language($lang_loader);
54        $user = new \phpbb\user($lang, '\phpbb\datetime');
55        $user->data = [
56            'user_id'    => 1,
57            'user_lang' => 'en',
58        ];
59        $lang->add_lang('common');
60
61        $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper')
62            ->disableOriginalConstructor()
63            ->getMock();
64
65        $user_loader = new phpbb\user_loader($avatar_helper, $db, $phpbb_root_path, $phpEx, USERS_TABLE);
66        $user_loader->load_users(array(2, 3, 4, 5, 6));
67
68        $this->notification = new phpbb_mock_notification_type_post(
69            $user_loader, null, null, null, $lang, $user, null, null, $phpbb_root_path, $phpEx, null, null
70        );
71    }
72
73    public static function user_list_trim_data()
74    {
75        return array(
76            array(
77                array(
78                    'topic_title'    => 'Test',
79                    'poster_id'        => 2,
80                    'post_username'    => 'A',
81                    'responders'    => null,
82                ),
83                '<strong>Reply</strong> from A in topic:',
84            ),
85            array(
86                array(
87                    'topic_title'    => 'Test',
88                    'poster_id'        => 2,
89                    'post_username'    => 'A',
90                    'responders'    => array(
91                        array('username' => '', 'poster_id' => 3),
92                    ),
93                ),
94                '<strong>Reply</strong> from A and <span class="username">B</span> in topic:',
95            ),
96            array(
97                array(
98                    'topic_title'    => 'Test',
99                    'poster_id'        => 2,
100                    'post_username'    => 'A',
101                    'responders'    => array(
102                        array('username' => '', 'poster_id' => 3),
103                        array('username' => '', 'poster_id' => 4),
104                    ),
105                ),
106                '<strong>Reply</strong> from A, <span class="username">B</span>, and <span class="username">C</span> in topic:',
107            ),
108            array(
109                array(
110                    'topic_title'    => 'Test',
111                    'poster_id'        => 2,
112                    'post_username'    => 'A',
113                    'responders'    => array(
114                        array('username' => '', 'poster_id' => 3),
115                        array('username' => '', 'poster_id' => 4),
116                        array('username' => '', 'poster_id' => 5),
117                    ),
118                ),
119                '<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and <span class="username">D</span> in topic:',
120            ),
121            array(
122                array(
123                    'topic_title'    => 'Test',
124                    'poster_id'        => 2,
125                    'post_username'    => 'A',
126                    'responders'    => array(
127                        array('username' => '', 'poster_id' => 3),
128                        array('username' => '', 'poster_id' => 4),
129                        array('username' => '', 'poster_id' => 5),
130                        array('username' => '', 'poster_id' => 6),
131                    ),
132                ),
133                '<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and 2 others in topic:',
134            ),
135        );
136    }
137
138    /**
139    * @dataProvider user_list_trim_data
140    */
141    public function test_user_list_trim($data, $expected_result)
142    {
143        $data = array('notification_data' => serialize($data));
144        $this->notification->set_initial_data($data);
145
146        $this->assertEquals($expected_result, $this->notification->get_title());
147    }
148}