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