From 9c24e3eff5390939e1f8542c281c5c37f0f9e894 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 | 16 +++++++--------- t/db_dependent/Koha/Old/Checkouts.t | 6 ++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Koha/Checkout.t b/t/db_dependent/Koha/Checkout.t index 7459cbcbf8a..1b4eb1eb428 100755 --- a/t/db_dependent/Koha/Checkout.t +++ b/t/db_dependent/Koha/Checkout.t @@ -54,26 +54,24 @@ subtest 'renewals() tests' => sub { plan tests => 2; $schema->storage->txn_begin; - my $checkout = $builder->build_object( - { - class => 'Koha::Checkouts' - } - ); + my $checkout = $builder->build_object( { class => 'Koha::Checkouts' } ); 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" ); + is( ref( $checkout->renewals ), 'Koha::Checkouts::Renewals', 'Object set type is correct' ); + is( $checkout->renewals->count, 2, "Count of renewals is correct" ); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Koha/Old/Checkouts.t b/t/db_dependent/Koha/Old/Checkouts.t index 233ccc39631..e3b65183c9e 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.45.2