From 6f8088805df2a957d8b8266fb054699451df5170 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 24 Aug 2022 12:50:31 +0000 Subject: [PATCH] Bug 30571: Z3950Servers.t - Add another subtest Subtest for testing nullability of host, syntax and encoding. Test plan: Run prove t/db_dependent/Koha/Z3950Servers.t. (Note: you need strict mode to pass this test.) Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Z3950Servers.t | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Z3950Servers.t b/t/db_dependent/Koha/Z3950Servers.t index 282f982db8..6f6dbd81c3 100755 --- a/t/db_dependent/Koha/Z3950Servers.t +++ b/t/db_dependent/Koha/Z3950Servers.t @@ -18,7 +18,8 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; +use Test::Exception; use t::lib::TestBuilder; use Koha::Database; @@ -39,6 +40,8 @@ subtest 'new, find and delete tests' => sub { servername => 'my_test_1', servertype => 'zed', recordtype => 'biblio', + syntax => 'USMARC', + encoding => 'MARC-8', })->store; my $new_z39_2 = Koha::Z3950Server->new({ host => 'my_host2.org', @@ -47,6 +50,8 @@ subtest 'new, find and delete tests' => sub { servername => 'my_test_2', servertype => 'zed', recordtype => 'authority', + syntax => 'USMARC', + encoding => 'MARC-8', })->store; like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id'); @@ -60,3 +65,33 @@ subtest 'new, find and delete tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'Host, syntax and encoding are NOT NULL now (BZ 30571)' => sub { + plan tests => 7; + $schema->storage->txn_begin; + local $SIG{__WARN__} = sub {}; # TODO Needed it for suppressing DBIx warns + + my $server = Koha::Z3950Server->new({ + port => '80', + db => 'db', + servername => 'my_test_3', + servertype => 'zed', + recordtype => 'biblio', + }); + + throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty host'; + like( $@->{msg}, qr/'host' doesn't have a default value/, 'Verified that DBIx blamed host' ); + + $server->host('host_added.nl'); + throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty syntax'; + like( $@->{msg}, qr/'syntax' doesn't have a default value/, 'Verified that DBIx blamed syntax' ); + + $server->syntax('USMARC'); + throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty encoding'; + like( $@->{msg}, qr/'encoding' doesn't have a default value/, 'Verified that DBIx blamed encoding' ); + + $server->encoding('utf8'); + lives_ok { $server->store } 'No exceptions anymore'; + + $schema->storage->txn_rollback; +}; -- 2.39.5