Koha/t/db_dependent/Ratings.t
Jonathan Druart 6ee8dd3a59 Bug 15407: Koha::Patron::Categories - replace C4::Category->all
The C4::Category module contained only 1 method to return the patron
categories available for the logged in user.
The new method Koha::Patron::Categories->search_limited does exactly the
same thing (see tests) and must be used in place of it.

Test plan:
- Same prerequisite as before
For the following pages, you should not see patron categories limited to
other libraries.
- On the 'Item circulation alerts' admin page
  (admin/item_circulation_alerts.pl), modify the settings for check-in
  and checkout (NOTE: Should not we display all patron categories on
  this page? If yes, it must be done in another bug report to ease
  backporting it).
- Search for patrons in the admin (budget) and acquisition (order) module.
- On the patron home page (search form in the header)

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-09-08 13:29:03 +00:00

121 lines
3.5 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 14;
use C4::Biblio qw/AddBiblio/;
use C4::Members;
use C4::Context;
use Koha::Database;
use Koha::Patron::Categories;
use t::lib::TestBuilder;
use_ok('C4::Ratings');
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;
my $library = $builder->build({
source => 'Branch',
});
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
my @categories = Koha::Patron::Categories->search_limited;
my $categorycode = $categories[0]->categorycode;
my $branchcode = $library->{branchcode};
my %john_doe = (
cardnumber => '123456',
firstname => 'John',
surname => 'Doe',
categorycode => $categorycode,
branchcode => $branchcode,
dateofbirth => '',
dateexpiry => '9999-12-31',
userid => 'john.doe'
);
my %jane_doe = (
cardnumber => '345678',
firstname => 'Jane',
surname => 'Doe',
categorycode => $categorycode,
branchcode => $branchcode,
dateofbirth => '',
dateexpiry => '9999-12-31',
userid => 'jane.doe'
);
my $borrowernumber1 = AddMember(%john_doe);
my $borrowernumber2 = AddMember(%jane_doe);
my $rating1 = AddRating( $biblionumber, $borrowernumber1, 3 );
my $rating2 = AddRating( $biblionumber, $borrowernumber2, 4 );
my $rating3 = ModRating( $biblionumber, $borrowernumber1, 5 );
my $rating4 = GetRating( $biblionumber, $borrowernumber2 );
my $rating5 = GetRating( $biblionumber );
ok( defined $rating1, 'add a rating' );
ok( defined $rating2, 'add another rating' );
ok( defined $rating3, 'update a rating' );
ok( defined $rating4, 'get a rating, with borrowernumber' );
ok( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
ok( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" );
ok( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" );
ok( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
my $rating_1 = GetRating( $biblionumber );
my $rating_1_1 = GetRating( $biblionumber, $borrowernumber1 );
is_deeply(
$rating_1,
{
rating_avg_int => 4.5,
rating_total => 2,
rating_avg => 4,
rating_value => undef,
},
'GetRating should return total, avg_int and avg if biblionumber is given'
);
is_deeply(
$rating_1_1,
{
rating_avg_int => 4.5,
rating_total => 2,
rating_avg => 4,
rating_value => 5,
},
'GetRating should return total, avg_int, avg and value if biblionumber is given'
);
my $rating6 = DelRating( $biblionumber, $borrowernumber1 );
my $rating7 = DelRating( $biblionumber, $borrowernumber2 );
ok( defined $rating6, 'delete a rating' );
ok( defined $rating7, 'delete another rating' );
is( GetRating( $biblionumber, $borrowernumber1 ),
undef, 'GetRating should return undef if no rating exist' );
1;