|
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 => 2; |
5 |
use Test::More tests => 3; |
| 6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
| 7 |
|
7 |
|
| 8 |
use C4::Context; |
8 |
use C4::Context; |
|
Lines 237-239
subtest 'update_columns, get_modules, get_columns, get_table_settings' => sub {
Link Here
|
| 237 |
$new_table_settings, |
237 |
$new_table_settings, |
| 238 |
); |
238 |
); |
| 239 |
}; |
239 |
}; |
| 240 |
- |
240 |
|
|
|
241 |
subtest 'test upgrade' => sub { |
| 242 |
|
| 243 |
plan tests => 2; |
| 244 |
|
| 245 |
subtest 'has default_* in yaml' => sub { |
| 246 |
|
| 247 |
plan tests => 6; |
| 248 |
|
| 249 |
$schema->storage->txn_begin; |
| 250 |
my $dbh = C4::Context->dbh; |
| 251 |
|
| 252 |
$dbh->do(q|DELETE FROM columns_settings|); |
| 253 |
$dbh->do(q|DELETE FROM tables_settings|); |
| 254 |
|
| 255 |
$yaml = { |
| 256 |
modules => { |
| 257 |
admin => { |
| 258 |
currency => { |
| 259 |
'currencies-table' => { |
| 260 |
default_display_length => 20, |
| 261 |
default_sort_order => 1, |
| 262 |
default_save_state => 1, |
| 263 |
default_save_state_search => 0, |
| 264 |
columns => [ |
| 265 |
{ |
| 266 |
columnname => 'currency', |
| 267 |
cannot_be_toggled => '1', |
| 268 |
cannot_be_modified => '1' |
| 269 |
}, |
| 270 |
] |
| 271 |
} |
| 272 |
} |
| 273 |
}, |
| 274 |
} |
| 275 |
}; |
| 276 |
|
| 277 |
my $modules_expected = { |
| 278 |
'admin' => { |
| 279 |
'currency' => { |
| 280 |
'currencies-table' => { |
| 281 |
|
| 282 |
# undef in DB we want the values from yaml |
| 283 |
default_display_length => 20, |
| 284 |
default_sort_order => 1, |
| 285 |
default_save_state => 1, |
| 286 |
default_save_state_search => 0, |
| 287 |
columns => [ |
| 288 |
{ |
| 289 |
columnname => 'currency', |
| 290 |
cannot_be_toggled => 1, |
| 291 |
cannot_be_modified => 1, |
| 292 |
|
| 293 |
# TODO |
| 294 |
# hidden => 0 is missing because we don't add it in get_modules for all columns |
| 295 |
# It should not cause any problems for now |
| 296 |
}, |
| 297 |
] |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
}; |
| 302 |
|
| 303 |
my $modules = C4::Utils::DataTables::TablesSettings::get_modules(); |
| 304 |
|
| 305 |
is_deeply( $modules, $modules_expected, 'get_modules returns all values' ); |
| 306 |
|
| 307 |
my $columns = C4::Utils::DataTables::TablesSettings::get_columns( 'admin', 'currency', 'currencies-table' ); |
| 308 |
is_deeply( $modules->{admin}, $modules_expected->{admin} ); |
| 309 |
|
| 310 |
my $table_settings = |
| 311 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 312 |
is_deeply( |
| 313 |
$table_settings, |
| 314 |
{ |
| 315 |
default_display_length => 20, |
| 316 |
default_save_state => 1, |
| 317 |
default_save_state_search => 0, |
| 318 |
default_sort_order => 1 |
| 319 |
} |
| 320 |
); |
| 321 |
|
| 322 |
C4::Utils::DataTables::TablesSettings::update_columns( |
| 323 |
{ |
| 324 |
columns => [ |
| 325 |
{ |
| 326 |
module => 'admin', |
| 327 |
page => 'currency', |
| 328 |
tablename => 'currencies-table', |
| 329 |
columnname => 'currency', |
| 330 |
cannot_be_toggled => 1, |
| 331 |
cannot_be_modified => 1, |
| 332 |
}, |
| 333 |
] |
| 334 |
} |
| 335 |
); |
| 336 |
|
| 337 |
$table_settings = |
| 338 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 339 |
is_deeply( |
| 340 |
$table_settings, |
| 341 |
{ |
| 342 |
default_display_length => 20, |
| 343 |
default_save_state => 1, |
| 344 |
default_save_state_search => 0, |
| 345 |
default_sort_order => 1 |
| 346 |
} |
| 347 |
); |
| 348 |
|
| 349 |
C4::Utils::DataTables::TablesSettings::update_table_settings( |
| 350 |
{ |
| 351 |
module => 'admin', |
| 352 |
page => 'currency', |
| 353 |
tablename => 'currencies-table', |
| 354 |
default_display_length => undef, |
| 355 |
default_sort_order => undef, |
| 356 |
default_save_state => undef, |
| 357 |
default_save_state_search => undef, |
| 358 |
} |
| 359 |
); |
| 360 |
|
| 361 |
$table_settings = |
| 362 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 363 |
is_deeply( |
| 364 |
$table_settings, |
| 365 |
{ |
| 366 |
default_display_length => 20, |
| 367 |
default_sort_order => 1, |
| 368 |
default_save_state => 1, |
| 369 |
default_save_state_search => 0, |
| 370 |
} |
| 371 |
); |
| 372 |
|
| 373 |
C4::Utils::DataTables::TablesSettings::update_table_settings( |
| 374 |
{ |
| 375 |
module => 'admin', |
| 376 |
page => 'currency', |
| 377 |
tablename => 'currencies-table', |
| 378 |
default_display_length => 42, |
| 379 |
default_sort_order => 2, |
| 380 |
default_save_state => 0, |
| 381 |
default_save_state_search => 0, |
| 382 |
} |
| 383 |
); |
| 384 |
|
| 385 |
$table_settings = |
| 386 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 387 |
is_deeply( |
| 388 |
$table_settings, |
| 389 |
{ |
| 390 |
default_display_length => 42, |
| 391 |
default_sort_order => 2, |
| 392 |
default_save_state => 0, |
| 393 |
default_save_state_search => 0, |
| 394 |
} |
| 395 |
); |
| 396 |
|
| 397 |
}; |
| 398 |
|
| 399 |
subtest 'does not have default_ in yaml' => sub { |
| 400 |
|
| 401 |
plan tests => 3; |
| 402 |
|
| 403 |
$schema->storage->txn_begin; |
| 404 |
my $dbh = C4::Context->dbh; |
| 405 |
|
| 406 |
$dbh->do(q|DELETE FROM columns_settings|); |
| 407 |
$dbh->do(q|DELETE FROM tables_settings|); |
| 408 |
|
| 409 |
$yaml = { |
| 410 |
modules => { |
| 411 |
admin => { |
| 412 |
currency => { |
| 413 |
'currencies-table' => { |
| 414 |
columns => [ |
| 415 |
{ |
| 416 |
columnname => 'currency', |
| 417 |
cannot_be_toggled => '1', |
| 418 |
cannot_be_modified => '1' |
| 419 |
}, |
| 420 |
] |
| 421 |
} |
| 422 |
} |
| 423 |
}, |
| 424 |
} |
| 425 |
}; |
| 426 |
|
| 427 |
my $modules_expected = { |
| 428 |
'admin' => { |
| 429 |
'currency' => { |
| 430 |
'currencies-table' => { |
| 431 |
|
| 432 |
# FIXME we don't include table settings if they are not present in the yaml |
| 433 |
#default_display_length => undef, |
| 434 |
#default_sort_order => undef, |
| 435 |
#default_save_state => undef, |
| 436 |
#default_save_state_search => undef, |
| 437 |
columns => [ |
| 438 |
{ |
| 439 |
columnname => 'currency', |
| 440 |
cannot_be_toggled => 1, |
| 441 |
cannot_be_modified => 1, |
| 442 |
|
| 443 |
# TODO |
| 444 |
# hidden => 0 is missing because we don't add it in get_modules for all columns |
| 445 |
# It should not cause any problems for now |
| 446 |
}, |
| 447 |
] |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
}; |
| 452 |
|
| 453 |
my $modules = C4::Utils::DataTables::TablesSettings::get_modules(); |
| 454 |
|
| 455 |
is_deeply( $modules, $modules_expected, 'get_modules returns all values' ); |
| 456 |
|
| 457 |
my $columns = C4::Utils::DataTables::TablesSettings::get_columns( 'admin', 'currency', 'currencies-table' ); |
| 458 |
is_deeply( $modules->{admin}, $modules_expected->{admin} ); |
| 459 |
|
| 460 |
my $table_settings = |
| 461 |
C4::Utils::DataTables::TablesSettings::get_table_settings( 'admin', 'currency', 'currencies-table' ); |
| 462 |
is_deeply( |
| 463 |
$table_settings, |
| 464 |
{ |
| 465 |
# default_display_length and default_sort_order default to undef |
| 466 |
# => the feature is not available |
| 467 |
default_display_length => undef, |
| 468 |
default_sort_order => undef, |
| 469 |
|
| 470 |
# default_save_state is disabled by default but can be enabled. |
| 471 |
default_save_state => 0, |
| 472 |
default_save_state_search => 0, |
| 473 |
} |
| 474 |
); |
| 475 |
}; |
| 476 |
}; |