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