Lines 19-31
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 4; |
23 |
|
23 |
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
25 |
use Test::Exception; |
25 |
use Test::Exception; |
26 |
|
26 |
|
27 |
use Koha::Database; |
27 |
use Koha::Database; |
28 |
use Koha::Patron::Attribute; |
|
|
29 |
use Koha::Patron::Attributes; |
28 |
use Koha::Patron::Attributes; |
30 |
|
29 |
|
31 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
Lines 157-276
subtest 'store() unique_id attributes tests' => sub {
Link Here
|
157 |
$schema->storage->txn_rollback; |
156 |
$schema->storage->txn_rollback; |
158 |
}; |
157 |
}; |
159 |
|
158 |
|
160 |
subtest 'opac_display() tests' => sub { |
159 |
subtest 'type() tests' => sub { |
161 |
|
160 |
|
162 |
plan tests => 2; |
161 |
plan tests => 4; |
163 |
|
162 |
|
164 |
$schema->storage->txn_begin; |
163 |
$schema->storage->txn_begin; |
165 |
|
164 |
|
166 |
my $patron |
165 |
my $patron |
167 |
= $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
166 |
= $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
168 |
my $attribute_type_1 = $builder->build( |
167 |
my $attr_type = $builder->build( { source => 'BorrowerAttributeType' } ); |
169 |
{ source => 'BorrowerAttributeType', |
168 |
my $attribute = Koha::Patron::Attribute->new( |
170 |
value => { opac_display => 1 } |
|
|
171 |
} |
172 |
); |
173 |
|
174 |
my $attribute_1 = Koha::Patron::Attribute->new( |
175 |
{ borrowernumber => $patron, |
169 |
{ borrowernumber => $patron, |
176 |
code => $attribute_type_1->{code}, |
170 |
code => $attr_type->{code}, |
177 |
attribute => $patron |
171 |
attribute => $patron |
178 |
} |
172 |
} |
179 |
); |
173 |
); |
180 |
is( $attribute_1->opac_display, 1, '->opac_display returns 1' ); |
|
|
181 |
|
174 |
|
182 |
my $attribute_type_2 = $builder->build( |
175 |
my $attribute_type = $attribute->type; |
183 |
{ source => 'BorrowerAttributeType', |
176 |
|
184 |
value => { opac_display => 0 } |
177 |
is( ref($attribute_type), |
185 |
} |
178 |
'Koha::Patron::Attribute::Type', |
|
|
179 |
'->type returns a Koha::Patron::Attribute::Type object' |
186 |
); |
180 |
); |
187 |
|
181 |
|
188 |
my $attribute_2 = Koha::Patron::Attribute->new( |
182 |
is( $attribute_type->code, |
189 |
{ borrowernumber => $patron, |
183 |
$attr_type->{code}, |
190 |
code => $attribute_type_2->{code}, |
184 |
'->type returns the right Koha::Patron::Attribute::Type object' ); |
191 |
attribute => $patron |
185 |
|
192 |
} |
186 |
is( $attribute_type->opac_editable, |
|
|
187 |
$attr_type->{opac_editable}, |
188 |
'->type returns the right Koha::Patron::Attribute::Type object' |
189 |
); |
190 |
|
191 |
is( $attribute_type->opac_display, |
192 |
$attr_type->{opac_display}, |
193 |
'->type returns the right Koha::Patron::Attribute::Type object' |
193 |
); |
194 |
); |
194 |
is( $attribute_2->opac_display, 0, '->opac_display returns 0' ); |
|
|
195 |
|
195 |
|
196 |
$schema->storage->txn_rollback; |
196 |
$schema->storage->txn_rollback; |
197 |
}; |
197 |
}; |
198 |
|
198 |
|
199 |
subtest 'opac_editable() tests' => sub { |
199 |
subtest 'search_opac_editable() and search_opac_displayable() tests' => sub { |
200 |
|
200 |
|
201 |
plan tests => 2; |
201 |
plan tests => 3; |
202 |
|
202 |
|
203 |
$schema->storage->txn_begin; |
203 |
$schema->storage->txn_begin; |
204 |
|
204 |
|
205 |
my $patron |
205 |
my $editable_attr_type = $builder->build_object( |
206 |
= $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
206 |
{ class => 'Koha::Patron::Attribute::Types', |
207 |
my $attribute_type_1 = $builder->build( |
207 |
value => { opac_editable => 1, opac_display => 1 } |
208 |
{ source => 'BorrowerAttributeType', |
|
|
209 |
value => { opac_editable => 1 } |
210 |
} |
208 |
} |
211 |
); |
209 |
); |
212 |
|
210 |
my $displayable_attr_type = $builder->build_object( |
213 |
my $attribute_1 = Koha::Patron::Attribute->new( |
211 |
{ class => 'Koha::Patron::Attribute::Types', |
214 |
{ borrowernumber => $patron, |
212 |
value => { opac_editable => 0, opac_display => 1 } |
215 |
code => $attribute_type_1->{code}, |
|
|
216 |
attribute => $patron |
217 |
} |
213 |
} |
218 |
); |
214 |
); |
219 |
is( $attribute_1->opac_editable, 1, '->opac_editable returns 1' ); |
215 |
my $staff_only_attr_type = $builder->build_object( |
220 |
|
216 |
{ class => 'Koha::Patron::Attribute::Types', |
221 |
my $attribute_type_2 = $builder->build( |
217 |
value => { opac_editable => 0, opac_display => 0 } |
222 |
{ source => 'BorrowerAttributeType', |
|
|
223 |
value => { opac_editable => 0 } |
224 |
} |
218 |
} |
225 |
); |
219 |
); |
226 |
|
220 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
227 |
my $attribute_2 = Koha::Patron::Attribute->new( |
221 |
my $editable_attr = $builder->build_object( |
228 |
{ borrowernumber => $patron, |
222 |
{ class => 'Koha::Patron::Attributes', |
229 |
code => $attribute_type_2->{code}, |
223 |
value => { |
230 |
attribute => $patron |
224 |
borrowernumber => $patron->borrowernumber, |
|
|
225 |
code => $editable_attr_type->code |
226 |
} |
231 |
} |
227 |
} |
232 |
); |
228 |
); |
233 |
is( $attribute_2->opac_editable, 0, '->opac_editable returns 0' ); |
229 |
my $displayable_attr = $builder->build_object( |
234 |
|
230 |
{ class => 'Koha::Patron::Attributes', |
235 |
$schema->storage->txn_rollback; |
231 |
value => { |
236 |
}; |
232 |
borrowernumber => $patron->borrowernumber, |
237 |
|
233 |
code => $displayable_attr_type->code |
238 |
subtest 'type() tests' => sub { |
234 |
} |
239 |
|
235 |
} |
240 |
plan tests => 4; |
236 |
); |
241 |
|
237 |
my $staff_only_attr = $builder->build_object( |
242 |
$schema->storage->txn_begin; |
238 |
{ class => 'Koha::Patron::Attributes', |
243 |
|
239 |
value => { |
244 |
my $patron |
240 |
borrowernumber => $patron->borrowernumber, |
245 |
= $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
241 |
code => $staff_only_attr_type->code |
246 |
my $attr_type = $builder->build( { source => 'BorrowerAttributeType' } ); |
242 |
} |
247 |
my $attribute = Koha::Patron::Attribute->new( |
|
|
248 |
{ borrowernumber => $patron, |
249 |
code => $attr_type->{code}, |
250 |
attribute => $patron |
251 |
} |
243 |
} |
252 |
); |
244 |
); |
253 |
|
245 |
|
254 |
my $attribute_type = $attribute->type; |
246 |
my $search_results = Koha::Patron::Attributes->search( |
|
|
247 |
{ borrowernumber => $patron->borrowernumber } ); |
248 |
is( $search_results->count, 3, '3 attributes present for patron' ); |
255 |
|
249 |
|
256 |
is( ref($attribute_type), |
250 |
$search_results = Koha::Patron::Attributes->search_opac_displayable( |
257 |
'Koha::Patron::Attribute::Type', |
251 |
{ borrowernumber => $patron->borrowernumber } ); |
258 |
'->type returns a Koha::Patron::Attribute::Type object' |
|
|
259 |
); |
260 |
|
252 |
|
261 |
is( $attribute_type->code, |
253 |
is( $search_results->count, 2, |
262 |
$attr_type->{code}, |
254 |
'2 attributes are opac displayable for patron' ); |
263 |
'->type returns the right Koha::Patron::Attribute::Type object' ); |
|
|
264 |
|
255 |
|
265 |
is( $attribute_type->opac_editable, |
256 |
$search_results = Koha::Patron::Attributes->search_opac_editable( |
266 |
$attr_type->{opac_editable}, |
257 |
{ borrowernumber => $patron->borrowernumber } ); |
267 |
'->type returns the right Koha::Patron::Attribute::Type object' |
|
|
268 |
); |
269 |
|
258 |
|
270 |
is( $attribute_type->opac_display, |
259 |
is( $search_results->count, 1, |
271 |
$attr_type->{opac_display}, |
260 |
'1 attribute is opac editable for patron' ); |
272 |
'->type returns the right Koha::Patron::Attribute::Type object' |
|
|
273 |
); |
274 |
|
261 |
|
275 |
$schema->storage->txn_rollback; |
262 |
$schema->storage->txn_rollback; |
276 |
}; |
263 |
}; |
277 |
- |
|
|