Bugzilla – Attachment 188224 Details for
Bug 40777
500 Error: Something went wrong when loading the table Should Exit Cleanly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40777: Add tests for invalid_item_type
Bug-40777-Add-tests-for-invaliditemtype.patch (text/plain), 5.42 KB, created by
Jonathan Druart
on 2025-10-21 13:47:47 UTC
(
hide
)
Description:
Bug 40777: Add tests for invalid_item_type
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-10-21 13:47:47 UTC
Size:
5.42 KB
patch
obsolete
>From d6ed1bdb44ec385f81e0ff7babb413fdb159b074 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 21 Oct 2025 14:35:18 +0200 >Subject: [PATCH] Bug 40777: Add tests for invalid_item_type > >--- > Koha/Database/DataInconsistency.pm | 11 ++- > .../Koha/Database/DataInconsistency.t | 82 ++++++++++++++++++- > 2 files changed, 89 insertions(+), 4 deletions(-) > >diff --git a/Koha/Database/DataInconsistency.pm b/Koha/Database/DataInconsistency.pm >index 24af88b04cd..f3f6a93bf86 100644 >--- a/Koha/Database/DataInconsistency.pm >+++ b/Koha/Database/DataInconsistency.pm >@@ -122,13 +122,18 @@ sub invalid_item_type { > } > } > } else { >- my $biblioitems_with_invalid_itemtype = >- Koha::Biblioitems->search( { biblionumber => $ids, itemtype => { not_in => \@itemtypes } } ); >+ my $biblioitems_with_invalid_itemtype = Koha::Biblioitems->search( >+ { >+ biblionumber => $ids, >+ -and => [ itemtype => { not_in => \@itemtypes }, itemtype => { '!=' => '' } ] >+ } >+ ); > if ( $biblioitems_with_invalid_itemtype->count ) { > while ( my $biblioitem = $biblioitems_with_invalid_itemtype->next ) { > push @errors, __x( >- "Biblioitem with biblioitemnumber={biblioitemnumber} does not have a valid itemtype value", >+ "Biblioitem with biblioitemnumber={biblioitemnumber} does not have a valid itemtype value ({itemtype})", > biblioitemnumber => $biblioitem->biblioitemnumber, >+ itemtype => $biblioitem->itemtype, > ); > } > } >diff --git a/t/db_dependent/Koha/Database/DataInconsistency.t b/t/db_dependent/Koha/Database/DataInconsistency.t >index cd7d8e97958..d8767217230 100755 >--- a/t/db_dependent/Koha/Database/DataInconsistency.t >+++ b/t/db_dependent/Koha/Database/DataInconsistency.t >@@ -1,7 +1,7 @@ > use Modern::Perl; > > #use Test::NoWarnings; >-use Test::More tests => 2; >+use Test::More tests => 3; > > use Koha::Items; > use Koha::Database::DataInconsistency; >@@ -184,3 +184,83 @@ subtest 'no_item_type' => sub { > }; > $schema->storage->txn_rollback(); > }; >+ >+subtest 'invalid_item_type' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin(); >+ >+ my $biblio_ok = $builder->build_sample_biblio; >+ my $item_ok = $builder->build_sample_item( { biblionumber => $biblio_ok->biblionumber } ); >+ my $biblio_ko = $builder->build_sample_biblio; >+ my $item_ko = $builder->build_sample_item( { biblionumber => $biblio_ko->biblionumber } ); >+ >+ my $biblios = Koha::Biblios->search( { biblionumber => [ $biblio_ok->biblionumber, $biblio_ko->biblionumber ] } ); >+ >+ my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); >+ my $deleted_itemtype = $itemtype->itemtype; >+ $itemtype->delete; >+ >+ subtest 'item-level_itypes = 1' => sub { >+ plan tests => 2; >+ t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); >+ subtest 'ok' => sub { >+ plan tests => 1; >+ my @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ is_deeply( \@errors, [] ); >+ }; >+ subtest 'itype is invalid' => sub { >+ plan tests => 2; >+ $item_ko->set( { itype => $deleted_itemtype } ); >+ Koha::Object::store($item_ko); # Do not call Koha::Item->store, it will set itype >+ >+ my @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ is_deeply( >+ \@errors, >+ [ >+ sprintf "Item with itemnumber=%s, biblionumber=%s does not have a valid itype value (%s)", >+ $item_ko->itemnumber, $item_ko->biblionumber, $item_ko->itype >+ ] >+ ); >+ >+ $item_ko->set( { itype => '' } ); >+ Koha::Object::store($item_ko); # Do not call Koha::Item->store, it will set itype >+ @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ >+ # Does not alert here, it's caught already in no_item_type >+ is_deeply( \@errors, [] ); >+ }; >+ }; >+ >+ subtest 'item-level_itypes = 0' => sub { >+ plan tests => 2; >+ t::lib::Mocks::mock_preference( 'item-level_itypes', 0 ); >+ subtest 'ok' => sub { >+ plan tests => 1; >+ my @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ is_deeply( \@errors, [] ); >+ }; >+ subtest 'itemtype is invalid' => sub { >+ plan tests => 2; >+ $biblio_ko->biblioitem->set( { itemtype => $deleted_itemtype } )->store; >+ >+ my @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ is_deeply( >+ \@errors, >+ [ >+ sprintf "Biblioitem with biblioitemnumber=%s does not have a valid itemtype value (%s)", >+ $biblio_ko->biblioitem->biblioitemnumber, $biblio_ko->biblioitem->itemtype >+ ] >+ ); >+ >+ $biblio_ko->biblioitem->set( { itemtype => ' ' } )->store; >+ @errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); >+ >+ # Does not alert here, it's caught already in no_item_type >+ is_deeply( \@errors, [] ); >+ }; >+ }; >+ >+ $schema->storage->txn_rollback(); >+}; >-- >2.34.1
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 40777
:
187526
|
187527
|
187528
|
188222
|
188223
| 188224 |
188225
|
188226
|
188227
|
189598