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/;
28 use t
::lib
::TestBuilder
;
30 use_ok
('C4::Ratings');
32 my $schema = Koha
::Database
->schema;
33 $schema->storage->txn_begin;
34 my $builder = t
::lib
::TestBuilder
->new;
35 my $dbh = C4
::Context
->dbh;
36 $dbh->{RaiseError
} = 1;
38 my $library = $builder->build({
42 my ($biblionumber) = AddBiblio
( MARC
::Record
->new, '' );
44 my @categories = C4
::Category
->all;
45 my $categorycode = $categories[0]->categorycode;
46 my $branchcode = $library->{branchcode
};
49 cardnumber
=> '123456',
52 categorycode
=> $categorycode,
53 branchcode
=> $branchcode,
55 dateexpiry
=> '9999-12-31',
60 cardnumber
=> '345678',
63 categorycode
=> $categorycode,
64 branchcode
=> $branchcode,
66 dateexpiry
=> '9999-12-31',
70 my $borrowernumber1 = AddMember
(%john_doe);
71 my $borrowernumber2 = AddMember
(%jane_doe);
73 my $rating1 = AddRating
( $biblionumber, $borrowernumber1, 3 );
74 my $rating2 = AddRating
( $biblionumber, $borrowernumber2, 4 );
75 my $rating3 = ModRating
( $biblionumber, $borrowernumber1, 5 );
76 my $rating4 = GetRating
( $biblionumber, $borrowernumber2 );
77 my $rating5 = GetRating
( $biblionumber );
79 ok
( defined $rating1, 'add a rating' );
80 ok
( defined $rating2, 'add another rating' );
81 ok
( defined $rating3, 'update a rating' );
82 ok
( defined $rating4, 'get a rating, with borrowernumber' );
84 ok
( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
85 ok
( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" );
86 ok
( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" );
87 ok
( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
89 my $rating_1 = GetRating
( $biblionumber );
90 my $rating_1_1 = GetRating
( $biblionumber, $borrowernumber1 );
94 rating_avg_int
=> 4.5,
97 rating_value
=> undef,
99 'GetRating should return total, avg_int and avg if biblionumber is given'
104 rating_avg_int
=> 4.5,
109 'GetRating should return total, avg_int, avg and value if biblionumber is given'
112 my $rating6 = DelRating
( $biblionumber, $borrowernumber1 );
113 my $rating7 = DelRating
( $biblionumber, $borrowernumber2 );
115 ok
( defined $rating6, 'delete a rating' );
116 ok
( defined $rating7, 'delete another rating' );
118 is
( GetRating
( $biblionumber, $borrowernumber1 ),
119 undef, 'GetRating should return undef if no rating exist' );