From 44062c07b7703190b46701a3fa31665d998eadfb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Jun 2016 10:43:14 +0100 Subject: [PATCH] Bug 12748: Code tidy Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Serials.pm | 7 ++++--- t/db_dependent/Serials.t | 40 ++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index b844a7e10b..5cbd7dfa54 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -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__ diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index b7258be854..e848280525 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -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; -- 2.39.5