Bug 24786: (QA follow-up) Remove trailing space in classes
[koha.git] / t / db_dependent / TablesSettings.t
blob97121093b4f0c360f963893b4b0922780a0b8d53
1 #!/usr/bin/perl;
3 use Modern::Perl;
4 use Test::More tests => 3;
5 use Test::MockModule;
7 use C4::Context;
8 use C4::Utils::DataTables::TablesSettings;
9 use Koha::Database;
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13 my $dbh = C4::Context->dbh;
15 $dbh->do(q|DELETE FROM columns_settings|);
17 my $module = Test::MockModule->new('C4::Utils::DataTables::TablesSettings');
18 $module->mock(
19     'get_yaml',
20     sub {
21         {
22             modules => {
23                 admin => {
24                     currency => {
25                         'currencies-table' => {
26                             default_display_length => 20,
27                             default_sort_order => 1,
28                             columns => [
29                                 {
30                                     columnname         => 'currency',
31                                     cannot_be_toggled  => '1',
32                                     cannot_be_modified => '1'
33                                 },
34                                 {
35                                     columnname         => 'rate',
36                                     cannot_be_toggled  => '1',
37                                     cannot_be_modified => '1'
38                                 },
39                                 {
40                                     columnname => 'symbol'
41                                 },
42                                 {
43                                     is_hidden  => '1',
44                                     columnname => 'iso_code'
45                                 },
46                                 {
47                                     columnname => 'last_updated'
48                                 },
49                                 {
50                                     columnname => 'active'
51                                 },
52                                 {
53                                     columnname => 'actions'
54                                 }
55                             ]
56                         }
57                     }
58                 },
59             }
60         };
61     }
64 C4::Utils::DataTables::TablesSettings::update_columns(
65     {
66         columns => [
67             {
68                 module             => 'admin',
69                 page               => 'currency',
70                 tablename          => 'currencies-table',
71                 columnname         => 'currency',
72                 cannot_be_toggled  => 1,
73                 cannot_be_modified => 1,
74             },
75             {
76                 module             => 'admin',
77                 page               => 'currency',
78                 tablename          => 'currencies-table',
79                 columnname         => 'rate',
80                 cannot_be_toggled  => 1,
81                 cannot_be_modified => 1,
82             },
83             {
84                 module     => 'admin',
85                 page       => 'currency',
86                 tablename  => 'currencies-table',
87                 columnname => 'symbol',
88             },
89             {
90                 module     => 'admin',
91                 page       => 'currency',
92                 tablename  => 'currencies-table',
93                 columnname => 'iso_code',
94                 is_hidden  => 0,
95             },
96             {
97                 module     => 'admin',
98                 page       => 'currency',
99                 tablename  => 'currencies-table',
100                 columnname => 'last_updated',
101             },
102             {
103                 module     => 'admin',
104                 page       => 'currency',
105                 tablename  => 'currencies-table',
106                 columnname => 'active',
107                 is_hidden  => 1,
108             },
109             {
110                 module            => 'admin',
111                 page              => 'currency',
112                 tablename         => 'currencies-table',
113                 columnname        => 'actions',
114                 cannot_be_toggled => 1,
115             },
116         ]
117     }
120 my $modules = C4::Utils::DataTables::TablesSettings::get_modules();
122 my $modules_expected = {
123     'admin' => {
124         'currency' => {
125             'currencies-table' => {
126                 default_display_length => 20,
127                 default_sort_order => 1,
128                 columns => [
129                     {
130                         columnname         => 'currency',
131                         cannot_be_toggled  => 1,
132                         cannot_be_modified => 1,
133                         is_hidden  => 0,
134                     },
135                     {
136                         columnname         => 'rate',
137                         cannot_be_toggled  => 1,
138                         cannot_be_modified => 1,
139                         is_hidden  => 0,
140                     },
141                     {
142                         columnname => 'symbol',
143                         cannot_be_toggled  => 0,
144                         cannot_be_modified => 0,
145                         is_hidden  => 0,
146                     },
147                     {
148                         columnname => 'iso_code',
149                         cannot_be_toggled  => 0,
150                         cannot_be_modified => 0,
151                         is_hidden  => 0,
152                     },
153                     {
154                         columnname => 'last_updated',
155                         cannot_be_toggled  => 0,
156                         cannot_be_modified => 0,
157                         is_hidden  => 0,
158                     },
159                     {
160                         columnname => 'active',
161                         cannot_be_toggled  => 0,
162                         cannot_be_modified => 0,
163                         is_hidden  => 1,
164                     },
165                     {
166                         columnname        => 'actions',
167                         cannot_be_toggled => 1,
168                         cannot_be_modified => 0,
169                         is_hidden  => 0,
170                     },
171                 ]
172             }
173         }
174     }
177 is_deeply( $modules, $modules_expected, 'get_modules returns all values' );
179 for my $m ( keys %$modules ) {
180     for my $p ( keys %{ $modules->{$m} } ) {
181         for my $t ( keys %{ $modules->{$m}{$p} } ) {
182             my $columns =
183               C4::Utils::DataTables::TablesSettings::get_columns( $m, $p, $t );
184             is_deeply(
185                 $columns,
186                 $modules->{$m}{$p}{$t}{columns},
187                 "columns for $m>$p>$t"
188             );
189             my $table_settings =
190               C4::Utils::DataTables::TablesSettings::get_table_settings( $m, $p, $t );
191             is_deeply(
192                 {
193                     default_display_length => $table_settings->{default_display_length},
194                     default_sort_order     => $table_settings->{default_sort_order}
195                 },
196                 {
197                     default_display_length => $modules->{$m}{$p}{$t}{default_display_length},
198                     default_sort_order     => $modules->{$m}{$p}{$t}{default_sort_order},
199                 }
200             );
201         }
202     }