From 7ef157b51f5a17b0fa153b61e4f480d435f124ad Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Aug 2020 14:32:43 +0200 Subject: [PATCH] Bug 24147: Don't assume search_related will return ordered values This test is failing randomly because it assume the order is always the same. But it's not. Note: Koha::Objects->search_related is never used , last use removed from commit 9aa724cdf29a57bc91e42b240b5bcd19e3814ada Bug 19599: Speed anonymise_issue_history up We should keep it however IMO Signed-off-by: Kyle M Hall --- t/db_dependent/Koha/Objects.t | 51 ++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 5c35546667..76e0393485 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -139,21 +139,48 @@ subtest 'find' => sub { }; subtest 'search_related' => sub { - plan tests => 8; + plan tests => 6; my $builder = t::lib::TestBuilder->new; my $patron_1 = $builder->build( { source => 'Borrower' } ); my $patron_2 = $builder->build( { source => 'Borrower' } ); - my $libraries = Koha::Patrons->search( { -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] } } )->search_related('branchcode'); - is( ref( $libraries ), 'Koha::Libraries', 'Koha::Objects->search_related should return an instanciated Koha::Objects-based object' ); - is( $libraries->count, 2, 'Koha::Objects->search_related should work as expected' ); - is( $libraries->next->branchcode, $patron_1->{branchcode}, 'Koha::Objects->search_related should work as expected' ); - is( $libraries->next->branchcode, $patron_2->{branchcode}, 'Koha::Objects->search_related should work as expected' ); - - my @libraries = Koha::Patrons->search( { -or => { borrowernumber => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] } } )->search_related('branchcode'); - is( ref( $libraries[0] ), 'Koha::Library', 'Koha::Objects->search_related should return a list of Koha::Object-based objects' ); - is( scalar(@libraries), 2, 'Koha::Objects->search_related should work as expected' ); - is( $libraries[0]->branchcode, $patron_1->{branchcode}, 'Koha::Objects->search_related should work as expected' ); - is( $libraries[1]->branchcode, $patron_2->{branchcode}, 'Koha::Objects->search_related should work as expected' ); + my $libraries = Koha::Patrons->search( + { + -or => { + borrowernumber => + [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] + } + } + )->search_related('branchcode'); + is( ref($libraries), 'Koha::Libraries', + 'Koha::Objects->search_related should return an instanciated Koha::Objects-based object' + ); + is( $libraries->count, 2, + 'Koha::Objects->search_related should work as expected' ); + ok( eq_array( + [ $libraries->get_column('branchcode') ], + [ $patron_1->{branchcode}, $patron_2->{branchcode} ] ), + 'Koha::Objects->search_related should work as expected' + ); + + my @libraries = Koha::Patrons->search( + { + -or => { + borrowernumber => + [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber} ] + } + } + )->search_related('branchcode'); + is( + ref( $libraries[0] ), 'Koha::Library', + 'Koha::Objects->search_related should return a list of Koha::Object-based objects' + ); + is( scalar(@libraries), 2, + 'Koha::Objects->search_related should work as expected' ); + ok( eq_array( + [ map { $_->branchcode } @libraries ], + [ $patron_1->{branchcode}, $patron_2->{branchcode} ] ), + 'Koha::Objects->search_related should work as expected' + ); }; subtest 'single' => sub { -- 2.24.1 (Apple Git-126)