View | Details | Raw Unified | Return to bug 35287
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t (-2 / +119 lines)
Lines 1-12 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 => 4;
4
use Test::More tests => 5;
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;
8
use Koha::Subscription;
8
use Koha::Subscription;
9
use Koha::AdditionalField;
9
use Koha::AdditionalField;
10
use Koha::AuthorisedValueCategory;
11
use Koha::ERM::License;
10
use C4::Context;
12
use C4::Context;
11
13
12
my $builder = t::lib::TestBuilder->new;
14
my $builder = t::lib::TestBuilder->new;
Lines 218-220 subtest 'add_additional_fields' => sub { Link Here
218
220
219
    $schema->txn_rollback;
221
    $schema->txn_rollback;
220
};
222
};
221
- 
223
224
subtest 'strings_map() tests' => sub {
225
    plan tests => 1;
226
227
    $schema->txn_begin;
228
229
    Koha::AdditionalFields->search->delete;
230
231
    my $license = Koha::ERM::License->new(
232
        {
233
            name   => "license name",
234
            type   => "national",
235
            status => "in_negotiation",
236
        }
237
    );
238
    $license->store()->discard_changes();
239
240
    my $field = Koha::AdditionalField->new(
241
        {
242
            tablename => 'erm_licenses',
243
            name      => 'af_1',
244
        }
245
    );
246
    $field->store()->discard_changes();
247
248
    my $field2 = Koha::AdditionalField->new(
249
        {
250
            tablename => 'erm_licenses',
251
            name      => 'af_2',
252
        }
253
    );
254
    $field2->store()->discard_changes();
255
256
    my $value = 'some license value';
257
    $license->set_additional_fields(
258
        [
259
            {
260
                id    => $field->id,
261
                value => $value . ' 1',
262
            },
263
            {
264
                id    => $field->id,
265
                value => $value . ' 2',
266
            }
267
        ]
268
    );
269
270
    $license->add_additional_fields(
271
        {
272
            $field2->id => ['second field'],
273
        },
274
        'erm_licenses'
275
    );
276
277
278
    my $av_category      = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } );
279
    $av_category->store()->discard_changes();
280
281
    my $av_value = Koha::AuthorisedValue->new(
282
        {
283
            category => $av_category->category_name,
284
            authorised_value => 'BOB',
285
            lib              => "Robert"
286
        }
287
    );
288
289
    my $av_field = Koha::AdditionalField->new(
290
        {
291
            tablename                 => "erm_licenses",
292
            name                      => "av_field",
293
            authorised_value_category => $av_category->category_name,
294
        }
295
    );
296
    $av_field->store()->discard_changes();
297
298
299
300
    $license->add_additional_fields(
301
        {
302
            $av_field->id => [$av_value->authorised_value],
303
        },
304
        'erm_licenses'
305
    );
306
307
    my $values = $license->get_additional_field_values_for_template;
308
309
    my $strings_map = $license->strings_map;
310
    is_deeply(
311
        $strings_map,
312
        {
313
            additional_field_values => [
314
                {
315
                    'field_id'    => $field->id,
316
                    'type'        => 'text',
317
                    'field_label' => $field->name,
318
                    'value_str'   => join( ', ', @{ $values->{ $field->id } } )
319
                },
320
                {
321
                    'field_id'    => $field2->id,
322
                    'type'        => 'text',
323
                    'field_label' => $field2->name,
324
                    'value_str'   => join( ', ', @{ $values->{ $field2->id } } )
325
                },
326
                {
327
                    'field_id'    => $av_field->id,
328
                    'type'        => 'av',
329
                    'field_label' => $av_field->name,
330
                    'value_str'   => join( ', ', @{ $values->{ $av_field->id } } )
331
                }
332
            ]
333
        },
334
        'strings_map looks good'
335
    );
336
337
    $schema->txn_rollback;
338
};

Return to bug 35287