From 46a62fa15acef5abed0f19051d6924243128bf28 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Wed, 3 Jul 2019 00:11:56 +0000 Subject: [PATCH] Bug 1985: (follow-up) Fix Reviews.t logic Read the tests to make sure they make sense. Before the patch is applied, they don't. $nb_of_approved_reviews + 2 did not make sense, because the three reviews added were not approved. search->count counts everything, so the use of approved+3 didn't make sense. Rather than duplicate the search->count test, changed the first one to reflect that the added reviews were all unapproved. Before applying patch, prove fails. After applying patch, prove passes. --- t/db_dependent/Koha/Reviews.t | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Koha/Reviews.t b/t/db_dependent/Koha/Reviews.t index 6dd859498b..edf03a52bb 100644 --- a/t/db_dependent/Koha/Reviews.t +++ b/t/db_dependent/Koha/Reviews.t @@ -43,6 +43,7 @@ my $biblio_1 = $builder->build({ source => 'Biblio' }); my $biblio_2 = $builder->build({ source => 'Biblio' }); my $nb_of_messages = Koha::Notice::Messages->search->count; my $nb_of_reviews = Koha::Reviews->search->count; +my $nb_of_unapproved_reviews = Koha::Reviews->search({ approved => 0 })->count; my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count; my $new_review_1_1 = Koha::Review->new({ borrowernumber => $patron_1->borrowernumber, @@ -61,7 +62,8 @@ my $new_review_2_1 = Koha::Review->new({ })->store; like( $new_review_1_1->reviewid, qr|^\d+$|, 'Adding a new review should have set the reviewid'); -is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' ); +is( Koha::Reviews->search({ approved => 0 })->count, $nb_of_unapproved_reviews + 3, + 'The 3 unapproved reviews should have been added' ); is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be new approved reviews' ); $new_review_1_1->approve; @@ -80,8 +82,9 @@ subtest 'search_limited' => sub { Koha::Library::Group->new({ parent_id => $group_1->id, branchcode => $patron_1->branchcode })->store(); Koha::Library::Group->new({ parent_id => $group_2->id, branchcode => $patron_2->branchcode })->store(); t::lib::Mocks::mock_userenv( { patron => $patron_1 } ); - is( Koha::Reviews->search->count, $nb_of_approved_reviews + 3, 'Koha::Reviews->search should return all reviews' ); - is( Koha::Reviews->search_limited->count, $nb_of_approved_reviews + 2, 'Koha::Reviews->search_limited should return reviews depending on patron permissions' ); + is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'Koha::Reviews->search should return all reviews' ); + is( Koha::Reviews->search_limited->count, 2, + 'Koha::Reviews->search_limited should return reviews depending on patron permissions' ); }; $retrieved_review_1_1->delete; -- 2.11.0