From 1bd5a177d0870332a959e9c773aaec80beeba74b Mon Sep 17 00:00:00 2001 From: remi Date: Mon, 8 Feb 2016 15:04:07 -0500 Subject: [PATCH] Bug 12748 - Add test for step 7 and 8 and rename findSerialByStatus https://bugs.koha-community.org/show_bug.cgi?id=12478 Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Serials.pm | 7 +++---- t/db_dependent/Serials.t | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 317c6a1fc1..b844a7e10b 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1175,8 +1175,7 @@ sub ModSerialStatus { } # create new expected entry if needed (ie : was "expected" and has changed) - # BUG 12748: Check if there are no other expected issues. - my $otherIssueExpected = scalar findSerialByStatus(EXPECTED, $subscriptionid); + my $otherIssueExpected = scalar findSerialsByStatus(EXPECTED, $subscriptionid); if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); @@ -2699,7 +2698,7 @@ sub _can_do_on_subscription { return 0; } -=head2 findSerialByStatus +=head2 findSerialsByStatus @serials = findSerialByStatus($status, $subscriptionid); @@ -2707,7 +2706,7 @@ sub _can_do_on_subscription { =cut -sub findSerialByStatus{ +sub findSerialsByStatus{ my($status, $subscriptionid) = @_; my $dbh = C4::Context->dbh; my $query = q| SELECT * from serial diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index b350ccd648..dac804f720 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 => 48; +use Test::More tests => 49; BEGIN { use_ok('C4::Serials'); @@ -173,7 +173,8 @@ is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription hist is(C4::Serials::ModSerialStatus(),undef, 'test modding serials'); -is(C4::Serials::findSerialByStatus(), 0, 'test finding serial by status with no parameters'); +is(C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters'); + is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered'); is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired'); @@ -219,7 +220,7 @@ for my $status ( @statuses ) { $counter++; } # Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1 -my @serialsByStatus = C4::Serials::findSerialByStatus(2,$subscriptionid); +my @serialsByStatus = C4::Serials::findSerialsByStatus(2,$subscriptionid); is(@serialsByStatus,2,"findSerialByStatus returns all serials with chosen status"); ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); @@ -247,4 +248,20 @@ 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'); +my @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"); + $dbh->rollback; -- 2.39.5