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