|
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 => 46; |
29 |
use Test::More tests => 41; |
| 30 |
|
30 |
|
| 31 |
use_ok('C4::Members::Attributes'); |
31 |
use_ok('C4::Members::Attributes'); |
| 32 |
|
32 |
|
|
Lines 70-81
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my de
Link Here
|
| 70 |
$attribute_type_limited->branches([ $new_library->{branchcode} ]); |
70 |
$attribute_type_limited->branches([ $new_library->{branchcode} ]); |
| 71 |
$attribute_type_limited->store; |
71 |
$attribute_type_limited->store; |
| 72 |
|
72 |
|
| 73 |
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
|
|
| 74 |
ok(1); |
| 75 |
#is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
| 76 |
$patron = Koha::Patrons->find($borrowernumber); |
73 |
$patron = Koha::Patrons->find($borrowernumber); |
| 77 |
$borrower_attributes = $patron->get_extended_attributes; |
74 |
my $borrower_attributes = $patron->get_extended_attributes; |
| 78 |
is( $borrower_attributes->count, 0, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
75 |
is( $borrower_attributes->count, 0, 'get_extended_attributes returns the correct number of borrower attributes' ); |
| 79 |
|
76 |
|
| 80 |
my $attributes = [ |
77 |
my $attributes = [ |
| 81 |
{ |
78 |
{ |
|
Lines 92-119
my $attributes = [
Link Here
|
| 92 |
} |
89 |
} |
| 93 |
]; |
90 |
]; |
| 94 |
|
91 |
|
| 95 |
my $set_borrower_attributes = C4::Members::Attributes::SetBorrowerAttributes(); |
92 |
my $set_borrower_attributes = C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes); |
| 96 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
|
|
| 97 |
is( @$borrower_attributes, 0, 'SetBorrowerAttributes without arguments does not add borrower attributes' ); |
| 98 |
|
| 99 |
$set_borrower_attributes = C4::Members::Attributes::SetBorrowerAttributes($borrowernumber); |
| 100 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
| 101 |
is( @$borrower_attributes, 0, 'SetBorrowerAttributes without the attributes does not add borrower attributes' ); |
| 102 |
|
| 103 |
$set_borrower_attributes = C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes); |
| 104 |
is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code' ); |
93 |
is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code' ); |
| 105 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
94 |
$borrower_attributes = $patron->get_extended_attributes; |
| 106 |
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
95 |
is( $borrower_attributes->count, 3, 'get_extended_attributes returns the correct number of borrower attributes' ); |
| 107 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
96 |
my $attr_0 = $borrower_attributes->next; |
| 108 |
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
97 |
is( $attr_0->code, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' ); |
| 109 |
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' ); |
98 |
is( $attr_0->type->description, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
| 110 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
99 |
is( $attr_0->attribute, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
| 111 |
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
100 |
my $attr_1 = $borrower_attributes->next; |
| 112 |
is( $borrower_attributes->[1]->{code}, $attributes->[1]->{code}, 'SetBorrowerAttributes stores the field code correctly' ); |
101 |
is( $attr_1->code, $attributes->[1]->{code}, 'SetBorrowerAttributes stores the field code correctly' ); |
| 113 |
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
102 |
is( $attr_1->type->description, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
| 114 |
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
103 |
is( $attr_1->attribute, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
| 115 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
|
|
| 116 |
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
| 117 |
|
104 |
|
| 118 |
$attributes = [ |
105 |
$attributes = [ |
| 119 |
{ |
106 |
{ |
|
Lines 126-133
$attributes = [
Link Here
|
| 126 |
} |
113 |
} |
| 127 |
]; |
114 |
]; |
| 128 |
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes); |
115 |
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes); |
| 129 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
116 |
$borrower_attributes = $patron->get_extended_attributes; |
| 130 |
is( @$borrower_attributes, 3, 'SetBorrowerAttributes should not have removed the attributes limited to another branch' ); |
117 |
is( $borrower_attributes->count, 3, 'SetBorrowerAttributes should not have removed the attributes limited to another branch' ); |
| 131 |
|
118 |
|
| 132 |
# TODO This is not implemented yet |
119 |
# TODO This is not implemented yet |
| 133 |
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited'); |
120 |
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited'); |
|
Lines 151-161
my $attribute = {
Link Here
|
| 151 |
code => $attribute_type1->code(), |
138 |
code => $attribute_type1->code(), |
| 152 |
}; |
139 |
}; |
| 153 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
140 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
| 154 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
141 |
$borrower_attributes = $patron->get_extended_attributes; |
| 155 |
is( @$borrower_attributes, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' ); |
142 |
is( $borrower_attributes->count, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' ); |
| 156 |
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' ); |
143 |
$attr_0 = $borrower_attributes->next; |
| 157 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' ); |
144 |
is( $attr_0->code, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' ); |
| 158 |
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' ); |
145 |
is( $attr_0->type->description, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' ); |
|
|
146 |
is( $attr_0->attribute, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' ); |
| 159 |
|
147 |
|
| 160 |
|
148 |
|
| 161 |
my $check_uniqueness = C4::Members::Attributes::CheckUniqueness(); |
149 |
my $check_uniqueness = C4::Members::Attributes::CheckUniqueness(); |
|
Lines 187-216
for my $attr( split(' ', $attributes->[1]->{value}) ) {
Link Here
|
| 187 |
|
175 |
|
| 188 |
|
176 |
|
| 189 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
177 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
| 190 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
178 |
$borrower_attributes = $patron->get_extended_attributes; |
| 191 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
179 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
| 192 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
180 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
| 193 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
181 |
$borrower_attributes = $patron->get_extended_attributes; |
| 194 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
182 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
| 195 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
183 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
| 196 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
184 |
$borrower_attributes = $patron->get_extended_attributes; |
| 197 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
185 |
is( $borrower_attributes->count, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
| 198 |
|
186 |
|
| 199 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
187 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
| 200 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
188 |
$borrower_attributes = $patron->get_extended_attributes; |
| 201 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
189 |
is( $borrower_attributes->count, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
| 202 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
190 |
$attr_0 = $borrower_attributes->next; |
| 203 |
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry'); |
191 |
is( $attr_0->code, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
| 204 |
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry'); |
192 |
is( $attr_0->type->description, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry'); |
|
|
193 |
is( $attr_0->attribute, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry'); |
| 205 |
|
194 |
|
| 206 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
195 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
| 207 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
196 |
$borrower_attributes = $patron->get_extended_attributes; |
| 208 |
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
197 |
is( $borrower_attributes->count, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
| 209 |
|
198 |
|
| 210 |
# Regression tests for bug 16504 |
199 |
# Regression tests for bug 16504 |
| 211 |
t::lib::Mocks::mock_userenv({ branchcode => $new_library->{branchcode} }); |
200 |
t::lib::Mocks::mock_userenv({ branchcode => $new_library->{branchcode} }); |
| 212 |
my $another_patron = $builder->build( |
201 |
my $another_patron = $builder->build_object( |
| 213 |
{ source => 'Borrower', |
202 |
{ class => 'Koha::Patrons', |
| 214 |
value => { |
203 |
value => { |
| 215 |
firstname => 'my another firstname', |
204 |
firstname => 'my another firstname', |
| 216 |
surname => 'my another surname', |
205 |
surname => 'my another surname', |
|
Lines 232-239
$attributes = [
Link Here
|
| 232 |
code => $attribute_type_limited->code(), |
221 |
code => $attribute_type_limited->code(), |
| 233 |
} |
222 |
} |
| 234 |
]; |
223 |
]; |
| 235 |
C4::Members::Attributes::SetBorrowerAttributes($another_patron->{borrowernumber}, $attributes); |
224 |
C4::Members::Attributes::SetBorrowerAttributes($another_patron->borrowernumber, $attributes); |
| 236 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($another_patron->{borrowernumber}); |
225 |
$borrower_attributes = $another_patron->get_extended_attributes; |
| 237 |
is( @$borrower_attributes, 3, 'SetBorrowerAttributes should have added the 3 attributes for another patron'); |
226 |
is( $borrower_attributes->count, 3, 'SetBorrowerAttributes should have added the 3 attributes for another patron'); |
| 238 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
227 |
$borrower_attributes = $patron->get_extended_attributes; |
| 239 |
is( @$borrower_attributes, 1, 'SetBorrowerAttributes should not have removed the attributes of other patrons' ); |
228 |
is( $borrower_attributes->count, 1, 'SetBorrowerAttributes should not have removed the attributes of other patrons' ); |