diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 0ca4842e56..a7545bf5c9 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -142,21 +142,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), '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' ); - 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[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 {