From 2d5b3cb04b4ef60f01109aa1dcd1da1e3ef17733 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 15 May 2024 16:12:31 -0300 Subject: [PATCH] Bug 36873: Unit tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Objects.t | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index a5444fc2a8..9f4a6f0323 100755 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -29,6 +29,7 @@ use C4::Context; use Koha::Authority::Types; use Koha::Cities; use Koha::Biblios; +use Koha::Items; use Koha::Patron::Category; use Koha::Patron::Categories; use Koha::Patrons; @@ -1286,13 +1287,13 @@ subtest 'empty() tests' => sub { subtest 'delete() tests' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; # Make sure no cities warnings_are { Koha::Cities->delete }[], - "No warnings, no Koha::City->delete called as it doesn't exist"; + "No warnings, no Koha::City->delete called as it doesn't exist"; # Mock Koha::City my $mocked_city = Test::MockModule->new('Koha::City'); @@ -1311,7 +1312,26 @@ subtest 'delete() tests' => sub { my $cities = Koha::Cities->search; $cities->next; warnings_are { $cities->delete } - [ "delete called!", "delete called!" ], + [ "delete called!", "delete called!" ], + "No warnings, no Koha::City->delete called as it doesn't exist"; + + my $item_id_1 = $builder->build_sample_item()->id; + my $item_id_2 = $builder->build_sample_item()->id; + + # Mock Koha::City + my $mocked_item = Test::MockModule->new('Koha::Item'); + $mocked_item->mock( + 'delete', + sub { + my ( $self, $params ) = @_; + warn ref($self); + warn $params->{skip_record_index}; + } + ); + my $items = Koha::Items->search( { itemnumber => [ $item_id_1, $item_id_2 ] } ); + + warning_is { $items->delete( { skip_record_index => 1 } ) } + [ "Koha::Item", "1", "Koha::Item", "1" ], "No warnings, no Koha::City->delete called as it doesn't exist"; $schema->storage->txn_rollback; -- 2.39.5