|
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 => 60; |
| 28 |
|
29 |
|
| 29 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
| 30 |
|
31 |
|
|
Lines 44-66
$dbh->do(q|DELETE FROM borrower_attribute_types|);
Link Here
|
| 44 |
my $library = $builder->build({ |
45 |
my $library = $builder->build({ |
| 45 |
source => 'Branch', |
46 |
source => 'Branch', |
| 46 |
}); |
47 |
}); |
| 47 |
my $borrowernumber = AddMember( |
|
|
| 48 |
firstname => 'my firstname', |
| 49 |
surname => 'my surname', |
| 50 |
categorycode => 'S', |
| 51 |
branchcode => $library->{branchcode}, |
| 52 |
); |
| 53 |
|
48 |
|
|
|
49 |
my $patron = $builder->build( |
| 50 |
{ source => 'Borrower', |
| 51 |
value => { |
| 52 |
firstname => 'my firstname', |
| 53 |
surname => 'my surname', |
| 54 |
categorycode => 'S', |
| 55 |
branchcode => $library->{branchcode}, |
| 56 |
} |
| 57 |
} |
| 58 |
); |
| 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 |
# TODO This is not implemented yet |
| 121 |
is( @$borrower_attributes, 1, 'GetBorrowerAttributes returns the correct number of borrower attributes with the filter opac_only' ); |
136 |
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited'); |
| 122 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'GetBorrowerAttributes returns the correct code' ); |
137 |
#is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes filtered on library' ); |
| 123 |
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'GetBorrowerAttributes returns the correct description' ); |
|
|
| 124 |
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'GetBorrowerAttributes returns the correct value' ); |
| 125 |
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'GetBorrowerAttributes returns the correct password' ); |
| 126 |
|
| 127 |
|
138 |
|
| 128 |
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue(); |
139 |
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue(); |
| 129 |
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' ); |
140 |
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' ); |
|
Lines 147-153
my $attribute = {
Link Here
|
| 147 |
}; |
158 |
}; |
| 148 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
159 |
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute); |
| 149 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
160 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 150 |
is( @$borrower_attributes, 2, 'UpdateBorrowerAttribute does not change the number of borrower attributes' ); |
161 |
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' ); |
162 |
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' ); |
163 |
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' ); |
164 |
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 |
|
196 |
|
| 186 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
197 |
C4::Members::Attributes::DeleteBorrowerAttribute(); |
| 187 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
198 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 188 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
199 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' ); |
| 189 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
200 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber); |
| 190 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
201 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 191 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
202 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' ); |
| 192 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
203 |
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute); |
| 193 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
204 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 194 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
205 |
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' ); |
| 195 |
|
206 |
|
| 196 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
207 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute); |
| 197 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
208 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 198 |
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
209 |
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
| 199 |
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry'); |
210 |
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'); |
211 |
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'); |
212 |
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 |
|
214 |
|
| 204 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
215 |
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]); |
| 205 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
216 |
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber); |
| 206 |
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
217 |
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' ); |
|
|
218 |
|
| 219 |
done_testing; |
| 207 |
- |
|
|