Lines 8-14
use Koha::Patrons;
Link Here
|
8 |
|
8 |
|
9 |
use t::lib::TestBuilder; |
9 |
use t::lib::TestBuilder; |
10 |
|
10 |
|
11 |
use Test::More tests => 33; |
11 |
use Test::More tests => 34; |
12 |
|
12 |
|
13 |
use_ok('Koha::Patron::Debarments'); |
13 |
use_ok('Koha::Patron::Debarments'); |
14 |
|
14 |
|
Lines 22-33
my $library = $builder->build({
Link Here
|
22 |
}); |
22 |
}); |
23 |
|
23 |
|
24 |
my $patron_category = $builder->build({ source => 'Category' }); |
24 |
my $patron_category = $builder->build({ source => 'Category' }); |
25 |
my $borrowernumber = Koha::Patron->new({ |
25 |
my $patron = $builder->build_object( |
26 |
firstname => 'my firstname', |
26 |
{ |
27 |
surname => 'my surname', |
27 |
class => 'Koha::Patrons', |
28 |
categorycode => $patron_category->{categorycode}, |
28 |
value => { |
29 |
branchcode => $library->{branchcode}, |
29 |
firstname => 'my firstname', |
30 |
})->store->borrowernumber; |
30 |
surname => 'my surname', |
|
|
31 |
categorycode => $patron_category->{categorycode}, |
32 |
branchcode => $library->{branchcode}, |
33 |
} |
34 |
} |
35 |
); |
36 |
my $borrowernumber = $patron->borrowernumber; |
31 |
|
37 |
|
32 |
my $success = Koha::Patron::Debarments::AddDebarment({ |
38 |
my $success = Koha::Patron::Debarments::AddDebarment({ |
33 |
borrowernumber => $borrowernumber, |
39 |
borrowernumber => $borrowernumber, |
Lines 38-48
my $success = Koha::Patron::Debarments::AddDebarment({
Link Here
|
38 |
is( $success, 1, "AddDebarment returned true" ); |
44 |
is( $success, 1, "AddDebarment returned true" ); |
39 |
|
45 |
|
40 |
|
46 |
|
41 |
my $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
47 |
my $restrictions = $patron->restrictions; |
42 |
is( @$debarments, 1, "GetDebarments returns 1 debarment" ); |
48 |
my $THE_restriction = $restrictions->next; |
43 |
is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
49 |
is( $restrictions->count, 1, '$patron->restrictions returns 1 restriction' ); |
44 |
is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" ); |
50 |
is( $THE_restriction->type->code, 'MANUAL', "Correctly stored 'type'" ); |
45 |
is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" ); |
51 |
is( $THE_restriction->expiration, '9999-06-10', "Correctly stored 'expiration'" ); |
|
|
52 |
is( $THE_restriction->comment, 'Test 1', "Correctly stored 'comment'" ); |
46 |
|
53 |
|
47 |
|
54 |
|
48 |
$success = Koha::Patron::Debarments::AddDebarment({ |
55 |
$success = Koha::Patron::Debarments::AddDebarment({ |
Lines 50-157
$success = Koha::Patron::Debarments::AddDebarment({
Link Here
|
50 |
comment => 'Test 2', |
57 |
comment => 'Test 2', |
51 |
}); |
58 |
}); |
52 |
|
59 |
|
53 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
60 |
$restrictions = $patron->restrictions; |
54 |
is( @$debarments, 2, "GetDebarments returns 2 debarments" ); |
61 |
$THE_restriction = $restrictions->last; |
55 |
is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
62 |
is( $restrictions->count, 2, '$patron->restrictions returns 2 restrictions' ); |
56 |
is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" ); |
63 |
is( $THE_restriction->type->code, 'MANUAL', "Correctly stored 'type'" ); |
57 |
is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" ); |
64 |
is( $THE_restriction->expiration, undef, "Correctly stored debarrment with no expiration" ); |
|
|
65 |
is( $THE_restriction->comment, 'Test 2', "Correctly stored 'comment'" ); |
58 |
|
66 |
|
59 |
|
67 |
|
60 |
Koha::Patron::Debarments::ModDebarment({ |
68 |
Koha::Patron::Debarments::ModDebarment({ |
61 |
borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'}, |
69 |
borrower_debarment_id => $THE_restriction->borrower_debarment_id, |
62 |
comment => 'Test 3', |
70 |
comment => 'Test 3', |
63 |
expiration => '9998-06-10', |
71 |
expiration => '9998-06-10', |
64 |
}); |
72 |
}); |
65 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
|
|
66 |
is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" ); |
67 |
|
73 |
|
68 |
my $patron = Koha::Patrons->find( $borrowernumber )->unblessed; |
74 |
$restrictions = $patron->restrictions; |
69 |
is( $patron->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly" ); |
75 |
$THE_restriction = $restrictions->last; |
70 |
is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); |
76 |
is( $restrictions->count, 2, '$patron->restrictions returns 2 restrictions' ); |
|
|
77 |
is( $THE_restriction->comment, 'Test 3', "ModDebarment functions correctly" ); |
78 |
|
79 |
$patron = $patron->get_from_storage; |
80 |
is( $patron->debarred, '9999-06-10', "Field borrowers.debarred set correctly" ); |
81 |
is( $patron->debarredcomment, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); |
71 |
|
82 |
|
72 |
|
83 |
|
73 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
84 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
74 |
borrowernumber => $borrowernumber, |
85 |
borrowernumber => $borrowernumber, |
75 |
type => 'OVERDUES' |
86 |
type => 'OVERDUES' |
76 |
}); |
87 |
}); |
77 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
88 |
|
78 |
borrowernumber => $borrowernumber, |
89 |
$restrictions = $patron->restrictions->search( |
79 |
type => 'OVERDUES', |
90 |
{ |
80 |
}); |
91 |
type => 'OVERDUES', |
81 |
is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" ); |
92 |
} |
82 |
is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); |
93 |
); |
|
|
94 |
$THE_restriction = $restrictions->next; |
95 |
is( $restrictions->count, 1, '$patron->restrictions->search({ type => "OVERDUES" }) returns 1 OVERDUES restriction after running AddUniqueDebarment once' ); |
96 |
is( $THE_restriction->type->code, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); |
83 |
|
97 |
|
84 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
98 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
85 |
borrowernumber => $borrowernumber, |
99 |
borrowernumber => $borrowernumber, |
86 |
expiration => '9999-11-09', |
100 |
expiration => '9999-11-09', |
87 |
type => 'OVERDUES' |
101 |
type => 'OVERDUES' |
88 |
}); |
102 |
}); |
89 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
103 |
|
90 |
borrowernumber => $borrowernumber, |
104 |
$restrictions = $patron->restrictions->search( |
91 |
type => 'OVERDUES', |
105 |
{ |
92 |
}); |
106 |
type => 'OVERDUES', |
93 |
is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" ); |
107 |
} |
94 |
is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" ); |
108 |
); |
|
|
109 |
$THE_restriction = $restrictions->next; |
110 |
is( $restrictions->count, 1, '$patron->restrictions->search({ type => "OVERDUES" }) returns 1 OVERDUES restriction after running AddUniqueDebarent twice' ); |
111 |
is( $THE_restriction->expiration, '9999-11-09', "AddUniqueDebarment updated the OVERDUES restriction correctly" ); |
95 |
|
112 |
|
96 |
|
113 |
|
97 |
my $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
114 |
my $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
98 |
}); |
115 |
}); |
99 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" ); |
116 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" ); |
100 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
117 |
|
101 |
borrowernumber => $borrowernumber, |
118 |
$restrictions = $patron->restrictions->search( |
102 |
type => 'OVERDUES', |
119 |
{ |
103 |
}); |
120 |
type => 'OVERDUES', |
104 |
is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); |
121 |
} |
|
|
122 |
); |
123 |
is( $restrictions->count, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); |
105 |
|
124 |
|
106 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
125 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
107 |
borrowernumber => $borrowernumber, |
126 |
borrowernumber => $borrowernumber, |
108 |
}); |
127 |
}); |
109 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" ); |
128 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" ); |
110 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
129 |
|
111 |
borrowernumber => $borrowernumber, |
130 |
$restrictions = $patron->restrictions->search( |
112 |
type => 'OVERDUES', |
131 |
{ |
113 |
}); |
132 |
type => 'OVERDUES', |
114 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); |
133 |
} |
|
|
134 |
); |
135 |
is( $restrictions->count, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); |
115 |
|
136 |
|
116 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
137 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
117 |
type => 'OVERDUES' |
138 |
type => 'OVERDUES' |
118 |
}); |
139 |
}); |
119 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" ); |
140 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" ); |
120 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
141 |
|
121 |
borrowernumber => $borrowernumber, |
142 |
$restrictions = $patron->restrictions->search( |
122 |
type => 'OVERDUES', |
143 |
{ |
123 |
}); |
144 |
type => 'OVERDUES', |
124 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); |
145 |
} |
|
|
146 |
); |
147 |
is( $restrictions->count, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); |
125 |
|
148 |
|
126 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
149 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
127 |
borrowernumber => $borrowernumber, |
150 |
borrowernumber => $borrowernumber, |
128 |
type => 'SUSPENSION', |
151 |
type => 'SUSPENSION', |
129 |
}); |
152 |
}); |
130 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" ); |
153 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" ); |
131 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
154 |
|
132 |
borrowernumber => $borrowernumber, |
155 |
$restrictions = $patron->restrictions->search( |
133 |
type => 'OVERDUES', |
156 |
{ |
134 |
}); |
157 |
type => 'OVERDUES', |
135 |
is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); |
158 |
} |
|
|
159 |
); |
160 |
is( $restrictions->count, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); |
136 |
|
161 |
|
137 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
162 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
138 |
borrowernumber => $borrowernumber, |
163 |
borrowernumber => $borrowernumber, |
139 |
type => 'OVERDUES', |
164 |
type => 'OVERDUES', |
140 |
}); |
165 |
}); |
141 |
is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" ); |
166 |
is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" ); |
142 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
|
|
143 |
borrowernumber => $borrowernumber, |
144 |
type => 'OVERDUES', |
145 |
}); |
146 |
is( @$debarments, 0, "DelUniqueDebarment functions correctly" ); |
147 |
|
167 |
|
|
|
168 |
$restrictions = $patron->restrictions->search( |
169 |
{ |
170 |
type => 'OVERDUES', |
171 |
} |
172 |
); |
173 |
is( $restrictions->count, 0, "DelUniqueDebarment functions correctly" ); |
148 |
|
174 |
|
149 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
175 |
$restrictions = $patron->restrictions; |
150 |
foreach my $d ( @$debarments ) { |
176 |
while ( my $restriction = $restrictions->next ) { |
151 |
Koha::Patron::Debarments::DelDebarment( $d->{'borrower_debarment_id'} ); |
177 |
Koha::Patron::Debarments::DelDebarment( $restriction->borrower_debarment_id ); |
152 |
} |
178 |
} |
153 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
179 |
|
154 |
is( @$debarments, 0, "DelDebarment functions correctly" ); |
180 |
$restrictions = $patron->restrictions; |
|
|
181 |
is( $restrictions->count, 0, "DelDebarment functions correctly" ); |
155 |
|
182 |
|
156 |
$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); |
183 |
$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); |
157 |
is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron with a debarred date in the past is not debarred' ); |
184 |
is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron with a debarred date in the past is not debarred' ); |
158 |
- |
|
|