From 5410802590e0d2d4d4d3140098d79a672ea5d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= Date: Tue, 9 Nov 2021 15:40:22 +0100 Subject: [PATCH] Bug 14783: (QA follow-up) Add unit tests. This commit adds unit tests for Bug 14783. Signed-off-by: Nick Clemens --- t/db_dependent/Hold.t | 52 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index 73007c18a0..1cfd5bdeca 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -29,7 +29,7 @@ use Koha::Item; use Koha::DateUtils qw( dt_from_string ); use t::lib::TestBuilder; -use Test::More tests => 35; +use Test::More tests => 36; use Test::Exception; use Test::Warn; @@ -386,3 +386,53 @@ subtest 'suspend() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'can_change_branch_opac() tests' => sub { + + plan tests => 8; + + $schema->storage->txn_begin; + + my $hold = $builder->build_object( + { class => 'Koha::Holds', + value => { found => undef, suspend => 0, suspend_until => undef, waitingdate => undef } + } + ); + + t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', '' ); + $hold->found(undef); + is( $hold->can_change_branch_opac, 0, "Pending hold pickup can't be changed (No change allowed)" ); + + $hold->found('T'); + is( $hold->can_change_branch_opac, 0, "In transit hold pickup can't be changed (No change allowed)" ); + + $hold->found('W'); + is( $hold->can_change_branch_opac, 0, "Waiting hold pickup can't be changed (No change allowed)" ); + + $hold->found(undef); + $dt = dt_from_string(); + + $hold->suspend_hold( $dt ); + is( $hold->can_change_branch_opac, 0, "Suspended hold pickup can't be changed (No change allowed)" ); + $hold->resume(); + + t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', 'pending,intransit,suspended' ); + $hold->found(undef); + is( $hold->can_change_branch_opac, 1, "Pending hold pickup can be changed (pending,intransit,suspended allowed)" ); + + $hold->found('T'); + is( $hold->can_change_branch_opac, 1, "In transit hold pickup can be changed (pending,intransit,suspended allowed)" ); + + $hold->found('W'); + is( $hold->can_change_branch_opac, 0, "Waiting hold pickup can't be changed (pending,intransit,suspended allowed)" ); + + $hold->found(undef); + $dt = dt_from_string(); + $hold->suspend_hold( $dt ); + is( $hold->can_change_branch_opac, 1, "Suspended hold pickup can be changed (pending,intransit,suspended allowed)" ); + $hold->resume(); + + + $schema->storage->txn_rollback; + +}; -- 2.30.2