|
Lines 2021-2027
subtest 'anonymize' => sub {
Link Here
|
| 2021 |
$schema->storage->txn_rollback; |
2021 |
$schema->storage->txn_rollback; |
| 2022 |
|
2022 |
|
| 2023 |
subtest 'extended_attributes' => sub { |
2023 |
subtest 'extended_attributes' => sub { |
| 2024 |
plan tests => 11; |
2024 |
plan tests => 14; |
| 2025 |
my $schema = Koha::Database->new->schema; |
2025 |
my $schema = Koha::Database->new->schema; |
| 2026 |
$schema->storage->txn_begin; |
2026 |
$schema->storage->txn_begin; |
| 2027 |
|
2027 |
|
|
Lines 2046-2051
subtest 'extended_attributes' => sub {
Link Here
|
| 2046 |
} |
2046 |
} |
| 2047 |
)->store; |
2047 |
)->store; |
| 2048 |
|
2048 |
|
|
|
2049 |
my $attribute_type3 = $builder->build_object({ class => 'Koha::Patron::Attribute::Types' }); |
| 2050 |
|
| 2049 |
my $deleted_attribute_type = $builder->build_object({ class => 'Koha::Patron::Attribute::Types' }); |
2051 |
my $deleted_attribute_type = $builder->build_object({ class => 'Koha::Patron::Attribute::Types' }); |
| 2050 |
my $deleted_attribute_type_code = $deleted_attribute_type->code; |
2052 |
my $deleted_attribute_type_code = $deleted_attribute_type->code; |
| 2051 |
$deleted_attribute_type->delete; |
2053 |
$deleted_attribute_type->delete; |
|
Lines 2112-2117
subtest 'extended_attributes' => sub {
Link Here
|
| 2112 |
$attribute_12 = $patron_2->get_extended_attribute( $attribute_type1->code ); |
2114 |
$attribute_12 = $patron_2->get_extended_attribute( $attribute_type1->code ); |
| 2113 |
is( $attribute_12->attribute, 'my attribute12', 'Koha::Patron->get_extended_attribute should return the correct attribute value' ); |
2115 |
is( $attribute_12->attribute, 'my attribute12', 'Koha::Patron->get_extended_attribute should return the correct attribute value' ); |
| 2114 |
|
2116 |
|
|
|
2117 |
warning_is { |
| 2118 |
$extended_attributes_for_2 = $patron_2->extended_attributes->merge_with( |
| 2119 |
[ |
| 2120 |
{ |
| 2121 |
attribute => 'my attribute12 XXX', |
| 2122 |
code => $attribute_type1->code(), |
| 2123 |
}, |
| 2124 |
{ |
| 2125 |
attribute => 'my nonexistent attribute 2', |
| 2126 |
code => $deleted_attribute_type_code, |
| 2127 |
}, |
| 2128 |
{ |
| 2129 |
attribute => 'my attribute 3', # Adding a new attribute using merge_with |
| 2130 |
code => $attribute_type3->code, |
| 2131 |
}, |
| 2132 |
] |
| 2133 |
); |
| 2134 |
} |
| 2135 |
"Cannot merge element: unrecognized code = '$deleted_attribute_type_code'", |
| 2136 |
"Trying to merge_with using a nonexistent attribute code should display a warning"; |
| 2137 |
|
| 2138 |
is( @$extended_attributes_for_2, 3, 'There should be 3 attributes now for patron 3'); |
| 2139 |
my $expected_attributes_for_2 = [ |
| 2140 |
{ |
| 2141 |
code => $attribute_type1->code(), |
| 2142 |
attribute => 'my attribute12 XXX', |
| 2143 |
}, |
| 2144 |
{ |
| 2145 |
code => $attribute_type_limited->code(), |
| 2146 |
attribute => 'my attribute limited 2', |
| 2147 |
}, |
| 2148 |
{ |
| 2149 |
attribute => 'my attribute 3', |
| 2150 |
code => $attribute_type3->code, |
| 2151 |
}, |
| 2152 |
]; |
| 2153 |
# Sorting them by code |
| 2154 |
$expected_attributes_for_2 = [ sort { $a->{code} cmp $b->{code} } @$expected_attributes_for_2 ]; |
| 2155 |
|
| 2156 |
is_deeply( |
| 2157 |
[ |
| 2158 |
{ |
| 2159 |
code => $extended_attributes_for_2->[0]->{code}, |
| 2160 |
attribute => $extended_attributes_for_2->[0]->{attribute} |
| 2161 |
}, |
| 2162 |
{ |
| 2163 |
code => $extended_attributes_for_2->[1]->{code}, |
| 2164 |
attribute => $extended_attributes_for_2->[1]->{attribute} |
| 2165 |
}, |
| 2166 |
{ |
| 2167 |
code => $extended_attributes_for_2->[2]->{code}, |
| 2168 |
attribute => $extended_attributes_for_2->[2]->{attribute} |
| 2169 |
}, |
| 2170 |
], |
| 2171 |
$expected_attributes_for_2 |
| 2172 |
); |
| 2173 |
|
| 2115 |
# TODO - What about multiple? POD explains the problem |
2174 |
# TODO - What about multiple? POD explains the problem |
| 2116 |
my $non_existent = $patron_2->get_extended_attribute( 'not_exist' ); |
2175 |
my $non_existent = $patron_2->get_extended_attribute( 'not_exist' ); |
| 2117 |
is( $non_existent, undef, 'Koha::Patron->get_extended_attribute must return undef if the attribute does not exist' ); |
2176 |
is( $non_existent, undef, 'Koha::Patron->get_extended_attribute must return undef if the attribute does not exist' ); |
| 2118 |
- |
|
|