From e78b9667bb3a88f14bfa7a5a35abf291cd187c41 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 27 Feb 2026 07:45:28 -0500 Subject: [PATCH] Bug 41462: (QA follow-up) Add basic unit tests and koha_object_class methods Signed-off-by: Kyle M Hall --- Koha/Schema/Result/OaiSet.pm | 10 ++- Koha/Schema/Result/OaiSetsBiblio.pm | 10 ++- t/db_dependent/Koha/OAI_Sets.t | 110 ++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100755 t/db_dependent/Koha/OAI_Sets.t diff --git a/Koha/Schema/Result/OaiSet.pm b/Koha/Schema/Result/OaiSet.pm index 4081a97bcce..7c59b0e5d9d 100644 --- a/Koha/Schema/Result/OaiSet.pm +++ b/Koha/Schema/Result/OaiSet.pm @@ -129,6 +129,14 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-07-08 15:06:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ju63fVMgLPbeFxeZJsQHRQ +=head2 koha_object_class + +Returns the Koha::Object class for this table + +=cut + +sub koha_object_class { + return 'Koha::OAI::Set'; +} -# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/Koha/Schema/Result/OaiSetsBiblio.pm b/Koha/Schema/Result/OaiSetsBiblio.pm index 70409ef09c8..4ec65b79a83 100644 --- a/Koha/Schema/Result/OaiSetsBiblio.pm +++ b/Koha/Schema/Result/OaiSetsBiblio.pm @@ -78,6 +78,14 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-07-08 15:06:22 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oGVUyyyune8FVOj504xizw +=head2 koha_object_class + +Returns the Koha::Object class for this table + +=cut + +sub koha_object_class { + return 'Koha::OAI::Set::Biblio'; +} -# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/t/db_dependent/Koha/OAI_Sets.t b/t/db_dependent/Koha/OAI_Sets.t new file mode 100755 index 00000000000..110df3ed2dd --- /dev/null +++ b/t/db_dependent/Koha/OAI_Sets.t @@ -0,0 +1,110 @@ +#!/usr/bin/perl + +# Copyright 2025 Aleisha Amohia +# +# 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 => 3; +use Test::Exception; + +use Test::NoWarnings; + +use t::lib::TestBuilder; + +use Koha::Database; +use Koha::OAI::Set; +use Koha::OAI::Sets; +use Koha::OAI::Set::Biblio; +use Koha::OAI::Set::Biblios; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +$schema->storage->txn_begin; + +subtest 'Koha::OAI::Set(s) tests' => sub { + plan tests => 5; + + my $nb_of_sets = Koha::OAI::Sets->search->count; + my $new_set = Koha::OAI::Set->new( + { + spec => 'test_spec', + name => 'Test Set', + } + )->store; + + ok( $new_set->id, 'New set should have an ID' ); + is( Koha::OAI::Sets->search->count, $nb_of_sets + 1, 'One set should have been added' ); + + my $retrieved_set = Koha::OAI::Sets->find( $new_set->id ); + is( $retrieved_set->name, 'Test Set', 'Retrieved set name should match' ); + + $retrieved_set->name('Updated Name')->store; + is( Koha::OAI::Sets->find( $new_set->id )->name, 'Updated Name', 'Set name should be updated' ); + + $retrieved_set->delete; + is( Koha::OAI::Sets->search->count, $nb_of_sets, 'Set should have been deleted' ); +}; + +subtest 'Koha::OAI::Set::Biblio(s) tests' => sub { + plan tests => 4; + + my $new_set = Koha::OAI::Set->new( + { + spec => 'test_spec_biblio', + name => 'Test Set Biblio', + } + )->store; + + my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); + + my $new_set_biblio = Koha::OAI::Set::Biblio->new( + { + set_id => $new_set->id, + biblionumber => $biblio->biblionumber, + } + )->store; + + ok( $new_set_biblio, 'New set biblio object created' ); + + my $retrieved_set_biblio = Koha::OAI::Set::Biblios->find( + { + set_id => $new_set->id, + biblionumber => $biblio->biblionumber + } + ); + ok( $retrieved_set_biblio, 'Retrieved set biblio object' ); + + $retrieved_set_biblio->delete; + ok( + !Koha::OAI::Set::Biblios->find( + { + set_id => $new_set->id, + biblionumber => $biblio->biblionumber + } + ), + 'Set biblio should have been deleted' + ); + + $new_set->delete; + ok( !Koha::OAI::Sets->find( $new_set->id ), 'Set should have been deleted' ); +}; + +$schema->storage->txn_rollback; + +1; -- 2.50.1 (Apple Git-155)