Bug 32350: Add subtest for bad columns
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 25 Nov 2022 10:09:57 +0000 (10:09 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 1 Dec 2022 12:41:27 +0000 (12:41 +0000)
Test plan:
Run t/db_dependent/TestBuilder.t
And now run the whole test suite :)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 46aa87c600871bc8556bfe3ab4840d673211a625)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/db_dependent/TestBuilder.t

index 30588da..1fa63d0 100755 (executable)
@@ -21,8 +21,9 @@ use Modern::Perl;
 
 use utf8;
 
-use Test::More tests => 15;
+use Test::More tests => 16;
 use Test::Warn;
+use Try::Tiny;
 use File::Basename qw(dirname);
 
 use Koha::Database;
@@ -544,3 +545,35 @@ subtest 'Existence of object is only checked using primary keys' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'Test bad columns' => sub {
+    plan tests => 3;
+    $schema->storage->txn_begin;
+
+    try {
+        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { wrong => 1 } });
+        ok( 0, 'Unexpected pass with wrong column' );
+    }
+    catch {
+        like( $_, qr/^Error: value hash contains unrecognized columns: wrong/, 'Column wrong is bad' );
+    };
+    try {
+        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { surname => 'Pass', nested => { ignored => 1 }} });
+        ok( 1, 'Nested hash ignored' );
+    }
+    catch {
+        ok( 0, 'Unexpected trouble with nested hash' );
+    };
+    try {
+        my $patron = $builder->build_object({
+            class => 'Koha::Patrons',
+             value => { surname => 'WontPass', categorycode => { description => 'bla', wrong_nested => 1 }},
+        });
+        ok( 0, 'Unexpected pass with wrong nested column' );
+    }
+    catch {
+        like( $_, qr/^Error: value hash contains unrecognized columns: wrong_nested/, 'Column wrong_nested is bad' );
+    };
+
+    $schema->storage->txn_rollback;
+};