Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
21.09% covered (danger)
21.09%
58 / 275
57.14% covered (warning)
57.14%
8 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_groupposition_legend_test
21.09% covered (danger)
21.09%
58 / 275
57.14% covered (warning)
57.14%
8 / 14
125.55
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_group_value_data
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_group_value
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 test_get_group_count
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 add_group_data
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
2
 test_add_group
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 delete_group_data
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 1
2
 test_delete_group
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 move_up_data
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 1
2
 test_move_up
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 move_down_data
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 1
2
 test_move_down
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 move_data
0.00% covered (danger)
0.00%
0 / 72
0.00% covered (danger)
0.00%
0 / 1
2
 test_move
100.00% covered (success)
100.00%
9 / 9
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_groupposition_legend_test extends phpbb_database_test_case
15{
16    public function getDataSet()
17    {
18        return $this->createXMLDataSet(__DIR__ . '/fixtures/legend.xml');
19    }
20
21    public static function get_group_value_data()
22    {
23        return array(
24            array(1, 0, ''),
25            array(3, 2, ''),
26            array(4, 0, '\phpbb\groupposition\exception'),
27        );
28    }
29
30    /**
31    * @dataProvider get_group_value_data
32    */
33    public function test_get_group_value($group_id, $expected, $throws_exception)
34    {
35        global $cache;
36
37        $cache = new phpbb_mock_cache;
38        $db = $this->new_dbal();
39
40        if ($throws_exception)
41        {
42            $this->expectException($throws_exception);
43        }
44
45        $test_class = new \phpbb\groupposition\legend($db);
46        $this->assertEquals($expected, $test_class->get_group_value($group_id));
47    }
48
49    public function test_get_group_count()
50    {
51        global $cache;
52
53        $cache = new phpbb_mock_cache;
54        $db = $this->new_dbal();
55
56        $test_class = new \phpbb\groupposition\legend($db);
57        $this->assertEquals(2, $test_class->get_group_count());
58    }
59
60    public static function add_group_data()
61    {
62        return array(
63            array(
64                1,
65                true,
66                array(
67                    array('group_id' => 1, 'group_legend' => 3),
68                    array('group_id' => 2, 'group_legend' => 1),
69                    array('group_id' => 3, 'group_legend' => 2),
70                ),
71            ),
72            array(
73                2,
74                false,
75                array(
76                    array('group_id' => 1, 'group_legend' => 0),
77                    array('group_id' => 2, 'group_legend' => 1),
78                    array('group_id' => 3, 'group_legend' => 2),
79                ),
80            ),
81        );
82    }
83
84    /**
85    * @dataProvider add_group_data
86    */
87    public function test_add_group($group_id, $expected_added, $expected)
88    {
89        global $cache;
90
91        $cache = new phpbb_mock_cache;
92        $db = $this->new_dbal();
93
94        $test_class = new \phpbb\groupposition\legend($db);
95        $this->assertEquals($expected_added, $test_class->add_group($group_id));
96
97        $result = $db->sql_query('SELECT group_id, group_legend
98            FROM ' . GROUPS_TABLE . '
99            ORDER BY group_id ASC');
100
101        $this->assertEquals($expected, $db->sql_fetchrowset($result));
102    }
103
104    public static function delete_group_data()
105    {
106        return array(
107            array(
108                1,
109                false,
110                false,
111                array(
112                    array('group_id' => 1, 'group_legend' => 0),
113                    array('group_id' => 2, 'group_legend' => 1),
114                    array('group_id' => 3, 'group_legend' => 2),
115                ),
116            ),
117            array(
118                2,
119                false,
120                true,
121                array(
122                    array('group_id' => 1, 'group_legend' => 0),
123                    array('group_id' => 2, 'group_legend' => 0),
124                    array('group_id' => 3, 'group_legend' => 1),
125                ),
126            ),
127            array(
128                3,
129                false,
130                true,
131                array(
132                    array('group_id' => 1, 'group_legend' => 0),
133                    array('group_id' => 2, 'group_legend' => 1),
134                    array('group_id' => 3, 'group_legend' => 0),
135                ),
136            ),
137            array(
138                1,
139                true,
140                false,
141                array(
142                    array('group_id' => 1, 'group_legend' => 0),
143                    array('group_id' => 2, 'group_legend' => 1),
144                    array('group_id' => 3, 'group_legend' => 2),
145                ),
146            ),
147            array(
148                2,
149                true,
150                true,
151                array(
152                    array('group_id' => 1, 'group_legend' => 0),
153                    array('group_id' => 2, 'group_legend' => 1),
154                    array('group_id' => 3, 'group_legend' => 1),
155                ),
156            ),
157            array(
158                3,
159                true,
160                true,
161                array(
162                    array('group_id' => 1, 'group_legend' => 0),
163                    array('group_id' => 2, 'group_legend' => 1),
164                    array('group_id' => 3, 'group_legend' => 2),
165                ),
166            ),
167        );
168    }
169
170    /**
171    * @dataProvider delete_group_data
172    */
173    public function test_delete_group($group_id, $skip_group, $expected_deleted, $expected)
174    {
175        global $cache;
176
177        $cache = new phpbb_mock_cache;
178        $db = $this->new_dbal();
179
180        $test_class = new \phpbb\groupposition\legend($db);
181        $this->assertEquals($expected_deleted, $test_class->delete_group($group_id, $skip_group));
182
183        $result = $db->sql_query('SELECT group_id, group_legend
184            FROM ' . GROUPS_TABLE . '
185            ORDER BY group_id ASC');
186
187        $this->assertEquals($expected, $db->sql_fetchrowset($result));
188    }
189
190    public static function move_up_data()
191    {
192        return array(
193            array(
194                1,
195                false,
196                array(
197                    array('group_id' => 1, 'group_legend' => 0),
198                    array('group_id' => 2, 'group_legend' => 1),
199                    array('group_id' => 3, 'group_legend' => 2),
200                ),
201            ),
202            array(
203                2,
204                false,
205                array(
206                    array('group_id' => 1, 'group_legend' => 0),
207                    array('group_id' => 2, 'group_legend' => 1),
208                    array('group_id' => 3, 'group_legend' => 2),
209                ),
210            ),
211            array(
212                3,
213                true,
214                array(
215                    array('group_id' => 1, 'group_legend' => 0),
216                    array('group_id' => 2, 'group_legend' => 2),
217                    array('group_id' => 3, 'group_legend' => 1),
218                ),
219            ),
220        );
221    }
222
223    /**
224    * @dataProvider move_up_data
225    */
226    public function test_move_up($group_id, $excepted_moved, $expected)
227    {
228        global $cache;
229
230        $cache = new phpbb_mock_cache;
231        $db = $this->new_dbal();
232
233        $test_class = new \phpbb\groupposition\legend($db);
234        $this->assertEquals($excepted_moved, $test_class->move_up($group_id));
235
236        $result = $db->sql_query('SELECT group_id, group_legend
237            FROM ' . GROUPS_TABLE . '
238            ORDER BY group_id ASC');
239
240        $this->assertEquals($expected, $db->sql_fetchrowset($result));
241    }
242
243    public static function move_down_data()
244    {
245        return array(
246            array(
247                1,
248                false,
249                array(
250                    array('group_id' => 1, 'group_legend' => 0),
251                    array('group_id' => 2, 'group_legend' => 1),
252                    array('group_id' => 3, 'group_legend' => 2),
253                ),
254            ),
255            array(
256                2,
257                true,
258                array(
259                    array('group_id' => 1, 'group_legend' => 0),
260                    array('group_id' => 2, 'group_legend' => 2),
261                    array('group_id' => 3, 'group_legend' => 1),
262                ),
263            ),
264            array(
265                3,
266                false,
267                array(
268                    array('group_id' => 1, 'group_legend' => 0),
269                    array('group_id' => 2, 'group_legend' => 1),
270                    array('group_id' => 3, 'group_legend' => 2),
271                ),
272            ),
273        );
274    }
275
276    /**
277    * @dataProvider move_down_data
278    */
279    public function test_move_down($group_id, $excepted_moved, $expected)
280    {
281        global $cache;
282
283        $cache = new phpbb_mock_cache;
284        $db = $this->new_dbal();
285
286        $test_class = new \phpbb\groupposition\legend($db);
287        $this->assertEquals($excepted_moved, $test_class->move_down($group_id));
288
289        $result = $db->sql_query('SELECT group_id, group_legend
290            FROM ' . GROUPS_TABLE . '
291            ORDER BY group_id ASC');
292
293        $this->assertEquals($expected, $db->sql_fetchrowset($result));
294    }
295
296    public static function move_data()
297    {
298        return array(
299            array(
300                1,
301                1,
302                false,
303                array(
304                    array('group_id' => 1, 'group_legend' => 0),
305                    array('group_id' => 2, 'group_legend' => 1),
306                    array('group_id' => 3, 'group_legend' => 2),
307                ),
308            ),
309            array(
310                1,
311                -1,
312                false,
313                array(
314                    array('group_id' => 1, 'group_legend' => 0),
315                    array('group_id' => 2, 'group_legend' => 1),
316                    array('group_id' => 3, 'group_legend' => 2),
317                ),
318            ),
319            array(
320                3,
321                3,
322                true,
323                array(
324                    array('group_id' => 1, 'group_legend' => 0),
325                    array('group_id' => 2, 'group_legend' => 2),
326                    array('group_id' => 3, 'group_legend' => 1),
327                ),
328            ),
329            array(
330                2,
331                0,
332                    false,
333                array(
334                    array('group_id' => 1, 'group_legend' => 0),
335                    array('group_id' => 2, 'group_legend' => 1),
336                    array('group_id' => 3, 'group_legend' => 2),
337                ),
338            ),
339            array(
340                2,
341                -1,
342                true,
343                array(
344                    array('group_id' => 1, 'group_legend' => 0),
345                    array('group_id' => 2, 'group_legend' => 2),
346                    array('group_id' => 3, 'group_legend' => 1),
347                ),
348            ),
349            array(
350                2,
351                -3,
352                true,
353                array(
354                    array('group_id' => 1, 'group_legend' => 0),
355                    array('group_id' => 2, 'group_legend' => 2),
356                    array('group_id' => 3, 'group_legend' => 1),
357                ),
358            ),
359            array(
360                3,
361                -1,
362                false,
363                array(
364                    array('group_id' => 1, 'group_legend' => 0),
365                    array('group_id' => 2, 'group_legend' => 1),
366                    array('group_id' => 3, 'group_legend' => 2),
367                ),
368            ),
369        );
370    }
371
372    /**
373    * @dataProvider move_data
374    */
375    public function test_move($group_id, $increment, $excepted_moved, $expected)
376    {
377        global $cache;
378
379        $cache = new phpbb_mock_cache;
380        $db = $this->new_dbal();
381
382        $test_class = new \phpbb\groupposition\legend($db);
383        $this->assertEquals($excepted_moved, $test_class->move($group_id, $increment));
384
385        $result = $db->sql_query('SELECT group_id, group_legend
386            FROM ' . GROUPS_TABLE . '
387            ORDER BY group_id ASC');
388
389        $this->assertEquals($expected, $db->sql_fetchrowset($result));
390    }
391}