Lines 19-24
$dbh->do("DELETE FROM authorised_value_categories");
Link Here
|
19 |
# insert |
19 |
# insert |
20 |
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; |
20 |
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; |
21 |
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; |
21 |
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; |
|
|
22 |
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store; |
22 |
my $av1 = Koha::AuthorisedValue->new( |
23 |
my $av1 = Koha::AuthorisedValue->new( |
23 |
{ |
24 |
{ |
24 |
category => 'av_for_testing', |
25 |
category => 'av_for_testing', |
Lines 58-63
my $av4 = Koha::AuthorisedValue->new(
Link Here
|
58 |
imageurl => 'image4.png', |
59 |
imageurl => 'image4.png', |
59 |
} |
60 |
} |
60 |
)->store(); |
61 |
)->store(); |
|
|
62 |
my $av_empty_string = Koha::AuthorisedValue->new( |
63 |
{ |
64 |
category => 'restricted_for_testing', |
65 |
authorised_value => undef, # Should have been defaulted to "" |
66 |
lib => 'display value undef', |
67 |
lib_opac => 'opac display value undef', |
68 |
} |
69 |
)->store(); |
70 |
my $av_0 = Koha::AuthorisedValue->new( |
71 |
{ |
72 |
category => 'restricted_for_testing', |
73 |
authorised_value => 0, |
74 |
lib => 'display value 0', |
75 |
lib_opac => 'opac display value 0', |
76 |
} |
77 |
)->store(); |
61 |
|
78 |
|
62 |
ok( $av1->id(), 'AV 1 is inserted' ); |
79 |
ok( $av1->id(), 'AV 1 is inserted' ); |
63 |
ok( $av2->id(), 'AV 2 is inserted' ); |
80 |
ok( $av2->id(), 'AV 2 is inserted' ); |
Lines 97-103
my $limits = $av1->branch_limitations;
Link Here
|
97 |
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' ); |
114 |
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' ); |
98 |
|
115 |
|
99 |
my @categories = Koha::AuthorisedValues->new->categories; |
116 |
my @categories = Koha::AuthorisedValues->new->categories; |
100 |
is( @categories, 2, 'There should have 2 categories inserted' ); |
117 |
is( @categories, 3, 'There should have 2 categories inserted' ); |
101 |
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); |
118 |
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); |
102 |
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); |
119 |
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); |
103 |
|
120 |
|
Lines 109-119
subtest 'search_by_*_field' => sub {
Link Here
|
109 |
$mss->delete if $mss; |
126 |
$mss->delete if $mss; |
110 |
$mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'd', frameworkcode => '' } ); |
127 |
$mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'd', frameworkcode => '' } ); |
111 |
$mss->delete if $mss; |
128 |
$mss->delete if $mss; |
|
|
129 |
$mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => '5', frameworkcode => '' } ); |
130 |
$mss->delete if $mss; |
112 |
Koha::AuthorisedValueCategory->new( { category_name => 'LOC' } )->store; |
131 |
Koha::AuthorisedValueCategory->new( { category_name => 'LOC' } )->store; |
113 |
Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store; |
132 |
Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store; |
114 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
133 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
115 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
134 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
116 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store; |
135 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store; |
|
|
136 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => '5', frameworkcode => '', authorised_value => 'restricted_for_testing', kohafield => 'items.restricted' } )->store; |
117 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_1' } )->store; |
137 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_1' } )->store; |
118 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_2' } )->store; |
138 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_2' } )->store; |
119 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_3' } )->store; |
139 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_3' } )->store; |
Lines 131-142
subtest 'search_by_*_field' => sub {
Link Here
|
131 |
is( $avs->next->authorised_value, 'location_1', ); |
151 |
is( $avs->next->authorised_value, 'location_1', ); |
132 |
}; |
152 |
}; |
133 |
subtest 'search_by_koha_field' => sub { |
153 |
subtest 'search_by_koha_field' => sub { |
134 |
plan tests => 3; |
154 |
plan tests => 8; |
135 |
my $avs; |
155 |
my $avs; |
136 |
$avs = Koha::AuthorisedValues->search_by_koha_field(); |
156 |
$avs = Koha::AuthorisedValues->search_by_koha_field(); |
137 |
is ( $avs, undef ); |
157 |
is ( $avs, undef ); |
138 |
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.location', tagfield => 952, tagsubfield => 'c' } ); |
158 |
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.location', tagfield => 952, tagsubfield => 'c' } ); |
139 |
is( $avs->count, 3, ); |
159 |
is( $avs->count, 3, ); |
140 |
is( $avs->next->authorised_value, 'location_1', ); |
160 |
is( $avs->next->authorised_value, 'location_1', ); |
|
|
161 |
|
162 |
# Test authorised_value = 0 |
163 |
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.restricted', authorised_value => 0 } ); |
164 |
is( $avs->count, 1, ); |
165 |
is( $avs->next->lib, $av_0->lib, ); |
166 |
# Test authorised_value = "" |
167 |
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.restricted', authorised_value => '' } ); |
168 |
is( $avs->count, 1, ); |
169 |
is( $avs->next->lib, $av_empty_string->lib, ); |
170 |
# Test authorised_value = undef => we do not want to retrieve anything |
171 |
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.restricted', authorised_value => undef } ); |
172 |
is( $avs->count, 0, ); |
173 |
|
141 |
}; |
174 |
}; |
142 |
}; |
175 |
}; |
143 |
- |
|
|