Bug 20047: Add Koha::Z3950Server Oject and use it to get server count
authorNick Clemens <nick@bywatersolutions.com>
Fri, 19 Jan 2018 15:57:02 +0000 (15:57 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 20 Apr 2018 16:34:41 +0000 (13:34 -0300)
To test:
1 - prove t/db_dependent/Koha/Z3950Servers.t
2 - Load cataloging and authority home pages
3 - Verify you can add form z395 on each page
4 - Delete all z3950 servers
5 - Viery option to add from Z3950 is removed on both pages

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Z3950Server.pm [new file with mode: 0644]
Koha/Z3950Servers.pm [new file with mode: 0644]
authorities/authorities-home.pl
cataloguing/addbooks.pl
t/db_dependent/Koha/Z3950Servers.t [new file with mode: 0644]

diff --git a/Koha/Z3950Server.pm b/Koha/Z3950Server.pm
new file mode 100644 (file)
index 0000000..e06ef04
--- /dev/null
@@ -0,0 +1,46 @@
+package Koha::Z3950Server;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Z3950Server - Koha Z3950Server Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 _type
+
+Return type of Object relating to Schema ResultSet
+
+=cut
+
+sub _type {
+    return 'Z3950server';
+}
+
+1;
diff --git a/Koha/Z3950Servers.pm b/Koha/Z3950Servers.pm
new file mode 100644 (file)
index 0000000..5cbf5f0
--- /dev/null
@@ -0,0 +1,58 @@
+package Koha::Z3950Servers;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use Koha::Z3950Server;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Z3950Servers - Koha Z3950Server Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+Return type of object, relating to Schema ResultSet
+
+=cut
+
+sub _type {
+    return 'Z3950server';
+}
+
+=head3 object_class
+
+Return object class
+
+=cut
+
+sub object_class {
+    return 'Koha::Z3950Server';
+}
+
+1;
index 7c46794..878c8d0 100755 (executable)
@@ -37,6 +37,7 @@ use Koha::Authority::Types;
 use Koha::SearchEngine::Search;
 use Koha::SearchEngine::QueryBuilder;
 use Koha::Token;
+use Koha::Z3950Servers;
 
 my $query = new CGI;
 my $dbh   = C4::Context->dbh;
@@ -205,15 +206,14 @@ if ( $op eq '' ) {
 
 }
 
-my $schema = Koha::Database->new()->schema();
-my $servers = $schema->resultset('Z3950server')->search(
-        {
-            recordtype => 'authority',
-            servertype => ['zed', 'sru'],
-        },
-        {   result_class => 'DBIx::Class::ResultClass::HashRefInflator',
-            order_by     => ['rank', 'servername'],
-        },
+my $servers = Koha::Z3950Servers->search(
+    {
+        recordtype => 'authority',
+        servertype => ['zed', 'sru'],
+    },
+    {   result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+        order_by     => ['rank', 'servername'],
+    },
 );
 
 $template->param(
index ae4d7ac..fdbf7c7 100755 (executable)
@@ -37,6 +37,7 @@ use C4::Search;
 use Koha::BiblioFrameworks;
 use Koha::SearchEngine::Search;
 use Koha::SearchEngine::QueryBuilder;
+use Koha::Z3950Servers;
 
 my $input = new CGI;
 
@@ -133,16 +134,7 @@ for my $resultsbr (@resultsbr) {
     };
 }
 
-my $schema = Koha::Database->new()->schema();
-my $servers = $schema->resultset('Z3950server')->search(
-        {
-            recordtype => 'biblio',
-            servertype => ['zed', 'sru'],
-        },
-        {   result_class => 'DBIx::Class::ResultClass::HashRefInflator',
-            order_by     => ['rank', 'servername'],
-        },
-);
+my $servers = Koha::Z3950Servers->search();
 
 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
 $template->param(
diff --git a/t/db_dependent/Koha/Z3950Servers.t b/t/db_dependent/Koha/Z3950Servers.t
new file mode 100644 (file)
index 0000000..9714cb4
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+# Copyright 2015 Koha Development team
+#
+# This file is part of Koha
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 4;
+
+use Koha::Z3950Server;
+use Koha::Z3950Servers;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+my $nb_of_z39s = Koha::Z3950Servers->search->count;
+my $new_z39_1 = Koha::Z3950Server->new({
+    host => 'my_host1.org',
+    port => '32',
+    db => 'db1',
+    servername => 'my_test_1',
+    servertype => 'zed',
+    recordtype => 'biblio',
+})->store;
+my $new_z39_2 = Koha::Z3950Server->new({
+    host => 'my_host2.org',
+    port => '64',
+    db => 'db2',
+    servername => 'my_test_2',
+    servertype => 'zed',
+    recordtype => 'authority',
+})->store;
+
+like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id');
+is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' );
+
+my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id );
+is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' );
+
+$retrieved_z39_1->delete;
+is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' );
+
+$schema->storage->txn_rollback;