From 1ae7206f732c96c4a3f686eefcb22f75534dfc77 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 20 Jul 2023 06:04:46 +0000 Subject: [PATCH] Bug 33608: (QA follow-up) Restore older gt zero tests Content-Type: text/plain; charset=utf-8 See the Bugzilla report. I have been asked to restore the former tests although I definitely think that they are wrong. Will address that on bug 34308 separately. This currently has the side-effect of negative lost values being interpreted as 'found'. (Do not use negative lost values!) The added subtest still reflects that now. Added a few TODOs. Test plan: [1] Prove t/db_dependent/Koha/Items.t Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Item.pm | 21 ++++++++++++++++----- t/db_dependent/Koha/Items.t | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 59dd937f4c..32310b144c 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -131,8 +131,9 @@ sub store { $self->cn_sort($cn_sort); } - if( $self->itemlost ) { - $self->_add_statistic('item_lost'); # should be quite rare when adding item + # should be quite rare when adding item + if ( $self->itemlost && $self->itemlost > 0 ) { # TODO BZ34308 + $self->_add_statistic('item_lost'); } } else { # ModItem @@ -190,10 +191,20 @@ sub store { $self->permanent_location( $self->location ); } - if( exists $updated_columns{itemlost} && !$updated_columns{itemlost} && $pre_mod_item->itemlost ) { # item found again - $self->_set_found_trigger($pre_mod_item); # reverse any list item charges if necessary + # TODO BZ 34308 (gt zero checks) + if ( exists $updated_columns{itemlost} + && ( !$updated_columns{itemlost} || $updated_columns{itemlost} <= 0 ) + && ( $pre_mod_item->itemlost && $pre_mod_item->itemlost > 0 ) ) + { + # item found + # reverse any list item charges if necessary + $self->_set_found_trigger($pre_mod_item); $self->_add_statistic('item_found'); - } elsif( exists $updated_columns{itemlost} && $updated_columns{itemlost} && !$pre_mod_item->itemlost ) { # item lost + } elsif ( exists $updated_columns{itemlost} + && ( $updated_columns{itemlost} && $updated_columns{itemlost} > 0 ) + && ( !$pre_mod_item->itemlost || $pre_mod_item->itemlost <= 0 ) ) + { + # item lost $self->_add_statistic('item_lost'); } } diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 5a51592e17..26f81dd7d4 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -33,6 +33,7 @@ use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); +use Koha::Statistics; use t::lib::TestBuilder; use t::lib::Mocks; @@ -68,7 +69,7 @@ my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber ); is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); subtest 'store' => sub { - plan tests => 7; + plan tests => 8; my $biblio = $builder->build_sample_biblio; my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); @@ -1363,6 +1364,22 @@ subtest 'store' => sub { "Item modification logged" ); }; + + subtest 'itemlost / statistics' => sub { # TODO BZ 34308 (gt zero checks) + plan tests => 5; + + my $item = $builder->build_sample_item; + $item->itemlost(-1)->store; # weird value; >0 test not triggered ? + is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 0, 'No statistics added' ); + $item->itemlost(1)->store; + is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 1, 'statistics added' ); + $item->itemlost(2)->store; + is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 1, 'No statistics added, already lost' ); + $item->itemlost(-1)->store; # weird value; <=0 test triggered ? + is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 2, 'statistics added' ); + $item->itemlost(-2)->store; # weird value, but no status change + is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 2, 'No statistics added, already *found*' ); + }; }; subtest 'get_transfer' => sub { -- 2.30.2