From 41c31d99a50d0f7e2285913f18caee8630f74726 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 10 Jan 2014 18:26:27 +0100 Subject: [PATCH] Bug 10212: Columns configuration for tables - Unit tests Signed-off-by: Jonathan Druart --- t/db_dependent/ColumnsSettings.t | 289 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 t/db_dependent/ColumnsSettings.t diff --git a/t/db_dependent/ColumnsSettings.t b/t/db_dependent/ColumnsSettings.t new file mode 100644 index 0000000..0201822 --- /dev/null +++ b/t/db_dependent/ColumnsSettings.t @@ -0,0 +1,289 @@ +#!/usr/bin/perl; + +use Modern::Perl; +use Test::More tests => 3; + +use C4::Context; +use C4::Utils::DataTables::ColumnsSettings; +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +$dbh->do(q|DELETE FROM columns_settings|); + +C4::Utils::DataTables::ColumnsSettings::update_columns( + { + columns => [ + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'barcode', + is_hidden => 1, + cannot_be_toggled => 1 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'call_number', + is_hidden => 0, + cannot_be_toggled => 1 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'delete', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'hold_date', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'info', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'priority', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'holdst', + columnname => 'title', + is_hidden => 0, + cannot_be_toggled => 1 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'call_no', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'charge', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'checked_out_from', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'checked_out_on', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'check_in', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'due_date', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'export', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'item_type', + is_hidden => 0, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'price', + is_hidden => 1, + cannot_be_toggled => 1 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'renew', + is_hidden => 1, + cannot_be_toggled => 0 + }, + { + module => 'circ', + page => 'circulation', + tablename => 'issuest', + columnname => 'title', + is_hidden => 0, + cannot_be_toggled => 1 + }, + ] + } +); + +my $modules = C4::Utils::DataTables::ColumnsSettings::get_modules(); + +my $modules_expected = { + 'circ' => { + 'circulation' => { + 'holdst' => [ + { + 'columnname' => 'hold_date', + 'is_hidden' => '1', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'title', + 'is_hidden' => '0', + 'cannot_be_toggled' => '1' + }, + { + 'columnname' => 'call_number', + 'is_hidden' => '0', + 'cannot_be_toggled' => '1' + }, + { + 'columnname' => 'barcode', + 'is_hidden' => '1', + 'cannot_be_toggled' => '1' + }, + { + 'columnname' => 'priority', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'delete', + 'is_hidden' => '1', + 'cannot_be_modified' => '1', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'info', + 'is_hidden' => '1', + 'cannot_be_modified' => '1', + 'cannot_be_toggled' => '0' + } + ], + 'issuest' => [ + { + 'columnname' => 'due_date', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'title', + 'is_hidden' => '0', + 'cannot_be_toggled' => '1' + }, + { + 'columnname' => 'item_type', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'checked_out_on', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'checked_out_from', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'call_no', + 'is_hidden' => '0', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'charge', + 'is_hidden' => '1', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'price', + 'is_hidden' => '1', + 'cannot_be_toggled' => '1' + }, + { + 'columnname' => 'renew', + 'is_hidden' => '1', + 'cannot_be_modified' => '1', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'check_in', + 'is_hidden' => '1', + 'cannot_be_modified' => '1', + 'cannot_be_toggled' => '0' + }, + { + 'columnname' => 'export', + 'is_hidden' => '1', + 'cannot_be_modified' => '1', + 'cannot_be_toggled' => '0' + } + ] + } + } +}; + +is_deeply( $modules, $modules_expected, 'get_modules returns all values' ); + +for my $m ( keys %$modules ) { + for my $p ( keys %{ $modules->{$m} } ) { + for my $t ( keys %{ $modules->{$m}{$p} } ) { + my $columns = + C4::Utils::DataTables::ColumnsSettings::get_columns( $m, $p, $t ); + is_deeply( + $columns, + $modules->{$m}{$p}{$t}, + "columns for $m>$p>$t" + ); + } + } +} + +$dbh->rollback; -- 1.7.10.4