Bug 10212: Columns configuration for tables - Unit tests
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 10 Jan 2014 17:26:27 +0000 (18:26 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Tue, 26 Aug 2014 12:28:18 +0000 (09:28 -0300)
test plan:
Verify the
  prove t/db_dependent/ColumnsSettings.t
returns green.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
admin/columns_settings.yml
t/db_dependent/ColumnsSettings.t [new file with mode: 0644]

index 91d69f4..9e9a49c 100644 (file)
@@ -1,10 +1,23 @@
 modules:
-  module_name:
-    page_name:
-      table_id:
+  admin:
+    currency:
+      currencies-table:
         -
-          columnname: my_column_name
+          columnname: currency
+          cannot_be_toggled: 1
+          cannot_be_modified: 1
         -
-          columnname: my_other_column_name
+          columnname: rate
           cannot_be_toggled: 1
           cannot_be_modified: 1
+        -
+          columnname: symbol
+        -
+          columnname: iso_code
+          is_hidden: 1
+        -
+          columnname: last_updated
+        -
+          columnname: active
+        -
+          columnname: actions
diff --git a/t/db_dependent/ColumnsSettings.t b/t/db_dependent/ColumnsSettings.t
new file mode 100644 (file)
index 0000000..460d547
--- /dev/null
@@ -0,0 +1,179 @@
+#!/usr/bin/perl;
+
+use Modern::Perl;
+use Test::More tests => 2;
+use Test::MockModule;
+
+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|);
+
+my $module = new Test::MockModule('C4::Utils::DataTables::ColumnsSettings');
+$module->mock(
+    'get_yaml',
+    sub {
+        {
+            modules => {
+                admin => {
+                    currency => {
+                        'currencies-table' => [
+                            {
+                                columnname         => 'currency',
+                                cannot_be_toggled  => '1',
+                                cannot_be_modified => '1'
+                            },
+                            {
+                                columnname         => 'rate',
+                                cannot_be_toggled  => '1',
+                                cannot_be_modified => '1'
+                            },
+                            {
+                                columnname => 'symbol'
+                            },
+                            {
+                                is_hidden  => '1',
+                                columnname => 'iso_code'
+                            },
+                            {
+                                columnname => 'last_updated'
+                            },
+                            {
+                                columnname => 'active'
+                            },
+                            {
+                                columnname => 'actions'
+                            }
+                        ]
+                    }
+                }
+              }
+
+        };
+    }
+);
+
+C4::Utils::DataTables::ColumnsSettings::update_columns(
+    {
+        columns => [
+            {
+                module             => 'admin',
+                page               => 'currency',
+                tablename          => 'currencies-table',
+                columnname         => 'currency',
+                cannot_be_toggled  => 1,
+                cannot_be_modified => 1,
+            },
+            {
+                module             => 'admin',
+                page               => 'currency',
+                tablename          => 'currencies-table',
+                columnname         => 'rate',
+                cannot_be_toggled  => 1,
+                cannot_be_modified => 1,
+            },
+            {
+                module     => 'admin',
+                page       => 'currency',
+                tablename  => 'currencies-table',
+                columnname => 'symbol',
+            },
+            {
+                module     => 'admin',
+                page       => 'currency',
+                tablename  => 'currencies-table',
+                columnname => 'iso_code',
+                is_hidden  => 0,
+            },
+            {
+                module     => 'admin',
+                page       => 'currency',
+                tablename  => 'currencies-table',
+                columnname => 'last_updated',
+            },
+            {
+                module     => 'admin',
+                page       => 'currency',
+                tablename  => 'currencies-table',
+                columnname => 'active',
+                is_hidden  => 1,
+            },
+            {
+                module            => 'admin',
+                page              => 'currency',
+                tablename         => 'currencies-table',
+                columnname        => 'actions',
+                cannot_be_toggled => 1,
+            },
+        ]
+    }
+);
+
+my $modules = C4::Utils::DataTables::ColumnsSettings::get_modules();
+
+my $modules_expected = {
+    'admin' => {
+        'currency' => {
+            'currencies-table' => [
+                {
+                    columnname         => 'currency',
+                    cannot_be_toggled  => 1,
+                    cannot_be_modified => 1,
+                    is_hidden  => 0,
+                },
+                {
+                    columnname         => 'rate',
+                    cannot_be_toggled  => 1,
+                    cannot_be_modified => 1,
+                    is_hidden  => 0,
+                },
+                {
+                    columnname => 'symbol',
+                    cannot_be_toggled  => 0,
+                    is_hidden  => 0,
+                },
+                {
+                    columnname => 'iso_code',
+                    cannot_be_toggled  => 0,
+                    is_hidden  => 0,
+                },
+                {
+                    columnname => 'last_updated',
+                    cannot_be_toggled  => 0,
+                    is_hidden  => 0,
+                },
+                {
+                    columnname => 'active',
+                    cannot_be_toggled  => 0,
+                    is_hidden  => 1,
+                },
+                {
+                    columnname        => 'actions',
+                    cannot_be_toggled => 1,
+                    is_hidden  => 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;