|
Lines 21-31
use Modern::Perl;
Link Here
|
| 21 |
|
21 |
|
| 22 |
use Koha::Database; |
22 |
use Koha::Database; |
| 23 |
use Koha::DateUtils qw( dt_from_string ); |
23 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
24 |
use Koha::Item::Transfers; |
| 24 |
|
25 |
|
|
|
26 |
use t::lib::Mocks; |
| 25 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
| 26 |
|
28 |
|
| 27 |
use Test::NoWarnings; |
29 |
use Test::NoWarnings; |
| 28 |
use Test::More tests => 8; |
30 |
use Test::More tests => 9; |
| 29 |
use Test::Exception; |
31 |
use Test::Exception; |
| 30 |
|
32 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
|
Lines 314-316
subtest 'cancel tests' => sub {
Link Here
|
| 314 |
|
316 |
|
| 315 |
$schema->storage->txn_rollback; |
317 |
$schema->storage->txn_rollback; |
| 316 |
}; |
318 |
}; |
| 317 |
- |
319 |
|
|
|
320 |
subtest 'store() tests' => sub { |
| 321 |
|
| 322 |
plan tests => 5; |
| 323 |
|
| 324 |
$schema->storage->txn_begin; |
| 325 |
|
| 326 |
my $library_a = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 327 |
my $library_b = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 328 |
|
| 329 |
my $item = $builder->build_sample_item( |
| 330 |
{ |
| 331 |
homebranch => $library_a->branchcode, |
| 332 |
holdingbranch => $library_b->branchcode, |
| 333 |
} |
| 334 |
); |
| 335 |
|
| 336 |
# make sure there aren't transfer logs |
| 337 |
$schema->resultset('ActionLog')->search( { module => 'TRANSFERS' } )->delete(); |
| 338 |
is( $schema->resultset('ActionLog')->search( { module => 'TRANSFERS' } )->count(), 0, 'No transfer logs' ); |
| 339 |
|
| 340 |
# enable logging |
| 341 |
t::lib::Mocks::mock_preference( 'TransfersLog', 1 ); |
| 342 |
|
| 343 |
# Add a new transfer entry |
| 344 |
my $transfer = Koha::Item::Transfer->new( |
| 345 |
{ |
| 346 |
itemnumber => $item->itemnumber, |
| 347 |
frombranch => $library_b->branchcode, |
| 348 |
tobranch => $library_a->branchcode, |
| 349 |
datesent => \'NOW()', |
| 350 |
datearrived => undef, |
| 351 |
datecancelled => undef, |
| 352 |
reason => 'Manual', |
| 353 |
cancellation_reason => undef, |
| 354 |
} |
| 355 |
)->store(); |
| 356 |
is( |
| 357 |
$schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'CREATE' } )->count(), 1, |
| 358 |
'Logging enabled, log added on creation' |
| 359 |
); |
| 360 |
|
| 361 |
$transfer->reason('Reserve')->store(); |
| 362 |
is( |
| 363 |
$schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'UPDATE' } )->count(), 1, |
| 364 |
'Logging enabled, log added on update' |
| 365 |
); |
| 366 |
|
| 367 |
# enable logging |
| 368 |
t::lib::Mocks::mock_preference( 'TransfersLog', 0 ); |
| 369 |
$transfer = Koha::Item::Transfer->new( |
| 370 |
{ |
| 371 |
itemnumber => $item->itemnumber, |
| 372 |
frombranch => $library_b->branchcode, |
| 373 |
tobranch => $library_a->branchcode, |
| 374 |
datesent => \'NOW()', |
| 375 |
datearrived => undef, |
| 376 |
datecancelled => undef, |
| 377 |
reason => 'Manual', |
| 378 |
cancellation_reason => undef, |
| 379 |
} |
| 380 |
)->store(); |
| 381 |
is( |
| 382 |
$schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'CREATE' } )->count(), 1, |
| 383 |
'Logging disabled, log not generated on creation' |
| 384 |
); |
| 385 |
|
| 386 |
$transfer->reason('Reserve')->store(); |
| 387 |
is( |
| 388 |
$schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'UPDATE' } )->count(), 1, |
| 389 |
'Logging enabled, log not generated on update' |
| 390 |
); |
| 391 |
|
| 392 |
$schema->storage->txn_rollback; |
| 393 |
}; |