View | Details | Raw Unified | Return to bug 18635
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +54 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 22;
22
use Test::More tests => 23;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 911-915 subtest 'account_locked' => sub { Link Here
911
$retrieved_patron_1->delete;
911
$retrieved_patron_1->delete;
912
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
912
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
913
913
914
subtest 'Patron->guarantees' => sub {
915
    plan tests => 5;
916
917
    my $builder = t::lib::TestBuilder->new;
918
919
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
920
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
921
922
    my $guarantor = $builder->build_object( { class => 'Koha::Patrons' } );
923
924
    my $guarantee1 = $builder->build_object( { class => 'Koha::Patrons' ,  value => {
925
            surname => 'Zebra',
926
            guarantorid => $guarantor->borrowernumber
927
        }
928
    })->borrowernumber;
929
930
    my $guarantee2 = $builder->build_object( { class => 'Koha::Patrons' ,  value => {
931
            surname => 'Yak',
932
            guarantorid => $guarantor->borrowernumber
933
        }
934
    })->borrowernumber;
935
936
    my $guarantee3 = $builder->build_object( { class => 'Koha::Patrons' ,  value => {
937
            surname => 'Xerus',
938
            firstname => 'Walrus',
939
            guarantorid => $guarantor->borrowernumber
940
        }
941
    })->borrowernumber;
942
943
    my $guarantee4 = $builder->build_object( { class => 'Koha::Patrons' ,  value => {
944
            surname => 'Xerus',
945
            firstname => 'Vulture',
946
            guarantorid => $guarantor->borrowernumber
947
        }
948
    })->borrowernumber;
949
950
    my $guarantee5 = $builder->build_object( { class => 'Koha::Patrons' ,  value => {
951
            surname => 'Xerus',
952
            firstname => 'Unicorn',
953
            guarantorid => $guarantor->borrowernumber
954
        }
955
    })->borrowernumber;
956
957
    my $guarantees = $guarantor->guarantees();
958
959
    is( $guarantees->next()->borrowernumber, $guarantee5, "Return first guarantor alphabetically" );
960
    is( $guarantees->next()->borrowernumber, $guarantee4, "Return second guarantor alphabetically" );
961
    is( $guarantees->next()->borrowernumber, $guarantee3, "Return third guarantor alphabetically" );
962
    is( $guarantees->next()->borrowernumber, $guarantee2, "Return fourth guarantor alphabetically" );
963
    is( $guarantees->next()->borrowernumber, $guarantee1, "Return fifth guarantor alphabetically" );
964
965
};
966
914
$schema->storage->txn_rollback;
967
$schema->storage->txn_rollback;
915
968
(-)a/t/db_dependent/Patrons.t (-108 lines)
Lines 1-107 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 17;
21
use Test::Warn;
22
23
use C4::Context;
24
use Koha::Database;
25
use Koha::DateUtils;
26
27
use t::lib::TestBuilder;
28
29
BEGIN {
30
    use_ok('Koha::Objects');
31
    use_ok('Koha::Patrons');
32
}
33
34
# Start transaction
35
my $database = Koha::Database->new();
36
my $schema = $database->schema();
37
$schema->storage->txn_begin();
38
my $builder = t::lib::TestBuilder->new;
39
40
my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
41
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
42
43
my $b1 = Koha::Patron->new(
44
    {
45
        surname      => 'Test 1',
46
        branchcode   => $branchcode,
47
        categorycode => $categorycode
48
    }
49
);
50
$b1->store();
51
my $now = dt_from_string;
52
my $b2 = Koha::Patron->new(
53
    {
54
        surname      => 'Test 2',
55
        branchcode   => $branchcode,
56
        categorycode => $categorycode
57
    }
58
);
59
$b2->store();
60
my $three_days_ago = dt_from_string->add( days => -3 );
61
my $b3 = Koha::Patron->new(
62
    {
63
        surname      => 'Test 3',
64
        branchcode   => $branchcode,
65
        categorycode => $categorycode,
66
        updated_on   => $three_days_ago,
67
    }
68
);
69
$b3->store();
70
71
my $b1_new = Koha::Patrons->find( $b1->borrowernumber() );
72
is( $b1->surname(), $b1_new->surname(), "Found matching patron" );
73
isnt( $b1_new->updated_on, undef, "borrowers.updated_on should be set" );
74
is( dt_from_string($b1_new->updated_on), $now, "borrowers.updated_on should have been set to now on creating" );
75
76
my $b3_new = Koha::Patrons->find( $b3->borrowernumber() );
77
is( dt_from_string($b3_new->updated_on), $three_days_ago, "borrowers.updated_on should have been kept to what we set on creating" );
78
$b3_new->set({ firstname => 'Some first name for Test 3' })->store();
79
$b3_new = Koha::Patrons->find( $b3->borrowernumber() );
80
is( dt_from_string($b3_new->updated_on), dt_from_string, "borrowers.updated_on should have been set to now on updating" );
81
82
my @patrons = Koha::Patrons->search( { branchcode => $branchcode } );
83
is( @patrons, 3, "Found 3 patrons with Search" );
84
85
my $unexistent = Koha::Patrons->find( '1234567890' );
86
is( $unexistent, undef, 'Koha::Objects->Find should return undef if the record does not exist' );
87
88
my $patrons = Koha::Patrons->search( { branchcode => $branchcode } );
89
is( $patrons->count( { branchcode => $branchcode } ), 3, "Counted 3 patrons with Count" );
90
91
my $b = $patrons->next();
92
is( $b->surname(), 'Test 1', "Next returns first patron" );
93
$b = $patrons->next();
94
is( $b->surname(), 'Test 2', "Next returns second patron" );
95
$b = $patrons->next();
96
is( $b->surname(), 'Test 3', "Next returns third patron" );
97
$b = $patrons->next();
98
is( $b, undef, "Next returns undef" );
99
100
# Test Reset and iteration in concert
101
$patrons->reset();
102
foreach my $b ( $patrons->as_list() ) {
103
    is( $b->categorycode(), $categorycode, "Iteration returns a patron object" );
104
}
105
106
$schema->storage->txn_rollback();
107
108
- 

Return to bug 18635