Lines 16-21
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
use utf8; |
19 |
|
20 |
|
20 |
use DateTime; |
21 |
use DateTime; |
21 |
use C4::Biblio; |
22 |
use C4::Biblio; |
Lines 27-33
use C4::Overdues qw(UpdateFine);
Link Here
|
27 |
use Koha::DateUtils; |
28 |
use Koha::DateUtils; |
28 |
use Koha::Database; |
29 |
use Koha::Database; |
29 |
|
30 |
|
30 |
use Test::More tests => 61; |
31 |
use Test::More tests => 69; |
31 |
|
32 |
|
32 |
BEGIN { |
33 |
BEGIN { |
33 |
use_ok('C4::Circulation'); |
34 |
use_ok('C4::Circulation'); |
Lines 594-599
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
594 |
is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" ); |
595 |
is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" ); |
595 |
} |
596 |
} |
596 |
|
597 |
|
|
|
598 |
##Preparing test Objects for the testReturnToShelvingCart() because none are available in this context. |
599 |
##The test can be easily moved to another context. |
600 |
#Create another record |
601 |
my $biblio = MARC::Record->new(); |
602 |
$biblio->append_fields( |
603 |
MARC::Field->new('100', ' ', ' ', a => 'The Anonymous'), |
604 |
MARC::Field->new('245', ' ', ' ', a => 'Something is worng here') |
605 |
); |
606 |
my ($biblionumber, $biblioitemnumber, $itemnumber) = C4::Biblio::AddBiblio($biblio, ''); |
607 |
$biblio = C4::Biblio::GetBiblio($biblionumber); |
608 |
#Create any circulable item |
609 |
($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem( |
610 |
{ |
611 |
homebranch => 'CPL', |
612 |
holdingbranch => 'CPL', |
613 |
barcode => 'SauliNiinistö', |
614 |
}, |
615 |
$biblionumber |
616 |
); |
617 |
$item = C4::Items::GetItem($itemnumber); |
618 |
# Create a borrower |
619 |
my $borrowernumber = C4::Members::AddMember( |
620 |
firstname => 'Fridolyn', |
621 |
surname => 'SOMERS', |
622 |
categorycode => 'S', |
623 |
branchcode => 'CPL', |
624 |
); |
625 |
$borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); |
626 |
testReturnToShelvingCart($borrower, $item); |
627 |
|
597 |
$dbh->rollback; |
628 |
$dbh->rollback; |
598 |
|
629 |
|
599 |
1; |
630 |
1; |
600 |
- |
631 |
|
|
|
632 |
=head1 testReturnToShelvingCart |
633 |
|
634 |
testReturnToShelvingCart($borrower, $item); |
635 |
|
636 |
Runs 8 tests for the ReturnToShelvingCart-feature. |
637 |
|
638 |
@PARAM1, borrower-hash from koha.borrowers-table, can be any Borrower who can check-out/in |
639 |
@PARAM2, item-hash from koha-items-table, can be any Item which can be circulated |
640 |
|
641 |
=cut |
642 |
|
643 |
sub testReturnToShelvingCart { |
644 |
my $borrower = shift; #Any borrower who can check-in-out will do. |
645 |
my $item = shift; #Any Item that can be circulated will do. |
646 |
my $originalIssues = C4::Circulation::GetIssues({borrowernumber => $borrower->{borrowernumber}}); |
647 |
my $originalReturnToShelvingCart = C4::Context->preference('ReturnToShelvingCart'); #Store the original preference so we can rollback changes |
648 |
C4::Context->set_preference('ReturnToShelvingCart', 1) unless $originalReturnToShelvingCart; #Make sure it is 'Move' |
649 |
|
650 |
#TEST1: Make sure the Item has an intelligible location and permanent_location |
651 |
my $location = 'BOOK'; |
652 |
my $anotherLocation = 'SHELF'; |
653 |
C4::Items::ModItem({location => $location}, $item->{biblionumber}, $item->{itemnumber}); |
654 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
655 |
ok($item->{permanent_location} eq $location, "ReturnToShelvingCart: Setting a proper location succeeded."); |
656 |
|
657 |
#TEST2: It makes no difference in which state the Item is, when it is returned, the location changes to 'CART' |
658 |
C4::Circulation::AddReturn($item->{barcode}, $borrower->{branchcode}); |
659 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
660 |
ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Item returned, location and permanent_location OK!"); |
661 |
|
662 |
#TEST3: Editing the Item didn't screw up the permanent_location |
663 |
C4::Items::ModItem({price => 12}, $item->{biblionumber}, $item->{itemnumber}); |
664 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
665 |
ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Minor modifying an Item doesn't overwrite permanent_location!"); |
666 |
|
667 |
#TEST4: Checking an Item out to test another possible state. |
668 |
C4::Items::ModItem({location => $location}, $item->{biblionumber}, $item->{itemnumber}); #Reset the original location, as if the cart_to_Shelf.pl-script has been ran. |
669 |
C4::Circulation::AddIssue($borrower, $item->{barcode}); |
670 |
my $issues = C4::Circulation::GetIssues({borrowernumber => $borrower->{borrowernumber}}); |
671 |
ok( scalar(@$originalIssues)+1 == scalar(@$issues) ,"ReturnToShelvingCart: Adding an Issue succeeded!" ); |
672 |
|
673 |
#TEST5: |
674 |
C4::Circulation::AddReturn($item->{barcode}, $borrower->{branchcode}); |
675 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
676 |
ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Item returned again, location and permanent_location OK!"); |
677 |
|
678 |
#TEST6: Editing the Item without a permanent_location |
679 |
# (like when Editing the item using the staff clients editing view @ additem.pl?biblionumber=469263) |
680 |
# didn't screw up the permanent_location |
681 |
delete $item->{permanent_location}; |
682 |
C4::Items::ModItem($item, $item->{biblionumber}, $item->{itemnumber}); |
683 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
684 |
ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Modifying the whole Item doesn't overwrite permanent_location!"); |
685 |
|
686 |
#TEST7: Modifying only the permanent_location is an interesting option! So our Item is in 'CART', but we want to keep it there (hypothetically) and change the real location! |
687 |
C4::Items::ModItem({permanent_location => $anotherLocation}, $item->{biblionumber}, $item->{itemnumber}); |
688 |
$item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. |
689 |
ok($item->{permanent_location} eq $anotherLocation && $item->{location} eq 'CART', "ReturnToShelvingCart: Modifying the permanent_location while the location is 'CART'."); |
690 |
|
691 |
#TEST8: Adding an Item without a permanent_location defined... Justin Case |
692 |
my $yetAnotherLocation = 'STAFF'; |
693 |
my ( $xyz4lol, $whysomany4, $addedItemnumber ) = C4::Items::AddItem( |
694 |
{ |
695 |
location => $yetAnotherLocation, |
696 |
homebranch => 'CPL', |
697 |
holdingbranch => 'MPL', |
698 |
barcode => 'Hölökyn kölökyn', |
699 |
replacementprice => 16.00 |
700 |
}, |
701 |
$item->{biblionumber} |
702 |
); |
703 |
my $addedItem = C4::Items::GetItem($addedItemnumber); |
704 |
ok($item->{permanent_location} eq $yetAnotherLocation && $item->{location} eq $yetAnotherLocation, "ReturnToShelvingCart: Adding a new Item with location also sets the permanent_location."); |
705 |
|
706 |
C4::Context->set_preference('ReturnToShelvingCart', $originalReturnToShelvingCart) unless $originalReturnToShelvingCart; #Set it to the original value |
707 |
} |