From 23cfdf97e379255139a6a3a73d74ee60f36aa5a2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 20 Jul 2023 20:16:39 -0300 Subject: [PATCH] Bug 34333: Add Koha::Hold->cancellation_requested This patch adds a helper method for telling if a hold has cancellation requests. To be used for embedding such information. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Hold.t => SUCCESS: Tests pass, the new method is covered by tests. 3. Sign off :-D Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/Hold.pm | 14 ++++++++++++++ t/db_dependent/Koha/Hold.t | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index f275530d97..2775e59184 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -645,6 +645,20 @@ sub cancellation_requests { return Koha::Hold::CancellationRequests->search( { hold_id => $self->id } ); } +=head3 cancellation_requested + + if ( $hold->cancellation_requested ) { ... } + +Returns true if a cancellation request has been placed for the hold. + +=cut + +sub cancellation_requested { + my ($self) = @_; + + return Koha::Hold::CancellationRequests->search( { hold_id => $self->id } )->count > 0; +} + =head3 cancel my $cancel_hold = $hold->cancel( diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index cc90dafb89..50d6ffdbe9 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -728,9 +728,9 @@ subtest 'suspend_hold() and resume() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { +subtest 'cancellation_requests(), add_cancellation_request() and cancellation_requested() tests' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; @@ -739,6 +739,7 @@ subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { my $hold = $builder->build_object( { class => 'Koha::Holds', } ); is( $hold->cancellation_requests->count, 0 ); + ok( !$hold->cancellation_requested ); # Add two cancellation requests my $request_1 = $hold->add_cancellation_request; @@ -756,6 +757,7 @@ subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { is( $request_2->creation_date, $creation_date, 'Passed creation_date set' ); is( $hold->cancellation_requests->count, 2 ); + ok( $hold->cancellation_requested ); $schema->storage->txn_rollback; }; -- 2.39.5