From da685564cb50ba1fd6f5d6902562d16e7aae69ed 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 --- Koha/Item.pm | 14 +++++++------- t/db_dependent/Koha/Items.t | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 84ab3c6c38..5c09b103ea 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -131,7 +131,7 @@ sub store { } # should be quite rare when adding item - if ( $self->itemlost ) { + if ( $self->itemlost && $self->itemlost > 0 ) { # TODO BZ34308 $self->_add_statistic('item_lost'); } @@ -190,18 +190,18 @@ sub store { $self->permanent_location( $self->location ); } + # TODO BZ 34308 (gt zero checks) if ( exists $updated_columns{itemlost} - && !$updated_columns{itemlost} - && $pre_mod_item->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 ) + } 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 8464ab2ce5..013439d0ae 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