|
Lines 29-34
use C4::Context;
Link Here
|
| 29 |
use C4::Members; |
29 |
use C4::Members; |
| 30 |
use C4::Members::Attributes qw( GetBorrowerAttributes ); |
30 |
use C4::Members::Attributes qw( GetBorrowerAttributes ); |
| 31 |
use Koha::Patrons; |
31 |
use Koha::Patrons; |
|
|
32 |
use Koha::Patron::Attribute; |
| 32 |
|
33 |
|
| 33 |
BEGIN { |
34 |
BEGIN { |
| 34 |
use_ok('Koha::Patron::Modification'); |
35 |
use_ok('Koha::Patron::Modification'); |
|
Lines 253-265
subtest 'approve tests' => sub {
Link Here
|
| 253 |
|
254 |
|
| 254 |
subtest 'pending_count() and pending() tests' => sub { |
255 |
subtest 'pending_count() and pending() tests' => sub { |
| 255 |
|
256 |
|
| 256 |
plan tests => 7; |
257 |
plan tests => 16; |
| 257 |
|
258 |
|
| 258 |
$schema->storage->txn_begin; |
259 |
$schema->storage->txn_begin; |
| 259 |
|
260 |
|
| 260 |
Koha::Patron::Modifications->search->delete; |
261 |
Koha::Patron::Modifications->search->delete; |
| 261 |
my $library_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
262 |
my $library_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 262 |
my $library_2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
263 |
my $library_2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
|
|
264 |
$builder->build({ source => 'BorrowerAttributeType', value => { code => 'CODE_1' } }); |
| 265 |
$builder->build({ source => 'BorrowerAttributeType', value => { code => 'CODE_2', repeatable => 1 } }); |
| 266 |
|
| 263 |
my $patron_1 |
267 |
my $patron_1 |
| 264 |
= $builder->build( |
268 |
= $builder->build( |
| 265 |
{ source => 'Borrower', value => { branchcode => $library_1 } } ) |
269 |
{ source => 'Borrower', value => { branchcode => $library_1 } } ) |
|
Lines 276-287
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 276 |
my $verification_token_2 = md5_hex( time().{}.rand().{}.$$ ); |
280 |
my $verification_token_2 = md5_hex( time().{}.rand().{}.$$ ); |
| 277 |
my $verification_token_3 = md5_hex( time().{}.rand().{}.$$ ); |
281 |
my $verification_token_3 = md5_hex( time().{}.rand().{}.$$ ); |
| 278 |
|
282 |
|
|
|
283 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_1, code => 'CODE_1', attribute => 'hello' } )->store(); |
| 284 |
Koha::Patron::Attribute->new({ borrowernumber => $patron_2, code => 'CODE_2', attribute => 'bye' } )->store(); |
| 279 |
|
285 |
|
| 280 |
my $modification_1 = Koha::Patron::Modification->new( |
286 |
my $modification_1 = Koha::Patron::Modification->new( |
| 281 |
{ borrowernumber => $patron_1, |
287 |
{ borrowernumber => $patron_1, |
| 282 |
surname => 'Hall', |
288 |
surname => 'Hall', |
| 283 |
firstname => 'Kyle', |
289 |
firstname => 'Kyle', |
| 284 |
verification_token => $verification_token_1 |
290 |
verification_token => $verification_token_1, |
|
|
291 |
extended_attributes => '[{"code":"CODE_1","value":""}]' |
| 285 |
} |
292 |
} |
| 286 |
)->store(); |
293 |
)->store(); |
| 287 |
|
294 |
|
|
Lines 292-304
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 292 |
{ borrowernumber => $patron_2, |
299 |
{ borrowernumber => $patron_2, |
| 293 |
surname => 'Smith', |
300 |
surname => 'Smith', |
| 294 |
firstname => 'Sandy', |
301 |
firstname => 'Sandy', |
| 295 |
verification_token => $verification_token_2 |
302 |
verification_token => $verification_token_2, |
|
|
303 |
extended_attributes => '[{"code":"CODE_2","value":"chau"},{"code":"CODE_2","value":"ciao"}]' |
| 296 |
} |
304 |
} |
| 297 |
)->store(); |
305 |
)->store(); |
| 298 |
|
306 |
|
| 299 |
my $modification_3 = Koha::Patron::Modification->new( |
307 |
my $modification_3 = Koha::Patron::Modification->new( |
| 300 |
{ borrowernumber => $patron_3, |
308 |
{ borrowernumber => $patron_3, |
| 301 |
surname => 'Smith', |
309 |
surname => 'Smithy', |
| 302 |
firstname => 'Sandy', |
310 |
firstname => 'Sandy', |
| 303 |
verification_token => $verification_token_3 |
311 |
verification_token => $verification_token_3 |
| 304 |
} |
312 |
} |
|
Lines 307-312
subtest 'pending_count() and pending() tests' => sub {
Link Here
|
| 307 |
is( Koha::Patron::Modifications->pending_count, |
315 |
is( Koha::Patron::Modifications->pending_count, |
| 308 |
3, 'pending_count() correctly returns 3' ); |
316 |
3, 'pending_count() correctly returns 3' ); |
| 309 |
|
317 |
|
|
|
318 |
my $pending = Koha::Patron::Modifications->pending(); |
| 319 |
is( scalar @{$pending}, 3, 'pending() returns an array with 3 elements' ); |
| 320 |
|
| 321 |
my @filtered_modifications = grep { $_->{borrowernumber} eq $patron_1 } @{$pending}; |
| 322 |
my $p1_pm = $filtered_modifications[0]; |
| 323 |
my $p1_pm_attribute_1 = $p1_pm->{extended_attributes}->[0]; |
| 324 |
|
| 325 |
is( scalar @{$p1_pm->{extended_attributes}}, 1, 'patron 1 has modification has one pending attribute modification' ); |
| 326 |
is( ref($p1_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); |
| 327 |
is( $p1_pm_attribute_1->attribute, '', 'patron 1 has an empty value for the attribute' ); |
| 328 |
|
| 329 |
@filtered_modifications = grep { $_->{borrowernumber} eq $patron_2 } @{$pending}; |
| 330 |
my $p2_pm = $filtered_modifications[0]; |
| 331 |
|
| 332 |
is( scalar @{$p2_pm->{extended_attributes}}, 2 , 'patron 2 has 2 attribute modifications' ); |
| 333 |
|
| 334 |
my $p2_pm_attribute_1 = $p2_pm->{extended_attributes}->[0]; |
| 335 |
my $p2_pm_attribute_2 = $p2_pm->{extended_attributes}->[1]; |
| 336 |
|
| 337 |
is( ref($p2_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); |
| 338 |
is( ref($p2_pm_attribute_2), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); |
| 339 |
|
| 340 |
is( $p2_pm_attribute_1->attribute, 'chau', 'patron modification has the right attribute change' ); |
| 341 |
is( $p2_pm_attribute_2->attribute, 'ciao', 'patron modification has the right attribute change' ); |
| 342 |
|
| 310 |
is( Koha::Patron::Modifications->pending_count($library_1), |
343 |
is( Koha::Patron::Modifications->pending_count($library_1), |
| 311 |
1, 'pending_count() correctly returns 1 if filtered by library' ); |
344 |
1, 'pending_count() correctly returns 1 if filtered by library' ); |
| 312 |
|
345 |
|
| 313 |
- |
|
|