Lines 23-30
use C4::Context;
Link Here
|
23 |
use C4::Members; |
23 |
use C4::Members; |
24 |
use C4::Members::AttributeTypes; |
24 |
use C4::Members::AttributeTypes; |
25 |
use Koha::Database; |
25 |
use Koha::Database; |
|
|
26 |
use t::lib::TestBuilder; |
26 |
|
27 |
|
27 |
use Test::More tests => 60; |
28 |
use Test::More tests => 57; |
28 |
|
29 |
|
29 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
30 |
|
31 |
|
Lines 40-66
$dbh->do(q|DELETE FROM issues|);
Link Here
|
40 |
$dbh->do(q|DELETE FROM borrowers|); |
41 |
$dbh->do(q|DELETE FROM borrowers|); |
41 |
$dbh->do(q|DELETE FROM borrower_attributes|); |
42 |
$dbh->do(q|DELETE FROM borrower_attributes|); |
42 |
$dbh->do(q|DELETE FROM borrower_attribute_types|); |
43 |
$dbh->do(q|DELETE FROM borrower_attribute_types|); |
43 |
|
|
|
44 |
my $library = $builder->build({ |
44 |
my $library = $builder->build({ |
45 |
source => 'Branch', |
45 |
source => 'Branch', |
46 |
}); |
46 |
}); |
47 |
my $borrowernumber = AddMember( |
|
|
48 |
firstname => 'my firstname', |
49 |
surname => 'my surname', |
50 |
categorycode => 'S', |
51 |
branchcode => $library->{branchcode}, |
52 |
); |
53 |
|
47 |
|
|
|
48 |
my $patron = $builder->build( |
49 |
{ source => 'Borrower', |
50 |
value => { |
51 |
firstname => 'my firstname', |
52 |
surname => 'my surname', |
53 |
categorycode => 'S', |
54 |
branchcode => $library->{branchcode}, |
55 |
} |
56 |
} |
57 |
); |
58 |
C4::Context->_new_userenv('DUMMY SESSION'); |
59 |
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', $library->{branchcode}, 'My Library', 0); |
60 |
my $borrowernumber = $patron->{borrowernumber}; |
54 |
|
61 |
|
55 |
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1'); |
62 |
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1'); |
56 |
$attribute_type1->unique_id(1); |
63 |
$attribute_type1->unique_id(1); |
57 |
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2'); |
|
|
58 |
$attribute_type2->opac_display(1); |
59 |
$attribute_type2->staff_searchable(1); |
60 |
|
61 |
my $attribute_types = C4::Members::Attributes::GetAttributes(); |
64 |
my $attribute_types = C4::Members::Attributes::GetAttributes(); |
62 |
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' ); |
65 |
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' ); |
63 |
|
|
|
64 |
$attribute_type1->store(); |
66 |
$attribute_type1->store(); |
65 |
$attribute_types = C4::Members::Attributes::GetAttributes(); |
67 |
$attribute_types = C4::Members::Attributes::GetAttributes(); |
66 |
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' ); |
68 |
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' ); |
Lines 68-73
is( $attribute_types->[0], $attribute_type1->code(), 'GetAttributes returns the
Link Here
|
68 |
$attribute_types = C4::Members::Attributes::GetAttributes(1); |
70 |
$attribute_types = C4::Members::Attributes::GetAttributes(1); |
69 |
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' ); |
71 |
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' ); |
70 |
|
72 |
|
|
|
73 |
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2'); |
74 |
$attribute_type2->opac_display(1); |
75 |
$attribute_type2->staff_searchable(1); |
71 |
$attribute_type2->store(); |
76 |
$attribute_type2->store(); |
72 |
$attribute_types = C4::Members::Attributes::GetAttributes(); |
77 |
$attribute_types = C4::Members::Attributes::GetAttributes(); |
73 |
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' ); |
78 |
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' ); |
Lines 75-80
is( $attribute_types->[1], $attribute_type2->code(), 'GetAttributes returns the
Link Here
|
75 |
$attribute_types = C4::Members::Attributes::GetAttributes(1); |
80 |
$attribute_types = C4::Members::Attributes::GetAttributes(1); |
76 |
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' ); |
81 |
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' ); |
77 |
|
82 |
|
|
|
83 |
my $new_library = $builder->build( { source => 'Branch' } ); |
84 |
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3'); |
85 |
$attribute_type_limited->branches([ $new_library->{branchcode} ]); |
86 |
$attribute_type_limited->store; |
78 |
|
87 |
|
79 |
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
88 |
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
80 |
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
89 |
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
Lines 91-96
my $attributes = [
Link Here
|
91 |
value => 'my attribute2', |
100 |
value => 'my attribute2', |
92 |
code => $attribute_type2->code(), |
101 |
code => $attribute_type2->code(), |
93 |
password => 'my password2', |
102 |
password => 'my password2', |
|
|
103 |
}, |
104 |
{ |
105 |
value => 'my attribute limited', |
106 |
code => $attribute_type_limited->code(), |
94 |
} |
107 |
} |
95 |
]; |
108 |
]; |
96 |
|
109 |
|
Lines 107-113
is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code
Link Here
|
107 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
120 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes(); |
108 |
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
121 |
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' ); |
109 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
122 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
110 |
is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
123 |
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
111 |
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' ); |
124 |
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' ); |
112 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
125 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
113 |
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
126 |
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
Lines 116-129
is( $borrower_attributes->[1]->{code}, $attributes->[1]->{code}, 'SetBorrowerAtt
Link Here
|
116 |
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
129 |
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' ); |
117 |
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
130 |
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' ); |
118 |
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' ); |
131 |
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' ); |
|
|
132 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
133 |
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' ); |
119 |
|
134 |
|
120 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 1); |
135 |
$attributes = [ |
121 |
is( @$borrower_attributes, 1, 'GetBorrowerAttributes returns the correct number of borrower attributes with the filter opac_only' ); |
136 |
{ |
122 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'GetBorrowerAttributes returns the correct code' ); |
137 |
value => 'my attribute1', |
123 |
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'GetBorrowerAttributes returns the correct description' ); |
138 |
code => $attribute_type1->code(), |
124 |
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'GetBorrowerAttributes returns the correct value' ); |
139 |
password => 'my password1', |
125 |
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'GetBorrowerAttributes returns the correct password' ); |
140 |
}, |
|
|
141 |
{ |
142 |
value => 'my attribute2', |
143 |
code => $attribute_type2->code(), |
144 |
password => 'my password2', |
145 |
} |
146 |
]; |
147 |
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes); |
148 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
149 |
is( @$borrower_attributes, 3, 'SetBorrowerAttributes should not have removed the attributes limited to another branch' ); |
126 |
|
150 |
|
|
|
151 |
# TODO This is not implemented yet |
152 |
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited'); |
153 |
#is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes filtered on library' ); |
127 |
|
154 |
|
128 |
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue(); |
155 |
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue(); |
129 |
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' ); |
156 |
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' ); |
Lines 147-153
my $attribute = {
Link Here
|
147 |
}; |
174 |
}; |
148 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
175 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
149 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
176 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
150 |
is( @$borrower_attributes, 2, 'UpdateBorrowerAttribute does not change the number of borrower attributes' ); |
177 |
is( @$borrower_attributes, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' ); |
151 |
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' ); |
178 |
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' ); |
152 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' ); |
179 |
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' ); |
153 |
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' ); |
180 |
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' ); |
Lines 185-201
for my $attr( split(' ', $attributes->[1]->{value}) ) {
Link Here
|
185 |
|
212 |
|
186 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
213 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
187 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
214 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
188 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
215 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
189 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
216 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
190 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
217 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
191 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
218 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
192 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
219 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
193 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
220 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
194 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
221 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
195 |
|
222 |
|
196 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
223 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
197 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
224 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
198 |
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
225 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
199 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
226 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
200 |
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry'); |
227 |
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry'); |
201 |
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry'); |
228 |
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry'); |
Lines 203-206
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete
Link Here
|
203 |
|
230 |
|
204 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
231 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
205 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
232 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
206 |
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
233 |
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |