From 6b950da9d9fcf17cee7f5d78615640442525615e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 17 Apr 2024 15:06:00 +0000 Subject: [PATCH] Bug 30888: Unit tests Content-Type: text/plain; charset=utf-8 Extending DelAuthority test in AuthoritiesMarc.t. Adding Koha/Authority.t for new method move_to_deleted. Test plan: Run both tests. Signed-off-by: Marcel de Rooy --- t/db_dependent/AuthoritiesMarc.t | 5 ++- t/db_dependent/Koha/Authority.t | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 t/db_dependent/Koha/Authority.t diff --git a/t/db_dependent/AuthoritiesMarc.t b/t/db_dependent/AuthoritiesMarc.t index 55435d281b..9dda769320 100755 --- a/t/db_dependent/AuthoritiesMarc.t +++ b/t/db_dependent/AuthoritiesMarc.t @@ -336,7 +336,7 @@ subtest 'ModAuthority() tests' => sub { subtest 'DelAuthority() tests' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; @@ -364,5 +364,8 @@ subtest 'DelAuthority() tests' => sub { undef, 'skip_merge passed, merge not called'; + # Check if last delete got moved to deletedauth_header + isnt( Koha::Database->new->schema->resultset('DeletedauthHeader')->find($auth_id), undef, 'Moved to deleted' ); + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Authority.t b/t/db_dependent/Koha/Authority.t new file mode 100755 index 0000000000..db79a92165 --- /dev/null +++ b/t/db_dependent/Koha/Authority.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +# Copyright 2024 Rijksmuseum, 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 => 1; + +use C4::AuthoritiesMarc; +use Koha::Authorities; +use Koha::Database; + +use t::lib::Mocks; +use t::lib::TestBuilder; + +my $builder = t::lib::TestBuilder->new; +my $schema = Koha::Database->new->schema; + +subtest 'move_to_deleted' => sub { + plan tests => 3; + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); # TODO UNIMARC? + + my $record = MARC::Record->new; + $record->append_fields( MARC::Field->new( '100', '1', '2', a => 'Name' ) ); + my $type = $builder->build( { source => 'AuthType', value => { auth_tag_to_report => '100' } } ); + my $authid = C4::AuthoritiesMarc::AddAuthority( + $record, undef, + $type->{authtypecode} + ); + my $authority = Koha::Authorities->find($authid); + + # Trivial test to see if 'move' really copies.. + my $count = $schema->resultset('DeletedauthHeader')->count; + my $rec = $authority->move_to_deleted; + is( $schema->resultset('DeletedauthHeader')->count, $count + 1, 'count one higher' ); + + # Check leader position 05 in marc and marcxml + is( substr( $rec->marc, 5, 1 ), 'd', 'Leader in marc blob correct' ); + like( $rec->marcxml, qr/\d{5}d/, 'Leader in marcxml checked also' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5