Bugzilla – Attachment 195139 Details for
Bug 42044
Automatically update record status (LDR/5) for modified records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 42044: Unit tests
Bug-42044-Unit-tests.patch (text/plain), 8.76 KB, created by
Janusz Kaczmarek
on 2026-03-11 20:42:05 UTC
(
hide
)
Description:
Bug 42044: Unit tests
Filename:
MIME Type:
Creator:
Janusz Kaczmarek
Created:
2026-03-11 20:42:05 UTC
Size:
8.76 KB
patch
obsolete
>From eb0841a47a9490f600441a60167f4d5b08442cb3 Mon Sep 17 00:00:00 2001 >From: Janusz Kaczmarek <januszop@gmail.com> >Date: Wed, 11 Mar 2026 20:22:07 +0000 >Subject: [PATCH] Bug 42044: Unit tests > >--- > t/db_dependent/AuthoritiesMarc.t | 95 +++++++++++++++++++++++++++++++- > t/db_dependent/Biblio.t | 81 ++++++++++++++++++++++++++- > 2 files changed, 174 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/AuthoritiesMarc.t b/t/db_dependent/AuthoritiesMarc.t >index e223ddba34..7cc094d06f 100755 >--- a/t/db_dependent/AuthoritiesMarc.t >+++ b/t/db_dependent/AuthoritiesMarc.t >@@ -6,11 +6,12 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 14; >+use Test::More tests => 15; > use Test::MockModule; > use Test::Warn; > use MARC::Field; > use MARC::Record; >+use POSIX qw( strftime ); > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -398,3 +399,95 @@ subtest 'DelAuthority() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'record status after ModAuthority' => sub { >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference( "marcflavour", 'MARC21' ); >+ t::lib::Mocks::mock_preference( "AutoUpdateRecordStatus", 1 ); >+ t::lib::Mocks::mock_preference( "AuthoritiesLog", 0 ); >+ my $c4_context = Test::MockModule->new('C4::Context'); >+ $c4_context->mock( 'userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe' }; } ); >+ my $mocked_authorities_marc = Test::MockModule->new('C4::AuthoritiesMarc'); >+ $mocked_authorities_marc->unmock('merge'); >+ >+ my $authtypecode = 'GEOGR_NAME'; >+ >+ my $marc_record_init = MARC::Record->new; >+ my $leader = $marc_record_init->leader; >+ substr( $leader, 5, 1, 'n' ); >+ $marc_record_init->leader($leader); >+ $marc_record_init->insert_fields_ordered( >+ MARC::Field->new( '008', POSIX::strftime( "%y%m%d", localtime ) . ( ' ' x 34 ) ) ); >+ $marc_record_init->insert_fields_ordered( >+ MARC::Field->new( >+ '040', ' ', ' ', >+ a => 'ABC', >+ c => 'ABC' >+ ) >+ ); >+ $marc_record_init->insert_fields_ordered( >+ MARC::Field->new( >+ '151', ' ', ' ', >+ a => 'Cape Horn' >+ ) >+ ); >+ >+ my $authid = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode ); >+ my $marc_record = $marc_record_init->clone; >+ >+ # AuthoritiesLog == 0 --> LDR/5 should be set to 'c' >+ C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode ); >+ >+ my $auth = Koha::Authorities->find($authid); >+ $marc_record = $auth->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # AuthoritiesLog == 1 --> LDR/5 should not be changed >+ t::lib::Mocks::mock_preference( "AuthoritiesLog", 1 ); >+ $authid = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode ); >+ $marc_record = $marc_record_init->clone; >+ >+ C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode ); >+ >+ $auth = Koha::Authorities->find($authid); >+ $marc_record = $auth->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'n', 'Record status unchanged' ); >+ >+ # 040 $d present --> LDR/5 should be set to 'c' >+ $marc_record->field('040')->add_subfields( d => 'ABC' ); >+ C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode ); >+ >+ $auth = Koha::Authorities->find($authid); >+ $marc_record = $auth->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # date entered on file != today --> LDR/5 should be set to 'c' >+ $authid = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode ); >+ $marc_record = $marc_record_init->clone; >+ $marc_record->field('008')->update( '010101' . ( ' ' x 34 ) ); >+ C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode ); >+ >+ $auth = Koha::Authorities->find($authid); >+ $marc_record = $auth->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # LDR/5 changed in $marc_record before ModAuthority --> no auto update >+ substr( $leader, 5, 1, 'p' ); >+ $marc_record->leader($leader); >+ $marc_record->field('040')->add_subfields( d => 'ABC' ); >+ C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode ); >+ >+ $auth = Koha::Authorities->find($authid); >+ $marc_record = $auth->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'p', 'Record status still "p"' ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index bca89014a2..5498d4c669 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -17,12 +17,13 @@ > > use Modern::Perl; > >-use Test::More tests => 26; >+use Test::More tests => 27; > use Test::NoWarnings; > use Test::MockModule; > use Test::Warn; > use List::MoreUtils qw( uniq ); > use MARC::Record; >+use POSIX qw( strftime ); > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -1376,6 +1377,84 @@ subtest 'AddBiblio/ModBiblio calling ModBiblioMarc for field 005' => sub { > ok( $field && $field->data, 'Record contains field 005 after ModBiblio' ); > }; > >+subtest 'record status after ModBiblio' => sub { >+ plan tests => 5; >+ >+ t::lib::Mocks::mock_preference( "marcflavour", 'MARC21' ); >+ t::lib::Mocks::mock_preference( "AutoUpdateRecordStatus", 1 ); >+ t::lib::Mocks::mock_preference( "CataloguingLog", 0 ); >+ my $c4_context = Test::MockModule->new('C4::Context'); >+ $c4_context->mock( 'userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe' }; } ); >+ >+ my $marc_record_init = MARC::Record->new; >+ my $leader = $marc_record_init->leader; >+ substr( $leader, 5, 1, 'n' ); >+ $marc_record_init->leader($leader); >+ $marc_record_init->insert_fields_ordered( >+ MARC::Field->new( '008', POSIX::strftime( "%y%m%d", localtime ) . ( ' ' x 34 ) ) ); >+ $marc_record_init->insert_fields_ordered( >+ MARC::Field->new( >+ '040', ' ', ' ', >+ a => 'ABC', >+ c => 'ABC' >+ ) >+ ); >+ >+ my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); >+ my $marc_record = $marc_record_init->clone; >+ >+ # CataloguingLog == 0 --> LDR/5 should be set to 'c' >+ C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); >+ >+ my $biblio = Koha::Biblios->find($biblionumber); >+ $marc_record = $biblio->metadata->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # CataloguingLog == 1 --> LDR/5 should not be changed >+ t::lib::Mocks::mock_preference( "CataloguingLog", 1 ); >+ ($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); >+ $marc_record = $marc_record_init->clone; >+ >+ C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); >+ >+ $biblio = Koha::Biblios->find($biblionumber); >+ $marc_record = $biblio->metadata->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'n', 'Record status unchanged' ); >+ >+ # 040 $d present --> LDR/5 should be set to 'c' >+ $marc_record->field('040')->add_subfields( d => 'ABC' ); >+ C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); >+ >+ $biblio = Koha::Biblios->find($biblionumber); >+ $marc_record = $biblio->metadata->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # date entered on file != today --> LDR/5 should be set to 'c' >+ ($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); >+ $marc_record = $marc_record_init->clone; >+ $marc_record->field('008')->update( '010101' . ( ' ' x 34 ) ); >+ C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); >+ >+ $biblio = Koha::Biblios->find($biblionumber); >+ $marc_record = $biblio->metadata->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); >+ >+ # LDR/5 explicitly changed in $marc_record before ModBiblio, added 040 $d --> no auto update >+ substr( $leader, 5, 1, 'p' ); >+ $marc_record->leader($leader); >+ $marc_record->field('040')->add_subfields( d => 'ABC' ); >+ C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); >+ >+ $biblio = Koha::Biblios->find($biblionumber); >+ $marc_record = $biblio->metadata->record; >+ $leader = $marc_record->leader; >+ is( substr( $leader, 5, 1 ), 'p', 'Record status still "p"' ); >+}; >+ > # Cleanup > Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-"); > $schema->storage->txn_rollback; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 42044
:
195137
|
195138
| 195139