Bug 20047: Add Koha::Z3950Server Oject and use it to get server count
[koha.git] / t / db_dependent / Koha / Z3950Servers.t
blob9714cb45992bddf5a18f7035b4ece1bb15eff6e9
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use Test::More tests => 4;
24 use Koha::Z3950Server;
25 use Koha::Z3950Servers;
26 use Koha::Database;
28 use t::lib::TestBuilder;
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
33 my $builder = t::lib::TestBuilder->new;
34 my $nb_of_z39s = Koha::Z3950Servers->search->count;
35 my $new_z39_1 = Koha::Z3950Server->new({
36 host => 'my_host1.org',
37 port => '32',
38 db => 'db1',
39 servername => 'my_test_1',
40 servertype => 'zed',
41 recordtype => 'biblio',
42 })->store;
43 my $new_z39_2 = Koha::Z3950Server->new({
44 host => 'my_host2.org',
45 port => '64',
46 db => 'db2',
47 servername => 'my_test_2',
48 servertype => 'zed',
49 recordtype => 'authority',
50 })->store;
52 like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id');
53 is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' );
55 my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id );
56 is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' );
58 $retrieved_z39_1->delete;
59 is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' );
61 $schema->storage->txn_rollback;