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

(-)a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t (-2 / +111 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 => 5;
4
use Test::More tests => 6;
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
use CGI;
13
use CGI;
12
14
Lines 280-282 subtest 'prepare_cgi_additional_field_values' => sub { Link Here
280
    $schema->txn_rollback;
282
    $schema->txn_rollback;
281
283
282
};
284
};
283
- 
285
286
subtest 'strings_map() tests' => sub {
287
    plan tests => 1;
288
     $schema->txn_begin;
289
     Koha::AdditionalFields->search->delete;
290
     my $license = Koha::ERM::License->new(
291
        {
292
            name   => "license name",
293
            type   => "national",
294
            status => "in_negotiation",
295
296
        }
297
    );
298
    $license->store()->discard_changes();
299
     my $field = Koha::AdditionalField->new(
300
        {
301
            tablename => 'erm_licenses',
302
            name      => 'af_1',
303
304
        }
305
    );
306
    $field->store()->discard_changes();
307
     my $field2 = Koha::AdditionalField->new(
308
        {
309
            tablename => 'erm_licenses',
310
            name      => 'af_2',
311
312
        }
313
    );
314
    $field2->store()->discard_changes();
315
     my $value = 'some license value';
316
    $license->set_additional_fields(
317
        [
318
            {
319
                id    => $field->id,
320
                value => $value . ' 1',
321
322
            },
323
            {
324
                id    => $field->id,
325
                value => $value . ' 2',
326
327
            }
328
        ]
329
    );
330
     $license->add_additional_fields(
331
        {
332
            $field2->id => ['second field'],
333
334
        },
335
        'erm_licenses'
336
    );
337
      my $av_category = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } );
338
    $av_category->store()->discard_changes();
339
     my $av_value = Koha::AuthorisedValue->new(
340
        {
341
            category         => $av_category->category_name,
342
            authorised_value => 'BOB',
343
            lib              => "Robert"
344
        }
345
    );
346
     my $av_field = Koha::AdditionalField->new(
347
        {
348
            tablename                 => "erm_licenses",
349
            name                      => "av_field",
350
            authorised_value_category => $av_category->category_name,
351
352
        }
353
    );
354
    $av_field->store()->discard_changes();
355
       $license->add_additional_fields(
356
        {
357
            $av_field->id => [ $av_value->authorised_value ],
358
359
        },
360
        'erm_licenses'
361
    );
362
     my $values      = $license->get_additional_field_values_for_template;
363
     my $strings_map = $license->strings_map;
364
    is_deeply(
365
        $strings_map,
366
        {
367
            additional_field_values => [
368
                {
369
                    'field_id'    => $field->id,
370
                    'type'        => 'text',
371
                    'field_label' => $field->name,
372
                    'value_str'   => join( ', ', @{ $values->{ $field->id } } )
373
                },
374
                {
375
                    'field_id'    => $field2->id,
376
                    'type'        => 'text',
377
                    'field_label' => $field2->name,
378
                    'value_str'   => join( ', ', @{ $values->{ $field2->id } } )
379
                },
380
                {
381
                    'field_id'    => $av_field->id,
382
                    'type'        => 'av',
383
                    'field_label' => $av_field->name,
384
                    'value_str'   => join( ', ', @{ $values->{ $av_field->id } } )
385
                }
386
            ]
387
        },
388
        'strings_map looks good'
389
    );
390
     $schema->txn_rollback;
391
    ;
392
};

Return to bug 35287