Lines 37-43
my $builder = t::lib::TestBuilder->new;
Link Here
|
37 |
|
37 |
|
38 |
subtest 'store() tests' => sub { |
38 |
subtest 'store() tests' => sub { |
39 |
|
39 |
|
40 |
plan tests => 6; |
40 |
plan tests => 7; |
41 |
|
41 |
|
42 |
subtest 'Update an attribute should update the patron "updated_on" field' => sub { |
42 |
subtest 'Update an attribute should update the patron "updated_on" field' => sub { |
43 |
|
43 |
|
Lines 282-287
subtest 'store() tests' => sub {
Link Here
|
282 |
$schema->storage->txn_rollback; |
282 |
$schema->storage->txn_rollback; |
283 |
}; |
283 |
}; |
284 |
|
284 |
|
|
|
285 |
subtest 'trim identifier tests (Bug 32767)' => sub { |
286 |
|
287 |
plan tests => 5; |
288 |
|
289 |
$schema->storage->txn_begin; |
290 |
|
291 |
my $patron_1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
292 |
my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
293 |
|
294 |
my $attribute_type_1 = $builder->build( |
295 |
{ source => 'BorrowerAttributeType', |
296 |
value => { unique_id => 1, trim_value => 0 } |
297 |
} |
298 |
); |
299 |
Koha::Patron::Attribute->new( |
300 |
{ borrowernumber => $patron_1, |
301 |
code => $attribute_type_1->{code}, |
302 |
attribute => '123' |
303 |
} |
304 |
)->store; |
305 |
Koha::Patron::Attribute->new( |
306 |
{ borrowernumber => $patron_2, |
307 |
code => $attribute_type_1->{code}, |
308 |
attribute => ' 123' |
309 |
} |
310 |
)->store; |
311 |
my $attr_count |
312 |
= Koha::Patron::Attributes->search( |
313 |
{ code => $attribute_type_1->{code} } ) |
314 |
->count; |
315 |
is( $attr_count, 2, |
316 |
'Two identical attributes stored and retrieved correctly because one of them had whitespace at the start' ); |
317 |
|
318 |
my $attribute_type_2 = $builder->build( |
319 |
{ source => 'BorrowerAttributeType', |
320 |
value => { unique_id => 1, trim_value => 1 } |
321 |
} |
322 |
); |
323 |
|
324 |
Koha::Patron::Attribute->new( |
325 |
{ borrowernumber => $patron_1, |
326 |
code => $attribute_type_2->{code}, |
327 |
attribute => '123' |
328 |
} |
329 |
)->store; |
330 |
throws_ok { |
331 |
Koha::Patron::Attribute->new( |
332 |
{ borrowernumber => $patron_2, |
333 |
code => $attribute_type_2->{code}, |
334 |
attribute => ' 123' |
335 |
} |
336 |
)->store; |
337 |
} |
338 |
'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', |
339 |
'Exception thrown trying to store more than one unique attribute now that we enabled trim_value'; |
340 |
|
341 |
is( |
342 |
"$@", |
343 |
"Your action breaks a unique constraint on the attribute. type=" |
344 |
. $attribute_type_2->{code} |
345 |
. " value=123", |
346 |
'Exception stringified correctly, attribute passed correctly' |
347 |
); |
348 |
|
349 |
my $attributes = Koha::Patron::Attributes->search( |
350 |
{ borrowernumber => $patron_1, code => $attribute_type_2->{code} } ); |
351 |
is( $attributes->count, 1, '1 unique attribute stored' ); |
352 |
is( $attributes->next->attribute, |
353 |
'123', 'our unique attribute remains unchanged' ); |
354 |
|
355 |
$schema->storage->txn_rollback; |
356 |
}; |
357 |
|
285 |
subtest 'invalid type tests' => sub { |
358 |
subtest 'invalid type tests' => sub { |
286 |
|
359 |
|
287 |
plan tests => 2; |
360 |
plan tests => 2; |
288 |
- |
|
|