From f863292a9226d3d99163d0b381befbbe7f75c67d Mon Sep 17 00:00:00 2001 From: Julian FIOL Date: Tue, 14 Apr 2015 10:00:02 +0200 Subject: [PATCH] Bug 13969: Replace calls to $sth->fetchrow* with a call to $dbh->selectrow* and Cleaning files 1. Replace all calls to $sth->fetchrow_array with a call to $dbh->selectrow_array 2. Cleaning Review.t file with perltiny 3. Cleaning Review.t && Review.pl files with koha-qa tool Signed-off-by: Bernardo Gonzalez Kriegel No koha-qa errors Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Review.pm | 59 +++--- t/db_dependent/Review.t | 449 +++++++++++++++++++--------------------- 2 files changed, 237 insertions(+), 271 deletions(-) diff --git a/C4/Review.pm b/C4/Review.pm index c8819d5f7f..5c6f45aff1 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -25,12 +25,12 @@ use C4::Context; use vars qw($VERSION @ISA @EXPORT); BEGIN { - # set the version for version checking + # set the version for version checking $VERSION = 3.07.00.049; - require Exporter; - @ISA = qw(Exporter); - @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber - getreviews getallreviews approvereview unapprovereview deletereview); + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber + getreviews getallreviews approvereview unapprovereview deletereview); } =head1 NAME @@ -66,9 +66,8 @@ Takes a borrowernumber and a biblionumber and returns the review of that biblio sub getreview { my ( $biblionumber, $borrowernumber ) = @_; my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?"; - my $sth = $dbh->prepare($query); + my $query = "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?"; + my $sth = $dbh->prepare($query); $sth->execute( $biblionumber, $borrowernumber ); return $sth->fetchrow_hashref(); } @@ -88,7 +87,7 @@ sub savereview { review,approved,datereviewed) VALUES (?,?,?,0,now())"; my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $biblionumber, $review); + $sth->execute( $borrowernumber, $biblionumber, $review ); } =head2 updatereview @@ -103,7 +102,7 @@ sub updatereview { my ( $biblionumber, $borrowernumber, $review ) = @_; my $dbh = C4::Context->dbh; my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?"; - my $sth = $dbh->prepare($query); + my $sth = $dbh->prepare($query); $sth->execute( $review, $borrowernumber, $biblionumber ); } @@ -118,13 +117,12 @@ Return the number of reviews where in the 'reviews' database : 'approved' = $sta sub numberofreviews { my ($param) = @_; - my $status = (defined($param) ? $param : 1); - my $dbh = C4::Context->dbh; - my $query = - "SELECT count(*) FROM reviews WHERE approved=?"; - my $sth = $dbh->prepare($query); - $sth->execute( $status ); - return $sth->fetchrow; + my $status = ( defined($param) ? $param : 1 ); + my $dbh = C4::Context->dbh; + my $query = "SELECT count(*) FROM reviews WHERE approved=?"; + my $sth = $dbh->prepare($query); + $sth->execute($status); + return $sth->fetchrow; } =head2 numberofreviewsbybiblionumber @@ -138,11 +136,10 @@ Return the number of reviews approved for a given biblionumber sub numberofreviewsbybiblionumber { my ($biblionumber) = @_; my $dbh = C4::Context->dbh; - my $query = - "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?"; - my $sth = $dbh->prepare($query); + my $query = "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?"; + my $sth = $dbh->prepare($query); $sth->execute( $biblionumber, 1 ); - return $sth->fetchrow; + return $sth->fetchrow; } =head2 getreviews @@ -157,11 +154,10 @@ Return all reviews where in the 'reviews' database : sub getreviews { my ( $biblionumber, $approved ) = @_; my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc"; - my $sth = $dbh->prepare($query); + my $query = "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc"; + my $sth = $dbh->prepare($query); $sth->execute( $biblionumber, $approved ); - return $sth->fetchall_arrayref({}); + return $sth->fetchall_arrayref( {} ); } =head2 getallreviews @@ -177,14 +173,13 @@ $offset position and the ($offset + $row_count) position. =cut sub getallreviews { - my ($status, $offset, $row_count) = @_; - my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20)); - my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; - my $sth = $dbh->prepare($query); + my ( $status, $offset, $row_count ) = @_; + my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) ); + my $dbh = C4::Context->dbh; + my $query = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; + my $sth = $dbh->prepare($query); $sth->execute(@params); - return $sth->fetchall_arrayref({}); + return $sth->fetchall_arrayref( {} ); } =head2 approvereview diff --git a/t/db_dependent/Review.t b/t/db_dependent/Review.t index 36aeb26196..5507e2fb3f 100644 --- a/t/db_dependent/Review.t +++ b/t/db_dependent/Review.t @@ -21,27 +21,26 @@ use Test::More tests => 117; use Time::Piece; BEGIN { - use_ok ('C4::Biblio'); - use_ok ('C4::Review'); - use_ok ('Koha::Borrower'); - use_ok ('MARC::Record'); + use_ok('C4::Biblio'); + use_ok('C4::Review'); + use_ok('Koha::Borrower'); + use_ok('MARC::Record'); } can_ok( 'C4::Review', qw( - getreview - savereview - updatereview - numberofreviews - numberofreviewsbybiblionumber - getreviews - getallreviews - approvereview - unapprovereview - deletereview ) + getreview + savereview + updatereview + numberofreviews + numberofreviewsbybiblionumber + getreviews + getallreviews + approvereview + unapprovereview + deletereview ) ); - my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; @@ -50,11 +49,10 @@ $dbh->do('DELETE FROM borrowers'); # ---------- Some borrowers for testing ------------------- my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); -my $branchcode = Koha::Database->new()->schema()->resultset('Branch') ->first()->branchcode(); +my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); my $b1 = Koha::Borrower->new( - { - surname => 'Borrower 1', + { surname => 'Borrower 1', branchcode => $branchcode, categorycode => $categorycode } @@ -62,8 +60,7 @@ my $b1 = Koha::Borrower->new( $b1->store(); my $b2 = Koha::Borrower->new( - { - surname => 'Borrower 2', + { surname => 'Borrower 2', branchcode => $branchcode, categorycode => $categorycode } @@ -71,98 +68,86 @@ my $b2 = Koha::Borrower->new( $b2->store(); my $b3 = Koha::Borrower->new( - { - surname => 'Borrower 3', + { surname => 'Borrower 3', branchcode => $branchcode, categorycode => $categorycode } ); $b3->store(); - # ---------- Some biblios for testing ------------------- -my ( $biblionumber1 ) = AddBiblio( MARC::Record->new, '' ); -my ( $biblionumber2 ) = AddBiblio( MARC::Record->new, '' ); -my ( $biblionumber3 ) = AddBiblio( MARC::Record->new, '' ); - +my ($biblionumber1) = AddBiblio( MARC::Record->new, '' ); +my ($biblionumber2) = AddBiblio( MARC::Record->new, '' ); +my ($biblionumber3) = AddBiblio( MARC::Record->new, '' ); # ---------- Some reviews for testing ------------------- my $rev1 = 'Review 1'; my $rev2 = 'Review 2'; my $rev3 = 'Review 3'; - # ---------- Testing savereview --------------------------- my $date = Time::Piece::localtime->strftime('%F %T'); -savereview($biblionumber1,$b1->borrowernumber,$rev1); +savereview( $biblionumber1, $b1->borrowernumber, $rev1 ); my $query = ' SELECT count(*) FROM reviews '; -my $sth = $dbh->prepare($query); -$sth->execute; -my $count = $sth->fetchrow_array; -is ($count, 1, 'There is 1 review'); +my $count = $dbh->selectrow_array($query); +is( $count, 1, 'There is 1 review' ); $query = ' SELECT reviewid, borrowernumber, biblionumber, review, approved, datereviewed FROM reviews '; -$sth = $dbh->prepare($query); -$sth->execute; -my ($reviewid, $borrowernumber, $biblionumber, $review, $approved, $datereviewed) = $sth->fetchrow_array; -is ($borrowernumber, $b1->borrowernumber, 'borrowernumber field is good' ); -is ($biblionumber, $biblionumber1, 'biblionumber field is good' ); -is ($review, $rev1, 'review field is good' ); -is ($approved, 0, 'approved field is 0 by default'); -is ($datereviewed, $date, 'datereviewed field is good' ); +my ( $reviewid, $borrowernumber, $biblionumber, $review, $approved, $datereviewed ) = $dbh->selectrow_array($query); +is( $borrowernumber, $b1->borrowernumber, 'borrowernumber field is good' ); +is( $biblionumber, $biblionumber1, 'biblionumber field is good' ); +is( $review, $rev1, 'review field is good' ); +is( $approved, 0, 'approved field is 0 by default' ); +is( $datereviewed, $date, 'datereviewed field is good' ); # We add some others reviews -savereview($biblionumber1,$b2->borrowernumber,$rev2); -savereview($biblionumber3,$b2->borrowernumber,$rev3); - +savereview( $biblionumber1, $b2->borrowernumber, $rev2 ); +savereview( $biblionumber3, $b2->borrowernumber, $rev3 ); # ---------- Testing getreview ---------------------------- -my $review1 = getreview($biblionumber1,$b1->borrowernumber); -my $review2 = getreview($biblionumber1,$b2->borrowernumber); -my $review3 = getreview($biblionumber3,$b2->borrowernumber); +my $review1 = getreview( $biblionumber1, $b1->borrowernumber ); +my $review2 = getreview( $biblionumber1, $b2->borrowernumber ); +my $review3 = getreview( $biblionumber3, $b2->borrowernumber ); $query = ' SELECT count(*) FROM reviews '; -$sth = $dbh->prepare($query); -$sth->execute; -$count = $sth->fetchrow_array; -is ($count, 3, 'There are 3 reviews'); - -isa_ok ($review1, 'HASH', '$review1 is defined as a hash'); -is ($review1->{borrowernumber}, $b1->borrowernumber, 'borrowernumber field is good' ); -is ($review1->{biblionumber}, $biblionumber1, 'biblionumber field is good' ); -is ($review1->{review}, $rev1, 'review field is good' ); -is ($review1->{approved}, 0, 'approved field is 0 by default'); -cmp_ok ($review1->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - -isa_ok ($review2, 'HASH', '$review2 is defined as a hash'); -is ($review2->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' ); -is ($review2->{biblionumber}, $biblionumber1, 'biblionumber field is good' ); -is ($review2->{review}, $rev2, 'review field is good' ); -is ($review2->{approved}, 0, 'approved field is 0 by default'); -cmp_ok ($review2->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - -isa_ok ($review3, 'HASH', '$review3 is defined as a hash'); -is ($review3->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' ); -is ($review3->{biblionumber}, $biblionumber3, 'biblionumber field is good' ); -is ($review3->{review}, $rev3, 'review field is good' ); -is ($review3->{approved}, 0, 'approved field is 0 by default'); -cmp_ok ($review3->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - +$count = $dbh->selectrow_array($query); +is( $count, 3, 'There are 3 reviews' ); + +isa_ok( $review1, 'HASH', '$review1 is defined as a hash' ); +is( $review1->{borrowernumber}, $b1->borrowernumber, 'borrowernumber field is good' ); +is( $review1->{biblionumber}, $biblionumber1, 'biblionumber field is good' ); +is( $review1->{review}, $rev1, 'review field is good' ); +is( $review1->{approved}, 0, 'approved field is 0 by default' ); +cmp_ok( $review1->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +isa_ok( $review2, 'HASH', '$review2 is defined as a hash' ); +is( $review2->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' ); +is( $review2->{biblionumber}, $biblionumber1, 'biblionumber field is good' ); +is( $review2->{review}, $rev2, 'review field is good' ); +is( $review2->{approved}, 0, 'approved field is 0 by default' ); +cmp_ok( $review2->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +isa_ok( $review3, 'HASH', '$review3 is defined as a hash' ); +is( $review3->{borrowernumber}, $b2->borrowernumber, 'borrowernumber field is good' ); +is( $review3->{biblionumber}, $biblionumber3, 'biblionumber field is good' ); +is( $review3->{review}, $rev3, 'review field is good' ); +is( $review3->{approved}, 0, 'approved field is 0 by default' ); +cmp_ok( $review3->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); # ---------- Testing getreviews --------------------------- my $status = 0; -my $reviews = getreviews($biblionumber1, $status); +my $reviews = getreviews( $biblionumber1, $status ); $query = ' SELECT count(*) @@ -170,43 +155,39 @@ $query = ' WHERE biblionumber = ? AND approved = ? '; -$sth = $dbh->prepare($query); -$sth->execute($biblionumber1, $status); -$count = $sth->fetchrow_array; -is ($count, 2, 'There are 2 reviews corresponding'); - -isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array'); - -isa_ok ($reviews->[0], 'HASH', '$reviews->[0] is defined as a hash'); -is ($reviews->[0]->{reviewid}, $review1->{reviewid}, 'reviewid field is good' ); -is ($reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' ); -is ($reviews->[0]->{biblionumber}, $review1->{biblionumber}, 'biblionumber field is good' ); -is ($reviews->[0]->{review}, $review1->{review}, 'review field is good' ); -is ($reviews->[0]->{approved}, $review1->{approved}, 'approved field is 0 by default'); -cmp_ok ($reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good'); - -isa_ok ($reviews->[1], 'HASH', '$reviews->[1] is defined as a hash'); -is ($reviews->[1]->{reviewid}, $review2->{reviewid}, 'reviewid field is good' ); -is ($reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' ); -is ($reviews->[1]->{biblionumber}, $review2->{biblionumber}, 'biblionumber field is good' ); -is ($reviews->[1]->{review}, $review2->{review}, 'review field is good' ); -is ($reviews->[1]->{approved}, $review2->{approved}, 'approved field is 0 by default'); -cmp_ok ($reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good'); +$count = $dbh->selectrow_array( $query, {}, $biblionumber1, $status ); +is( $count, 2, 'There are 2 reviews corresponding' ); + +isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' ); + +isa_ok( $reviews->[0], 'HASH', '$reviews->[0] is defined as a hash' ); +is( $reviews->[0]->{reviewid}, $review1->{reviewid}, 'reviewid field is good' ); +is( $reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' ); +is( $reviews->[0]->{biblionumber}, $review1->{biblionumber}, 'biblionumber field is good' ); +is( $reviews->[0]->{review}, $review1->{review}, 'review field is good' ); +is( $reviews->[0]->{approved}, $review1->{approved}, 'approved field is 0 by default' ); +cmp_ok( $reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +isa_ok( $reviews->[1], 'HASH', '$reviews->[1] is defined as a hash' ); +is( $reviews->[1]->{reviewid}, $review2->{reviewid}, 'reviewid field is good' ); +is( $reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' ); +is( $reviews->[1]->{biblionumber}, $review2->{biblionumber}, 'biblionumber field is good' ); +is( $reviews->[1]->{review}, $review2->{review}, 'review field is good' ); +is( $reviews->[1]->{approved}, $review2->{approved}, 'approved field is 0 by default' ); +cmp_ok( $reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); $status = 1; -$reviews = getreviews($biblionumber1, $status); -isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array'); -is_deeply($reviews, [], '$reviews is empty, there is no approved review' ); - +$reviews = getreviews( $biblionumber1, $status ); +isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' ); +is_deeply( $reviews, [], '$reviews is empty, there is no approved review' ); # ---------- Testing getallreviews ------------------------ -$status = 1; +$status = 1; $reviews = getallreviews($status); -isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array'); -is_deeply($reviews, [], '$reviews is empty, there is no approved review' ); +isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' ); +is_deeply( $reviews, [], '$reviews is empty, there is no approved review' ); - -$status = 0; +$status = 0; $reviews = getallreviews($status); $query = ' @@ -214,201 +195,191 @@ $query = ' FROM reviews WHERE approved = ? '; -$sth = $dbh->prepare($query); -$sth->execute($status); -$count = $sth->fetchrow_array; -is ($count, 3, 'There are 3 reviews corresponding'); +$count = $dbh->selectrow_array( $query, {}, $status ); +is( $count, 3, 'There are 3 reviews corresponding' ); my $count2 = numberofreviews($status); -is ($count2, $count, 'number of reviews returned is good'); - - -isa_ok ($reviews, 'ARRAY', '$reviews is defined as an array'); - -isa_ok ($reviews->[0], 'HASH', '$reviews->[0] is defined as a hash'); -is ($reviews->[0]->{reviewid}, $review1->{reviewid}, 'reviewid field is good' ); -is ($reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' ); -is ($reviews->[0]->{biblionumber}, $review1->{biblionumber}, 'biblionumber field is good' ); -is ($reviews->[0]->{review}, $review1->{review}, 'review field is good' ); -is ($reviews->[0]->{approved}, $review1->{approved}, 'approved field is 0 by default'); -cmp_ok ($reviews->[0]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - -isa_ok ($reviews->[1], 'HASH', '$reviews->[1] is defined as a hash'); -is ($reviews->[1]->{reviewid}, $review2->{reviewid}, 'reviewid field is good' ); -is ($reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' ); -is ($reviews->[1]->{biblionumber}, $review2->{biblionumber}, 'biblionumber field is good' ); -is ($reviews->[1]->{review}, $review2->{review}, 'review field is good' ); -is ($reviews->[1]->{approved}, $review2->{approved}, 'approved field is 0 by default'); -cmp_ok ($reviews->[1]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - -isa_ok ($reviews->[2], 'HASH', '$reviews->[2] is defined as a hash'); -is ($reviews->[2]->{reviewid}, $review3->{reviewid}, 'reviewid field is good' ); -is ($reviews->[2]->{borrowernumber}, $review3->{borrowernumber}, 'borrowernumber field is good' ); -is ($reviews->[2]->{biblionumber}, $review3->{biblionumber}, 'biblionumber field is good' ); -is ($reviews->[2]->{review}, $review3->{review}, 'review field is good' ); -is ($reviews->[2]->{approved}, $review3->{approved}, 'approved field is 0 by default'); -cmp_ok ($reviews->[2]->{datereviewed}, 'ge' ,$date , 'datereviewed field is good'); - -my $offset = 1; +is( $count2, $count, 'number of reviews returned is good' ); + +isa_ok( $reviews, 'ARRAY', '$reviews is defined as an array' ); + +isa_ok( $reviews->[0], 'HASH', '$reviews->[0] is defined as a hash' ); +is( $reviews->[0]->{reviewid}, $review1->{reviewid}, 'reviewid field is good' ); +is( $reviews->[0]->{borrowernumber}, $review1->{borrowernumber}, 'borrowernumber field is good' ); +is( $reviews->[0]->{biblionumber}, $review1->{biblionumber}, 'biblionumber field is good' ); +is( $reviews->[0]->{review}, $review1->{review}, 'review field is good' ); +is( $reviews->[0]->{approved}, $review1->{approved}, 'approved field is 0 by default' ); +cmp_ok( $reviews->[0]->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +isa_ok( $reviews->[1], 'HASH', '$reviews->[1] is defined as a hash' ); +is( $reviews->[1]->{reviewid}, $review2->{reviewid}, 'reviewid field is good' ); +is( $reviews->[1]->{borrowernumber}, $review2->{borrowernumber}, 'borrowernumber field is good' ); +is( $reviews->[1]->{biblionumber}, $review2->{biblionumber}, 'biblionumber field is good' ); +is( $reviews->[1]->{review}, $review2->{review}, 'review field is good' ); +is( $reviews->[1]->{approved}, $review2->{approved}, 'approved field is 0 by default' ); +cmp_ok( $reviews->[1]->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +isa_ok( $reviews->[2], 'HASH', '$reviews->[2] is defined as a hash' ); +is( $reviews->[2]->{reviewid}, $review3->{reviewid}, 'reviewid field is good' ); +is( $reviews->[2]->{borrowernumber}, $review3->{borrowernumber}, 'borrowernumber field is good' ); +is( $reviews->[2]->{biblionumber}, $review3->{biblionumber}, 'biblionumber field is good' ); +is( $reviews->[2]->{review}, $review3->{review}, 'review field is good' ); +is( $reviews->[2]->{approved}, $review3->{approved}, 'approved field is 0 by default' ); +cmp_ok( $reviews->[2]->{datereviewed}, 'ge', $date, 'datereviewed field is good' ); + +my $offset = 1; my $row_count = 1; -$reviews = getallreviews($status, $offset); -is (@$reviews, 2, 'There are only 2 Reviews here'); -is_deeply ($reviews->[0], $review2, 'We have Review2...'); -is_deeply ($reviews->[1], $review3, '...and Review3'); - -$reviews = getallreviews($status, $offset, $row_count); -is (@$reviews, 1, 'There is only 1 Review here'); -is_deeply ($reviews->[0], $review2, 'We have only Review2'); +$reviews = getallreviews( $status, $offset ); +is( @$reviews, 2, 'There are only 2 Reviews here' ); +is_deeply( $reviews->[0], $review2, 'We have Review2...' ); +is_deeply( $reviews->[1], $review3, '...and Review3' ); +$reviews = getallreviews( $status, $offset, $row_count ); +is( @$reviews, 1, 'There is only 1 Review here' ); +is_deeply( $reviews->[0], $review2, 'We have only Review2' ); # ---------- Testing numberofreviews ---------------------- $status = 0; -$count = numberofreviews($status); -is($count, 3, 'There are 3 reviews where approved = 0'); +$count = numberofreviews($status); +is( $count, 3, 'There are 3 reviews where approved = 0' ); $status = 1; -$count = numberofreviews($status); -is($count, 0, 'There is no review where approved = 0'); +$count = numberofreviews($status); +is( $count, 0, 'There is no review where approved = 0' ); $count = numberofreviews(); -is($count, 0, 'There is no review where approved = 0 (Default)'); - +is( $count, 0, 'There is no review where approved = 0 (Default)' ); # ---------- Testing approvereview ------------------------ -is($review1->{approved}, 0, 'review1 is not approved'); -approvereview($review1->{reviewid}); -$review1 = getreview($biblionumber1,$b1->borrowernumber); -is($review1->{approved}, 1, 'review1 is approved'); - -is($review2->{approved}, 0, 'review2 is not approved'); -approvereview($review2->{reviewid}); -$review2 = getreview($biblionumber1,$b2->borrowernumber); -is($review2->{approved}, 1, 'review2 is approved'); - -is($review3->{approved}, 0, 'review3 is not approved'); -approvereview($review3->{reviewid}); -$review3 = getreview($biblionumber3,$b2->borrowernumber); -is($review3->{approved}, 1, 'review3 is approved'); - -$status = 1; +is( $review1->{approved}, 0, 'review1 is not approved' ); +approvereview( $review1->{reviewid} ); +$review1 = getreview( $biblionumber1, $b1->borrowernumber ); +is( $review1->{approved}, 1, 'review1 is approved' ); + +is( $review2->{approved}, 0, 'review2 is not approved' ); +approvereview( $review2->{reviewid} ); +$review2 = getreview( $biblionumber1, $b2->borrowernumber ); +is( $review2->{approved}, 1, 'review2 is approved' ); + +is( $review3->{approved}, 0, 'review3 is not approved' ); +approvereview( $review3->{reviewid} ); +$review3 = getreview( $biblionumber3, $b2->borrowernumber ); +is( $review3->{approved}, 1, 'review3 is approved' ); + +$status = 1; $reviews = getallreviews($status); $count = numberofreviews($status); -is ($count, 3, '3 reviews are approved'); +is( $count, 3, '3 reviews are approved' ); $status = 0; -$count = numberofreviews($status); -is ($count, 0, 'No review are not approved'); - +$count = numberofreviews($status); +is( $count, 0, 'No review are not approved' ); # ---------- Testing unapprovereview ---------------------- -is($review1->{approved}, 1, 'review1 is approved'); -unapprovereview($review1->{reviewid}); -$review1 = getreview($biblionumber1,$b1->borrowernumber); -is($review1->{approved}, 0, 'review1 is not approved'); - -is($review2->{approved}, 1, 'review2 is approved'); -unapprovereview($review2->{reviewid}); -$review2 = getreview($biblionumber1,$b2->borrowernumber); -is($review2->{approved}, 0, 'review2 is not approved'); - -is($review3->{approved}, 1, 'review3 is approved'); -unapprovereview($review3->{reviewid}); -$review3 = getreview($biblionumber3,$b2->borrowernumber); -is($review3->{approved}, 0, 'review3 is not approved'); - -$status = 0; +is( $review1->{approved}, 1, 'review1 is approved' ); +unapprovereview( $review1->{reviewid} ); +$review1 = getreview( $biblionumber1, $b1->borrowernumber ); +is( $review1->{approved}, 0, 'review1 is not approved' ); + +is( $review2->{approved}, 1, 'review2 is approved' ); +unapprovereview( $review2->{reviewid} ); +$review2 = getreview( $biblionumber1, $b2->borrowernumber ); +is( $review2->{approved}, 0, 'review2 is not approved' ); + +is( $review3->{approved}, 1, 'review3 is approved' ); +unapprovereview( $review3->{reviewid} ); +$review3 = getreview( $biblionumber3, $b2->borrowernumber ); +is( $review3->{approved}, 0, 'review3 is not approved' ); + +$status = 0; $reviews = getallreviews($status); $count = numberofreviews($status); -is ($count, 3, '3 reviews are not approved'); +is( $count, 3, '3 reviews are not approved' ); $status = 1; -$count = numberofreviews($status); -is ($count, 0, 'No review are approved'); - +$count = numberofreviews($status); +is( $count, 0, 'No review are approved' ); # ---------- Testing numberofreviewsbybiblionumber -------- -approvereview($review1->{reviewid}); -approvereview($review2->{reviewid}); -approvereview($review3->{reviewid}); +approvereview( $review1->{reviewid} ); +approvereview( $review2->{reviewid} ); +approvereview( $review3->{reviewid} ); $biblionumber = $biblionumber1; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 2, 'There are 2 reviews for biblionumber1 and approved = 1'); +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 2, 'There are 2 reviews for biblionumber1 and approved = 1' ); $biblionumber = $biblionumber2; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 0, 'There is no review for biblionumber2 and approved = 1'); +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 0, 'There is no review for biblionumber2 and approved = 1' ); $biblionumber = $biblionumber3; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 1, 'There 1 review for biblionumber3 and approved = 1'); +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 1, 'There 1 review for biblionumber3 and approved = 1' ); -unapprovereview($review1->{reviewid}); -unapprovereview($review3->{reviewid}); +unapprovereview( $review1->{reviewid} ); +unapprovereview( $review3->{reviewid} ); $biblionumber = $biblionumber1; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 1, 'There is 1 review for biblionumber1 and approved = 1'); +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 1, 'There is 1 review for biblionumber1 and approved = 1' ); $biblionumber = $biblionumber2; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 0, 'There is no review for biblionumber2 and approved = 1'); +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 0, 'There is no review for biblionumber2 and approved = 1' ); $biblionumber = $biblionumber3; -$count = numberofreviewsbybiblionumber($biblionumber); -is($count, 0, 'There is no review for biblionumber3 and approved = 1'); - +$count = numberofreviewsbybiblionumber($biblionumber); +is( $count, 0, 'There is no review for biblionumber3 and approved = 1' ); # ---------- Testing updatereview ------------------------- my $rev1b = 'Review 1 bis'; my $rev2b = 'Review 2 bis'; my $rev3b = 'Review 3 bis'; -is ($review1->{review}, $rev1, 'review field is "Review 1"'); -updatereview($biblionumber1,$b1->borrowernumber,$rev1b); -$review1 = getreview($biblionumber1, $b1->borrowernumber); -is ($review1->{review}, $rev1b, 'review field is "Review 1 bis"'); - -is ($review2->{review}, $rev2, 'review field is "Review 2"'); -updatereview($biblionumber1,$b2->borrowernumber,$rev2b); -$review2 = getreview($biblionumber1, $b2->borrowernumber); -is ($review2->{review}, $rev2b, 'review field is "Review 2 bis"'); +is( $review1->{review}, $rev1, 'review field is "Review 1"' ); +updatereview( $biblionumber1, $b1->borrowernumber, $rev1b ); +$review1 = getreview( $biblionumber1, $b1->borrowernumber ); +is( $review1->{review}, $rev1b, 'review field is "Review 1 bis"' ); -is ($review3->{review}, $rev3, 'review field is "Review 3"'); -updatereview($biblionumber3,$b2->borrowernumber,$rev3b); -$review3 = getreview($biblionumber3, $b2->borrowernumber); -is ($review3->{review}, $rev3b, 'review field is "Review 3 bis"'); +is( $review2->{review}, $rev2, 'review field is "Review 2"' ); +updatereview( $biblionumber1, $b2->borrowernumber, $rev2b ); +$review2 = getreview( $biblionumber1, $b2->borrowernumber ); +is( $review2->{review}, $rev2b, 'review field is "Review 2 bis"' ); +is( $review3->{review}, $rev3, 'review field is "Review 3"' ); +updatereview( $biblionumber3, $b2->borrowernumber, $rev3b ); +$review3 = getreview( $biblionumber3, $b2->borrowernumber ); +is( $review3->{review}, $rev3b, 'review field is "Review 3 bis"' ); # ---------- Testing deletereview ------------------------- my $status0 = 0; my $status1 = 1; my $numberOfReviews = numberofreviews($status0) + numberofreviews($status1); -is ($numberOfReviews, 3, 'There are 3 reviews in database'); +is( $numberOfReviews, 3, 'There are 3 reviews in database' ); -deletereview($review1->{reviewid}); -$review1 = getreview($biblionumber1, $b3->borrowernumber); -ok (!defined($review1), 'Review1 is no longer defined'); +deletereview( $review1->{reviewid} ); +$review1 = getreview( $biblionumber1, $b3->borrowernumber ); +ok( !defined($review1), 'Review1 is no longer defined' ); $numberOfReviews = numberofreviews($status0) + numberofreviews($status1); -is ($numberOfReviews, 2, 'There are 2 reviews left in database'); +is( $numberOfReviews, 2, 'There are 2 reviews left in database' ); -deletereview($review2->{reviewid}); -$review2 = getreview($biblionumber2, $b2->borrowernumber); -ok (!defined($review2), 'Review2 is no longer defined'); +deletereview( $review2->{reviewid} ); +$review2 = getreview( $biblionumber2, $b2->borrowernumber ); +ok( !defined($review2), 'Review2 is no longer defined' ); $numberOfReviews = numberofreviews($status0) + numberofreviews($status1); -is ($numberOfReviews, 1, 'There is 1 review left in database'); +is( $numberOfReviews, 1, 'There is 1 review left in database' ); -deletereview($review3->{reviewid}); -$review3 = getreview($biblionumber3, $b2->borrowernumber); -ok (!defined($review3), 'Review3 is no longer defined'); +deletereview( $review3->{reviewid} ); +$review3 = getreview( $biblionumber3, $b2->borrowernumber ); +ok( !defined($review3), 'Review3 is no longer defined' ); $numberOfReviews = numberofreviews($status0) + numberofreviews($status1); -is ($numberOfReviews, 0, 'There is no review left in database'); - +is( $numberOfReviews, 0, 'There is no review left in database' ); -$dbh->rollback; \ No newline at end of file +$dbh->rollback; -- 2.39.5