Bug 24757: Leap day failing tests - Fix the tests!
[koha.git] / t / db_dependent / Koha / Z3950Servers.t
1 #!/usr/bin/perl
2
3 # Copyright 2015 Koha Development team
4 #
5 # This file is part of Koha
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 4;
23
24 use Koha::Z3950Server;
25 use Koha::Z3950Servers;
26 use Koha::Database;
27
28 use t::lib::TestBuilder;
29
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
32
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;
51
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' );
54
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' );
57
58 $retrieved_z39_1->delete;
59 is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' );
60
61 $schema->storage->txn_rollback;