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

(-)a/C4/Review.pm (-32 / +27 lines)
Lines 25-36 use C4::Context; Link Here
25
use vars qw($VERSION @ISA @EXPORT);
25
use vars qw($VERSION @ISA @EXPORT);
26
26
27
BEGIN {
27
BEGIN {
28
  # set the version for version checking
28
    # set the version for version checking
29
    $VERSION = 3.07.00.049;
29
    $VERSION = 3.07.00.049;
30
  require Exporter;
30
    require Exporter;
31
  @ISA    = qw(Exporter);
31
    @ISA    = qw(Exporter);
32
  @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
32
    @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
33
    getreviews getallreviews approvereview unapprovereview deletereview);
33
      getreviews getallreviews approvereview unapprovereview deletereview);
34
}
34
}
35
35
36
=head1 NAME
36
=head1 NAME
Lines 66-74 Takes a borrowernumber and a biblionumber and returns the review of that biblio Link Here
66
sub getreview {
66
sub getreview {
67
    my ( $biblionumber, $borrowernumber ) = @_;
67
    my ( $biblionumber, $borrowernumber ) = @_;
68
    my $dbh   = C4::Context->dbh;
68
    my $dbh   = C4::Context->dbh;
69
    my $query =
69
    my $query = "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
70
      "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
70
    my $sth   = $dbh->prepare($query);
71
    my $sth = $dbh->prepare($query);
72
    $sth->execute( $biblionumber, $borrowernumber );
71
    $sth->execute( $biblionumber, $borrowernumber );
73
    return $sth->fetchrow_hashref();
72
    return $sth->fetchrow_hashref();
74
}
73
}
Lines 88-94 sub savereview { Link Here
88
  review,approved,datereviewed) VALUES
87
  review,approved,datereviewed) VALUES
89
  (?,?,?,0,now())";
88
  (?,?,?,0,now())";
90
    my $sth = $dbh->prepare($query);
89
    my $sth = $dbh->prepare($query);
91
    $sth->execute( $borrowernumber, $biblionumber, $review);
90
    $sth->execute( $borrowernumber, $biblionumber, $review );
92
}
91
}
93
92
94
=head2 updatereview
93
=head2 updatereview
Lines 103-109 sub updatereview { Link Here
103
    my ( $biblionumber, $borrowernumber, $review ) = @_;
102
    my ( $biblionumber, $borrowernumber, $review ) = @_;
104
    my $dbh   = C4::Context->dbh;
103
    my $dbh   = C4::Context->dbh;
105
    my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
104
    my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
106
    my $sth = $dbh->prepare($query);
105
    my $sth   = $dbh->prepare($query);
107
    $sth->execute( $review, $borrowernumber, $biblionumber );
106
    $sth->execute( $review, $borrowernumber, $biblionumber );
108
}
107
}
109
108
Lines 118-130 Return the number of reviews where in the 'reviews' database : 'approved' = $sta Link Here
118
117
119
sub numberofreviews {
118
sub numberofreviews {
120
    my ($param) = @_;
119
    my ($param) = @_;
121
    my $status = (defined($param) ? $param : 1);
120
    my $status = ( defined($param) ? $param : 1 );
122
    my $dbh            = C4::Context->dbh;
121
    my $dbh    = C4::Context->dbh;
123
    my $query          =
122
    my $query  = "SELECT count(*) FROM reviews WHERE approved=?";
124
      "SELECT count(*) FROM reviews WHERE approved=?";
123
    my $sth    = $dbh->prepare($query);
125
    my $sth = $dbh->prepare($query);
124
    $sth->execute($status);
126
    $sth->execute( $status );
125
    return $sth->fetchrow;
127
  return $sth->fetchrow;
128
}
126
}
129
127
130
=head2 numberofreviewsbybiblionumber
128
=head2 numberofreviewsbybiblionumber
Lines 138-148 Return the number of reviews approved for a given biblionumber Link Here
138
sub numberofreviewsbybiblionumber {
136
sub numberofreviewsbybiblionumber {
139
    my ($biblionumber) = @_;
137
    my ($biblionumber) = @_;
140
    my $dbh            = C4::Context->dbh;
138
    my $dbh            = C4::Context->dbh;
141
    my $query          =
139
    my $query          = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
142
      "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
140
    my $sth            = $dbh->prepare($query);
143
    my $sth = $dbh->prepare($query);
144
    $sth->execute( $biblionumber, 1 );
141
    $sth->execute( $biblionumber, 1 );
145
  return $sth->fetchrow;
142
    return $sth->fetchrow;
146
}
143
}
147
144
148
=head2 getreviews
145
=head2 getreviews
Lines 157-167 Return all reviews where in the 'reviews' database : Link Here
157
sub getreviews {
154
sub getreviews {
158
    my ( $biblionumber, $approved ) = @_;
155
    my ( $biblionumber, $approved ) = @_;
159
    my $dbh   = C4::Context->dbh;
156
    my $dbh   = C4::Context->dbh;
160
    my $query =
157
    my $query = "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
161
      "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
158
    my $sth   = $dbh->prepare($query);
162
    my $sth = $dbh->prepare($query);
163
    $sth->execute( $biblionumber, $approved );
159
    $sth->execute( $biblionumber, $approved );
164
  return $sth->fetchall_arrayref({});
160
    return $sth->fetchall_arrayref( {} );
165
}
161
}
166
162
167
=head2 getallreviews
163
=head2 getallreviews
Lines 177-190 $offset position and the ($offset + $row_count) position. Link Here
177
=cut
173
=cut
178
174
179
sub getallreviews {
175
sub getallreviews {
180
    my ($status, $offset, $row_count) = @_;
176
    my ( $status, $offset, $row_count ) = @_;
181
    my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20));
