X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2Fdb_dependent%2FCirculation_issue.t;h=11669c3c41dfe49cc1eb0f96a2d1d3c017d5662c;hb=4b0b273cb078c17b82818211576fb7b3b17c2703;hp=ea701318a6fcabf9f10b4d032b9d3d7b69e794ca;hpb=0b2e9dbf620afeca2ec4a82b583c6787d8f1208b;p=koha.git diff --git a/t/db_dependent/Circulation_issue.t b/t/db_dependent/Circulation_issue.t index ea701318a6..11669c3c41 100644 --- a/t/db_dependent/Circulation_issue.t +++ b/t/db_dependent/Circulation_issue.t @@ -1,6 +1,22 @@ #!/usr/bin/perl +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + use Modern::Perl; + use Koha::DateUtils; use DateTime::Duration; use C4::Biblio; @@ -10,7 +26,7 @@ use C4::Circulation; use C4::Items; use C4::Context; -use Test::More tests => 27; +use Test::More tests => 30; BEGIN { use_ok('C4::Circulation'); @@ -193,16 +209,19 @@ my $sth = $dbh->prepare($query); $sth->execute; my $countissue = $sth -> fetchrow_array; is ($countissue ,0, "there is no issue"); -my $datedue1 = C4::Circulation::AddIssue( $borrower_1, 'barcode_1', $daysago10,0, $today, '' ); +my $issue1 = C4::Circulation::AddIssue( $borrower_1, 'barcode_1', $daysago10,0, $today, '' ); +is( ref $issue1, 'Koha::Schema::Result::Issue', + 'AddIssue returns a Koha::Schema::Result::Issue object' ); +my $datedue1 = dt_from_string( $issue1->date_due() ); like( $datedue1, qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, - "AddRenewal returns a date" + "Koha::Schema::Result::Issue->date_due() returns a date" ); my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef ); -my $datedue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' ); -is( $datedue2, undef, "AddIssue returns undef if no datedue is specified" ); +my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' ); +is( $issue2, undef, "AddIssue returns undef if no datedue is specified" ); my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef ); $sth->execute; @@ -252,8 +271,7 @@ my $openissue = GetOpenIssue($borrower_id1, $item_id1); my @renewcount; #Test GetRenewCount -$datedue2 = C4::Circulation::AddIssue( $borrower_1, 'barcode_1' ); -isnt( $datedue2, undef, "AddIssue does not return undef if datedue is specified" ); +my $issue3 = C4::Circulation::AddIssue( $borrower_1, 'barcode_1' ); #Without anything in DB @renewcount = C4::Circulation::GetRenewCount(); is_deeply( @@ -331,16 +349,43 @@ is_deeply( "With issuing rules (renewal allowed, 1 remaining) and with a valid parameter, Getrenewcount of item1 returns 0 renews left" ); -$dbh->do("TRUNCATE TABLE old_issues"); +$dbh->do("DELETE FROM old_issues"); AddReturn('barcode_1'); my $return = $dbh->selectrow_hashref("SELECT DATE(returndate) AS return_date, CURRENT_DATE() AS today FROM old_issues LIMIT 1" ); ok( $return->{return_date} eq $return->{today}, "Item returned with no return date specified has todays date" ); -$dbh->do("TRUNCATE TABLE old_issues"); +$dbh->do("DELETE FROM old_issues"); C4::Circulation::AddIssue( $borrower_1, 'barcode_1', $daysago10, 0, $today ); AddReturn('barcode_1', undef, undef, undef, '2014-04-01 23:42'); $return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" ); ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" ); +my $itemnumber; +($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem( + { + barcode => 'barcode_3', + itemcallnumber => 'callnumber3', + homebranch => $samplebranch1->{branchcode}, + holdingbranch => $samplebranch1->{branchcode}, + notforloan => 1, + }, + $biblionumber +); + +C4::Context->set_preference( 'UpdateNotForLoanStatusOnCheckin', q{} ); +AddReturn( 'barcode_3', $samplebranch1->{branchcode} ); +my $item = GetItem( $itemnumber ); +ok( $item->{notforloan} eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' ); + +C4::Context->set_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' ); +AddReturn( 'barcode_3', $samplebranch1->{branchcode} ); +$item = GetItem( $itemnumber ); +ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} ); + +AddReturn( 'barcode_3', $samplebranch1->{branchcode} ); +$item = GetItem( $itemnumber ); +ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} ); + + #End transaction $dbh->rollback;