| Lines 135-169
          subtest 'waiting_or_in_transit' => sub {
      
      
        Link Here | 
        
          | 135 | }; | 135 | }; | 
        
          | 136 |  | 136 |  | 
        
          | 137 | subtest 'can_be_transferred' => sub { | 137 | subtest 'can_be_transferred' => sub { | 
          
            
              | 138 |     plan tests => 11; | 138 |     plan tests => 8; | 
        
          | 139 |  | 139 |  | 
        
          | 140 |     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); | 140 |     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); | 
        
          | 141 |     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); | 141 |     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); | 
        
          | 142 |  | 142 |  | 
          
            
              | 143 |     my $library1 = $builder->build( { source => 'Branch' } )->{branchcode}; | 143 |     my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); | 
            
              | 144 |     my $library2 = $builder->build( { source => 'Branch' } )->{branchcode}; | 144 |     my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); | 
            
              | 145 |     my $library3 = $builder->build( { source => 'Branch' } )->{branchcode}; | 145 |     my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); | 
        
          | 146 |     my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); | 146 |     my ($bibnum, $title, $bibitemnum) = create_helper_biblio('ONLY1'); | 
        
          | 147 |     my ($item_bibnum, $item_bibitemnum, $itemnumber) | 147 |     my ($item_bibnum, $item_bibitemnum, $itemnumber) | 
          
            
              | 148 |         = AddItem({ homebranch => $library1, holdingbranch => $library1 }, $bibnum); | 148 |         = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $bibnum); | 
        
          | 149 |     my $item  = Koha::Items->find($itemnumber); | 149 |     my $item  = Koha::Items->find($itemnumber); | 
        
          | 150 |     my $biblio = Koha::Biblios->find($bibnum); | 150 |     my $biblio = Koha::Biblios->find($bibnum); | 
        
          | 151 |  | 151 |  | 
        
          | 152 |     is(Koha::Item::Transfer::Limits->search({ | 152 |     is(Koha::Item::Transfer::Limits->search({ | 
          
            
              | 153 |         fromBranch => $library1, | 153 |         fromBranch => $library1->branchcode, | 
            
              | 154 |         toBranch => $library2, | 154 |         toBranch => $library2->branchcode, | 
        
          | 155 |     })->count, 0, 'There are no transfer limits between libraries.'); | 155 |     })->count, 0, 'There are no transfer limits between libraries.'); | 
        
          | 156 |     ok($biblio->can_be_transferred({ to => $library2 }), | 156 |     ok($biblio->can_be_transferred({ to => $library2 }), | 
        
          | 157 |         'Some items of this biblio can be transferred between libraries.'); | 157 |         'Some items of this biblio can be transferred between libraries.'); | 
        
          | 158 |  | 158 |  | 
        
          | 159 |     my $limit = Koha::Item::Transfer::Limit->new({ | 159 |     my $limit = Koha::Item::Transfer::Limit->new({ | 
          
            
              | 160 |         fromBranch => $library1, | 160 |         fromBranch => $library1->branchcode, | 
            
              | 161 |         toBranch => $library2, | 161 |         toBranch => $library2->branchcode, | 
        
          | 162 |         itemtype => $item->effective_itemtype, | 162 |         itemtype => $item->effective_itemtype, | 
        
          | 163 |     })->store; | 163 |     })->store; | 
        
          | 164 |     is(Koha::Item::Transfer::Limits->search({ | 164 |     is(Koha::Item::Transfer::Limits->search({ | 
          
            
              | 165 |         fromBranch => $library1, | 165 |         fromBranch => $library1->branchcode, | 
            
              | 166 |         toBranch => $library2, | 166 |         toBranch => $library2->branchcode, | 
        
          | 167 |     })->count, 1, 'Given we have added a transfer limit that applies for all ' | 167 |     })->count, 1, 'Given we have added a transfer limit that applies for all ' | 
        
          | 168 |         .'of this biblio\s items,'); | 168 |         .'of this biblio\s items,'); | 
        
          | 169 |     is($biblio->can_be_transferred({ to => $library2 }), 0, | 169 |     is($biblio->can_be_transferred({ to => $library2 }), 0, | 
  
    | Lines 171-199
          subtest 'can_be_transferred' => sub {
      
      
        Link Here | 
        
          | 171 |         .'libraries.'); | 171 |         .'libraries.'); | 
        
          | 172 |     is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, | 172 |     is($biblio->can_be_transferred({ to => $library2, from => $library1 }), 0, | 
        
          | 173 |          'We get the same result also if we pass the from-library parameter.'); | 173 |          'We get the same result also if we pass the from-library parameter.'); | 
          
            
              | 174 |     $item->holdingbranch($library2)->store; | 174 |     $item->holdingbranch($library2->branchcode)->store; | 
        
          | 175 |     is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' | 175 |     is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the ' | 
        
          | 176 |          .'items is already located at to-library, then the transfer is possible.'); | 176 |          .'items is already located at to-library, then the transfer is possible.'); | 
          
            
              | 177 |     $item->holdingbranch($library1)->store; | 177 |     $item->holdingbranch($library1->branchcode)->store; | 
        
          | 178 |     my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) | 178 |     my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) | 
          
            
              | 179 |         = AddItem({ homebranch => $library1, holdingbranch => $library3 }, $bibnum); | 179 |         = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $bibnum); | 
        
          | 180 |     my $item2  = Koha::Items->find($itemnumber2); | 180 |     my $item2  = Koha::Items->find($itemnumber2); | 
        
          | 181 |     is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' | 181 |     is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added ' | 
        
          | 182 |         .'another item that should have no transfer limits applying on, then ' | 182 |         .'another item that should have no transfer limits applying on, then ' | 
        
          | 183 |         .'the transfer is possible.'); | 183 |         .'the transfer is possible.'); | 
          
            
              | 184 |     $item2->holdingbranch($library1)->store; | 184 |     $item2->holdingbranch($library1->branchcode)->store; | 
        
          | 185 |     is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' | 185 |     is($biblio->can_be_transferred({ to => $library2 }), 0, 'Given all of items' | 
        
          | 186 |         .' of the biblio are from same, transfer limited library, then transfer' | 186 |         .' of the biblio are from same, transfer limited library, then transfer' | 
        
          | 187 |         .' is not possible.'); | 187 |         .' is not possible.'); | 
            
              | 188 |     throws_ok { $biblio->can_be_transferred({ to => undef }); } |  |  | 
            
              | 189 |               'Koha::Exceptions::Library::NotFound', | 
            
              | 190 |               'Exception thrown when no library given.'; | 
            
              | 191 |     throws_ok { $biblio->can_be_transferred({ to => 'heaven' }); } | 
            
              | 192 |               'Koha::Exceptions::Library::NotFound', | 
            
              | 193 |               'Exception thrown when invalid library is given.'; | 
            
              | 194 |     throws_ok { $biblio->can_be_transferred({ to => $library2, from => 'hell' }); } | 
            
              | 195 |               'Koha::Exceptions::Library::NotFound', | 
            
              | 196 |               'Exception thrown when invalid library is given.'; | 
        
          | 197 | }; | 188 | }; | 
        
          | 198 |  | 189 |  | 
        
          | 199 | $schema->storage->txn_rollback; | 190 | $schema->storage->txn_rollback; |