|
Lines 1-6
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
# Copyright 2015 Koha Development team |
3 |
# Copyright 2019 Koha Development team |
| 4 |
# |
4 |
# |
| 5 |
# This file is part of Koha |
5 |
# This file is part of Koha |
| 6 |
# |
6 |
# |
|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 21; |
22 |
use Test::More tests => 22; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 30-37
use Koha::Patron::Category;
Link Here
|
| 30 |
use Koha::Patron::Categories; |
30 |
use Koha::Patron::Categories; |
| 31 |
use Koha::Patrons; |
31 |
use Koha::Patrons; |
| 32 |
use Koha::Database; |
32 |
use Koha::Database; |
|
|
33 |
use Koha::DateUtils qw( dt_from_string ); |
| 33 |
|
34 |
|
| 34 |
use t::lib::TestBuilder; |
35 |
use t::lib::TestBuilder; |
|
|
36 |
use t::lib::Mocks; |
| 35 |
|
37 |
|
| 36 |
use Try::Tiny; |
38 |
use Try::Tiny; |
| 37 |
|
39 |
|
|
Lines 759-764
subtest "attributes_from_api() tests" => sub {
Link Here
|
| 759 |
$city->attributes_from_api($api_attributes) |
761 |
$city->attributes_from_api($api_attributes) |
| 760 |
); |
762 |
); |
| 761 |
|
763 |
|
|
|
764 |
$schema->storage->txn_rollback; |
| 765 |
|
| 766 |
}; |
| 767 |
|
| 768 |
subtest "filter_by_last_update" => sub { |
| 769 |
|
| 770 |
$schema->storage->txn_begin; |
| 771 |
|
| 772 |
my $now = dt_from_string->truncate( to => 'day' ); |
| 773 |
my @borrowernumbers; |
| 774 |
# Building 6 patrons that have been created today, yesterday, ... 1 per day |
| 775 |
for my $i ( 0 .. 5 ) { |
| 776 |
push @borrowernumbers, |
| 777 |
$builder->build_object( |
| 778 |
{ |
| 779 |
class => 'Koha::Patrons', |
| 780 |
value => { updated_on => $now->clone->subtract( days => $i ) } |
| 781 |
} |
| 782 |
)->borrowernumber; |
| 783 |
} |
| 784 |
|
| 785 |
my $patrons = Koha::Patrons->search( |
| 786 |
{ borrowernumber => { -in => \@borrowernumbers } } ); |
| 787 |
|
| 788 |
try { |
| 789 |
$patrons->filter_by_last_update( { timestamp_column_name => 'updated_on' } ) |
| 790 |
->count; |
| 791 |
} |
| 792 |
catch { |
| 793 |
ok( |
| 794 |
$_->isa('Koha::Exceptions::MissingParameter'), |
| 795 |
'Should raise an exception if no parameter given' |
| 796 |
); |
| 797 |
}; |
| 798 |
|
| 799 |
my $count = $patrons->filter_by_last_update( |
| 800 |
{ timestamp_column_name => 'updated_on', days => 2 } )->count; |
| 801 |
is( $count, 3, '3 patrons have been updated before the last 2 days (exclusive)' ); |
| 802 |
|
| 803 |
$count = $patrons->filter_by_last_update( |
| 804 |
{ timestamp_column_name => 'updated_on', days => 1 } )->count; |
| 805 |
is( $count, 4, '4 patrons have been updated before yesterday (exclusive)' ); |
| 806 |
|
| 807 |
$count = $patrons->filter_by_last_update( |
| 808 |
{ timestamp_column_name => 'updated_on', days => 0 } )->count; |
| 809 |
is( $count, 5, '5 patrons have been updated before today (exclusive)' ); |
| 810 |
|
| 811 |
$count = $patrons->filter_by_last_update( |
| 812 |
{ timestamp_column_name => 'updated_on', from => $now } )->count; |
| 813 |
is( $count, 1, '1 patron has been updated "from today" (inclusive)' ); |
| 814 |
|
| 815 |
$count = $patrons->filter_by_last_update( |
| 816 |
{ timestamp_column_name => 'updated_on', to => $now } )->count; |
| 817 |
is( $count, 6, '6 patrons have been updated "to today" (inclusive)' ); |
| 818 |
|
| 819 |
$count = $patrons->filter_by_last_update( |
| 820 |
{ |
| 821 |
timestamp_column_name => 'updated_on', |
| 822 |
from => $now->clone->subtract( days => 4 ), |
| 823 |
to => $now->clone->subtract( days => 2 ) |
| 824 |
} |
| 825 |
)->count; |
| 826 |
is( $count, 3, '3 patrons have been updated between D-4 and D-2' ); |
| 827 |
|
| 828 |
t::lib::Mocks::mock_preference( 'dateformat', 'metric' ); |
| 829 |
try { |
| 830 |
$count = $patrons->filter_by_last_update( |
| 831 |
{ timestamp_column_name => 'updated_on', from => '1970-12-31' } ) |
| 832 |
->count; |
| 833 |
} |
| 834 |
catch { |
| 835 |
ok( |
| 836 |
$_->isa( |
| 837 |
'No exception raised, from and to parameters can take an iso formatted date' |
| 838 |
) |
| 839 |
); |
| 840 |
}; |
| 841 |
try { |
| 842 |
$count = $patrons->filter_by_last_update( |
| 843 |
{ timestamp_column_name => 'updated_on', from => '31/12/1970' } ) |
| 844 |
->count; |
| 845 |
} |
| 846 |
catch { |
| 847 |
ok( |
| 848 |
$_->isa( |
| 849 |
'No exception raised, from and to parameters can take an metric formatted date (depending on dateformat syspref)' |
| 850 |
) |
| 851 |
); |
| 852 |
}; |
| 853 |
|
| 762 |
$schema->storage->txn_rollback; |
854 |
$schema->storage->txn_rollback; |
| 763 |
}; |
855 |
}; |
| 764 |
|
856 |
|
| 765 |
- |
|
|