3 # Copyright 2015 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test::More tests => 2;
24 use t::lib::TestBuilder;
26 use Koha::Z3950Server;
27 use Koha::Z3950Servers;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'new, find and delete tests' => sub {
34 $schema->storage->txn_begin;
35 my $nb_of_z39s = Koha::Z3950Servers->search->count;
36 my $new_z39_1 = Koha::Z3950Server->new({
37 host => 'my_host1.org',
40 servername => 'my_test_1',
42 recordtype => 'biblio',
46 my $new_z39_2 = Koha::Z3950Server->new({
47 host => 'my_host2.org',
50 servername => 'my_test_2',
52 recordtype => 'authority',
57 like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id');
58 is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' );
60 my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id );
61 is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' );
63 $retrieved_z39_1->delete;
64 is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' );
66 $schema->storage->txn_rollback;
69 subtest 'Host, syntax and encoding are NOT NULL now (BZ 30571)' => sub {
71 $schema->storage->txn_begin;
72 local $SIG{__WARN__} = sub {}; # TODO Needed it for suppressing DBIx warns
74 my $server = Koha::Z3950Server->new({
77 servername => 'my_test_3',
79 recordtype => 'biblio',
82 throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty host';
83 like( $@->{msg}, qr/'host' doesn't have a default value/, 'Verified that DBIx blamed host' );
85 $server->host('host_added.nl');
86 throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty syntax';
87 like( $@->{msg}, qr/'syntax' doesn't have a default value/, 'Verified that DBIx blamed syntax' );
89 $server->syntax('USMARC');
90 throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty encoding';
91 like( $@->{msg}, qr/'encoding' doesn't have a default value/, 'Verified that DBIx blamed encoding' );
93 $server->encoding('utf8');
94 lives_ok { $server->store } 'No exceptions anymore';
96 $schema->storage->txn_rollback;