| 
      
            Lines 19-25
          
      
      
        Link Here
      
     | 
  
        
          | 19 | 
           | 
          19 | 
           | 
        
        
          | 20 | 
          use Modern::Perl;  | 
          20 | 
          use Modern::Perl;  | 
        
        
          | 21 | 
           | 
          21 | 
           | 
        
          
            
              | 22 | 
              use Test::More tests => 7;  | 
              22 | 
              use Test::More tests => 8;  | 
            
        
          | 23 | 
           | 
          23 | 
           | 
        
        
          | 24 | 
          use C4::Circulation;  | 
          24 | 
          use C4::Circulation;  | 
        
        
          | 25 | 
          use Koha::Item;  | 
          25 | 
          use Koha::Item;  | 
        
  
    | 
      
            Lines 41-46
          my $new_item_1  = Koha::Item->new(
      
      
        Link Here
      
     | 
  
        
          | 41 | 
                  homebranch       => $library->{branchcode}, | 
          41 | 
                  homebranch       => $library->{branchcode}, | 
        
        
          | 42 | 
                  holdingbranch    => $library->{branchcode}, | 
          42 | 
                  holdingbranch    => $library->{branchcode}, | 
        
        
          | 43 | 
                  barcode          => "a_barcode_for_t",  | 
          43 | 
                  barcode          => "a_barcode_for_t",  | 
        
            
               | 
               | 
              44 | 
                      itype            => 'BK',  | 
            
        
          | 44 | 
              }  | 
          45 | 
              }  | 
        
        
          | 45 | 
          )->store;  | 
          46 | 
          )->store;  | 
        
        
          | 46 | 
          my $new_item_2 = Koha::Item->new(  | 
          47 | 
          my $new_item_2 = Koha::Item->new(  | 
        
  
    | 
      
            Lines 49-57
          my $new_item_2 = Koha::Item->new(
      
      
        Link Here
      
     | 
  
        
          | 49 | 
                  homebranch       => $library->{branchcode}, | 
          50 | 
                  homebranch       => $library->{branchcode}, | 
        
        
          | 50 | 
                  holdingbranch    => $library->{branchcode}, | 
          51 | 
                  holdingbranch    => $library->{branchcode}, | 
        
        
          | 51 | 
                  barcode          => "another_barcode_for_t",  | 
          52 | 
                  barcode          => "another_barcode_for_t",  | 
        
            
               | 
               | 
              53 | 
                      itype            => 'BK',  | 
            
        
          | 52 | 
              }  | 
          54 | 
              }  | 
        
        
          | 53 | 
          )->store;  | 
          55 | 
          )->store;  | 
        
        
          | 54 | 
           | 
          56 | 
           | 
        
            
               | 
               | 
              57 | 
              C4::Context->_new_userenv('xxx'); | 
            
            
              | 58 | 
              C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); | 
            
            
              | 59 | 
               | 
            
        
          | 55 | 
          like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' );  | 
          60 | 
          like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' );  | 
        
        
          | 56 | 
          is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' );  | 
          61 | 
          is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' );  | 
        
        
          | 57 | 
           | 
          62 | 
           | 
        
  
    | 
      
            Lines 90-95
          subtest 'biblioitem' => sub {
      
      
        Link Here
      
     | 
  
        
          | 90 | 
              is( $biblioitem->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblioitem should return the correct biblioitem' );  | 
          95 | 
              is( $biblioitem->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblioitem should return the correct biblioitem' );  | 
        
        
          | 91 | 
          };  | 
          96 | 
          };  | 
        
        
          | 92 | 
           | 
          97 | 
           | 
        
            
               | 
               | 
              98 | 
              subtest 'checkout' => sub { | 
            
            
              | 99 | 
                  plan tests => 5;  | 
            
            
              | 100 | 
                  my $item = Koha::Items->find( $new_item_1->itemnumber );  | 
            
            
              | 101 | 
                  # No checkout yet  | 
            
            
              | 102 | 
                  my $checkout = $item->checkout;  | 
            
            
              | 103 | 
                  is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' );  | 
            
            
              | 104 | 
               | 
            
            
              | 105 | 
                  # Add a checkout  | 
            
            
              | 106 | 
                  my $patron = $builder->build({ source => 'Borrower' }); | 
            
            
              | 107 | 
                  C4::Circulation::AddIssue( $patron, $item->barcode );  | 
            
            
              | 108 | 
                  $checkout = $retrieved_item_1->checkout;  | 
            
            
              | 109 | 
                  is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' );  | 
            
            
              | 110 | 
                  is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' );  | 
            
            
              | 111 | 
                  is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' ); | 
            
            
              | 112 | 
               | 
            
            
              | 113 | 
                  # Do the return  | 
            
            
              | 114 | 
                  C4::Circulation::AddReturn( $item->barcode );  | 
            
            
              | 115 | 
               | 
            
            
              | 116 | 
                  # There is no more checkout on this item, making sure it will not return old checkouts  | 
            
            
              | 117 | 
                  $checkout = $item->checkout;  | 
            
            
              | 118 | 
                  is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' );  | 
            
            
              | 119 | 
              };  | 
            
            
              | 120 | 
               | 
            
        
          | 93 | 
          $retrieved_item_1->delete;  | 
          121 | 
          $retrieved_item_1->delete;  | 
        
        
          | 94 | 
          is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );  | 
          122 | 
          is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );  | 
        
        
          | 95 | 
           | 
          123 | 
           | 
        
            
              | 96 | 
              -   | 
               | 
               |