|
Lines 43-50
subtest 'store() tests' => sub {
Link Here
|
| 43 |
|
43 |
|
| 44 |
my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
44 |
my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
| 45 |
my $attribute_type_1 = $builder->build( |
45 |
my $attribute_type_1 = $builder->build( |
| 46 |
{ source => 'BorrowerAttributeType', |
46 |
{ |
| 47 |
value => { repeatable => 1 } |
47 |
source => 'BorrowerAttributeType', |
|
|
48 |
value => { repeatable => 1, is_date => 0 } |
| 48 |
} |
49 |
} |
| 49 |
); |
50 |
); |
| 50 |
Koha::Patron::Attribute->new( |
51 |
Koha::Patron::Attribute->new( |
|
Lines 67-74
subtest 'store() tests' => sub {
Link Here
|
| 67 |
'2 repeatable attributes stored and retrieved correcctly' ); |
68 |
'2 repeatable attributes stored and retrieved correcctly' ); |
| 68 |
|
69 |
|
| 69 |
my $attribute_type_2 = $builder->build( |
70 |
my $attribute_type_2 = $builder->build( |
| 70 |
{ source => 'BorrowerAttributeType', |
71 |
{ |
| 71 |
value => { repeatable => 0 } |
72 |
source => 'BorrowerAttributeType', |
|
|
73 |
value => { repeatable => 0, is_date => 0 } |
| 72 |
} |
74 |
} |
| 73 |
); |
75 |
); |
| 74 |
|
76 |
|
|
Lines 107-126
subtest 'store() tests' => sub {
Link Here
|
| 107 |
}; |
109 |
}; |
| 108 |
|
110 |
|
| 109 |
subtest 'is_date attributes tests' => sub { |
111 |
subtest 'is_date attributes tests' => sub { |
| 110 |
plan tests => 2; |
112 |
plan tests => 3; |
| 111 |
|
113 |
|
| 112 |
$schema->storage->txn_begin; |
114 |
$schema->storage->txn_begin; |
| 113 |
|
115 |
|
| 114 |
my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
116 |
my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
| 115 |
my $attribute_type_1 = $builder->build( |
117 |
my $attribute_type_1 = $builder->build( |
| 116 |
{ source => 'BorrowerAttributeType', |
118 |
{ |
|
|
119 |
source => 'BorrowerAttributeType', |
| 117 |
value => { is_date => 1 } |
120 |
value => { is_date => 1 } |
| 118 |
} |
121 |
} |
| 119 |
); |
122 |
); |
| 120 |
|
123 |
|
| 121 |
throws_ok { |
124 |
throws_ok { |
| 122 |
Koha::Patron::Attribute->new( |
125 |
Koha::Patron::Attribute->new( |
| 123 |
{ borrowernumber => $patron, |
126 |
{ |
|
|
127 |
borrowernumber => $patron, |
| 124 |
code => $attribute_type_1->{code}, |
128 |
code => $attribute_type_1->{code}, |
| 125 |
attribute => 'not_a_date' |
129 |
attribute => 'not_a_date' |
| 126 |
} |
130 |
} |
|
Lines 131-155
subtest 'store() tests' => sub {
Link Here
|
| 131 |
|
135 |
|
| 132 |
is( |
136 |
is( |
| 133 |
"$@", |
137 |
"$@", |
| 134 |
"Tried to use an invalid value for attribute type. type=" |
138 |
"Tried to use an invalid value for attribute type. type=" . $attribute_type_1->{code} . " value=not_a_date", |
| 135 |
. $attribute_type_1->{code} |
|
|
| 136 |
. " value=not_a_date", |
| 137 |
'Exception stringified correctly, attribute passed correctly' |
139 |
'Exception stringified correctly, attribute passed correctly' |
| 138 |
); |
140 |
); |
| 139 |
|
141 |
|
| 140 |
Koha::Patron::Attribute->new( |
142 |
Koha::Patron::Attribute->new( |
| 141 |
{ borrowernumber => $patron, |
143 |
{ |
|
|
144 |
borrowernumber => $patron, |
| 142 |
code => $attribute_type_1->{code}, |
145 |
code => $attribute_type_1->{code}, |
| 143 |
attribute => '2024-03-04' |
146 |
attribute => '2024-03-04' |
| 144 |
} |
147 |
} |
| 145 |
)->store; |
148 |
)->store; |
| 146 |
|
149 |
|
| 147 |
my $attr_count |
150 |
my $attr_count = |
| 148 |
= Koha::Patron::Attributes->search( |
151 |
Koha::Patron::Attributes->search( { borrowernumber => $patron, code => $attribute_type_1->{code} } )->count; |
| 149 |
{ borrowernumber => $patron, code => $attribute_type_1->{code} } ) |
152 |
is( |
| 150 |
->count; |
153 |
$attr_count, 1, |
| 151 |
is( $attr_count, 1, |
154 |
'1 date attribute stored and retrieved correctly' |
| 152 |
'1 date attribute stored and retrieved correctly' ); |
155 |
); |
| 153 |
|
156 |
|
| 154 |
$schema->storage->txn_rollback; |
157 |
$schema->storage->txn_rollback; |
| 155 |
}; |
158 |
}; |
|
Lines 164-171
subtest 'store() tests' => sub {
Link Here
|
| 164 |
my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
167 |
my $patron_2 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
| 165 |
|
168 |
|
| 166 |
my $attribute_type_1 = $builder->build( |
169 |
my $attribute_type_1 = $builder->build( |
| 167 |
{ source => 'BorrowerAttributeType', |
170 |
{ |
| 168 |
value => { unique_id => 0 } |
171 |
source => 'BorrowerAttributeType', |
|
|
172 |
value => { unique_id => 0, is_date => 0 } |
| 169 |
} |
173 |
} |
| 170 |
); |
174 |
); |
| 171 |
Koha::Patron::Attribute->new( |
175 |
Koha::Patron::Attribute->new( |
|
Lines 188-195
subtest 'store() tests' => sub {
Link Here
|
| 188 |
'2 non-unique attributes stored and retrieved correcctly' ); |
192 |
'2 non-unique attributes stored and retrieved correcctly' ); |
| 189 |
|
193 |
|
| 190 |
my $attribute_type_2 = $builder->build( |
194 |
my $attribute_type_2 = $builder->build( |
| 191 |
{ source => 'BorrowerAttributeType', |
195 |
{ |
| 192 |
value => { unique_id => 1 } |
196 |
source => 'BorrowerAttributeType', |
|
|
197 |
value => { unique_id => 1, is_date => 0 } |
| 193 |
} |
198 |
} |
| 194 |
); |
199 |
); |
| 195 |
|
200 |
|
|
Lines 239-245
subtest 'store() tests' => sub {
Link Here
|
| 239 |
class => 'Koha::Patron::Attribute::Types', |
244 |
class => 'Koha::Patron::Attribute::Types', |
| 240 |
value => { |
245 |
value => { |
| 241 |
unique_id => 0, |
246 |
unique_id => 0, |
| 242 |
repeatable => 0 |
247 |
repeatable => 0, |
|
|
248 |
is_date => 0 |
| 243 |
} |
249 |
} |
| 244 |
} |
250 |
} |
| 245 |
); |
251 |
); |
|
Lines 278-283
subtest 'store() tests' => sub {
Link Here
|
| 278 |
mandatory => 0, |
284 |
mandatory => 0, |
| 279 |
repeatable => 0, |
285 |
repeatable => 0, |
| 280 |
unique_id => 1, |
286 |
unique_id => 1, |
|
|
287 |
is_date => 0, |
| 281 |
category_code => undef |
288 |
category_code => undef |
| 282 |
} |
289 |
} |
| 283 |
} |
290 |
} |
|
Lines 352-370
subtest 'merge_and_replace_with' => sub {
Link Here
|
| 352 |
my $unique_attribute_type = $builder->build_object( |
359 |
my $unique_attribute_type = $builder->build_object( |
| 353 |
{ |
360 |
{ |
| 354 |
class => 'Koha::Patron::Attribute::Types', |
361 |
class => 'Koha::Patron::Attribute::Types', |
| 355 |
value => { unique_id=> 1, repeatable => 0 } |
362 |
value => { |
|
|
363 |
unique_id => 1, |
| 364 |
repeatable => 0, |
| 365 |
is_date => 0 |
| 366 |
} |
| 356 |
} |
367 |
} |
| 357 |
); |
368 |
); |
| 358 |
my $repeatable_attribute_type = $builder->build_object( |
369 |
my $repeatable_attribute_type = $builder->build_object( |
| 359 |
{ |
370 |
{ |
| 360 |
class => 'Koha::Patron::Attribute::Types', |
371 |
class => 'Koha::Patron::Attribute::Types', |
| 361 |
value => { unique_id => 0, repeatable => 1 } |
372 |
value => { |
|
|
373 |
unique_id => 0, |
| 374 |
repeatable => 1, |
| 375 |
is_date => 0 |
| 376 |
} |
| 362 |
} |
377 |
} |
| 363 |
); |
378 |
); |
| 364 |
my $normal_attribute_type = $builder->build_object( |
379 |
my $normal_attribute_type = $builder->build_object( |
| 365 |
{ |
380 |
{ |
| 366 |
class => 'Koha::Patron::Attribute::Types', |
381 |
class => 'Koha::Patron::Attribute::Types', |
| 367 |
value => { unique_id => 0, repeatable => 0 } |
382 |
value => { |
|
|
383 |
unique_id => 0, |
| 384 |
repeatable => 0, |
| 385 |
is_date => 0 |
| 386 |
} |
| 368 |
} |
387 |
} |
| 369 |
); |
388 |
); |
| 370 |
my $non_existent_attribute_type = $builder->build_object( |
389 |
my $non_existent_attribute_type = $builder->build_object( |
| 371 |
- |
|
|