|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2025 Aleisha Amohia <aleisha@catalyst.net.nz> |
| 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 <https://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 3; |
| 23 |
use Test::Exception; |
| 24 |
|
| 25 |
use Test::NoWarnings; |
| 26 |
|
| 27 |
use t::lib::TestBuilder; |
| 28 |
|
| 29 |
use Koha::Database; |
| 30 |
use Koha::OAI::Set; |
| 31 |
use Koha::OAI::Sets; |
| 32 |
use Koha::OAI::Set::Biblio; |
| 33 |
use Koha::OAI::Set::Biblios; |
| 34 |
|
| 35 |
my $schema = Koha::Database->new->schema; |
| 36 |
my $builder = t::lib::TestBuilder->new; |
| 37 |
|
| 38 |
$schema->storage->txn_begin; |
| 39 |
|
| 40 |
subtest 'Koha::OAI::Set(s) tests' => sub { |
| 41 |
plan tests => 5; |
| 42 |
|
| 43 |
my $nb_of_sets = Koha::OAI::Sets->search->count; |
| 44 |
my $new_set = Koha::OAI::Set->new( |
| 45 |
{ |
| 46 |
spec => 'test_spec', |
| 47 |
name => 'Test Set', |
| 48 |
} |
| 49 |
)->store; |
| 50 |
|
| 51 |
ok( $new_set->id, 'New set should have an ID' ); |
| 52 |
is( Koha::OAI::Sets->search->count, $nb_of_sets + 1, 'One set should have been added' ); |
| 53 |
|
| 54 |
my $retrieved_set = Koha::OAI::Sets->find( $new_set->id ); |
| 55 |
is( $retrieved_set->name, 'Test Set', 'Retrieved set name should match' ); |
| 56 |
|
| 57 |
$retrieved_set->name('Updated Name')->store; |
| 58 |
is( Koha::OAI::Sets->find( $new_set->id )->name, 'Updated Name', 'Set name should be updated' ); |
| 59 |
|
| 60 |
$retrieved_set->delete; |
| 61 |
is( Koha::OAI::Sets->search->count, $nb_of_sets, 'Set should have been deleted' ); |
| 62 |
}; |
| 63 |
|
| 64 |
subtest 'Koha::OAI::Set::Biblio(s) tests' => sub { |
| 65 |
plan tests => 4; |
| 66 |
|
| 67 |
my $new_set = Koha::OAI::Set->new( |
| 68 |
{ |
| 69 |
spec => 'test_spec_biblio', |
| 70 |
name => 'Test Set Biblio', |
| 71 |
} |
| 72 |
)->store; |
| 73 |
|
| 74 |
my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); |
| 75 |
|
| 76 |
my $new_set_biblio = Koha::OAI::Set::Biblio->new( |
| 77 |
{ |
| 78 |
set_id => $new_set->id, |
| 79 |
biblionumber => $biblio->biblionumber, |
| 80 |
} |
| 81 |
)->store; |
| 82 |
|
| 83 |
ok( $new_set_biblio, 'New set biblio object created' ); |
| 84 |
|
| 85 |
my $retrieved_set_biblio = Koha::OAI::Set::Biblios->find( |
| 86 |
{ |
| 87 |
set_id => $new_set->id, |
| 88 |
biblionumber => $biblio->biblionumber |
| 89 |
} |
| 90 |
); |
| 91 |
ok( $retrieved_set_biblio, 'Retrieved set biblio object' ); |
| 92 |
|
| 93 |
$retrieved_set_biblio->delete; |
| 94 |
ok( |
| 95 |
!Koha::OAI::Set::Biblios->find( |
| 96 |
{ |
| 97 |
set_id => $new_set->id, |
| 98 |
biblionumber => $biblio->biblionumber |
| 99 |
} |
| 100 |
), |
| 101 |
'Set biblio should have been deleted' |
| 102 |
); |
| 103 |
|
| 104 |
$new_set->delete; |
| 105 |
ok( !Koha::OAI::Sets->find( $new_set->id ), 'Set should have been deleted' ); |
| 106 |
}; |
| 107 |
|
| 108 |
$schema->storage->txn_rollback; |
| 109 |
|
| 110 |
1; |