View | Details | Raw Unified | Return to bug 12022
Collapse All | Expand All

(-)a/C4/Review.pm (-2 / +17 lines)
Lines 172-180 $offset position and the ($offset + $row_count) position. Link Here
172
172
173
sub getallreviews {
173
sub getallreviews {
174
    my ( $status, $offset, $row_count ) = @_;
174
    my ( $status, $offset, $row_count ) = @_;
175
    my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) );
175
    my @params;
176
    push( @params, $status );
177
178
    my $library_limit = C4::Context->IsSuperLibrarian() ? q{} : q{ AND borrowers.branchcode = ?};
179
    push( @params, C4::Context->userenv->{'branch'} ) if ( $library_limit && C4::Context->userenv );
180
181
    push( @params, $offset ? $offset : 0 );
182
    push( @params, $row_count ? $row_count : 20 );
183
176
    my $dbh    = C4::Context->dbh;
184
    my $dbh    = C4::Context->dbh;
177
    my $query  = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
185
    my $query  = qq{
186
        SELECT reviews.* FROM reviews
187
        LEFT JOIN borrowers USING ( borrowernumber )
188
        WHERE approved = ?
189
        $library_limit
190
        ORDER BY datereviewed DESC
191
        LIMIT ?, ?
192
    };
178
    my $sth    = $dbh->prepare($query);
193
    my $sth    = $dbh->prepare($query);
179
    $sth->execute(@params);
194
    $sth->execute(@params);
180
    return $sth->fetchall_arrayref( {} );
195
    return $sth->fetchall_arrayref( {} );
(-)a/t/db_dependent/Review.t (-2 / +39 lines)
Lines 18-28 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 117;
21
use Test::More tests => 118;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Time::Piece;
25
use Time::Piece;
26
use Test::MockModule;
26
27
27
BEGIN {
28
BEGIN {
28
    use_ok('C4::Biblio');
29
    use_ok('C4::Biblio');
Lines 58-63 my $builder = t::lib::TestBuilder->new; Link Here
58
# ---------- Some borrowers for testing -------------------
59
# ---------- Some borrowers for testing -------------------
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60
my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
61
my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
62
my $branchcode2   = $builder->build({ source => 'Branch' })->{ branchcode };
63
64
my $context = new Test::MockModule('C4::Context');
65
$context->mock(
66
    'userenv',
67
    sub {
68
        return {
69
            flags  => 0,
70
            id     => 'my_userid',
71
            branch => $branchcode,
72
        };
73
    }
74
);
61
75
62
my $b1 = Koha::Patron->new(
76
my $b1 = Koha::Patron->new(
63
    {   surname      => 'Borrower 1',
77
    {   surname      => 'Borrower 1',
Lines 246-251 $reviews = getallreviews( $status, $offset, $row_count ); Link Here
246
is( @$reviews, 1, 'There is only 1 Review here' );
260
is( @$reviews, 1, 'There is only 1 Review here' );
247
is_deeply( $reviews->[0], $review2, 'We have only Review2' );
261
is_deeply( $reviews->[0], $review2, 'We have only Review2' );
248
262
263
$context->mock(
264
    'userenv',
265
    sub {
266
        return {
267
            flags  => 0,
268
            id     => 'my_userid',
269
            branch => $branchcode2,
270
        };
271
    }
272
);
273
my $no_reviews = getallreviews($status);
274
is( @{$no_reviews}, 0, "No reviews returned for unused branchcode" );
275
$context->mock(
276
    'userenv',
277
    sub {
278
        return {
279
            flags  => 0,
280
            id     => 'my_userid',
281
            branch => $branchcode,
282
        };
283
    }
284
);
285
286
249
# ---------- Testing numberofreviews ----------------------
287
# ---------- Testing numberofreviews ----------------------
250
$status = 0;
288
$status = 0;
251
$count  = numberofreviews($status);
289
$count  = numberofreviews($status);
252
- 

Return to bug 12022