3 # Copyright 2015 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test
::More tests
=> 7;
28 use t
::lib
::TestBuilder
;
30 my $schema = Koha
::Database
->new->schema;
31 $schema->storage->txn_begin;
33 my $builder = t
::lib
::TestBuilder
->new;
34 my $patron_1 = $builder->build({ source
=> 'Borrower' });
35 my $patron_2 = $builder->build({ source
=> 'Borrower' });
36 my $biblio_1 = $builder->build({ source
=> 'Biblio' });
37 my $biblio_2 = $builder->build({ source
=> 'Biblio' });
38 my $nb_of_reviews = Koha
::Reviews
->search->count;
39 my $nb_of_approved_reviews = Koha
::Reviews
->search({ approved
=> 1 })->count;
40 my $new_review_1_1 = Koha
::Review
->new({
41 borrowernumber
=> $patron_1->{borrowernumber
},
42 biblionumber
=> $biblio_1->{biblionumber
},
43 review
=> 'a kind review',
45 my $new_review_1_2 = Koha
::Review
->new({
46 borrowernumber
=> $patron_1->{borrowernumber
},
47 biblionumber
=> $biblio_2->{biblionumber
},
48 review
=> 'anoter kind review',
50 my $new_review_2_1 = Koha
::Review
->new({
51 borrowernumber
=> $patron_2->{borrowernumber
},
52 biblionumber
=> $biblio_1->{biblionumber
},
53 review
=> 'just anoter review',
56 like
( $new_review_1_1->reviewid, qr
|^\d
+$|, 'Adding a new review should have set the reviewid');
57 is
( Koha
::Reviews
->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' );
59 is
( Koha
::Reviews
->search({approved
=> 1})->count, $nb_of_approved_reviews, 'There should not be new approved reviews' );
60 $new_review_1_1->approve;
61 is
( Koha
::Reviews
->search({approved
=> 1})->count, $nb_of_approved_reviews + 1, 'There should be 1 new approved review' );
62 $new_review_1_1->unapprove;
63 is
( Koha
::Reviews
->search({approved
=> 1})->count, $nb_of_approved_reviews, 'There should not be any new approved review anymore' );
65 my $retrieved_review_1_1 = Koha
::Reviews
->find( $new_review_1_1->reviewid );
66 is
( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' );
68 $retrieved_review_1_1->delete;
69 is
( Koha
::Reviews
->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' );
71 $schema->storage->txn_rollback;