From 8b2fd003f707e9d01ff2af567ef806575a804ca7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 1 Aug 2024 18:00:57 +0000 Subject: [PATCH] Bug 37550: Unit test for CheckItemPreSave --- t/db_dependent/Items.t | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index f6451c6f4e5..48315d6288b 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -20,7 +20,7 @@ use Data::Dumper; use MARC::Record; use C4::Items - qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ModDateLastSeen CartToShelf ); + qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ModDateLastSeen CartToShelf CheckItemPreSave ); use C4::Biblio qw( GetMarcFromKohaField AddBiblio ); use C4::Circulation qw( AddIssue ); use Koha::BackgroundJobs; @@ -36,7 +36,7 @@ use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 13; +use Test::More tests => 14; use Test::Warn; @@ -129,6 +129,28 @@ subtest 'General Add, Get and Del tests' => sub { $schema->storage->txn_rollback; }; +subtest 'CheckItemPreSave tests' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $builder = t::lib::TestBuilder->new; + my $item = Koha::Items->find( { barcode => 'SPAGHETTI' } ); + $item = $builder->build_sample_item( { barcode => "SPAGHETTI" } ) unless $item; + + my $check_item = $item->unblessed; + delete $check_item->{itemnumber}; + $check_item->{barcode} = " SPAGHETTI"; + + my %errors = CheckItemPreSave($check_item); + is_deeply( + \%errors, { duplicate_barcode => " SPAGHETTI" }, + "We get a duplicate item error for barcode even if whitespace" + ); + + $schema->storage->txn_rollback; +}; + subtest 'ModItemTransfer tests' => sub { plan tests => 8; -- 2.39.2