Bug 12748: Code tidy
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 14 Jun 2016 09:43:14 +0000 (10:43 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 17 Jun 2016 14:25:19 +0000 (14:25 +0000)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Serials.pm
t/db_dependent/Serials.t

index b844a7e..5cbd7df 100644 (file)
@@ -2706,9 +2706,9 @@ sub _can_do_on_subscription {
 
 =cut
 
-sub findSerialsByStatus{
-    my($status, $subscriptionid) = @_;
-    my $dbh = C4::Context->dbh;
+sub findSerialsByStatus {
+    my ( $status, $subscriptionid ) = @_;
+    my $dbh   = C4::Context->dbh;
     my $query = q| SELECT * from serial
                     WHERE status = ?
                     AND subscriptionid = ?
@@ -2716,6 +2716,7 @@ sub findSerialsByStatus{
     my $serials = $dbh->selectall_arrayref( $query, { Slice => {} }, $status, $subscriptionid );
     return @$serials;
 }
+
 1;
 __END__
 
index b7258be..e848280 100755 (executable)
@@ -15,7 +15,7 @@ use C4::Bookseller;
 use C4::Biblio;
 use C4::Budgets;
 use Koha::DateUtils;
-use Test::More tests => 49;
+use Test::More tests => 48;
 
 BEGIN {
     use_ok('C4::Serials');
@@ -248,20 +248,28 @@ for my $am ( @arrived_missing ) {
 }
 is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
 
-my ( $expected_serial ) = GetSerials2( $subscriptionid, [1] );
-#Find serialid for serial with status Expected
-my $serialexpected = (C4::Serials::findSerialsByStatus(1,$subscriptionid))[0];
-#delete serial with status Expected
-C4::Serials::ModSerialStatus( $serialexpected->{serialid},$serialexpected->{serialseq},$publisheddate,$publisheddate, $publisheddate,'1','an useless note');
-@serialsByStatus = C4::Serials::findSerialsByStatus(1,$subscriptionid);
-is (@serialsByStatus,1,"ModSerialStatus delete corectly serial expected and create another if not exist");
-# add 1 serial with status=Expected 1
-C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
-#Now we have two serials it have status expected
-#put status delete for last serial
-C4::Serials::ModSerialStatus( $serialexpected->{serialid},$serialexpected->{serialseq},$publisheddate,$publisheddate, $publisheddate,'1','an useless note');
-#try if create or note another serial with status is expected
-@serialsByStatus = C4::Serials::findSerialsByStatus(1,$subscriptionid);
-is(@serialsByStatus,1,"ModSerialStatus delete corectly serial expected and not create another if exist");
+subtest "Do not generate an expected if one already exists" => sub {
+    plan tests => 2;
+    my ($expected_serial) = GetSerials2( $subscriptionid, [1] );
+
+    #Find serialid for serial with status Expected
+    my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0];
+
+    #delete serial with status Expected
+    C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
+    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
+    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" );
+
+    # add 1 serial with status=Expected 1
+    C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
+
+    #Now we have two serials it have status expected
+    #put status delete for last serial
+    C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
+
+    #try if create or not another serial with status is expected
+    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
+    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
+};
 
 $dbh->rollback;