Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 2; |
4 |
use Test::More tests => 4; |
5 |
use t::lib::TestBuilder; |
5 |
use t::lib::TestBuilder; |
6 |
use String::Random qw(random_string); |
6 |
use String::Random qw(random_string); |
7 |
use Koha::Database; |
7 |
use Koha::Database; |
Lines 89-91
subtest 'set_additional_fields with marcfield_mode = "set"' => sub {
Link Here
|
89 |
|
89 |
|
90 |
$schema->txn_rollback; |
90 |
$schema->txn_rollback; |
91 |
}; |
91 |
}; |
92 |
- |
92 |
|
|
|
93 |
subtest 'get_additional_field_values_for_template' => sub { |
94 |
plan tests => 2; |
95 |
|
96 |
$schema->txn_begin; |
97 |
|
98 |
my $biblio = $builder->build_sample_biblio(); |
99 |
my $subscription = Koha::Subscription->new( |
100 |
{ |
101 |
biblionumber => $biblio->biblionumber, |
102 |
} |
103 |
); |
104 |
$subscription->store()->discard_changes(); |
105 |
|
106 |
my $field = Koha::AdditionalField->new( |
107 |
{ |
108 |
tablename => 'subscription', |
109 |
name => random_string( 'c' x 100 ) |
110 |
} |
111 |
); |
112 |
$field->store()->discard_changes(); |
113 |
|
114 |
my $field2 = Koha::AdditionalField->new( |
115 |
{ |
116 |
tablename => 'subscription', |
117 |
name => random_string( 'c' x 100 ) |
118 |
} |
119 |
); |
120 |
$field2->store()->discard_changes(); |
121 |
|
122 |
my $value = 'some value'; |
123 |
$subscription->set_additional_fields( |
124 |
[ |
125 |
{ |
126 |
id => $field->id, |
127 |
value => $value . ' 1', |
128 |
}, |
129 |
{ |
130 |
id => $field->id, |
131 |
value => $value . ' 2', |
132 |
}, |
133 |
{ |
134 |
id => $field2->id, |
135 |
value => 'second field', |
136 |
}, |
137 |
] |
138 |
); |
139 |
|
140 |
my $template_additional_field_values = $subscription->get_additional_field_values_for_template; |
141 |
|
142 |
is( |
143 |
ref($template_additional_field_values), 'HASH', |
144 |
'->get_additional_field_values_for_template should return a hash' |
145 |
); |
146 |
is_deeply( |
147 |
$template_additional_field_values, |
148 |
{ $field->id => [ $value . ' 1', $value . ' 2' ], $field2->id => ['second field'] }, |
149 |
'->get_additional_field_values_for_template should return the correct values' |
150 |
); |
151 |
|
152 |
$schema->txn_rollback; |
153 |
}; |
154 |
|
155 |
subtest 'add_additional_fields' => sub { |
156 |
plan tests => 1; |
157 |
|
158 |
$schema->txn_begin; |
159 |
|
160 |
Koha::AdditionalFields->search->delete; |
161 |
|
162 |
my $biblio = $builder->build_sample_biblio(); |
163 |
my $subscription = Koha::Subscription->new( |
164 |
{ |
165 |
biblionumber => $biblio->biblionumber, |
166 |
} |
167 |
); |
168 |
$subscription->store()->discard_changes(); |
169 |
|
170 |
my $field = Koha::AdditionalField->new( |
171 |
{ |
172 |
tablename => 'subscription', |
173 |
name => random_string( 'c' x 100 ) |
174 |
} |
175 |
); |
176 |
$field->store()->discard_changes(); |
177 |
|
178 |
my $field2 = Koha::AdditionalField->new( |
179 |
{ |
180 |
tablename => 'subscription', |
181 |
name => random_string( 'c' x 100 ) |
182 |
} |
183 |
); |
184 |
$field2->store()->discard_changes(); |
185 |
|
186 |
my $value = 'some value'; |
187 |
$subscription->set_additional_fields( |
188 |
[ |
189 |
{ |
190 |
id => $field->id, |
191 |
value => $value . ' 1', |
192 |
}, |
193 |
{ |
194 |
id => $field->id, |
195 |
value => $value . ' 2', |
196 |
} |
197 |
] |
198 |
); |
199 |
|
200 |
$subscription->add_additional_fields( |
201 |
{ |
202 |
$field2->id => [ |
203 |
'second field' |
204 |
], |
205 |
}, |
206 |
'subscription' |
207 |
); |
208 |
|
209 |
my $template_additional_field_values = $subscription->get_additional_field_values_for_template; |
210 |
|
211 |
|
212 |
|
213 |
is_deeply( |
214 |
$template_additional_field_values, |
215 |
{ $field->id => [ $value . ' 1', $value . ' 2' ], $field2->id => ['second field'] }, |
216 |
'->add_additional_fields should have only added to existing field values' |
217 |
); |
218 |
|
219 |
$schema->txn_rollback; |
220 |
}; |