|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 46; |
22 |
use Test::More tests => 47; |
| 23 |
use Test::NoWarnings; |
23 |
use Test::NoWarnings; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
|
Lines 41-46
use C4::Circulation qw( AddIssue AddReturn );
Link Here
|
| 41 |
|
41 |
|
| 42 |
use t::lib::TestBuilder; |
42 |
use t::lib::TestBuilder; |
| 43 |
use t::lib::Mocks; |
43 |
use t::lib::Mocks; |
|
|
44 |
use Test::MockModule; |
| 44 |
|
45 |
|
| 45 |
my $schema = Koha::Database->new->schema; |
46 |
my $schema = Koha::Database->new->schema; |
| 46 |
my $builder = t::lib::TestBuilder->new; |
47 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 816-829
subtest 'is_superlibrarian() tests' => sub {
Link Here
|
| 816 |
{ |
817 |
{ |
| 817 |
class => 'Koha::Patrons', |
818 |
class => 'Koha::Patrons', |
| 818 |
|
819 |
|
| 819 |
value => { flags => 4 } |
820 |
value => { flags => 16 } |
| 820 |
} |
821 |
} |
| 821 |
); |
822 |
); |
| 822 |
|
823 |
|
| 823 |
my %permissions = $patron->permissions; |
824 |
my $permissions = $patron->permissions; |
|
|
825 |
is( $permissions->{superlibrarian}, undef, 'Patron does not have superlibrarian permission' ); |
| 824 |
|
826 |
|
| 825 |
is( scalar keys %permissions, 1, "Patron has one module permission" ); |
827 |
$patron->flags(1)->store->discard_changes; |
| 826 |
is( $permissions{catalogue}, 1, "Patron has catalogue permission" ); |
828 |
|
|
|
829 |
$permissions = $patron->permissions; |
| 830 |
is( $permissions->{superlibrarian}, 1, 'Patron has superlibrarian permission' ); |
| 827 |
|
831 |
|
| 828 |
$schema->storage->txn_rollback; |
832 |
$schema->storage->txn_rollback; |
| 829 |
}; |
833 |
}; |
|
Lines 2382-2391
subtest 'alert_subscriptions tests' => sub {
Link Here
|
| 2382 |
|
2386 |
|
| 2383 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2387 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2384 |
|
2388 |
|
| 2385 |
my $subscription1 = $builder->build_object( { class => 'Koha::Subscriptions' } ); |
2389 |
my $subscription1 = $builder->build_object( { |
|
|
2390 |
class => 'Koha::Subscriptions', |
| 2391 |
value => { |
| 2392 |
librarian => $patron->borrowernumber, |
| 2393 |
} |
| 2394 |
}); |
| 2386 |
$subscription1->add_subscriber($patron); |
2395 |
$subscription1->add_subscriber($patron); |
| 2387 |
|
2396 |
|
| 2388 |
my $subscription2 = $builder->build_object( { class => 'Koha::Subscriptions' } ); |
2397 |
|
|
|
2398 |
my $subscription2 = $builder->build_object( { |
| 2399 |
class => 'Koha::Subscriptions', |
| 2400 |
value => { |
| 2401 |
librarian => $patron->borrowernumber, |
| 2402 |
} |
| 2403 |
}); |
| 2389 |
$subscription2->add_subscriber($patron); |
2404 |
$subscription2->add_subscriber($patron); |
| 2390 |
|
2405 |
|
| 2391 |
my @subscriptions = $patron->alert_subscriptions->as_list; |
2406 |
my @subscriptions = $patron->alert_subscriptions->as_list; |
|
Lines 2421-2426
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2421 |
plan tests => 26; |
2436 |
plan tests => 26; |
| 2422 |
$schema->storage->txn_begin; |
2437 |
$schema->storage->txn_begin; |
| 2423 |
|
2438 |
|
|
|
2439 |
my $mock_cache = Test::MockModule->new('Koha::Cache'); |
| 2440 |
my %fake_cache; |
| 2441 |
|
| 2442 |
$mock_cache->mock('set_in_cache', sub { |
| 2443 |
my ( $self, $key, $value ) = @_; |
| 2444 |
$fake_cache{$key} = $value; |
| 2445 |
return; |
| 2446 |
}); |
| 2447 |
|
| 2448 |
$mock_cache->mock('get_from_cache', sub { |
| 2449 |
my ( $self, $key ) = @_; |
| 2450 |
return $fake_cache{$key}; |
| 2451 |
}); |
| 2452 |
|
| 2424 |
my $cache = Koha::Caches->get_instance(); |
2453 |
my $cache = Koha::Caches->get_instance(); |
| 2425 |
|
2454 |
|
| 2426 |
t::lib::Mocks::mock_preference( |
2455 |
t::lib::Mocks::mock_preference( |
|
Lines 2429-2440
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2429 |
); |
2458 |
); |
| 2430 |
|
2459 |
|
| 2431 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2460 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2432 |
my $userid = $patron->userid; |
|
|
| 2433 |
$patron->lastseen(undef); |
| 2434 |
my $patron_info = $patron->unblessed; |
2461 |
my $patron_info = $patron->unblessed; |
| 2435 |
delete $patron_info->{borrowernumber}; |
2462 |
delete $patron_info->{borrowernumber}; |
| 2436 |
$patron->delete(); |
2463 |
$patron->delete(); |
| 2437 |
$patron = Koha::Patron->new($patron_info)->store(); |
2464 |
$patron = Koha::Patron->new($patron_info)->store(); |
|
|
2465 |
$patron->update_lastseen({ activity => 'creation' }); |
| 2466 |
$patron->discard_changes(); |
| 2438 |
|
2467 |
|
| 2439 |
my $now = dt_from_string(); |
2468 |
my $now = dt_from_string(); |
| 2440 |
my $today = $now->ymd(); |
2469 |
my $today = $now->ymd(); |
|
Lines 2444-2464
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2444 |
'Patron should have last seen when newly created if requested' |
2473 |
'Patron should have last seen when newly created if requested' |
| 2445 |
); |
2474 |
); |
| 2446 |
|
2475 |
|
| 2447 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
2476 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
| 2448 |
my $cache_value = $cache->get_from_cache($cache_key); |
2477 |
is( $cache->get_from_cache($cache_key), $today, "Cache was updated as expected" ); |
| 2449 |
is( $cache_value, $today, "Cache was updated as expected" ); |
|
|
| 2450 |
|
2478 |
|
| 2451 |
$patron->delete(); |
2479 |
$patron->delete(); |
| 2452 |
|
2480 |
|
| 2453 |
t::lib::Mocks::mock_preference( |
2481 |
t::lib::Mocks::mock_preference( |
| 2454 |
'TrackLastPatronActivityTriggers', |
2482 |
'TrackLastPatronActivityTriggers', |
| 2455 |
'login,connection,check_in,check_out,renewal,hold,article' |
2483 |
'' |
|
|
2484 |
); |
| 2485 |
my $patron_no_trigger = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2486 |
|
| 2487 |
$patron_no_trigger->lastseen(undef)->store(); |
| 2488 |
|
| 2489 |
$patron_no_trigger->update_lastseen({ activity => 'login' }); |
| 2490 |
$patron_no_trigger->discard_changes(); |
| 2491 |
|
| 2492 |
is( $patron_no_trigger->lastseen, undef, |
| 2493 |
'Patron should have not last seen when newly created if trigger not set' |
| 2456 |
); |
2494 |
); |
| 2457 |
|
2495 |
|
| 2458 |
$patron = Koha::Patron->new($patron_info)->store(); |
|
|
| 2459 |
$cache_key = "track_activity_" . $patron->borrowernumber; |
| 2460 |
|
2496 |
|
| 2461 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); |
2497 |
t::lib::Mocks::mock_preference( |
|
|
2498 |
'TrackLastPatronActivityTriggers', |
| 2499 |
'login,connection,check_in,check_out,renewal,hold,article' |
| 2500 |
); |
| 2501 |
|
| 2462 |
|
2502 |
|
| 2463 |
$now = dt_from_string(); |
2503 |
$now = dt_from_string(); |
| 2464 |
Time::Fake->offset( $now->epoch ); |
2504 |
Time::Fake->offset( $now->epoch ); |
|
Lines 2553-2564
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2553 |
'login,connection,check_in,check_out,renewal,hold,article' |
2593 |
'login,connection,check_in,check_out,renewal,hold,article' |
| 2554 |
); |
2594 |
); |
| 2555 |
|
2595 |
|
| 2556 |
$cache->clear_from_cache($cache_key); |
2596 |
%fake_cache = (); |
| 2557 |
$patron->update_lastseen('login'); |
2597 |
$patron->update_lastseen('login'); |
| 2558 |
$patron->_result()->discard_changes(); |
2598 |
$patron->_result()->discard_changes(); |
| 2559 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); |
2599 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); |
| 2560 |
|
2600 |
|
| 2561 |
$cache->clear_from_cache($cache_key); |
2601 |
%fake_cache = (); |
| 2562 |
$patron->update_lastseen('connection'); |
2602 |
$patron->update_lastseen('connection'); |
| 2563 |
$patron->_result()->discard_changes(); |
2603 |
$patron->_result()->discard_changes(); |
| 2564 |
isnt( |
2604 |
isnt( |
|
Lines 2566-2572
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2566 |
'Patron last seen should be changed after a connection if we cleared the cache' |
2606 |
'Patron last seen should be changed after a connection if we cleared the cache' |
| 2567 |
); |
2607 |
); |
| 2568 |
|
2608 |
|
| 2569 |
$cache->clear_from_cache($cache_key); |
2609 |
%fake_cache = (); |
| 2570 |
$patron->update_lastseen('check_out'); |
2610 |
$patron->update_lastseen('check_out'); |
| 2571 |
$patron->_result()->discard_changes(); |
2611 |
$patron->_result()->discard_changes(); |
| 2572 |
isnt( |
2612 |
isnt( |
|
Lines 2574-2580
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2574 |
'Patron last seen should be changed after a check_out if we cleared the cache' |
2614 |
'Patron last seen should be changed after a check_out if we cleared the cache' |
| 2575 |
); |
2615 |
); |
| 2576 |
|
2616 |
|
| 2577 |
$cache->clear_from_cache($cache_key); |
2617 |
%fake_cache = (); |
| 2578 |
$patron->update_lastseen('check_in'); |
2618 |
$patron->update_lastseen('check_in'); |
| 2579 |
$patron->_result()->discard_changes(); |
2619 |
$patron->_result()->discard_changes(); |
| 2580 |
isnt( |
2620 |
isnt( |
|
Lines 2582-2594
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2582 |
'Patron last seen should be changed after a check_in if we cleared the cache' |
2622 |
'Patron last seen should be changed after a check_in if we cleared the cache' |
| 2583 |
); |
2623 |
); |
| 2584 |
|
2624 |
|
| 2585 |
$cache->clear_from_cache($cache_key); |
2625 |
%fake_cache = (); |
| 2586 |
$patron->update_lastseen('hold'); |
2626 |
$patron->update_lastseen('hold'); |
| 2587 |
$patron->_result()->discard_changes(); |
2627 |
$patron->_result()->discard_changes(); |
| 2588 |
isnt( |
2628 |
isnt( |
| 2589 |
$patron->lastseen, $last_seen, |
2629 |
$patron->lastseen, $last_seen, |
| 2590 |
'Patron last seen should be changed after a hold if we cleared the cache' |
2630 |
'Patron last seen should be changed after a hold if we cleared the cache' |
| 2591 |
); |
2631 |
); |
|
|
2632 |
|
| 2633 |
%fake_cache = (); |
| 2592 |
$patron->update_lastseen('article'); |
2634 |
$patron->update_lastseen('article'); |
| 2593 |
$patron->_result()->discard_changes(); |
2635 |
$patron->_result()->discard_changes(); |
| 2594 |
isnt( |
2636 |
isnt( |
|
Lines 2596-2602
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2596 |
'Patron last seen should be changed after a article if we cleared the cache' |
2638 |
'Patron last seen should be changed after a article if we cleared the cache' |
| 2597 |
); |
2639 |
); |
| 2598 |
|
2640 |
|
| 2599 |
$cache->clear_from_cache($cache_key); |
2641 |
%fake_cache = (); |
| 2600 |
$patron->update_lastseen('renewal'); |
2642 |
$patron->update_lastseen('renewal'); |
| 2601 |
$patron->_result()->discard_changes(); |
2643 |
$patron->_result()->discard_changes(); |
| 2602 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
2644 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
|
Lines 2604-2610
subtest 'update_lastseen tests' => sub {
Link Here
|
| 2604 |
# Check that the preference takes effect |
2646 |
# Check that the preference takes effect |
| 2605 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
2647 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
| 2606 |
$patron->lastseen(undef)->store; |
2648 |
$patron->lastseen(undef)->store; |
| 2607 |
$cache->clear_from_cache($cache_key); |
2649 |
%fake_cache = (); |
| 2608 |
$patron->update_lastseen('login'); |
2650 |
$patron->update_lastseen('login'); |
| 2609 |
$patron->_result()->discard_changes(); |
2651 |
$patron->_result()->discard_changes(); |
| 2610 |
is( |
2652 |
is( |
| 2611 |
- |
|
|