177
    my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) );
182
    my $dbh      = C4::Context->dbh;
178
    my $dbh    = C4::Context->dbh;
183
    my $query    =
179
    my $query  = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
184
      "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
180
    my $sth    = $dbh->prepare($query);
185
    my $sth = $dbh->prepare($query);
186
    $sth->execute(@params);
181
    $sth->execute(@params);
187
  return $sth->fetchall_arrayref({});
182
    return $sth->fetchall_arrayref( {} );
188
}
183
}
189
184
190
=head2 approvereview
185
=head2 approvereview
(-)a/t/db_dependent/Review.t (-240 / +210 lines)
Lines 21-47 use Test::More tests => 117; Link Here
21
use Time::Piece;
21
use Time::Piece;
22
22
23
BEGIN {
23
BEGIN {
24
    use_ok ('C4::Biblio');
24
    use_ok('C4::Biblio');
25
    use_ok ('C4::Review');
25
    use_ok('C4::Review');
26
    use_ok ('Koha::Borrower');
26
    use_ok('Koha::Borrower');
27
    use_ok ('MARC::Record');
27
    use_ok('MARC::Record');
28
}
28
}
29
29
30
can_ok(
30
can_ok(
31
    'C4::Review', qw(
31
    'C4::Review', qw(
32
        getreview
32
      getreview
33
        savereview
33
      savereview
34
        updatereview
34
      updatereview
35
        numberofreviews
35
      numberofreviews
36
        numberofreviewsbybiblionumber
36
      numberofreviewsbybiblionumber
37
        getreviews
37
      getreviews
38
        getallreviews
38
      getallreviews
39
        approvereview
39
      approvereview
40
        unapprovereview
40
      unapprovereview
41
        deletereview )
41
      deletereview )
42
);
42
);
43
43
44
45
my $dbh = C4::Context->dbh;
44
my $dbh = C4::Context->dbh;
46
$dbh->{AutoCommit} = 0;
45
$dbh->{AutoCommit} = 0;
47
$dbh->{RaiseError} = 1;
46
$dbh->{RaiseError} = 1;
Lines 50-60 $dbh->do('DELETE FROM borrowers'); Link Here
50
49
51
# ---------- Some borrowers for testing -------------------
50
# ---------- Some borrowers for testing -------------------
52
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode();
51
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode();
53
my $branchcode   = Koha::Database->new()->schema()->resultset('Branch')  ->first()->branchcode();
52
my $branchcode   = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
54
53
55
my $b1 = Koha::Borrower->new(
54
my $b1 = Koha::Borrower->new(
56
    {
55
    {   surname      => 'Borrower 1',
57
        surname      => 'Borrower 1',
58
        branchcode   => $branchcode,
56
        branchcode   => $branchcode,
59
        categorycode => $categorycode
57
        categorycode => $categorycode
60
    }
58
    }
Lines 62-69 my $b1 = Koha::Borrower->new( Link Here
62
$b1->store();
60
$b1->store();
63
61
64
my $b2 = Koha::Borrower->new(
62
my $b2 = Koha::Borrower->new(
65
    {
63
    {   surname      => 'Borrower 2',
66
        surname      => 'Borrower 2',
67
        branchcode   => $branchcode,
64
        branchcode   => $branchcode,
68
        categorycode => $categorycode
65
        categorycode => $categorycode
69
    }
66
    }
Lines 71-168 my $b2 = Koha::Borrower->new( Link Here
71
$b2->store();
68
$b2->store();
72
69
73
my $b3 = Koha::Borrower->new(
70
my $b3 = Koha::Borrower->new(
74
    {
71
    {   surname      => 'Borrower 3',
75
        surname      => 'Borrower 3',
76
        branchcode   => $branchcode,
72
        branchcode   => $branchcode,
77
        categorycode => $categorycode
73
        categorycode => $categorycode
78
    }
74
    }
79
);
75
);
80
$b3->store();
76
$b3->store();
81
77
82
83
# ---------- Some biblios for testing -------------------
78
# ---------- Some biblios for testing -------------------
84
my ( $biblionumber1 ) = AddBiblio( MARC::Record->new, '' );
79
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' );
85
my ( $biblionumber2 ) = AddBiblio( MARC::Record->new, '' );
80
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' );
86
my ( $biblionumber3 ) = AddBiblio( MARC::Record->new, '' );
81
my ($biblionumber3) = AddBiblio( MARC::Record->new, '' );
87
88
82
89
# ---------- Some reviews for testing -------------------
83
# ---------- Some reviews for testing -------------------
90
my $rev1 = 'Review 1';
84
my $rev1 = 'Review 1';
91
my $rev2 = 'Review 2';
85
my $rev2 = 'Review 2';
92
my $rev3 = 'Review 3';
86
my $rev3 = 'Review 3';
93
87
94
95
# ---------- Testing savereview ---------------------------
88
# ---------- Testing savereview ---------------------------
96
my $date = Time::Piece::localtime->strftime('%F %T');
89
my $date = Time::Piece::localtime->strftime('%F %T');
97
90
98
savereview($biblionumber1,$b1->borrowernumber,$rev1);
91
savereview( $biblionumber1, $b1->borrowernumber, $rev1 );
99
92
100
my $query = '
93
my $query = '
101
  SELECT count(*)
94
  SELECT count(*)
102
  FROM reviews
95
  FROM reviews
103
';
96
';
104
my $sth = $dbh->prepare($query);
97
my $count = $dbh->selectrow_array($query);
105
$sth->execute;
98
is( $count, 1, 'There is 1 review' );
106
my $count = $sth->fetchrow_array;
107
is ($count, 1, 'There is 1 review');
108
99
109
$query = '
100
$query = '
110
  SELECT reviewid, borrowernumber, biblionumber, review, approved, datereviewed
101
  SELECT reviewid, borrowernumber, biblionumber, review, approved, datereviewed
111
  FROM reviews
102
  FROM reviews
112
';
103
';
113
$sth = $dbh->prepare($query);
104
my ( $reviewid, $borrowernumber, $biblionumber, $review, $approved, $datereviewed ) = $dbh->selectrow_array($query);
114
$sth->execute;
105
is( $borrowernumber, $b1->borrowernumber, 'borrowernumber field is good' );
115
my ($reviewid, $borrowernumber, $biblionumber, $review, $approved, $datereviewed) = $sth->fetchrow_array;
106
is( $biblionumber,   $biblionumber1,      'biblionumber field is good' );
116
is ($borrowernumber, $b1->borrowernumber, 'borrowernumber field is good'  );
107
is( $review,         $rev1,               'review field is good' );
117
is ($biblionumber,   $biblionumber1,      'biblionumber field is good'    );
108
is( $approved,       0,                   'approved field is 0 by default' );
118
is ($review,         $rev1,               'review field is good'          );
109
is( $datereviewed,   $date,               'datereviewed field is good' );
119
is ($approved,       0,                   'approved field is 0 by default');
120
is ($datereviewed,   $date,               'datereviewed field is good'    );
121
110
122
# We add some others reviews
111
# We add some others reviews
123
savereview($biblionumber1,$b2->borrowernumber,$rev2);
112
savereview( $biblionumber1, $b2->borrowernumber, $rev2 );
124
savereview($biblionumber3,$b2->borrowernumber,$rev3);
113
savereview( $biblionumber3, $b2->borrowernumber, $rev3 );
125
126
114
127
# ---------- Testing getreview ----------------------------
115
# ---------- Testing getreview ----------------------------
128
my $review1 = getreview($biblionumber1,$b1->borrowernumber);
116
my $review1 = getreview( $biblionumber1, $b1->borrowernumber );
129
my $review2 = getreview($biblionumber1,$b2->borrowernumber);
117
my $review2 = getreview( $biblionumber1, $b2->borrowernumber );
130
my $review3 = getreview($biblionumber3,$b2->borrowernumber);
118
my $review3 = getreview( $biblionumber3, $b2->borrowernumber );
131
119
132
$query = '
120
$query = '
133
  SELECT count(*)
121
  SELECT count(*)
134
  FROM reviews
122
  FROM reviews
135
';
123
';
136
$sth = $dbh->prepare($query);
124
$count = $dbh->selectrow_array($query);
137
$sth->execute;
125
is( $count, 3, 'There are 3 reviews' );
138
$count = $sth->fetchrow_array;
126
139
is ($count, 3, 'There are 3 reviews');
127
isa_ok( $review1, 'HASH', '$review1 is defined as a hash' );
140
128
is( $review1->{borrowernumber}, $b1->borrowernumber, 'borrowernumber field is good' );
141
isa_ok ($review1, 'HASH', '$review1 is defined as a hash');
129
is( $review1->{biblionumber},   $biblionumber1,      'biblionumber field is good' );
142
is ($review1->{borrowernumber}, $b1->borrowernumber, 'borrowernumber field is good'  );
130
is( $review1->{review},         $rev1,               'review field is good' );
143
is ($review1->{biblionumber},   $biblionumber1,      'biblionumber field is good'    );
131
is( $review1->{approved},       0,                   'approved field is 0 by default' );
144
is ($review1->{review},         $rev1,               'review field is good'          );
132
cmp_ok( $review1->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
145
is ($review1->{approved},       0,                   'approved field is 0 by default');
133
146
cmp_ok ($review1->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
134
isa_ok( $review2, 'HASH', '$review2 is defined as a hash' );
147
135
is( $review2->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' );
148
isa_ok ($review2, 'HASH', '$review2 is defined as a hash');
136
is( $review2->{biblionumber},   $biblionumber1,      'biblionumber field is good' );
149
is ($review2->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good'  );
137
is( $review2->{review},         $rev2,               'review field is good' );
150
is ($review2->{biblionumber},   $biblionumber1,      'biblionumber field is good'    );
138
is( $review2->{approved},       0,                   'approved field is 0 by default' );
151
is ($review2->{review},         $rev2,               'review field is good'          );
139
cmp_ok( $review2->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
152
is ($review2->{approved},       0,                   'approved field is 0 by default');
140
153
cmp_ok ($review2->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
141
isa_ok( $review3, 'HASH', '$review3 is defined as a hash' );
154
142
is( $review3->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' );
155
isa_ok ($review3, 'HASH', '$review3 is defined as a hash');
143
is( $review3->{biblionumber},   $biblionumber3,      'biblionumber field is good' );
156
is ($review3->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good'  );
144
is( $review3->{review},         $rev3,               'review field is good' );
157
is ($review3->{biblionumber},   $biblionumber3,      'biblionumber field is good'    );
145
is( $review3->{approved},       0,                   'approved field is 0 by default' );
158
is ($review3->{review},         $rev3,               'review field is good'          );
146
cmp_ok( $review3->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
159
is ($review3->{approved},       0,                   'approved field is 0 by default');
160
cmp_ok ($review3->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
161
162
147
163
# ---------- Testing getreviews ---------------------------
148
# ---------- Testing getreviews ---------------------------
164
my $status = 0;
149
my $status = 0;
165
my $reviews = getreviews($biblionumber1, $status);
150
my $reviews = getreviews( $biblionumber1, $status );
166
151
167
$query = '
152
$query = '
168
  SELECT count(*)
153
  SELECT count(*)
Lines 170-212 $query = ' Link Here
170
  WHERE biblionumber = ?
155
  WHERE biblionumber = ?
171
    AND approved = ?
156
    AND approved = ?
172
';
157
';
173
$sth = $dbh->prepare($query);
158
$count = $dbh->selectrow_array( $query, {}, $biblionumber1, $status );
174
$sth->execute($biblionumber1, $status);
159
is( $count, 2, 'There are 2 reviews corresponding' );
175
$count = $sth->fetchrow_array;
160
176
is ($count, 2, 'There are 2 reviews corresponding');
161
isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' );
177
162
178
isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array');
163
isa_ok( $reviews->[0], 'HASH', '$reviews->[0] is defined as a hash' );
179
164
is( $reviews->[0]->{reviewid},       $review1->{reviewid},       'reviewid field is good' );
180
isa_ok ($reviews->[0], 'HASH', '$reviews->[0] is defined as a hash');
165
is( $reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' );
181
is ($reviews->[0]->{reviewid},       $review1->{reviewid},       'reviewid field is good'        );
166
is( $reviews->[0]->{biblionumber},   $review1->{biblionumber},   'biblionumber field is good' );
182
is ($reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good'  );
167
is( $reviews->[0]->{review},         $review1->{review},         'review field is good' );
183
is ($reviews->[0]->{biblionumber},   $review1->{biblionumber},   'biblionumber field is good'    );
168
is( $reviews->[0]->{approved},       $review1->{approved},       'approved field is 0 by default' );
184
is ($reviews->[0]->{review},         $review1->{review},         'review field is good'          );
169
cmp_ok( $reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
185
is ($reviews->[0]->{approved},       $review1->{approved},       'approved field is 0 by default');
170
186
cmp_ok ($reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good');
171
isa_ok( $reviews->[1], 'HASH', '$reviews->[1] is defined as a hash' );
187
172
is( $reviews->[1]->{reviewid},       $review2->{reviewid},       'reviewid field is good' );
188
isa_ok ($reviews->[1], 'HASH', '$reviews->[1] is defined as a hash');
173
is( $reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' );
189
is ($reviews->[1]->{reviewid},       $review2->{reviewid},       'reviewid field is good'        );
174
is( $reviews->[1]->{biblionumber},   $review2->{biblionumber},   'biblionumber field is good' );
190
is ($reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good'  );
175
is( $reviews->[1]->{review},         $review2->{review},         'review field is good' );
191
is ($reviews->[1]->{biblionumber},   $review2->{biblionumber},   'biblionumber field is good'    );
176
is( $reviews->[1]->{approved},       $review2->{approved},       'approved field is 0 by default' );
192
is ($reviews->[1]->{review},         $review2->{review},         'review field is good'          );
177
cmp_ok( $reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
193
is ($reviews->[1]->{approved},       $review2->{approved},       'approved field is 0 by default');
194
cmp_ok ($reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good');
195
178
196
$status = 1;
179
$status = 1;
197
$reviews = getreviews($biblionumber1, $status);
180
$reviews = getreviews( $biblionumber1, $status );
198
isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array');
181
isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' );
199
is_deeply($reviews, [], '$reviews is empty, there is no approved review' );
182
is_deeply( $reviews, [], '$reviews is empty, there is no approved review' );
200
201
183
202
# ---------- Testing getallreviews ------------------------
184
# ---------- Testing getallreviews ------------------------
203
$status = 1;
185
$status  = 1;
204
$reviews = getallreviews($status);
186
$reviews = getallreviews($status);
205
isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array');
187
isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' );
206
is_deeply($reviews, [], '$reviews is empty, there is no approved review' );
188
is_deeply( $reviews, [], '$reviews is empty, there is no approved review' );
207
189
208
190
$status  = 0;
209
$status = 0;
210
$reviews = getallreviews($status);
191
$reviews = getallreviews($status);
211
192
212
$query = '
193
$query = '
Lines 214-414 $query = ' Link Here
214
  FROM reviews
195
  FROM reviews
215
  WHERE approved = ?
196
  WHERE approved = ?
216
';
197
';
217
$sth = $dbh->prepare($query);
198
$count = $dbh->selectrow_array( $query, {}, $status );
218
$sth->execute($status);
199
is( $count, 3, 'There are 3 reviews corresponding' );
219
$count = $sth->fetchrow_array;
220
is ($count, 3, 'There are 3 reviews corresponding');
221
200
222
my $count2 = numberofreviews($status);
201
my $count2 = numberofreviews($status);
223
is ($count2, $count, 'number of reviews returned is good');
202
is( $count2, $count, 'number of reviews returned is good' );
224
203
225
204
isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' );
226
isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array');
205
227
206
isa_ok( $reviews->[0], 'HASH', '$reviews->[0] is defined as a hash' );
228
isa_ok ($reviews->[0], 'HASH', '$reviews->[0] is defined as a hash');
207
is( $reviews->[0]->{reviewid},       $review1->{reviewid},       'reviewid field is good' );
229
is ($reviews->[0]->{reviewid},       $review1->{reviewid},       'reviewid field is good'        );
208
is( $reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' );
230
is ($reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good'  );
209
is( $reviews->[0]->{biblionumber},   $review1->{biblionumber},   'biblionumber field is good' );
231
is ($reviews->[0]->{biblionumber},   $review1->{biblionumber},   'biblionumber field is good'    );
210
is( $reviews->[0]->{review},         $review1->{review},         'review field is good' );
232
is ($reviews->[0]->{review},         $review1->{review},         'review field is good'          );
211
is( $reviews->[0]->{approved},       $review1->{approved},       'approved field is 0 by default' );
233
is ($reviews->[0]->{approved},       $review1->{approved},       'approved field is 0 by default');
212
cmp_ok( $reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
234
cmp_ok ($reviews->[0]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
213
235
214
isa_ok( $reviews->[1], 'HASH', '$reviews->[1] is defined as a hash' );
236
isa_ok ($reviews->[1], 'HASH', '$reviews->[1] is defined as a hash');
215
is( $reviews->[1]->{reviewid},       $review2->{reviewid},       'reviewid field is good' );
237
is ($reviews->[1]->{reviewid},       $review2->{reviewid},       'reviewid field is good'        );
216
is( $reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' );
238
is ($reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good'  );
217
is( $reviews->[1]->{biblionumber},   $review2->{biblionumber},   'biblionumber field is good' );
239
is ($reviews->[1]->{biblionumber},   $review2->{biblionumber},   'biblionumber field is good'    );
218
is( $reviews->[1]->{review},         $review2->{review},         'review field is good' );
240
is ($reviews->[1]->{review},         $review2->{review},         'review field is good'          );
219
is( $reviews->[1]->{approved},       $review2->{approved},       'approved field is 0 by default' );
241
is ($reviews->[1]->{approved},       $review2->{approved},       'approved field is 0 by default');
220
cmp_ok( $reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
242
cmp_ok ($reviews->[1]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
221
243
222
isa_ok( $reviews->[2], 'HASH', '$reviews->[2] is defined as a hash' );
244
isa_ok ($reviews->[2], 'HASH', '$reviews->[2] is defined as a hash');
223
is( $reviews->[2]->{reviewid},       $review3->{reviewid},       'reviewid field is good' );
245
is ($reviews->[2]->{reviewid},       $review3->{reviewid},       'reviewid field is good'        );
224
is( $reviews->[2]->{borrowernumber}, $review3->{borrowernumber}, 'borrowernumber field is good' );
246
is ($reviews->[2]->{borrowernumber}, $review3->{borrowernumber}, 'borrowernumber field is good'  );
225
is( $reviews->[2]->{biblionumber},   $review3->{biblionumber},   'biblionumber field is good' );
247
is ($reviews->[2]->{biblionumber},   $review3->{biblionumber},   'biblionumber field is good'    );
226
is( $reviews->[2]->{review},         $review3->{review},         'review field is good' );
248
is ($reviews->[2]->{review},         $review3->{review},         'review field is good'          );
227
is( $reviews->[2]->{approved},       $review3->{approved},       'approved field is 0 by default' );
249
is ($reviews->[2]->{approved},       $review3->{approved},       'approved field is 0 by default');
228
cmp_ok( $reviews->[2]->{datereviewed}, 'ge', $date, 'datereviewed field is good' );
250
cmp_ok ($reviews->[2]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good');
229
251
230
my $offset    = 1;
252
my $offset = 1;
253
my $row_count = 1;
231
my $row_count = 1;
254
$reviews = getallreviews($status, $offset);
232
$reviews = getallreviews( $status, $offset );
255
is (@$reviews, 2, 'There are only 2 Reviews here');
233
is( @$reviews, 2, 'There are only 2 Reviews here' );
256
is_deeply ($reviews->[0], $review2, 'We have Review2...');
234
is_deeply( $reviews->[0], $review2, 'We have Review2...' );
257
is_deeply ($reviews->[1], $review3, '...and Review3');
235
is_deeply( $reviews->[1], $review3, '...and Review3' );
258
259
$reviews = getallreviews($status, $offset, $row_count);
260
is (@$reviews, 1, 'There is only 1 Review here');
261
is_deeply ($reviews->[0], $review2, 'We have only Review2');
262
236
237
$reviews = getallreviews( $status, $offset, $row_count );
238
is( @$reviews, 1, 'There is only 1 Review here' );
239
is_deeply( $reviews->[0], $review2, 'We have only Review2' );
263
240
264
# ---------- Testing numberofreviews ----------------------
241
# ---------- Testing numberofreviews ----------------------
265
$status = 0;
242
$status = 0;
266
$count = numberofreviews($status);
243
$count  = numberofreviews($status);
267
is($count, 3, 'There are 3 reviews where approved = 0');
244
is( $count, 3, 'There are 3 reviews where approved = 0' );
268
245
269
$status = 1;
246
$status = 1;
270
$count = numberofreviews($status);
247
$count  = numberofreviews($status);
271
is($count, 0, 'There is no review where approved = 0');
248
is( $count, 0, 'There is no review where approved = 0' );
272
249
273
$count = numberofreviews();
250
$count = numberofreviews();
274
is($count, 0, 'There is no review where approved = 0 (Default)');
251
is( $count, 0, 'There is no review where approved = 0 (Default)' );
275
276
252
277
# ---------- Testing approvereview ------------------------
253
# ---------- Testing approvereview ------------------------
278
is($review1->{approved}, 0, 'review1 is not approved');
254
is( $review1->{approved}, 0, 'review1 is not approved' );
279
approvereview($review1->{reviewid});
255
approvereview( $review1->{reviewid} );
280
$review1 = getreview($biblionumber1,$b1->borrowernumber);
256
$review1 = getreview( $biblionumber1, $b1->borrowernumber );
281
is($review1->{approved}, 1, 'review1 is approved');
257
is( $review1->{approved}, 1, 'review1 is approved' );
282
258
283
is($review2->{approved}, 0, 'review2 is not approved');
259
is( $review2->{approved}, 0, 'review2 is not approved' );
284
approvereview($review2->{reviewid});
260
approvereview( $review2->{reviewid} );
285
$review2 = getreview($biblionumber1,$b2->borrowernumber);
261
$review2 = getreview( $biblionumber1, $b2->borrowernumber );
286
is($review2->{approved}, 1, 'review2 is approved');
262
is( $review2->{approved}, 1, 'review2 is approved' );
287
263
288
is($review3->{approved}, 0, 'review3 is not approved');
264
is( $review3->{approved}, 0, 'review3 is not approved' );
289
approvereview($review3->{reviewid});
265
approvereview( $review3->{reviewid} );
290
$review3 = getreview($biblionumber3,$b2->borrowernumber);
266
$review3 = getreview( $biblionumber3, $b2->borrowernumber );
291
is($review3->{approved}, 1, 'review3 is approved');
267
is( $review3->{approved}, 1, 'review3 is approved' );
292
268
293
$status = 1;
269
$status  = 1;
294
$reviews = getallreviews($status);
270
$reviews = getallreviews($status);
295
271
296
$count = numberofreviews($status);
272
$count = numberofreviews($status);
297
is ($count, 3, '3 reviews are approved');
273
is( $count, 3, '3 reviews are approved' );
298
274
299
$status = 0;
275
$status = 0;
300
$count = numberofreviews($status);
276
$count  = numberofreviews($status);
301
is ($count, 0, 'No review are not approved');
277
is( $count, 0, 'No review are not approved' );
302
303
278
304
# ---------- Testing unapprovereview ----------------------
279
# ---------- Testing unapprovereview ----------------------
305
is($review1->{approved}, 1, 'review1 is approved');
280
is( $review1->{approved}, 1, 'review1 is approved' );
306
unapprovereview($review1->{reviewid});
281
unapprovereview( $review1->{reviewid} );
307
$review1 = getreview($biblionumber1,$b1->borrowernumber);
282
$review1 = getreview( $biblionumber1, $b1->borrowernumber );
308
is($review1->{approved}, 0, 'review1 is not approved');
283
is( $review1->{approved}, 0, 'review1 is not approved' );
309
284
310
is($review2->{approved}, 1, 'review2 is approved');
285
is( $review2->{approved}, 1, 'review2 is approved' );
311
unapprovereview($review2->{reviewid});
286
unapprovereview( $review2->{reviewid} );
312
$review2 = getreview($biblionumber1,$b2->borrowernumber);
287
$review2 = getreview( $biblionumber1, $b2->borrowernumber );
313
is($review2->{approved}, 0, 'review2 is not approved');
288
is( $review2->{approved}, 0, 'review2 is not approved' );
314
289
315
is($review3->{approved}, 1, 'review3 is approved');
290
is( $review3->{approved}, 1, 'review3 is approved' );
316
unapprovereview($review3->{reviewid});
291
unapprovereview( $review3->{reviewid} );
317
$review3 = getreview($biblionumber3,$b2->borrowernumber);
292
$review3 = getreview( $biblionumber3, $b2->borrowernumber );
318
is($review3->{approved}, 0, 'review3 is not approved');
293
is( $review3->{approved}, 0, 'review3 is not approved' );
319
294
320
$status = 0;
295
$status  = 0;
321
$reviews = getallreviews($status);
296
$reviews = getallreviews($status);
322
297
323
$count = numberofreviews($status);
298
$count = numberofreviews($status);
324
is ($count, 3, '3 reviews are not approved');
299
is( $count, 3, '3 reviews are not approved' );
325
300
326
$status = 1;
301
$status = 1;
327
$count = numberofreviews($status);
302
$count  = numberofreviews($status);
328
is ($count, 0, 'No review are approved');
303
is( $count, 0, 'No review are approved' );
329
330
304
331
# ---------- Testing numberofreviewsbybiblionumber --------
305
# ---------- Testing numberofreviewsbybiblionumber --------
332
approvereview($review1->{reviewid});
306
approvereview( $review1->{reviewid} );
333
approvereview($review2->{reviewid});
307
approvereview( $review2->{reviewid} );
334
approvereview($review3->{reviewid});
308
approvereview( $review3->{reviewid} );
335
309
336
$biblionumber = $biblionumber1;
310
$biblionumber = $biblionumber1;
337
$count = numberofreviewsbybiblionumber($biblionumber);
311
$count        = numberofreviewsbybiblionumber($biblionumber);
338
is($count, 2, 'There are 2 reviews for biblionumber1 and approved = 1');
312
is( $count, 2, 'There are 2 reviews for biblionumber1 and approved = 1' );
339
313
340
$biblionumber = $biblionumber2;
314
$biblionumber = $biblionumber2;
341
$count = numberofreviewsbybiblionumber($biblionumber);
315
$count        = numberofreviewsbybiblionumber($biblionumber);
342
is($count, 0, 'There is no review for biblionumber2 and  approved = 1');
316
is( $count, 0, 'There is no review for biblionumber2 and  approved = 1' );
343
317
344
$biblionumber = $biblionumber3;
318
$biblionumber = $biblionumber3;
345
$count = numberofreviewsbybiblionumber($biblionumber);
319
$count        = numberofreviewsbybiblionumber($biblionumber);
346
is($count, 1, 'There 1 review for biblionumber3 and approved = 1');
320
is( $count, 1, 'There 1 review for biblionumber3 and approved = 1' );
347
321
348
unapprovereview($review1->{reviewid});
322
unapprovereview( $review1->{reviewid} );
349
unapprovereview($review3->{reviewid});
323
unapprovereview( $review3->{reviewid} );
350
324
351
$biblionumber = $biblionumber1;
325
$biblionumber = $biblionumber1;
352
$count = numberofreviewsbybiblionumber($biblionumber);
326
$count        = numberofreviewsbybiblionumber($biblionumber);
353
is($count, 1, 'There is 1 review for biblionumber1 and approved = 1');
327
is( $count, 1, 'There is 1 review for biblionumber1 and approved = 1' );
354
328
355
$biblionumber = $biblionumber2;
329
$biblionumber = $biblionumber2;
356
$count = numberofreviewsbybiblionumber($biblionumber);
330
$count        = numberofreviewsbybiblionumber($biblionumber);
357
is($count, 0, 'There is no review for biblionumber2 and  approved = 1');
331
is( $count, 0, 'There is no review for biblionumber2 and  approved = 1' );
358
332
359
$biblionumber = $biblionumber3;
333
$biblionumber = $biblionumber3;
360
$count = numberofreviewsbybiblionumber($biblionumber);
334
$count        = numberofreviewsbybiblionumber($biblionumber);
361
is($count, 0, 'There is no review for biblionumber3 and approved = 1');
335
is( $count, 0, 'There is no review for biblionumber3 and approved = 1' );
362
363
336
364
# ---------- Testing updatereview -------------------------
337
# ---------- Testing updatereview -------------------------
365
my $rev1b = 'Review 1 bis';
338
my $rev1b = 'Review 1 bis';
366
my $rev2b = 'Review 2 bis';
339
my $rev2b = 'Review 2 bis';
367
my $rev3b = 'Review 3 bis';
340
my $rev3b = 'Review 3 bis';
368
341
369
is ($review1->{review}, $rev1, 'review field is "Review 1"');
342
is( $review1->{review}, $rev1, 'review field is "Review 1"' );
370
updatereview($biblionumber1,$b1->borrowernumber,$rev1b);
343
updatereview( $biblionumber1, $b1->borrowernumber, $rev1b );
371
$review1 = getreview($biblionumber1, $b1->borrowernumber);
344
$review1 = getreview( $biblionumber1, $b1->borrowernumber );
372
is ($review1->{review}, $rev1b, 'review field is "Review 1 bis"');
345
is( $review1->{review}, $rev1b, 'review field is "Review 1 bis"' );
373
374
is ($review2->{review}, $rev2, 'review field is "Review 2"');
375
updatereview($biblionumber1,$b2->borrowernumber,$rev2b);
376
$review2 = getreview($biblionumber1, $b2->borrowernumber);
377
is ($review2->{review}, $rev2b, 'review field is "Review 2 bis"');
378
346
379
is ($review3->{review}, $rev3, 'review field is "Review 3"');
347
is( $review2->{review}, $rev2, 'review field is "Review 2"' );
380
updatereview($biblionumber3,$b2->borrowernumber,$rev3b);
348
updatereview( $biblionumber1, $b2->borrowernumber, $rev2b );
381
$review3 = getreview($biblionumber3, $b2->borrowernumber);
349
$review2 = getreview( $biblionumber1, $b2->borrowernumber );
382
is ($review3->{review}, $rev3b, 'review field is "Review 3 bis"');
350
is( $review2->{review}, $rev2b, 'review field is "Review 2 bis"' );
383
351
352
is( $review3->{review}, $rev3, 'review field is "Review 3"' );
353
updatereview( $biblionumber3, $b2->borrowernumber, $rev3b );
354
$review3 = getreview( $biblionumber3, $b2->borrowernumber );
355
is( $review3->{review}, $rev3b, 'review field is "Review 3 bis"' );
384
356
385
# ---------- Testing deletereview -------------------------
357
# ---------- Testing deletereview -------------------------
386
my $status0 = 0;
358
my $status0 = 0;
387
my $status1 = 1;
359
my $status1 = 1;
388
360
389
my $numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
361
my $numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
390
is ($numberOfReviews, 3, 'There are 3 reviews in database');
362
is( $numberOfReviews, 3, 'There are 3 reviews in database' );
391
363
392
deletereview($review1->{reviewid});
364
deletereview( $review1->{reviewid} );
393
$review1 = getreview($biblionumber1, $b3->borrowernumber);
365
$review1 = getreview( $biblionumber1, $b3->borrowernumber );
394
ok (!defined($review1), 'Review1 is no longer defined');
366
ok( !defined($review1), 'Review1 is no longer defined' );
395
367
396
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
368
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
397
is ($numberOfReviews, 2, 'There are 2 reviews left in database');
369
is( $numberOfReviews, 2, 'There are 2 reviews left in database' );
398
370
399
deletereview($review2->{reviewid});
371
deletereview( $review2->{reviewid} );
400
$review2 = getreview($biblionumber2, $b2->borrowernumber);
372
$review2 = getreview( $biblionumber2, $b2->borrowernumber );
401
ok (!defined($review2), 'Review2 is no longer defined');
373
ok( !defined($review2), 'Review2 is no longer defined' );
402
374
403
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
375
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
404
is ($numberOfReviews, 1, 'There is 1 review left in database');
376
is( $numberOfReviews, 1, 'There is 1 review left in database' );
405
377
406
deletereview($review3->{reviewid});
378
deletereview( $review3->{reviewid} );
407
$review3 = getreview($biblionumber3, $b2->borrowernumber);
379
$review3 = getreview( $biblionumber3, $b2->borrowernumber );
408
ok (!defined($review3), 'Review3 is no longer defined');
380
ok( !defined($review3), 'Review3 is no longer defined' );
409
381
410
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
382
$numberOfReviews = numberofreviews($status0) + numberofreviews($status1);
411
is ($numberOfReviews, 0, 'There is no review left in database');
383
is( $numberOfReviews, 0, 'There is no review left in database' );
412
413
384
414
$dbh->rollback;
385
$dbh->rollback;
415
- 

Return to bug 13969