From 5af00a2816612274711de1e21e8cf98395073a4b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 5 May 2023 16:22:20 -0300 Subject: [PATCH] Bug 22440: (follow-up) Fix existing tests As we are introducing a FK for illrequests.biblio_id, TestBuilder is generating a linked biblio, and so tests expecting undef are failing. This fixes it by explicitly setting biblio_id => undef on creating the request. The patch also cleans the area a bit, removing a redundant and fragile test as well. --- t/db_dependent/Illrequests.t | 82 ++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t index 65c1bc6fa5d..8ee9da5ca03 100755 --- a/t/db_dependent/Illrequests.t +++ b/t/db_dependent/Illrequests.t @@ -191,63 +191,53 @@ subtest 'store borrowernumber change also updates holds' => sub { subtest 'Working with related objects' => sub { - plan tests => 7; + plan tests => 6; $schema->storage->txn_begin; - Koha::Illrequests->search->delete; - - my $patron = $builder->build({ source => 'Borrower' }); - my $illrq = $builder->build({ - source => 'Illrequest', - value => { borrowernumber => $patron->{borrowernumber} } - }); - my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); - - isa_ok($illrq_obj->patron, 'Koha::Patron', - "OK accessing related patron."); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $illrq = $builder->build_object( + { class => 'Koha::Illrequests', + value => { borrowernumber => $patron->id, biblio_id => undef } + } + ); - $builder->build({ - source => 'Illrequestattribute', - value => { illrequest_id => $illrq_obj->illrequest_id, type => 'X' } - }); - $builder->build({ - source => 'Illrequestattribute', - value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Y' } - }); - $builder->build({ - source => 'Illrequestattribute', - value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Z' } - }); + isa_ok( $illrq->patron, 'Koha::Patron', "OK accessing related patron." ); - is($illrq_obj->illrequestattributes->count, Koha::Illrequestattributes->search->count, - "Fetching expected number of Illrequestattributes for our request."); + $builder->build( + { source => 'Illrequestattribute', + value => { illrequest_id => $illrq->illrequest_id, type => 'X' } + } + ); + $builder->build( + { source => 'Illrequestattribute', + value => { illrequest_id => $illrq->illrequest_id, type => 'Y' } + } + ); + $builder->build( + { source => 'Illrequestattribute', + value => { illrequest_id => $illrq->illrequest_id, type => 'Z' } + } + ); - my $illrq1 = $builder->build({ source => 'Illrequest' }); - $builder->build({ - source => 'Illrequestattribute', - value => { illrequest_id => $illrq1->{illrequest_id}, type => 'X' } - }); + my $rs = Koha::Illrequestattributes->search( { illrequest_id => $illrq->id } ); - is($illrq_obj->illrequestattributes->count + 1, Koha::Illrequestattributes->search->count, - "Fetching expected number of Illrequestattributes for our request."); + is( $illrq->extended_attributes->count, + $rs->count, "Fetching expected number of Illrequestattributes for our request." ); - is($illrq_obj->biblio, undef, "->biblio returns undef if no biblio"); - my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); - my $req_bib = $builder->build_object({ - class => 'Koha::Illrequests', - value => { - biblio_id => $biblio->biblionumber + is( $illrq->biblio, undef, "->biblio returns undef if no biblio" ); + my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); + my $req_bib = $builder->build_object( + { class => 'Koha::Illrequests', + value => { biblio_id => $biblio->biblionumber } } - }); - isa_ok($req_bib->biblio, 'Koha::Biblio', "OK accessing related biblio"); + ); + isa_ok( $req_bib->biblio, 'Koha::Biblio', "OK accessing related biblio" ); - $illrq_obj->delete; - is(Koha::Illrequestattributes->search->count, 1, - "Correct number of illrequestattributes after delete."); + $illrq->delete; + is( $rs->count, 0, "Correct number of illrequestattributes after delete." ); - isa_ok(Koha::Patrons->find($patron->{borrowernumber}), 'Koha::Patron', - "Borrower was not deleted after illrq delete."); + isa_ok( Koha::Patrons->find( $patron->id ), 'Koha::Patron', "Borrower was not deleted after illrq delete." ); $schema->storage->txn_rollback; }; -- 2.40.1