From 335bf041f2d35962c0007f4fc7d2cb0efb02c3d8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 8 Jul 2024 17:16:19 +0100 Subject: [PATCH] Bug 33284: (follow-up) Fix unit tests We have a case here where we have checkout_id pointing at issues and old_issues tables. We need to trick TestBuilder to NOT automagically build our related checkout.. This patch passes 'undef' to the foreign key field and then sets it after the fact to the related Old::Checkouts objects we've already built above. This patch should prevent the random failures we were seeing before --- t/db_dependent/Koha/Checkout.t | 6 ++++-- t/db_dependent/Koha/Old/Checkout.t | 6 ++++-- t/db_dependent/Koha/Old/Checkouts.t | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/Checkout.t b/t/db_dependent/Koha/Checkout.t index 4693863adfc..0321906d30f 100755 --- a/t/db_dependent/Koha/Checkout.t +++ b/t/db_dependent/Koha/Checkout.t @@ -119,15 +119,17 @@ subtest 'renewals() tests' => sub { my $renewal1 = $builder->build_object( { class => 'Koha::Checkouts::Renewals', - value => { checkout_id => $checkout->issue_id } + value => { checkout_id => undef } } ); + $renewal1->checkout_id( $checkout->issue_id )->store(); my $renewal2 = $builder->build_object( { class => 'Koha::Checkouts::Renewals', - value => { checkout_id => $checkout->issue_id } + value => { checkout_id => undef } } ); + $renewal2->checkout_id( $checkout->issue_id )->store(); is( ref( $checkout->renewals ), 'Koha::Checkouts::Renewals', 'Object set type is correct' ); is( $checkout->renewals->count, 2, "Count of renewals is correct" ); diff --git a/t/db_dependent/Koha/Old/Checkout.t b/t/db_dependent/Koha/Old/Checkout.t index 1ccaebac317..e419015a9e0 100755 --- a/t/db_dependent/Koha/Old/Checkout.t +++ b/t/db_dependent/Koha/Old/Checkout.t @@ -54,21 +54,23 @@ subtest 'anonymize() tests' => sub { { class => 'Koha::Checkouts::Renewals', value => { - checkout_id => $checkout_2->id, + checkout_id => undef, interface => 'opac', renewer_id => $patron->id } } ); + $renewal_1->checkout_id( $checkout_2->id )->store(); my $renewal_2 = $builder->build_object( { class => 'Koha::Checkouts::Renewals', value => { - checkout_id => $checkout_2->id, + checkout_id => undef, interface => 'intranet' } } ); + $renewal_2->checkout_id( $checkout_2->id )->store(); is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' ); diff --git a/t/db_dependent/Koha/Old/Checkouts.t b/t/db_dependent/Koha/Old/Checkouts.t index d4bdaac5984..7c7dca616bb 100755 --- a/t/db_dependent/Koha/Old/Checkouts.t +++ b/t/db_dependent/Koha/Old/Checkouts.t @@ -93,21 +93,23 @@ subtest 'anonymize() tests' => sub { { class => 'Koha::Checkouts::Renewals', value => { - checkout_id => $checkout_4->id, + checkout_id => undef, interface => 'opac', renewer_id => $patron->id } } ); + $renewal_1->checkout_id( $checkout_4->id )->store(); my $renewal_2 = $builder->build_object( { class => 'Koha::Checkouts::Renewals', value => { - checkout_id => $checkout_4->id, + checkout_id => undef, interface => 'intranet' } } ); + $renewal_2->checkout_id( $checkout_4->id )->store(); is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' ); is( $checkout_4->renewals->count, 2, 'Checkout 4 has 2 renewals' ); -- 2.48.1