From e3b9da3aa395080e8eca0d6d7167b179e3a675b7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 9 Jan 2018 11:45:47 +0000 Subject: [PATCH] Bug 19929 - Add Koha objects for class sources and sorters prove -v t/db_dependent/Koha/ClassSortRules.t prove -v t/db_dependent/Koha/ClassSources.t --- Koha/ClassSortRule.pm | 44 +++++++++++++++++++++++++++ Koha/ClassSortRules.pm | 50 ++++++++++++++++++++++++++++++ Koha/ClassSource.pm | 44 +++++++++++++++++++++++++++ Koha/ClassSources.pm | 50 ++++++++++++++++++++++++++++++ t/db_dependent/Koha/ClassSortRules.t | 55 +++++++++++++++++++++++++++++++++ t/db_dependent/Koha/ClassSources.t | 59 ++++++++++++++++++++++++++++++++++++ 6 files changed, 302 insertions(+) create mode 100644 Koha/ClassSortRule.pm create mode 100644 Koha/ClassSortRules.pm create mode 100644 Koha/ClassSource.pm create mode 100644 Koha/ClassSources.pm create mode 100644 t/db_dependent/Koha/ClassSortRules.t create mode 100644 t/db_dependent/Koha/ClassSources.t diff --git a/Koha/ClassSortRule.pm b/Koha/ClassSortRule.pm new file mode 100644 index 0000000..9e856b2 --- /dev/null +++ b/Koha/ClassSortRule.pm @@ -0,0 +1,44 @@ +package Koha::ClassSortRule; + +# 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::ClassSortRule Koha Classfication Sorting Rule Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ClassSortRule'; +} + +1; diff --git a/Koha/ClassSortRules.pm b/Koha/ClassSortRules.pm new file mode 100644 index 0000000..197b91d --- /dev/null +++ b/Koha/ClassSortRules.pm @@ -0,0 +1,50 @@ +package Koha::ClassSortRules; + +# 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::ClassSortRule; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ClassSortRules - Koha Classification Sort Rules Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ClassSortRule'; +} + +sub object_class { + return 'Koha::ClassSortRule'; +} + +1; diff --git a/Koha/ClassSource.pm b/Koha/ClassSource.pm new file mode 100644 index 0000000..373c1e0 --- /dev/null +++ b/Koha/ClassSource.pm @@ -0,0 +1,44 @@ +package Koha::ClassSource; + +# 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::ClassSource - Koha Classfication Source Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ClassSource'; +} + +1; diff --git a/Koha/ClassSources.pm b/Koha/ClassSources.pm new file mode 100644 index 0000000..f15abd7 --- /dev/null +++ b/Koha/ClassSources.pm @@ -0,0 +1,50 @@ +package Koha::ClassSources; + +# 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::ClassSource; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ClassSources - Koha Classification Source Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ClassSource'; +} + +sub object_class { + return 'Koha::ClassSource'; +} + +1; diff --git a/t/db_dependent/Koha/ClassSortRules.t b/t/db_dependent/Koha/ClassSortRules.t new file mode 100644 index 0000000..e83d93b --- /dev/null +++ b/t/db_dependent/Koha/ClassSortRules.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +# Copyright 2017 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 . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Database; + +use Koha::ClassSortRules; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $nb_of_class_sort_rules = Koha::ClassSortRules->search->count; +my $new_cs_1 = Koha::ClassSortRule->new({ + class_sort_rule => 'sort_rule1', + description => 'a_sort_test_1', + sort_routine => 'lcc', +})->store; +my $new_cs_2 = Koha::ClassSortRule->new({ + class_sort_rule => 'sort_rule2', + description => 'a_sort_test_2', + sort_routine => 'dewey', +})->store; + +is( $new_cs_1->class_sort_rule, 'sort_rule1', 'Adding a new classification sort should have set the class_sort_rule'); +is( Koha::ClassSortRules->search->count, $nb_of_class_sort_rules + 2, 'The 2 classification sorters should have been added' ); + +my $retrieved_cs_1 = Koha::ClassSortRules->find( $new_cs_1->class_sort_rule ); +is( $retrieved_cs_1->description, $new_cs_1->description, 'Find a sorter by class_sort_rule should return the correct source' ); + +$retrieved_cs_1->delete; +is( Koha::ClassSortRules->search->count, $nb_of_class_sort_rules + 1, 'Delete should have deleted the sort' ); + +$schema->storage->txn_rollback; diff --git a/t/db_dependent/Koha/ClassSources.t b/t/db_dependent/Koha/ClassSources.t new file mode 100644 index 0000000..f188e0f --- /dev/null +++ b/t/db_dependent/Koha/ClassSources.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +# Copyright 2017 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 . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Database; + +use Koha::ClassSources; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $class_sort_1 = $builder->build({ source=>'ClassSortRule' }); +my $class_sort_2 = $builder->build({ source=>'ClassSortRule' }); +my $nb_of_class_sources = Koha::ClassSources->search->count; +my $new_cs_1 = Koha::ClassSource->new({ + cn_source => 'source_1', + description => 'a_test_1', + used => '1', + class_sort_rule => $class_sort_1->{class_sort_rule},#'sort_rule_1', +})->store; +my $new_cs_2 = Koha::ClassSource->new({ + cn_source => 'source_2', + description => 'a_test_2', + used => '0', + class_sort_rule => $class_sort_2->{class_sort_rule},#'sort_rule_1', +})->store; + +is( $new_cs_1->cn_source, 'source_1', 'Adding a new classification should have set the cn_source'); +is( Koha::ClassSources->search->count, $nb_of_class_sources + 2, 'The 2 classifcations should have been added' ); + +my $retrieved_cs_1 = Koha::ClassSources->find( $new_cs_1->cn_source ); +is( $retrieved_cs_1->description, $new_cs_1->description, 'Find a source by cn_source should return the correct source' ); + +$retrieved_cs_1->delete; +is( Koha::ClassSources->search->count, $nb_of_class_sources + 1, 'Delete should have deleted the classification' ); + +$schema->storage->txn_rollback; -- 2.1.4