| 
      
            Lines 17-23
          
      
      
        Link Here
      
     | 
  
        
          | 17 | 
           | 
          17 | 
           | 
        
        
          | 18 | 
          use Modern::Perl;  | 
          18 | 
          use Modern::Perl;  | 
        
        
          | 19 | 
           | 
          19 | 
           | 
        
          
            
              | 20 | 
              use Test::More tests => 77;  | 
              20 | 
              use Test::More tests => 73;  | 
            
        
          | 21 | 
          use Test::MockModule;  | 
          21 | 
          use Test::MockModule;  | 
        
        
          | 22 | 
          use Test::Warn;  | 
          22 | 
          use Test::Warn;  | 
        
        
          | 23 | 
           | 
          23 | 
           | 
        
  
    | 
      
            Lines 32-38
          use C4::Items;
      
      
        Link Here
      
     | 
  
        
          | 32 | 
          use C4::Biblio qw( GetMarcFromKohaField ModBiblio );  | 
          32 | 
          use C4::Biblio qw( GetMarcFromKohaField ModBiblio );  | 
        
        
          | 33 | 
          use C4::HoldsQueue;  | 
          33 | 
          use C4::HoldsQueue;  | 
        
        
          | 34 | 
          use C4::Members;  | 
          34 | 
          use C4::Members;  | 
        
          
            
              | 35 | 
              use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );  | 
              35 | 
              use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );  | 
            
        
          | 36 | 
          use Koha::ActionLogs;  | 
          36 | 
          use Koha::ActionLogs;  | 
        
        
          | 37 | 
          use Koha::Biblios;  | 
          37 | 
          use Koha::Biblios;  | 
        
        
          | 38 | 
          use Koha::Caches;  | 
          38 | 
          use Koha::Caches;  | 
        
  
    | 
      
            Lines 44-49
          use Koha::Notice::Templates;
      
      
        Link Here
      
     | 
  
        
          | 44 | 
          use Koha::Patrons;  | 
          44 | 
          use Koha::Patrons;  | 
        
        
          | 45 | 
          use Koha::Patron::Categories;  | 
          45 | 
          use Koha::Patron::Categories;  | 
        
        
          | 46 | 
          use Koha::CirculationRules;  | 
          46 | 
          use Koha::CirculationRules;  | 
        
            
               | 
               | 
              47 | 
              use Koha::Policy::Patrons::Holds;  | 
            
        
          | 47 | 
           | 
          48 | 
           | 
        
        
          | 48 | 
          BEGIN { | 
          49 | 
          BEGIN { | 
        
        
          | 49 | 
              require_ok('C4::Reserves'); | 
          50 | 
              require_ok('C4::Reserves'); | 
        
  
    | 
      
            Lines 136-159
          $requesters{$branch_1} = Koha::Patron->new({
      
      
        Link Here
      
     | 
  
        
          | 136 | 
              branchcode   => $branch_1,  | 
          137 | 
              branchcode   => $branch_1,  | 
        
        
          | 137 | 
              categorycode => $category_2,  | 
          138 | 
              categorycode => $category_2,  | 
        
        
          | 138 | 
              surname      => "borrower from $branch_1",  | 
          139 | 
              surname      => "borrower from $branch_1",  | 
        
          
            
              | 139 | 
              })->store->borrowernumber;  | 
              140 | 
              })->store;  | 
            
        
          | 140 | 
          for my $i ( 2 .. 5 ) { | 
          141 | 
          for my $i ( 2 .. 5 ) { | 
        
        
          | 141 | 
              $requesters{"CPL$i"} = Koha::Patron->new({ | 
          142 | 
              $requesters{"CPL$i"} = Koha::Patron->new({ | 
        
        
          | 142 | 
                  branchcode   => $branch_1,  | 
          143 | 
                  branchcode   => $branch_1,  | 
        
        
          | 143 | 
                  categorycode => $category_2,  | 
          144 | 
                  categorycode => $category_2,  | 
        
        
          | 144 | 
                  surname      => "borrower $i from $branch_1",  | 
          145 | 
                  surname      => "borrower $i from $branch_1",  | 
        
          
            
              | 145 | 
                  })->store->borrowernumber;  | 
              146 | 
                  })->store;  | 
            
        
          | 146 | 
          }  | 
          147 | 
          }  | 
        
        
          | 147 | 
          $requesters{$branch_2} = Koha::Patron->new({ | 
          148 | 
          $requesters{$branch_2} = Koha::Patron->new({ | 
        
        
          | 148 | 
              branchcode   => $branch_2,  | 
          149 | 
              branchcode   => $branch_2,  | 
        
        
          | 149 | 
              categorycode => $category_2,  | 
          150 | 
              categorycode => $category_2,  | 
        
        
          | 150 | 
              surname      => "borrower from $branch_2",  | 
          151 | 
              surname      => "borrower from $branch_2",  | 
        
          
            
              | 151 | 
              })->store->borrowernumber;  | 
              152 | 
              })->store;  | 
            
        
          | 152 | 
          $requesters{$branch_3} = Koha::Patron->new({ | 
          153 | 
          $requesters{$branch_3} = Koha::Patron->new({ | 
        
        
          | 153 | 
              branchcode   => $branch_3,  | 
          154 | 
              branchcode   => $branch_3,  | 
        
        
          | 154 | 
              categorycode => $category_2,  | 
          155 | 
              categorycode => $category_2,  | 
        
        
          | 155 | 
              surname      => "borrower from $branch_3",  | 
          156 | 
              surname      => "borrower from $branch_3",  | 
        
          
            
              | 156 | 
              })->store->borrowernumber;  | 
              157 | 
              })->store;  | 
            
        
          | 157 | 
           | 
          158 | 
           | 
        
        
          | 158 | 
          # Configure rules so that $branch_1 allows only $branch_1 patrons  | 
          159 | 
          # Configure rules so that $branch_1 allows only $branch_1 patrons  | 
        
        
          | 159 | 
          # to request its items, while $branch_2 will allow its items  | 
          160 | 
          # to request its items, while $branch_2 will allow its items  | 
        
  
    | 
      
            Lines 222-228
          $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
      
      
        Link Here
      
     | 
  
        
          | 222 | 
          AddReserve(  | 
          223 | 
          AddReserve(  | 
        
        
          | 223 | 
              { | 
          224 | 
              { | 
        
        
          | 224 | 
                  branchcode     => $branch_3,  | 
          225 | 
                  branchcode     => $branch_3,  | 
        
          
            
              | 225 | 
                      borrowernumber => $requesters{$branch_3}, | 
              226 | 
                      borrowernumber => $requesters{$branch_3}->borrowernumber, | 
            
        
          | 226 | 
                  biblionumber   => $bibnum2,  | 
          227 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 227 | 
                  priority       => 1,  | 
          228 | 
                  priority       => 1,  | 
        
        
          | 228 | 
              }  | 
          229 | 
              }  | 
        
  
    | 
      
            Lines 230-236
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 230 | 
          AddReserve(  | 
          231 | 
          AddReserve(  | 
        
        
          | 231 | 
              { | 
          232 | 
              { | 
        
        
          | 232 | 
                  branchcode     => $branch_2,  | 
          233 | 
                  branchcode     => $branch_2,  | 
        
          
            
              | 233 | 
                      borrowernumber => $requesters{$branch_2}, | 
              234 | 
                      borrowernumber => $requesters{$branch_2}->borrowernumber, | 
            
        
          | 234 | 
                  biblionumber   => $bibnum2,  | 
          235 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 235 | 
                  priority       => 2,  | 
          236 | 
                  priority       => 2,  | 
        
        
          | 236 | 
              }  | 
          237 | 
              }  | 
        
  
    | 
      
            Lines 238-249
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 238 | 
          AddReserve(  | 
          239 | 
          AddReserve(  | 
        
        
          | 239 | 
              { | 
          240 | 
              { | 
        
        
          | 240 | 
                  branchcode     => $branch_1,  | 
          241 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 241 | 
                      borrowernumber => $requesters{$branch_1}, | 
              242 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 242 | 
                  biblionumber   => $bibnum2,  | 
          243 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 243 | 
                  priority       => 3,  | 
          244 | 
                  priority       => 3,  | 
        
        
          | 244 | 
              }  | 
          245 | 
              }  | 
        
        
          | 245 | 
          );  | 
          246 | 
          );  | 
        
          
            
              | 246 | 
              ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0); | 
              247 | 
              ModReserveAffect($itemnum_cpl, $requesters{$branch_3}->borrowernumber, 0); | 
            
        
          | 247 | 
           | 
          248 | 
           | 
        
        
          | 248 | 
          # Now it should have different priorities.  | 
          249 | 
          # Now it should have different priorities.  | 
        
        
          | 249 | 
          my $biblio = Koha::Biblios->find( $bibnum2 );  | 
          250 | 
          my $biblio = Koha::Biblios->find( $bibnum2 );  | 
        
  
    | 
      
            Lines 252-267
          is($holds->next->priority, 0, 'Item is correctly waiting');
      
      
        Link Here
      
     | 
  
        
          | 252 | 
          is($holds->next->priority, 1, 'Item is correctly priority 1');  | 
          253 | 
          is($holds->next->priority, 1, 'Item is correctly priority 1');  | 
        
        
          | 253 | 
          is($holds->next->priority, 2, 'Item is correctly priority 2');  | 
          254 | 
          is($holds->next->priority, 2, 'Item is correctly priority 2');  | 
        
        
          | 254 | 
           | 
          255 | 
           | 
        
          
            
              | 255 | 
              my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting->as_list; | 
              256 | 
              my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3}->borrowernumber })->waiting->as_list; | 
            
        
          | 256 | 
          is( @reserves, 1, 'GetWaiting got only the waiting reserve' );  | 
          257 | 
          is( @reserves, 1, 'GetWaiting got only the waiting reserve' );  | 
        
          
            
              | 257 | 
              is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' ); | 
              258 | 
              is( $reserves[0]->borrowernumber(), $requesters{$branch_3}->borrowernumber, 'GetWaiting got the reserve for the correct borrower' ); | 
            
        
          | 258 | 
           | 
          259 | 
           | 
        
        
          | 259 | 
           | 
          260 | 
           | 
        
        
          | 260 | 
          $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); | 
          261 | 
          $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); | 
        
        
          | 261 | 
          AddReserve(  | 
          262 | 
          AddReserve(  | 
        
        
          | 262 | 
              { | 
          263 | 
              { | 
        
        
          | 263 | 
                  branchcode     => $branch_3,  | 
          264 | 
                  branchcode     => $branch_3,  | 
        
          
            
              | 264 | 
                      borrowernumber => $requesters{$branch_3}, | 
              265 | 
                      borrowernumber => $requesters{$branch_3}->borrowernumber, | 
            
        
          | 265 | 
                  biblionumber   => $bibnum2,  | 
          266 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 266 | 
                  priority       => 1,  | 
          267 | 
                  priority       => 1,  | 
        
        
          | 267 | 
              }  | 
          268 | 
              }  | 
        
  
    | 
      
            Lines 269-275
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 269 | 
          AddReserve(  | 
          270 | 
          AddReserve(  | 
        
        
          | 270 | 
              { | 
          271 | 
              { | 
        
        
          | 271 | 
                  branchcode     => $branch_2,  | 
          272 | 
                  branchcode     => $branch_2,  | 
        
          
            
              | 272 | 
                      borrowernumber => $requesters{$branch_2}, | 
              273 | 
                      borrowernumber => $requesters{$branch_2}->borrowernumber, | 
            
        
          | 273 | 
                  biblionumber   => $bibnum2,  | 
          274 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 274 | 
                  priority       => 2,  | 
          275 | 
                  priority       => 2,  | 
        
        
          | 275 | 
              }  | 
          276 | 
              }  | 
        
  
    | 
      
            Lines 278-284
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 278 | 
          AddReserve(  | 
          279 | 
          AddReserve(  | 
        
        
          | 279 | 
              { | 
          280 | 
              { | 
        
        
          | 280 | 
                  branchcode     => $branch_1,  | 
          281 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 281 | 
                      borrowernumber => $requesters{$branch_1}, | 
              282 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 282 | 
                  biblionumber   => $bibnum2,  | 
          283 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 283 | 
                  priority       => 3,  | 
          284 | 
                  priority       => 3,  | 
        
        
          | 284 | 
              }  | 
          285 | 
              }  | 
        
  
    | 
      
            Lines 293-299
          my $messages;
      
      
        Link Here
      
     | 
  
        
          | 293 | 
          # requests cannot be filled by that item per policy.  | 
          294 | 
          # requests cannot be filled by that item per policy.  | 
        
        
          | 294 | 
          (undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2); | 
          295 | 
          (undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2); | 
        
        
          | 295 | 
          is( $messages->{ResFound}->{borrowernumber}, | 
          296 | 
          is( $messages->{ResFound}->{borrowernumber}, | 
        
          
            
              | 296 | 
                  $requesters{$branch_1}, | 
              297 | 
                  $requesters{$branch_1}->borrowernumber, | 
            
        
          | 297 | 
              'restrictive library\'s items only fill requests by own patrons (bug 10272)');  | 
          298 | 
              'restrictive library\'s items only fill requests by own patrons (bug 10272)');  | 
        
        
          | 298 | 
           | 
          299 | 
           | 
        
        
          | 299 | 
          # Return the FPL item at FPL.  The hold that should be triggered is  | 
          300 | 
          # Return the FPL item at FPL.  The hold that should be triggered is  | 
        
  
    | 
      
            Lines 305-311
          t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' );
      
      
        Link Here
      
     | 
  
        
          | 305 | 
           | 
          306 | 
           | 
        
        
          | 306 | 
          (undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2); | 
          307 | 
          (undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2); | 
        
        
          | 307 | 
          is( $messages->{ResFound}->{borrowernumber}, | 
          308 | 
          is( $messages->{ResFound}->{borrowernumber}, | 
        
          
            
              | 308 | 
                  $requesters{$branch_3}, | 
              309 | 
                  $requesters{$branch_3}->borrowernumber, | 
            
        
          | 309 | 
              'for generous library, its items fill first hold request in line (bug 10272)');  | 
          310 | 
              'for generous library, its items fill first hold request in line (bug 10272)');  | 
        
        
          | 310 | 
           | 
          311 | 
           | 
        
        
          | 311 | 
          $biblio = Koha::Biblios->find( $biblionumber );  | 
          312 | 
          $biblio = Koha::Biblios->find( $biblionumber );  | 
        
  
    | 
      
            Lines 320-326
          $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
      
      
        Link Here
      
     | 
  
        
          | 320 | 
          AddReserve(  | 
          321 | 
          AddReserve(  | 
        
        
          | 321 | 
              { | 
          322 | 
              { | 
        
        
          | 322 | 
                  branchcode     => $branch_1,  | 
          323 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 323 | 
                      borrowernumber => $requesters{$branch_1}, | 
              324 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 324 | 
                  biblionumber   => $bibnum,  | 
          325 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 325 | 
                  priority       => 1,  | 
          326 | 
                  priority       => 1,  | 
        
        
          | 326 | 
              }  | 
          327 | 
              }  | 
        
  
    | 
      
            Lines 338-344
          $resdate->add_duration(DateTime::Duration->new(days => 4));
      
      
        Link Here
      
     | 
  
        
          | 338 | 
          my $reserve_id = AddReserve(  | 
          339 | 
          my $reserve_id = AddReserve(  | 
        
        
          | 339 | 
              { | 
          340 | 
              { | 
        
        
          | 340 | 
                  branchcode       => $branch_1,  | 
          341 | 
                  branchcode       => $branch_1,  | 
        
          
            
              | 341 | 
                      borrowernumber   => $requesters{$branch_1}, | 
              342 | 
                      borrowernumber   => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 342 | 
                  biblionumber     => $bibnum,  | 
          343 | 
                  biblionumber     => $bibnum,  | 
        
        
          | 343 | 
                  priority         => 1,  | 
          344 | 
                  priority         => 1,  | 
        
        
          | 344 | 
                  reservation_date => $resdate,  | 
          345 | 
                  reservation_date => $resdate,  | 
        
  
    | 
      
            Lines 372-378
          my $now_holder = $builder->build_object({ class => 'Koha::Patrons', value => {
      
      
        Link Here
      
     | 
  
        
          | 372 | 
          my $now_reserve_id = AddReserve(  | 
          373 | 
          my $now_reserve_id = AddReserve(  | 
        
        
          | 373 | 
              { | 
          374 | 
              { | 
        
        
          | 374 | 
                  branchcode       => $branch_1,  | 
          375 | 
                  branchcode       => $branch_1,  | 
        
          
            
              | 375 | 
                      borrowernumber   => $requesters{$branch_1}, | 
              376 | 
                      borrowernumber   => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 376 | 
                  biblionumber     => $bibnum,  | 
          377 | 
                  biblionumber     => $bibnum,  | 
        
        
          | 377 | 
                  priority         => 2,  | 
          378 | 
                  priority         => 2,  | 
        
        
          | 378 | 
                  reservation_date => dt_from_string(),  | 
          379 | 
                  reservation_date => dt_from_string(),  | 
        
  
    | 
      
            Lines 391-402
          ModReserve({ reserve_id => $now_reserve_id, rank => 'del', cancellation_reason =
      
      
        Link Here
      
     | 
  
        
          | 391 | 
           | 
          392 | 
           | 
        
        
          | 392 | 
          # test marking a hold as captured  | 
          393 | 
          # test marking a hold as captured  | 
        
        
          | 393 | 
          my $hold_notice_count = count_hold_print_messages();  | 
          394 | 
          my $hold_notice_count = count_hold_print_messages();  | 
        
          
            
              | 394 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); | 
              395 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); | 
            
        
          | 395 | 
          my $new_count = count_hold_print_messages();  | 
          396 | 
          my $new_count = count_hold_print_messages();  | 
        
        
          | 396 | 
          is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');  | 
          397 | 
          is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');  | 
        
        
          | 397 | 
           | 
          398 | 
           | 
        
        
          | 398 | 
          # test that duplicate notices aren't generated  | 
          399 | 
          # test that duplicate notices aren't generated  | 
        
          
            
              | 399 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); | 
              400 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); | 
            
        
          | 400 | 
          $new_count = count_hold_print_messages();  | 
          401 | 
          $new_count = count_hold_print_messages();  | 
        
        
          | 401 | 
          is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');  | 
          402 | 
          is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');  | 
        
        
          | 402 | 
           | 
          403 | 
           | 
        
  
    | 
      
            Lines 422-428
          $resdate->add_duration(DateTime::Duration->new(days => 2));
      
      
        Link Here
      
     | 
  
        
          | 422 | 
          AddReserve(  | 
          423 | 
          AddReserve(  | 
        
        
          | 423 | 
              { | 
          424 | 
              { | 
        
        
          | 424 | 
                  branchcode       => $branch_1,  | 
          425 | 
                  branchcode       => $branch_1,  | 
        
          
            
              | 425 | 
                      borrowernumber   => $requesters{$branch_1}, | 
              426 | 
                      borrowernumber   => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 426 | 
                  biblionumber     => $bibnum,  | 
          427 | 
                  biblionumber     => $bibnum,  | 
        
        
          | 427 | 
                  priority         => 1,  | 
          428 | 
                  priority         => 1,  | 
        
        
          | 428 | 
                  reservation_date => $resdate,  | 
          429 | 
                  reservation_date => $resdate,  | 
        
  
    | 
      
            Lines 438-444
          $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
      
      
        Link Here
      
     | 
  
        
          | 438 | 
          AddReserve(  | 
          439 | 
          AddReserve(  | 
        
        
          | 439 | 
              { | 
          440 | 
              { | 
        
        
          | 440 | 
                  branchcode       => $branch_1,  | 
          441 | 
                  branchcode       => $branch_1,  | 
        
          
            
              | 441 | 
                      borrowernumber   => $requesters{$branch_1}, | 
              442 | 
                      borrowernumber   => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 442 | 
                  biblionumber     => $bibnum,  | 
          443 | 
                  biblionumber     => $bibnum,  | 
        
        
          | 443 | 
                  priority         => 1,  | 
          444 | 
                  priority         => 1,  | 
        
        
          | 444 | 
                  reservation_date => $resdate,  | 
          445 | 
                  reservation_date => $resdate,  | 
        
  
    | 
      
            Lines 448-454
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 448 | 
          $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); | 
          449 | 
          $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); | 
        
        
          | 449 | 
          is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );  | 
          450 | 
          is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );  | 
        
        
          | 450 | 
          # 9788c: current_holds returns future wait (confirmed future hold)  | 
          451 | 
          # 9788c: current_holds returns future wait (confirmed future hold)  | 
        
          
            
              | 451 | 
              ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); #confirm hold | 
              452 | 
              ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0); #confirm hold | 
            
        
          | 452 | 
          $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); | 
          453 | 
          $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); | 
        
        
          | 453 | 
          is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );  | 
          454 | 
          is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );  | 
        
        
          | 454 | 
          # End of tests for bug 9788  | 
          455 | 
          # End of tests for bug 9788  | 
        
  
    | 
      
            Lines 460-466
          is($p, 4, 'CalculatePriority should now return priority 4');
      
      
        Link Here
      
     | 
  
        
          | 460 | 
          AddReserve(  | 
          461 | 
          AddReserve(  | 
        
        
          | 461 | 
              { | 
          462 | 
              { | 
        
        
          | 462 | 
                  branchcode     => $branch_1,  | 
          463 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 463 | 
                      borrowernumber => $requesters{'CPL2'}, | 
              464 | 
                      borrowernumber => $requesters{'CPL2'}->borrowernumber, | 
            
        
          | 464 | 
                  biblionumber   => $bibnum2,  | 
          465 | 
                  biblionumber   => $bibnum2,  | 
        
        
          | 465 | 
                  priority       => $p,  | 
          466 | 
                  priority       => $p,  | 
        
        
          | 466 | 
              }  | 
          467 | 
              }  | 
        
  
    | 
      
            Lines 475-481
          is($p, 1, 'CalculatePriority should now return priority 1');
      
      
        Link Here
      
     | 
  
        
          | 475 | 
          AddReserve(  | 
          476 | 
          AddReserve(  | 
        
        
          | 476 | 
              { | 
          477 | 
              { | 
        
        
          | 477 | 
                  branchcode     => $branch_1,  | 
          478 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 478 | 
                      borrowernumber => $requesters{$branch_1}, | 
              479 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 479 | 
                  biblionumber   => $bibnum,  | 
          480 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 480 | 
                  priority       => $p,  | 
          481 | 
                  priority       => $p,  | 
        
        
          | 481 | 
                  itemnumber     => $item->itemnumber,  | 
          482 | 
                  itemnumber     => $item->itemnumber,  | 
        
  
    | 
      
            Lines 483-496
          AddReserve(
      
      
        Link Here
      
     | 
  
        
          | 483 | 
          );  | 
          484 | 
          );  | 
        
        
          | 484 | 
          $p = C4::Reserves::CalculatePriority($bibnum);  | 
          485 | 
          $p = C4::Reserves::CalculatePriority($bibnum);  | 
        
        
          | 485 | 
          is($p, 2, 'CalculatePriority should now return priority 2');  | 
          486 | 
          is($p, 2, 'CalculatePriority should now return priority 2');  | 
        
          
            
              | 486 | 
              ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); | 
              487 | 
              ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0); | 
            
        
          | 487 | 
          $p = C4::Reserves::CalculatePriority($bibnum);  | 
          488 | 
          $p = C4::Reserves::CalculatePriority($bibnum);  | 
        
        
          | 488 | 
          is($p, 1, 'CalculatePriority should now return priority 1');  | 
          489 | 
          is($p, 1, 'CalculatePriority should now return priority 1');  | 
        
        
          | 489 | 
          #add another biblio hold, no resdate  | 
          490 | 
          #add another biblio hold, no resdate  | 
        
        
          | 490 | 
          AddReserve(  | 
          491 | 
          AddReserve(  | 
        
        
          | 491 | 
              { | 
          492 | 
              { | 
        
        
          | 492 | 
                  branchcode     => $branch_1,  | 
          493 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 493 | 
                      borrowernumber => $requesters{'CPL2'}, | 
              494 | 
                      borrowernumber => $requesters{'CPL2'}->borrowernumber, | 
            
        
          | 494 | 
                  biblionumber   => $bibnum,  | 
          495 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 495 | 
                  priority       => $p,  | 
          496 | 
                  priority       => $p,  | 
        
        
          | 496 | 
              }  | 
          497 | 
              }  | 
        
  
    | 
      
            Lines 504-510
          $resdate->add_duration(DateTime::Duration->new(days => 1));
      
      
        Link Here
      
     | 
  
        
          | 504 | 
          AddReserve(  | 
          505 | 
          AddReserve(  | 
        
        
          | 505 | 
              { | 
          506 | 
              { | 
        
        
          | 506 | 
                  branchcode     => $branch_1,  | 
          507 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 507 | 
                      borrowernumber => $requesters{'CPL2'}, | 
              508 | 
                      borrowernumber => $requesters{'CPL2'}->borrowernumber, | 
            
        
          | 508 | 
                  biblionumber   => $bibnum,  | 
          509 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 509 | 
                  priority       => $p,  | 
          510 | 
                  priority       => $p,  | 
        
        
          | 510 | 
                  reservation_date => $resdate,  | 
          511 | 
                  reservation_date => $resdate,  | 
        
  
    | 
      
            Lines 561-614
          $dbh->do('DELETE FROM reserves', undef, ($bibnum));
      
      
        Link Here
      
     | 
  
        
          | 561 | 
          AddReserve(  | 
          562 | 
          AddReserve(  | 
        
        
          | 562 | 
              { | 
          563 | 
              { | 
        
        
          | 563 | 
                  branchcode     => $branch_1,  | 
          564 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 564 | 
                      borrowernumber => $requesters{$branch_1}, | 
              565 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 565 | 
                  biblionumber   => $bibnum,  | 
          566 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 566 | 
                  priority       => 1,  | 
          567 | 
                  priority       => 1,  | 
        
        
          | 567 | 
              }  | 
          568 | 
              }  | 
        
        
          | 568 | 
          );  | 
          569 | 
          );  | 
        
        
          | 569 | 
          my (undef, $canres, undef) = CheckReserves( $item );  | 
          570 | 
          my (undef, $canres, undef) = CheckReserves( $item );  | 
        
        
          | 570 | 
           | 
          571 | 
           | 
        
          
            
              | 571 | 
              is( CanReserveBeCanceledFromOpac(), undef,  | 
              572 | 
              my $hold      = Koha::Holds->find( $canres->{reserve_id} ); | 
            
            
              | 572 | 
                  'CanReserveBeCanceledFromOpac should return undef if called without any parameter'  | 
              573 | 
              my $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold ); | 
            
            
              | 573 | 
              );  | 
              574 | 
              ok( $cancancel, 'Can user cancel its own reserve' );  | 
            
            
              | 574 | 
              is(  | 
               | 
               | 
            
            
              | 575 | 
                  CanReserveBeCanceledFromOpac( $canres->{resserve_id} ), | 
            
            
              | 576 | 
                  undef,  | 
            
            
              | 577 | 
                  'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id'  | 
            
            
              | 578 | 
              );  | 
            
            
              | 579 | 
              is(  | 
            
            
              | 580 | 
                  CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ), | 
            
            
              | 581 | 
                  undef,  | 
            
            
              | 582 | 
                  'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber'  | 
            
            
              | 583 | 
              );  | 
            
            
              | 584 | 
               | 
            
            
              | 585 | 
              my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); | 
            
            
              | 586 | 
              is($cancancel, 1, 'Can user cancel its own reserve');  | 
            
        
          | 587 | 
           | 
          575 | 
           | 
        
          
            
              | 588 | 
              $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2}); | 
              576 | 
              $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_2}, $hold ); | 
            
            
              | 589 | 
              is($cancancel, 0, 'Other user cant cancel reserve');  | 
              577 | 
              ok( !$cancancel, 'Other user cant cancel reserve' );  | 
            
        
          | 590 | 
           | 
          578 | 
           | 
        
          
            
              | 591 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1); | 
              579 | 
              ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 1 ); | 
            
            
              | 592 | 
              $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); | 
              580 | 
              $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage ); | 
            
            
              | 593 | 
              is($cancancel, 0, 'Reserve in transfer status cant be canceled');  | 
              581 | 
              ok( !$cancancel, 'Reserve in transfer status cant be canceled' );  | 
            
            
              | 594 | 
               | 
               | 
               | 
            
            
              | 595 | 
              $dbh->do('DELETE FROM reserves', undef, ($bibnum)); | 
            
            
              | 596 | 
              is( CanReserveBeCanceledFromOpac($canres->{resserve_id}, $requesters{$branch_1}), undef, | 
            
            
              | 597 | 
                  'Cannot cancel a deleted hold' );  | 
            
        
          | 598 | 
           | 
          582 | 
           | 
        
        
          | 599 | 
          AddReserve(  | 
          583 | 
          AddReserve(  | 
        
        
          | 600 | 
              { | 
          584 | 
              { | 
        
        
          | 601 | 
                  branchcode     => $branch_1,  | 
          585 | 
                  branchcode     => $branch_1,  | 
        
          
            
              | 602 | 
                      borrowernumber => $requesters{$branch_1}, | 
              586 | 
                      borrowernumber => $requesters{$branch_1}->borrowernumber, | 
            
        
          | 603 | 
                  biblionumber   => $bibnum,  | 
          587 | 
                  biblionumber   => $bibnum,  | 
        
        
          | 604 | 
                  priority       => 1,  | 
          588 | 
                  priority       => 1,  | 
        
        
          | 605 | 
              }  | 
          589 | 
              }  | 
        
        
          | 606 | 
          );  | 
          590 | 
          );  | 
        
        
          | 607 | 
          (undef, $canres, undef) = CheckReserves( $item );  | 
          591 | 
          (undef, $canres, undef) = CheckReserves( $item );  | 
        
        
          | 608 | 
           | 
          592 | 
           | 
        
          
            
              | 609 | 
              ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); | 
              593 | 
              ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0 ); | 
            
            
              | 610 | 
              $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); | 
              594 | 
              $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage ); | 
            
            
              | 611 | 
              is($cancancel, 0, 'Reserve in waiting status cant be canceled');  | 
              595 | 
              ok( !$cancancel, 'Reserve in waiting status cant be canceled' );  | 
            
        
          | 612 | 
           | 
          596 | 
           | 
        
        
          | 613 | 
          # End of tests for bug 12876  | 
          597 | 
          # End of tests for bug 12876  | 
        
        
          | 614 | 
           | 
          598 | 
           | 
        
            
              | 615 | 
              -   | 
               | 
               |