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 <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-08-24 12:50:31 +00:00 committed by Tomas Cohen Arazi
parent c24a67a28d
commit 6f8088805d
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -18,7 +18,8 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
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;
};