|
Lines 26-32
use Koha::Database;
Link Here
|
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
| 27 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
| 28 |
|
28 |
|
| 29 |
use Test::More tests => 41; |
29 |
use Test::More tests => 38; |
| 30 |
|
30 |
|
| 31 |
use_ok('C4::Members::Attributes'); |
31 |
use_ok('C4::Members::Attributes'); |
| 32 |
|
32 |
|
|
Lines 124-136
$patron = Koha::Patrons->find($borrowernumber);
Link Here
|
| 124 |
my $extended_attributes = $patron->get_extended_attributes; |
124 |
my $extended_attributes = $patron->get_extended_attributes; |
| 125 |
my $attribute_value = $extended_attributes->search({ code => 'my invalid code' }); |
125 |
my $attribute_value = $extended_attributes->search({ code => 'my invalid code' }); |
| 126 |
is( $attribute_value->count, 0, 'non existent attribute should return empty result set'); |
126 |
is( $attribute_value->count, 0, 'non existent attribute should return empty result set'); |
| 127 |
$attribute_value = $patron->get_extended_attribute_value('my invalid code'); |
127 |
$attribute_value = $patron->get_extended_attribute('my invalid code'); |
| 128 |
is( $attribute_value, undef, 'non existent attribute should undef'); |
128 |
is( $attribute_value, undef, 'non existent attribute should undef'); |
| 129 |
|
129 |
|
| 130 |
$attribute_value = $patron->get_extended_attribute_value($attributes->[0]->{code}); |
130 |
$attribute_value = $patron->get_extended_attribute($attributes->[0]->{code}); |
| 131 |
is( $attribute_value, $attributes->[0]->{value}, 'get_extended_attribute_value returns the correct attribute value' ); |
131 |
is( $attribute_value->attribute, $attributes->[0]->{value}, 'get_extended_attribute returns the correct attribute value' ); |
| 132 |
$attribute_value = $patron->get_extended_attribute_value($attributes->[1]->{code}); |
132 |
$attribute_value = $patron->get_extended_attribute($attributes->[1]->{code}); |
| 133 |
is( $attribute_value, $attributes->[1]->{value}, 'get_extended_attribute_value returns the correct attribute value' ); |
133 |
is( $attribute_value->attribute, $attributes->[1]->{value}, 'get_extended_attribute returns the correct attribute value' ); |
| 134 |
|
134 |
|
| 135 |
|
135 |
|
| 136 |
my $attribute = { |
136 |
my $attribute = { |
|
Lines 174-200
for my $attr( split(' ', $attributes->[1]->{value}) ) {
Link Here
|
| 174 |
} |
174 |
} |
| 175 |
|
175 |
|
| 176 |
|
176 |
|
| 177 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
177 |
$patron->get_extended_attribute($attribute->{code})->delete; |
| 178 |
$borrower_attributes = $patron->get_extended_attributes; |
178 |
$borrower_attributes = $patron->get_extended_attributes; |
| 179 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
179 |
is( $borrower_attributes->count, 2, 'delete attribute by code' ); |
| 180 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
|
|
| 181 |
$borrower_attributes = $patron->get_extended_attributes; |
| 182 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
| 183 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
| 184 |
$borrower_attributes = $patron->get_extended_attributes; |
| 185 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
| 186 |
|
| 187 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
| 188 |
$borrower_attributes = $patron->get_extended_attributes; |
| 189 |
is( $borrower_attributes->count, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
| 190 |
$attr_0 = $borrower_attributes->next; |
180 |
$attr_0 = $borrower_attributes->next; |
| 191 |
is( $attr_0->code, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
181 |
is( $attr_0->code, $attributes->[1]->{code}, 'delete attribute by code'); |
| 192 |
is( $attr_0->type->description, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry'); |
182 |
is( $attr_0->type->description, $attribute_type2->description(), 'delete attribute by code'); |
| 193 |
is( $attr_0->attribute, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry'); |
183 |
is( $attr_0->attribute, $attributes->[1]->{value}, 'delete attribute by code'); |
| 194 |
|
184 |
|
| 195 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
185 |
$patron->get_extended_attribute($attributes->[1]->{code})->delete; |
| 196 |
$borrower_attributes = $patron->get_extended_attributes; |
186 |
$borrower_attributes = $patron->get_extended_attributes; |
| 197 |
is( $borrower_attributes->count, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
187 |
is( $borrower_attributes->count, 1, 'delete attribute by code' ); |
| 198 |
|
188 |
|
| 199 |
# Regression tests for bug 16504 |
189 |
# Regression tests for bug 16504 |
| 200 |
t::lib::Mocks::mock_userenv({ branchcode => $new_library->{branchcode} }); |
190 |
t::lib::Mocks::mock_userenv({ branchcode => $new_library->{branchcode} }); |