From 1af30926423cde9f09e6b4bc5df21ca781611161 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 30 Aug 2023 13:46:17 +0000 Subject: [PATCH] Bug 34656: Unit test Signed-off-by: Emily Lamancusa Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Tomas Cohen Arazi (cherry picked from commit aff84104127552fe5f5e4394f84b501dafcbc497) Signed-off-by: Fridolin Somers --- t/db_dependent/Items.t | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 8dec62ca20..be63a071b8 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -19,9 +19,10 @@ use Modern::Perl; use Data::Dumper; use MARC::Record; -use C4::Items qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ModDateLastSeen ); +use C4::Items qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ModDateLastSeen CartToShelf ); use C4::Biblio qw( GetMarcFromKohaField AddBiblio ); use C4::Circulation qw( AddIssue ); +use Koha::BackgroundJobs; use Koha::Items; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -34,7 +35,7 @@ use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 12; +use Test::More tests => 13; use Test::Warn; @@ -972,3 +973,34 @@ subtest 'ModDateLastSeen' => sub { is( $item->itemlost, 0, "Item no longer lost when no parameter is passed"); is( $logs_after, $logs_before + 1, "ModDateLastSeen logs if item was lost and now found"); }; + +subtest 'CartToShelf test' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + my $dbh = C4::Context->dbh; + my $builder = t::lib::TestBuilder->new; + + my $item = $builder->build_sample_item(); + + $item->permanent_location('BANANA')->location('CART')->store(); + + CartToShelf( $item->id ); + + $item->discard_changes; + + is( $item->location, 'BANANA', 'Item is correctly returned to permanent location'); + + + my $mock_RTHQ = Test::MockModule->new("Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue"); + $mock_RTHQ->mock( enqueue => sub { warn "RTHQ" } ); + t::lib::Mocks::mock_preference('RealTimeHoldsQueue', '1'); + + $item->location('CART')->store({ skip_holds_queue => 1 }); + warnings_are{ + CartToShelf( $item->id ); + } [], 'No RTHQ update triggered by CartToShelf'; + + $schema->storage->txn_rollback; + +}; -- 2.20.1