|
Lines 2-8
Link Here
|
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
use Test::NoWarnings; |
4 |
use Test::NoWarnings; |
| 5 |
use Test::More tests => 4; |
5 |
use Test::More tests => 2; |
| 6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
| 7 |
|
7 |
|
| 8 |
use C4::Context; |
8 |
use C4::Context; |
|
Lines 10-207
use C4::Utils::DataTables::TablesSettings;
Link Here
|
| 10 |
use Koha::Database; |
10 |
use Koha::Database; |
| 11 |
|
11 |
|
| 12 |
my $schema = Koha::Database->new->schema; |
12 |
my $schema = Koha::Database->new->schema; |
| 13 |
$schema->storage->txn_begin; |
|
|
| 14 |
my $dbh = C4::Context->dbh; |
| 15 |
|
| 16 |
$dbh->do(q|DELETE FROM columns_settings|); |
| 17 |
|
13 |
|
|
|
14 |
my $yaml; |
| 18 |
my $module = Test::MockModule->new('C4::Utils::DataTables::TablesSettings'); |
15 |
my $module = Test::MockModule->new('C4::Utils::DataTables::TablesSettings'); |
| 19 |
$module->mock( |
16 |
$module->mock( |
| 20 |
'get_yaml', |
17 |
'get_yaml', |
| 21 |
sub { |
18 |
sub { return $yaml; } |
| 22 |
{ |
|
|
| 23 |
modules => { |
| 24 |
admin => { |
| 25 |
currency => { |
| 26 |
'currencies-table' => { |
| 27 |
default_display_length => 20, |
| 28 |
default_sort_order => 1, |
| 29 |
default_save_state => 1, |
| 30 |
default_save_state_search => 0, |
| 31 |
columns => [ |
| 32 |
{ |
| 33 |
columnname => 'currency', |
| 34 |
cannot_be_toggled => '1', |
| 35 |
cannot_be_modified => '1' |
| 36 |
}, |
| 37 |
{ |
| 38 |
columnname => 'rate', |
| 39 |
cannot_be_toggled => '1', |
| 40 |
cannot_be_modified => '1' |
| 41 |
}, |
| 42 |
{ columnname => 'symbol' }, |
| 43 |
{ |
| 44 |
is_hidden => '1', |
| 45 |
columnname => 'iso_code' |
| 46 |
}, |
| 47 |
{ columnname => 'last_updated' }, |
| 48 |
{ columnname => 'active' }, |
| 49 |
{ columnname => 'actions' } |
| 50 |
] |
| 51 |
} |
| 52 |
} |
| 53 |
}, |
| 54 |
} |
| 55 |
}; |
| 56 |
} |
| 57 |
); |
19 |
); |
| 58 |
|
20 |
|
| 59 |
C4::Utils::DataTables::TablesSettings::update_columns( |
21 |
subtest 'update_columns, get_modules, get_columns, get_table_settings' => sub { |
| 60 |
{ |
22 |
plan tests => 5; |
| 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 |
|
23 |
|
| 115 |
my $modules = C4::Utils::DataTables::TablesSettings::get_modules(); |
24 |
$schema->storage->txn_begin; |
| 116 |
|
25 |
my $dbh = C4::Context->dbh; |
| 117 |
my $modules_expected = { |
26 |
|
| 118 |
'admin' => { |
27 |
$dbh->do(q|DELETE FROM columns_settings|); |
| 119 |
'currency' => { |
28 |
$dbh->do(q|DELETE FROM tables_settings|); |
| 120 |
'currencies-table' => { |
29 |
|
| 121 |
default_display_length => 20, |
30 |
$yaml = { |
| 122 |
default_sort_order => 1, |
31 |
modules => { |
| 123 |
default_save_state => 1, |
32 |
admin => { |
| 124 |
default_save_state_search => 0, |
33 |
currency => { |
| 125 |
columns => [ |
34 |
'currencies-table' => { |
| 126 |
{ |
35 |
default_display_length => 20, |
| 127 |
columnname => 'currency', |
36 |
default_sort_order => 1, |
| 128 |
cannot_be_toggled => 1, |
37 |
default_save_state => 1, |
| 129 |
cannot_be_modified => 1, |
38 |
default_save_state_search => 0, |
| 130 |
is_hidden => 0, |
39 |
columns => [ |
| 131 |
}, |
40 |
{ |
| 132 |
{ |
41 |
columnname => 'currency', |
| 133 |
columnname => 'rate', |
42 |
cannot_be_toggled => '1', |
| 134 |
cannot_be_toggled => 1, |
43 |
cannot_be_modified => '1' |
| 135 |
cannot_be_modified => 1, |
44 |
}, |
| 136 |
is_hidden => 0, |
45 |
{ |
| 137 |
}, |
46 |
columnname => 'rate', |
| 138 |
{ |
47 |
cannot_be_toggled => '1', |
| 139 |
columnname => 'symbol', |
48 |
cannot_be_modified => '1' |
| 140 |
cannot_be_toggled => 0, |
49 |
}, |
| 141 |
cannot_be_modified => 0, |
50 |
{ columnname => 'symbol' }, |
| 142 |
is_hidden => 0, |
51 |
{ |
| 143 |
}, |
52 |
is_hidden => '1', |
| 144 |
{ |
53 |
columnname => 'iso_code' |
| 145 |
columnname => 'iso_code', |
54 |
}, |
| 146 |
cannot_be_toggled => 0, |
55 |
{ columnname => 'last_updated' }, |
| 147 |
cannot_be_modified => 0, |
56 |
{ columnname => 'active' }, |
| 148 |
is_hidden => 0, |
57 |
{ columnname => 'actions' } |
| 149 |
}, |
58 |
] |
| 150 |
{ |
59 |
} |
| 151 |
columnname => 'last_updated', |
60 |
} |
| 152 |
cannot_be_toggled => 0, |
61 |
}, |
| 153 |
cannot_be_modified => 0, |
|
|
| 154 |
is_hidden => 0, |
| 155 |
}, |
| 156 |
{ |
| 157 |
columnname => 'active', |
| 158 |
cannot_be_toggled => 0, |
| 159 |
cannot_be_modified => 0, |
| 160 |
is_hidden => 1, |
| 161 |
}, |
| 162 |
{ |
| 163 |
columnname => 'actions', |
| 164 |
cannot_be_toggled => 1, |
| 165 |
cannot_be_modified => 0, |
| 166 |
is_hidden => 0, |
| 167 |
}, |
| 168 |
] |
| 169 |
} |
| 170 |
} |
62 |
} |
| 171 |
} |
63 |
}; |
| 172 |
}; |
|
|
| 173 |
|
64 |
|
| 174 |
is_deeply( $modules, $modules_expected, 'get_modules returns all values' ); |
65 |
C4::Utils::DataTables::TablesSettings::update_columns( |
| 175 |
|
66 |
{ |
| 176 |
for my $m ( keys %$modules ) { |
67 |
columns => [ |
| 177 |
for my $p ( keys %{ $modules->{$m} } ) { |
68 |
{ |
| 178 |
for my $t ( keys %{ $modules->{$m}{$p} } ) { |
69 |
module => 'admin', |
| 179 |
my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $m, $p, $t ); |
70 |
page => 'currency', |
| 180 |
|
71 |
tablename => 'currencies-table', |
| 181 |
# We do not store default_save_state and default_save_state_search in the yml file |
72 |
columnname => 'currency', |
| 182 |
# Removing them before comparison |
73 |
cannot_be_toggled => 1, |
| 183 |
delete $_->{default_save_state} for @$columns; |
74 |
cannot_be_modified => 1, |
| 184 |
delete $_->{default_save_state_search} for @$columns; |
75 |
}, |
| 185 |
is_deeply( |
|
|
| 186 |
$columns, |
| 187 |
$modules->{$m}{$p}{$t}{columns}, |
| 188 |
"columns for $m>$p>$t" |
| 189 |
); |
| 190 |
my $table_settings = C4::Utils::DataTables::TablesSettings::get_table_settings( $m, $p, $t ); |
| 191 |
is_deeply( |
| 192 |
{ |
76 |
{ |
| 193 |
default_display_length => $table_settings->{default_display_length}, |
77 |
module => 'admin', |
| 194 |
default_sort_order => $table_settings->{default_sort_order}, |
78 |
page => 'currency', |
| 195 |
default_save_state => $table_settings->{default_save_state}, |
79 |
tablename => 'currencies-table', |
| 196 |
default_save_state_search => $table_settings->{default_save_state_search}, |
80 |
columnname => 'rate', |
|
|
81 |
cannot_be_toggled => 1, |
| 82 |
cannot_be_modified => 1, |
| 197 |
}, |
83 |
}, |
| 198 |
{ |
84 |
{ |
| 199 |
default_display_length => $modules->{$m}{$p}{$t}{default_display_length}, |
85 |
module => 'admin', |
| 200 |
default_sort_order => $modules->{$m}{$p}{$t}{default_sort_order}, |
86 |
page => 'currency', |
| 201 |
default_save_state => $modules->{$m}{$p}{$t}{default_save_state}, |
87 |
tablename => 'currencies-table', |
| 202 |
default_save_state_search => $modules->{$m}{$p}{$t}{default_save_state_search}, |
88 |
columnname => 'symbol', |
|
|
89 |
}, |
| 90 |
{ |
| 91 |
module => 'admin', |
| 92 |
page => 'currency', |
| 93 |
tablename => 'currencies-table', |
| 94 |
columnname => 'iso_code', |
| 95 |
is_hidden => 0, |
| 96 |
}, |
| 97 |
{ |
| 98 |
module => 'admin', |
| 99 |
page => 'currency', |
| 100 |
tablename => 'currencies-table', |
| 101 |
columnname => 'last_updated', |
| 102 |
}, |
| 103 |
{ |
| 104 |
module => 'admin', |
| 105 |
page => 'currency', |
| 106 |
tablename => 'currencies-table', |
| 107 |
columnname => 'active', |
| 108 |
is_hidden => 1, |
| 109 |
}, |
| 110 |
{ |
| 111 |
module => 'admin', |
| 112 |
page => 'currency', |
| 113 |
tablename => 'currencies-table', |
| 114 |
columnname => 'actions', |
| 115 |
cannot_be_toggled => 1, |
| 116 |
}, |
| 117 |
] |
| 118 |
} |
| 119 |
); |
| 120 |
|
| 121 |
my $table_settings = |
| 122 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 123 |
is_deeply( |
| 124 |
$table_settings, |
| 125 |
{ |
| 126 |
default_display_length => 20, |
| 127 |
default_sort_order => 1, |
| 128 |
default_save_state => 1, |
| 129 |
default_save_state_search => 0, |
| 130 |
} |
| 131 |
); |
| 132 |
|
| 133 |
# No changes to table settings |
| 134 |
C4::Utils::DataTables::TablesSettings::update_table_settings( |
| 135 |
{ |
| 136 |
module => 'admin', |
| 137 |
page => 'currency', |
| 138 |
tablename => 'currencies-table', |
| 139 |
default_display_length => 20, |
| 140 |
default_sort_order => 1, |
| 141 |
default_save_state => 1, |
| 142 |
default_save_state_search => 0, |
| 143 |
} |
| 144 |
); |
| 145 |
|
| 146 |
my $modules_expected = { |
| 147 |
'admin' => { |
| 148 |
'currency' => { |
| 149 |
'currencies-table' => { |
| 150 |
default_display_length => 20, |
| 151 |
default_sort_order => 1, |
| 152 |
default_save_state => 1, |
| 153 |
default_save_state_search => 0, |
| 154 |
columns => [ |
| 155 |
{ |
| 156 |
columnname => 'currency', |
| 157 |
cannot_be_toggled => 1, |
| 158 |
cannot_be_modified => 1, |
| 159 |
is_hidden => 0, |
| 160 |
}, |
| 161 |
{ |
| 162 |
columnname => 'rate', |
| 163 |
cannot_be_toggled => 1, |
| 164 |
cannot_be_modified => 1, |
| 165 |
is_hidden => 0, |
| 166 |
}, |
| 167 |
{ |
| 168 |
columnname => 'symbol', |
| 169 |
cannot_be_toggled => 0, |
| 170 |
cannot_be_modified => 0, |
| 171 |
is_hidden => 0, |
| 172 |
}, |
| 173 |
{ |
| 174 |
columnname => 'iso_code', |
| 175 |
cannot_be_toggled => 0, |
| 176 |
cannot_be_modified => 0, |
| 177 |
is_hidden => 0, |
| 178 |
}, |
| 179 |
{ |
| 180 |
columnname => 'last_updated', |
| 181 |
cannot_be_toggled => 0, |
| 182 |
cannot_be_modified => 0, |
| 183 |
is_hidden => 0, |
| 184 |
}, |
| 185 |
{ |
| 186 |
columnname => 'active', |
| 187 |
cannot_be_toggled => 0, |
| 188 |
cannot_be_modified => 0, |
| 189 |
is_hidden => 1, |
| 190 |
}, |
| 191 |
{ |
| 192 |
columnname => 'actions', |
| 193 |
cannot_be_toggled => 1, |
| 194 |
cannot_be_modified => 0, |
| 195 |
is_hidden => 0, |
| 196 |
}, |
| 197 |
] |
| 203 |
} |
198 |
} |
| 204 |
); |
199 |
} |
|
|
200 |
} |
| 201 |
}; |
| 202 |
|
| 203 |
my $modules = C4::Utils::DataTables::TablesSettings::get_modules(); |
| 204 |
|
| 205 |
is_deeply( $modules, $modules_expected, 'get_modules returns all values' ); |
| 206 |
|
| 207 |
my $columns = C4::Utils::DataTables::TablesSettings::get_columns( 'admin', 'currency', 'currencies-table' ); |
| 208 |
is_deeply( $modules->{admin}, $modules_expected->{admin} ); |
| 209 |
|
| 210 |
$table_settings = |
| 211 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 212 |
is_deeply( |
| 213 |
$table_settings, |
| 214 |
{ |
| 215 |
default_display_length => 20, |
| 216 |
default_sort_order => 1, |
| 217 |
default_save_state => 1, |
| 218 |
default_save_state_search => 0, |
| 205 |
} |
219 |
} |
| 206 |
} |
220 |
); |
| 207 |
} |
221 |
|
|
|
222 |
# Changes to table settings |
| 223 |
my $new_table_settings = { |
| 224 |
default_display_length => 42, |
| 225 |
default_sort_order => 2, |
| 226 |
default_save_state => 0, |
| 227 |
default_save_state_search => 0, |
| 228 |
}; |
| 229 |
|
| 230 |
C4::Utils::DataTables::TablesSettings::update_table_settings( |
| 231 |
{ module => 'admin', page => 'currency', tablename => 'currencies-table', %$new_table_settings } ); |
| 232 |
|
| 233 |
$table_settings = |
| 234 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 235 |
is_deeply( |
| 236 |
$table_settings, |
| 237 |
$new_table_settings, |
| 238 |
); |
| 239 |
}; |
| 208 |
- |
|
|