Bug 15380: Introduce Koha::Authorit[y|ies] and Koha::Authority::Type[s]

Based on Koha::Objects.

Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
This commit is contained in:
Jonathan Druart 2015-12-15 11:41:24 +00:00 committed by Brendan Gallagher
parent 03c89fa02e
commit 895c60b8d3
5 changed files with 256 additions and 0 deletions

56
Koha/Authorities.pm Normal file
View File

@ -0,0 +1,56 @@
package Koha::Authorities;
# 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, 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::Authority;
use base qw(Koha::Objects);
=head1 NAME
Koha::Authorities - Koha Authority object set class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub type {
return 'AuthHeader';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::Authority';
}
1;

46
Koha/Authority.pm Normal file
View File

@ -0,0 +1,46 @@
package Koha::Authority;
# 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, 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::Authority - Koha Authority Object class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub type {
return 'AuthHeader';
}
1;

49
Koha/Authority/Type.pm Normal file
View File

@ -0,0 +1,49 @@
package Koha::Authority::Type;
# 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::Authority::Type - Koha Authority Type Object class
=head1 API
=head2 Class Methods
=cut
sub auth_tag_structures {
my ( $self ) = @_;
return $self->_result->auth_tag_structures;
}
=head3 type
=cut
sub type {
return 'AuthType';
}
1;

50
Koha/Authority/Types.pm Normal file
View File

@ -0,0 +1,50 @@
package Koha::Authority::Types;
# 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::Authority::Type;
use base qw(Koha::Objects);
=head1 NAME
Koha::Authority::Types - Koha Authority Type Object set class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub type {
return 'AuthType';
}
sub object_class {
return 'Koha::Authority::Type';
}
1;

View File

@ -0,0 +1,55 @@
#!/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 => 3;
use Koha::Authority;
use Koha::Authorities;
use Koha::Authority::Type;
use Koha::Authority::Types;
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_authorities = Koha::Authorities->search->count;
my $nb_of_authority_types = Koha::Authority::Types->search->count;
my $new_authority_type_1 = Koha::Authority::Type->new(
{ authtypecode => 'my_ac_1',
authtypetext => 'my authority type text 1',
auth_tag_to_report => '100',
summary => 'my summary for authority 1',
}
)->store;
my $new_authority_1 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store;
my $new_authority_2 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store;
is( Koha::Authority::Types->search->count, $nb_of_authority_types + 1, 'The authority type should have been added' );
is( Koha::Authorities->search->count, $nb_of_authorities + 2, 'The 2 authorities should have been added' );
$new_authority_1->delete;
is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the library' );
$schema->storage->txn_rollback;
1;