From 9ada85f8296977acecef2cd0293771060e6f24ec 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 --- C4/Review.pm | 14 +- t/db_dependent/Review.t | 459 +++++++++++++++++++++++------------------------- 2 files changed, 222 insertions(+), 251 deletions(-) diff --git a/C4/Review.pm b/C4/Review.pm index a502852..dbc8078 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -77,7 +77,7 @@ sub getreview { savereview($biblionumber,$borrowernumber, $review); -Save a review in the 'reviews' database +Save a review in the 'reviews' database =cut @@ -85,7 +85,7 @@ sub savereview { my ( $biblionumber, $borrowernumber, $review ) = @_; my $dbh = C4::Context->dbh; my $query = "INSERT INTO reviews (borrowernumber,biblionumber, - review,approved,datereviewed) VALUES + review,approved,datereviewed) VALUES (?,?,?,0,now())"; my $sth = $dbh->prepare($query); $sth->execute( $borrowernumber, $biblionumber, $review); @@ -95,7 +95,7 @@ sub savereview { updateview($biblionumber,$borrowernumber, $review); -Update the review description in the 'reviews' database +Update the review description in the 'reviews' database =cut @@ -111,7 +111,7 @@ sub updatereview { my $count=numberofreviews( [$status] ); -Return the number of reviews where in the 'reviews' database : 'approved' = $status +Return the number of reviews where in the 'reviews' database : 'approved' = $status (By default $status = 1) =cut @@ -149,7 +149,7 @@ sub numberofreviewsbybiblionumber { my $reviews=getreviews($biblionumber, $status); -Return all reviews where in the 'reviews' database : +Return all reviews where in the 'reviews' database : 'biblionumber' = $biblionumber and 'approved' = $status =cut @@ -170,8 +170,8 @@ sub getreviews { Return all reviews where in the 'reviews' database : 'approved' = $status -If offset and row_count are fiven, it's return all reviews between the -$offset position and the ($offset + $row_count) position. +If offset and row_count are fiven, it's return all reviews between the +$offset position and the ($offset + $row_count) position. (By default : $offset = 0 and $row_count = 20) =cut diff --git a/t/db_dependent/Review.t b/t/db_dependent/Review.t index c97b725..5507e2f 100644 --- a/t/db_dependent/Review.t +++ b/t/db_dependent/Review.t @@ -18,30 +18,29 @@ use Modern::Perl; use Test::More tests => 117; -use Time::Piece; +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,344 +68,318 @@ 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(*) + 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(*) + 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(*) + SELECT count(*) FROM reviews 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 = ' - SELECT count(*) + SELECT count(*) 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.3.3