From d2d980b5d3c4d24d9ec61021afcd4f144f8ccf1e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Jun 2020 13:51:00 +0100 Subject: [PATCH] Bug 23092: Add unit tests Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Item/Transfers.t | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item/Transfers.t b/t/db_dependent/Koha/Item/Transfers.t index b49f78091a..28e070671f 100644 --- a/t/db_dependent/Koha/Item/Transfers.t +++ b/t/db_dependent/Koha/Item/Transfers.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Koha::Item::Transfer; use Koha::Item::Transfers; @@ -27,6 +27,7 @@ use Koha::Database; use Koha::DateUtils; use t::lib::TestBuilder; +use t::lib::Dates; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -66,3 +67,43 @@ is( $retrieved_transfer_1->itemnumber, $new_transfer_1->itemnumber, 'Find a tran $schema->storage->txn_rollback; +subtest 'daterequested tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + my $library_from = $builder->build( { source => 'Branch' } ); + my $library_to = $builder->build( { source => 'Branch' } ); + my $item = $builder->build( + { + source => 'Item', + value => { + holding_branch => $library_from->{branchcode}, + homebranch => $library_to->{branchcode} + } + } + ); + + my $now = dt_from_string; + my $transfer = Koha::Item::Transfer->new( + { + itemnumber => $item->{itemnumber}, + frombranch => $library_from->{branchcode}, + tobranch => $library_to->{branchcode} + } + )->store; + $transfer->discard_changes; + + ok( $transfer->daterequested, 'daterequested set on creation' ); + is( t::lib::Dates::compare( $transfer->daterequested, $now ), + 0, 'daterequested was set correctly' ); + + my $new_date = $now->clone->add( hours => 1 ); + $transfer->set({ datesent => $new_date })->store; + $transfer->discard_changes; + + is( t::lib::Dates::compare( $transfer->daterequested, $now ), + 0, 'daterequested is not updated when other fields are updated' ); + + $schema->storage->txn_rollback; +}; -- 2.20.1