3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test
::More tests
=> 14;
22 use C4
::Biblio qw
/AddBiblio/;
27 use_ok
('C4::Ratings');
29 my $dbh = C4
::Context
->dbh;
30 $dbh->{RaiseError
} = 1;
31 $dbh->{AutoCommit
} = 0;
33 my ($biblionumber) = AddBiblio
( MARC
::Record
->new, '' );
35 my @categories = C4
::Category
->all;
36 my $categorycode = $categories[0]->categorycode;
37 my $branchcode = 'CPL';
40 cardnumber
=> '123456',
43 categorycode
=> $categorycode,
44 branchcode
=> $branchcode,
46 dateexpiry
=> '9999-12-31',
51 cardnumber
=> '345678',
54 categorycode
=> $categorycode,
55 branchcode
=> $branchcode,
57 dateexpiry
=> '9999-12-31',
61 my $borrowernumber1 = AddMember
(%john_doe);
62 my $borrowernumber2 = AddMember
(%jane_doe);
64 my $rating1 = AddRating
( $biblionumber, $borrowernumber1, 3 );
65 my $rating2 = AddRating
( $biblionumber, $borrowernumber2, 4 );
66 my $rating3 = ModRating
( $biblionumber, $borrowernumber1, 5 );
67 my $rating4 = GetRating
( $biblionumber, $borrowernumber2 );
68 my $rating5 = GetRating
( $biblionumber );
70 ok
( defined $rating1, 'add a rating' );
71 ok
( defined $rating2, 'add another rating' );
72 ok
( defined $rating3, 'update a rating' );
73 ok
( defined $rating4, 'get a rating, with borrowernumber' );
75 ok
( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
76 ok
( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" );
77 ok
( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" );
78 ok
( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
80 my $rating_1 = GetRating
( $biblionumber );
81 my $rating_1_1 = GetRating
( $biblionumber, $borrowernumber1 );
85 rating_avg_int
=> 4.5,
88 rating_value
=> undef,
90 'GetRating should return total, avg_int and avg if biblionumber is given'
95 rating_avg_int
=> 4.5,
100 'GetRating should return total, avg_int, avg and value if biblionumber is given'
103 my $rating6 = DelRating
( $biblionumber, $borrowernumber1 );
104 my $rating7 = DelRating
( $biblionumber, $borrowernumber2 );
106 ok
( defined $rating6, 'delete a rating' );
107 ok
( defined $rating7, 'delete another rating' );
109 is
( GetRating
( $biblionumber, $borrowernumber1 ),
110 undef, 'GetRating should return undef if no rating exist' );