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