Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
26.32% covered (danger)
26.32%
5 / 19
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_tests_tree_nestedset_forum_regenerate_test
26.32% covered (danger)
26.32%
5 / 19
50.00% covered (danger)
50.00%
1 / 2
3.60
0.00% covered (danger)
0.00%
0 / 1
 regenerate_left_right_ids_data
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 test_regenerate_left_right_ids
100.00% covered (success)
100.00%
5 / 5
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
14require_once __DIR__ . '/nestedset_forum_base.php';
15
16class phpbb_tests_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base
17{
18    protected $fixed_set = array(
19        array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
20        array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
21        array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''),
22
23        array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''),
24        array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''),
25        array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''),
26
27        array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''),
28        array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
29        array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''),
30        array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''),
31        array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),
32    );
33
34    public static function regenerate_left_right_ids_data()
35    {
36        return array(
37            array('UPDATE phpbb_forums
38                SET left_id = 0,
39                    right_id = 0', false),
40            array('UPDATE phpbb_forums
41                SET left_id = 28,
42                    right_id = 28
43                WHERE left_id > 12', false),
44            array('UPDATE phpbb_forums
45                SET left_id = left_id * 2,
46                    right_id = right_id * 2', false),
47            array('UPDATE phpbb_forums
48                SET left_id = left_id * 2,
49                    right_id = right_id * 2
50                WHERE left_id > 12', false),
51            array('UPDATE phpbb_forums
52                SET left_id = left_id - 4,
53                    right_id = right_id * 4
54                WHERE left_id > 4', false),
55            array('UPDATE phpbb_forums
56                SET left_id = 0,
57                    right_id = 0
58                WHERE left_id > 12', true),
59        );
60    }
61
62    /**
63    * @dataProvider regenerate_left_right_ids_data
64    */
65    public function test_regenerate_left_right_ids($breaking_query, $reset_ids)
66    {
67        $result = $this->db->sql_query($breaking_query);
68
69        $this->assertEquals(23, $this->set->regenerate_left_right_ids(1, 0, $reset_ids));
70
71        $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents
72            FROM phpbb_forums
73            ORDER BY left_id, forum_id ASC');
74        $this->assertEquals($this->fixed_set, $this->db->sql_fetchrowset($result));
75    }
76}