| 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 26-32
          use C4::Reserves;
      
      
        Link Here | 
        
          | 26 | use Koha::DateUtils; | 27 | use Koha::DateUtils; | 
        
          | 27 | use Koha::Database; | 28 | use Koha::Database; | 
        
          | 28 |  | 29 |  | 
          
            
              | 29 | use Test::More tests => 59; | 30 | use Test::More tests => 66; | 
        
          | 30 |  | 31 |  | 
        
          | 31 | BEGIN { | 32 | BEGIN { | 
        
          | 32 |     use_ok('C4::Circulation'); | 33 |     use_ok('C4::Circulation'); | 
  
    | Lines 539-544
          C4::Context->dbh->do("DELETE FROM accountlines");
      
      
        Link Here | 
        
          | 539 |  | 540 |  | 
        
          | 540 | } | 541 | } | 
        
          | 541 |  | 542 |  | 
            
              |  |  | 543 | ##Preparing test Objects for the testReturnToShelvingCart() because none are available in this context. | 
            
              | 544 | ##The test can be easily moved to another context. | 
            
              | 545 | #Create another record | 
            
              | 546 | my $biblio = MARC::Record->new(); | 
            
              | 547 | $biblio->append_fields( | 
            
              | 548 |     MARC::Field->new('100', ' ', ' ', a => 'The Anonymous'), | 
            
              | 549 |     MARC::Field->new('245', ' ', ' ', a => 'Something is worng here') | 
            
              | 550 | ); | 
            
              | 551 | my ($biblionumber, $biblioitemnumber, $itemnumber) = C4::Biblio::AddBiblio($biblio, ''); | 
            
              | 552 | $biblio = C4::Biblio::GetBiblio($biblionumber); | 
            
              | 553 | #Create any circulable item | 
            
              | 554 | ($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem( | 
            
              | 555 |     { | 
            
              | 556 |         homebranch       => 'CPL', | 
            
              | 557 |         holdingbranch    => 'CPL', | 
            
              | 558 |         barcode          => 'SauliNiinistö', | 
            
              | 559 |     }, | 
            
              | 560 |     $biblionumber | 
            
              | 561 | ); | 
            
              | 562 | $item = C4::Items::GetItem($itemnumber); | 
            
              | 563 | # Create a borrower | 
            
              | 564 | my $borrowernumber = C4::Members::AddMember( | 
            
              | 565 |     firstname =>  'Fridolyn', | 
            
              | 566 |     surname => 'SOMERS', | 
            
              | 567 |     categorycode => 'S', | 
            
              | 568 |     branchcode => 'CPL', | 
            
              | 569 | ); | 
            
              | 570 | $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); | 
            
              | 571 | testReturnToShelvingCart($borrower, $item); | 
            
              | 572 |  | 
        
          | 542 | $dbh->rollback; | 573 | $dbh->rollback; | 
        
          | 543 |  | 574 |  | 
        
          | 544 | 1; | 575 | 1; | 
          
            
              | 545 | -  | 576 |  | 
            
              |  |  | 577 | =head testReturnToShelvingCart | 
            
              | 578 |  | 
            
              | 579 |     testReturnToShelvingCart($borrower, $item); | 
            
              | 580 |  | 
            
              | 581 |     Runs 7 tests for the ReturnToShelvingCart-feature. | 
            
              | 582 |  | 
            
              | 583 | @PARAM1, borrower-hash from koha.borrowers-table, can be any Borrower who can check-out/in | 
            
              | 584 | @PARAM2, item-hash from koha-items-table, can be any Item which can be circulated | 
            
              | 585 |  | 
            
              | 586 | =cut | 
            
              | 587 | sub testReturnToShelvingCart { | 
            
              | 588 |     my $borrower = shift; #Any borrower who can check-in-out will do. | 
            
              | 589 |     my $item = shift; #Any Item that can be circulated will do. | 
            
              | 590 |     my $originalIssues = C4::Circulation::GetIssues({borrowernumber => $borrower->{borrowernumber}}); | 
            
              | 591 |     my $originalReturnToShelvingCart = C4::Context->preference('ReturnToShelvingCart'); #Store the original preference so we can rollback changes | 
            
              | 592 |     C4::Context->set_preference('ReturnToShelvingCart', 1) unless $originalReturnToShelvingCart; #Make sure it is 'Move' | 
            
              | 593 |  | 
            
              | 594 |     #TEST1: Make sure the Item has an intelligible location and permanent_location | 
            
              | 595 |     my $location = 'BOOK'; | 
            
              | 596 |     my $anotherLocation = 'SHELF'; | 
            
              | 597 |     C4::Items::ModItem({location => $location}, $item->{biblionumber}, $item->{itemnumber}); | 
            
              | 598 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 599 |     ok($item->{permanent_location} eq $location, "ReturnToShelvingCart: Setting a proper location succeeded."); | 
            
              | 600 |  | 
            
              | 601 |     #TEST2: It makes no difference in which state the Item is, when it is returned, the location changes to 'CART' | 
            
              | 602 |     C4::Circulation::AddReturn($item->{barcode}, $borrower->{branchcode}); | 
            
              | 603 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 604 |     ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Item returned, location and permanent_location OK!"); | 
            
              | 605 |  | 
            
              | 606 |     #TEST3: Editing the Item didn't screw up the permanent_location | 
            
              | 607 |     C4::Items::ModItem({price => 12}, $item->{biblionumber}, $item->{itemnumber}); | 
            
              | 608 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 609 |     ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Minor modifying an Item doesn't overwrite permanent_location!"); | 
            
              | 610 |  | 
            
              | 611 |     #TEST4: Checking an Item out to test another possible state. | 
            
              | 612 |     C4::Items::ModItem({location => $location}, $item->{biblionumber}, $item->{itemnumber}); #Reset the original location, as if the cart_to_Shelf.pl-script has been ran. | 
            
              | 613 |     C4::Circulation::AddIssue($borrower, $item->{barcode}); | 
            
              | 614 |     my $issues = C4::Circulation::GetIssues({borrowernumber => $borrower->{borrowernumber}}); | 
            
              | 615 |     ok(  scalar(@$originalIssues)+1 == scalar(@$issues)  ,"ReturnToShelvingCart: Adding an Issue succeeded!"  ); | 
            
              | 616 |  | 
            
              | 617 |     #TEST5: | 
            
              | 618 |     C4::Circulation::AddReturn($item->{barcode}, $borrower->{branchcode}); | 
            
              | 619 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 620 |     ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Item returned again, location and permanent_location OK!"); | 
            
              | 621 |  | 
            
              | 622 |     #TEST6: Editing the Item without a permanent_location | 
            
              | 623 |     #  (like when Editing the item using the staff clients editing view @ additem.pl?biblionumber=469263) | 
            
              | 624 |     #  didn't screw up the permanent_location | 
            
              | 625 |     delete $item->{permanent_location}; | 
            
              | 626 |     C4::Items::ModItem($item, $item->{biblionumber}, $item->{itemnumber}); | 
            
              | 627 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 628 |     ok($item->{permanent_location} eq $location && $item->{location} eq 'CART', "ReturnToShelvingCart: Modifying the whole Item doesn't overwrite permanent_location!"); | 
            
              | 629 |  | 
            
              | 630 |     #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! | 
            
              | 631 |     C4::Items::ModItem({permanent_location => $anotherLocation}, $item->{biblionumber}, $item->{itemnumber}); | 
            
              | 632 |     $item = C4::Items::GetItem($item->{itemnumber}); #Update the DB changes. | 
            
              | 633 |     ok($item->{permanent_location} eq $anotherLocation && $item->{location} eq 'CART', "ReturnToShelvingCart: Modifying the permanent_location while the location is 'CART'."); | 
            
              | 634 |  | 
            
              | 635 |     C4::Context->set_preference('ReturnToShelvingCart', $originalReturnToShelvingCart) unless $originalReturnToShelvingCart; #Set it to the original value | 
            
              | 636 | } |