|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use utf8; |
21 |
use utf8; |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 2; |
23 |
use Test::More tests => 3; |
| 24 |
|
24 |
|
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
| 26 |
|
26 |
|
|
Lines 324-326
subtest 'store() tests' => sub {
Link Here
|
| 324 |
|
324 |
|
| 325 |
$schema->storage->txn_rollback; |
325 |
$schema->storage->txn_rollback; |
| 326 |
}; |
326 |
}; |
| 327 |
- |
327 |
|
|
|
328 |
subtest 'delete() tests' => sub { |
| 329 |
plan tests => 3; |
| 330 |
|
| 331 |
$schema->storage->txn_begin; |
| 332 |
|
| 333 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 334 |
my $biblio = $builder->build_sample_biblio; |
| 335 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 336 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
| 337 |
my $end_0 = $start_0->clone->add( days => 6 ); |
| 338 |
my $original_notices_count = Koha::Notice::Messages->search( |
| 339 |
{ |
| 340 |
letter_code => 'BOOKING_CANCELLATION', |
| 341 |
borrowernumber => $patron->borrowernumber, |
| 342 |
} |
| 343 |
)->count; |
| 344 |
|
| 345 |
$item_1->bookable(1)->store; |
| 346 |
|
| 347 |
my $booking = Koha::Booking->new( |
| 348 |
{ |
| 349 |
patron_id => $patron->borrowernumber, |
| 350 |
biblio_id => $biblio->biblionumber, |
| 351 |
item_id => $item_1->itemnumber, |
| 352 |
pickup_library_id => $item_1->homebranch, |
| 353 |
start_date => $start_0, |
| 354 |
end_date => $end_0 |
| 355 |
} |
| 356 |
)->store; |
| 357 |
|
| 358 |
my $deleted = $booking->delete; |
| 359 |
is( |
| 360 |
ref($deleted), 'Koha::Booking', |
| 361 |
'Koha::Booking->delete should return the Koha::Booking object if the booking has been correctly deleted' |
| 362 |
); |
| 363 |
is( |
| 364 |
Koha::Bookings->search( { booking_id => $booking->booking_id } )->count, 0, |
| 365 |
'Koha::Booking->delete should have deleted the booking' |
| 366 |
); |
| 367 |
|
| 368 |
subtest 'notice trigger' => sub { |
| 369 |
plan tests => 1; |
| 370 |
|
| 371 |
my $post_notices_count = Koha::Notice::Messages->search( |
| 372 |
{ |
| 373 |
letter_code => 'BOOKING_CANCELLATION', |
| 374 |
borrowernumber => $patron->borrowernumber, |
| 375 |
} |
| 376 |
)->count; |
| 377 |
is( |
| 378 |
$post_notices_count, |
| 379 |
$original_notices_count + 1, |
| 380 |
'Koha::Booking->delete should have enqueued a BOOKING_CANCELLATION email' |
| 381 |
); |
| 382 |
}; |
| 383 |
|
| 384 |
$schema->storage->txn_rollback; |
| 385 |
}; |