Passed
Push — master ( 8747ce...da763d )
by Maurício
13:18 queued 28s
created

NaviFormTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 102
dl 0
loc 131
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testRegisteredForms() 0 88 1
A testGetFields() 0 34 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests\Config\Forms\User;
6
7
use PhpMyAdmin\Config\ConfigFile;
8
use PhpMyAdmin\Config\Form;
9
use PhpMyAdmin\Config\FormDisplay;
10
use PhpMyAdmin\Config\Forms\BaseForm;
11
use PhpMyAdmin\Config\Forms\User\NaviForm;
12
use PhpMyAdmin\Tests\AbstractTestCase;
13
use PHPUnit\Framework\Attributes\CoversClass;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
#[CoversClass(NaviForm::class)]
16
#[CoversClass(BaseForm::class)]
17
#[CoversClass(FormDisplay::class)]
18
#[CoversClass(Form::class)]
19
final class NaviFormTest extends AbstractTestCase
20
{
21
    public function testRegisteredForms(): void
22
    {
23
        Form::resetGroupCounter();
24
25
        $naviForm = new NaviForm(new ConfigFile([]), 1);
26
        self::assertSame('Navigation panel', NaviForm::getName());
27
28
        $forms = $naviForm->getRegisteredForms();
29
        self::assertCount(5, $forms);
30
31
        self::assertArrayHasKey('Navi_panel', $forms);
0 ignored issues
show
Bug introduced by
It seems like $forms can also be of type Countable; however, parameter $array of PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept ArrayAccess|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        self::assertArrayHasKey('Navi_panel', /** @scrutinizer ignore-type */ $forms);
Loading history...
32
        $form = $forms['Navi_panel'];
33
        self::assertSame('Navi_panel', $form->name);
34
        self::assertSame(1, $form->index);
35
        self::assertSame([], $form->default);
36
        self::assertSame(
37
            [
38
                'ShowDatabasesNavigationAsTree' => 'ShowDatabasesNavigationAsTree',
39
                'NavigationLinkWithMainPanel' => 'NavigationLinkWithMainPanel',
40
                'NavigationDisplayLogo' => 'NavigationDisplayLogo',
41
                'NavigationLogoLink' => 'NavigationLogoLink',
42
                'NavigationLogoLinkWindow' => 'NavigationLogoLinkWindow',
43
                'NavigationTreePointerEnable' => 'NavigationTreePointerEnable',
44
                'FirstLevelNavigationItems' => 'FirstLevelNavigationItems',
45
                'NavigationTreeDisplayItemFilterMinimum' => 'NavigationTreeDisplayItemFilterMinimum',
46
                'NumRecentTables' => 'NumRecentTables',
47
                'NumFavoriteTables' => 'NumFavoriteTables',
48
                'NavigationWidth' => 'NavigationWidth',
49
            ],
50
            $form->fields,
51
        );
52
53
        self::assertArrayHasKey('Navi_tree', $forms);
54
        $form = $forms['Navi_tree'];
55
        self::assertSame('Navi_tree', $form->name);
56
        self::assertSame(1, $form->index);
57
        self::assertSame([], $form->default);
58
        self::assertSame(
59
            [
60
                'MaxNavigationItems' => 'MaxNavigationItems',
61
                'NavigationTreeEnableGrouping' => 'NavigationTreeEnableGrouping',
62
                'NavigationTreeEnableExpansion' => 'NavigationTreeEnableExpansion',
63
                'NavigationTreeShowTables' => 'NavigationTreeShowTables',
64
                'NavigationTreeShowViews' => 'NavigationTreeShowViews',
65
                'NavigationTreeShowFunctions' => 'NavigationTreeShowFunctions',
66
                'NavigationTreeShowProcedures' => 'NavigationTreeShowProcedures',
67
                'NavigationTreeShowEvents' => 'NavigationTreeShowEvents',
68
                'NavigationTreeAutoexpandSingleDb' => 'NavigationTreeAutoexpandSingleDb',
69
            ],
70
            $form->fields,
71
        );
72
73
        self::assertArrayHasKey('Navi_servers', $forms);
74
        $form = $forms['Navi_servers'];
75
        self::assertSame('Navi_servers', $form->name);
76
        self::assertSame(1, $form->index);
77
        self::assertSame([], $form->default);
78
        self::assertSame(
79
            ['NavigationDisplayServers' => 'NavigationDisplayServers', 'DisplayServersList' => 'DisplayServersList'],
80
            $form->fields,
81
        );
82
83
        self::assertArrayHasKey('Navi_databases', $forms);
84
        $form = $forms['Navi_databases'];
85
        self::assertSame('Navi_databases', $form->name);
86
        self::assertSame(1, $form->index);
87
        self::assertSame([], $form->default);
88
        self::assertSame(
89
            [
90
                'NavigationTreeDisplayDbFilterMinimum' => 'NavigationTreeDisplayDbFilterMinimum',
91
                'NavigationTreeDbSeparator' => 'NavigationTreeDbSeparator',
92
            ],
93
            $form->fields,
94
        );
95
96
        self::assertArrayHasKey('Navi_tables', $forms);
97
        $form = $forms['Navi_tables'];
98
        self::assertSame('Navi_tables', $form->name);
99
        self::assertSame(1, $form->index);
100
        self::assertSame([], $form->default);
101
        self::assertSame(
102
            [
103
                'NavigationTreeDefaultTabTable' => 'NavigationTreeDefaultTabTable',
104
                'NavigationTreeDefaultTabTable2' => 'NavigationTreeDefaultTabTable2',
105
                'NavigationTreeTableSeparator' => 'NavigationTreeTableSeparator',
106
                'NavigationTreeTableLevel' => 'NavigationTreeTableLevel',
107
            ],
108
            $form->fields,
109
        );
110
    }
111
112
    public function testGetFields(): void
113
    {
114
        self::assertSame(
115
            [
116
                'ShowDatabasesNavigationAsTree',
117
                'NavigationLinkWithMainPanel',
118
                'NavigationDisplayLogo',
119
                'NavigationLogoLink',
120
                'NavigationLogoLinkWindow',
121
                'NavigationTreePointerEnable',
122
                'FirstLevelNavigationItems',
123
                'NavigationTreeDisplayItemFilterMinimum',
124
                'NumRecentTables',
125
                'NumFavoriteTables',
126
                'NavigationWidth',
127
                'MaxNavigationItems',
128
                'NavigationTreeEnableGrouping',
129
                'NavigationTreeEnableExpansion',
130
                'NavigationTreeShowTables',
131
                'NavigationTreeShowViews',
132
                'NavigationTreeShowFunctions',
133
                'NavigationTreeShowProcedures',
134
                'NavigationTreeShowEvents',
135
                'NavigationTreeAutoexpandSingleDb',
136
                'NavigationDisplayServers',
137
                'DisplayServersList',
138
                'NavigationTreeDisplayDbFilterMinimum',
139
                'NavigationTreeDbSeparator',
140
                'NavigationTreeDefaultTabTable',
141
                'NavigationTreeDefaultTabTable2',
142
                'NavigationTreeTableSeparator',
143
                'NavigationTreeTableLevel',
144
            ],
145
            NaviForm::getFields(),
146
        );
147
    }
148
}
149