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

(-)a/Koha/Object.pm (-1 / +6 lines)
Lines 500-506 sub attributes_from_api { Link Here
500
          : $key;
500
          : $key;
501
501
502
        if ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) {
502
        if ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) {
503
            $value = dt_from_string($value, 'rfc3339');
503
            try {
504
                $value = dt_from_string($value, 'rfc3339');
505
            }
506
            catch {
507
                Koha::Exceptions::BadParameter->throw( parameter => $key );
508
            };
504
        }
509
        }
505
510
506
        $params->{$koha_field_name} = $value;
511
        $params->{$koha_field_name} = $value;
(-)a/t/db_dependent/Koha/Object.t (-2 / +69 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 16;
20
use Test::More tests => 17;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
use DateTime;
23
use DateTime;
Lines 385-390 subtest 'new_from_api() tests' => sub { Link Here
385
    $schema->storage->txn_rollback;
385
    $schema->storage->txn_rollback;
386
};
386
};
387
387
388
subtest 'attributes_from_api() tests' => sub {
389
390
    plan tests => 8;
391
392
    my $patron = Koha::Patron->new();
393
394
    use Data::Printer colored => 1;
395
396
    my $attrs = $patron->attributes_from_api(
397
        {
398
            updated_on  => '2019-12-27T14:53:00'
399
        }
400
    );
401
402
    ok( exists $attrs->{updated_on},
403
        'No translation takes place if no mapping' );
404
    is(
405
        ref( $attrs->{updated_on} ),
406
        'DateTime',
407
        'Given a string, a timestamp field is converted into a DateTime object'
408
    );
409
410
    $attrs = $patron->attributes_from_api(
411
        {
412
            last_seen  => '2019-12-27T14:53:00'
413
        }
414
    );
415
416
    ok( exists $attrs->{lastseen},
417
        'Translation takes place because of the defined mapping' );
418
    is(
419
        ref( $attrs->{lastseen} ),
420
        'DateTime',
421
        'Given a string, a datetime field is converted into a DateTime object'
422
    );
423
424
    $attrs = $patron->attributes_from_api(
425
        {
426
            date_of_birth  => '2019-12-27'
427
        }
428
    );
429
430
    ok( exists $attrs->{dateofbirth},
431
        'Translation takes place because of the defined mapping' );
432
    is(
433
        ref( $attrs->{dateofbirth} ),
434
        'DateTime',
435
        'Given a string, a date field is converted into a DateTime object'
436
    );
437
438
    throws_ok
439
        {
440
            $attrs = $patron->attributes_from_api(
441
                {
442
                    date_of_birth => '20141205',
443
                }
444
            );
445
        }
446
        'Koha::Exceptions::BadParameter',
447
        'Bad date throws an exception';
448
449
    is(
450
        $@->parameter,
451
        'date_of_birth',
452
        'Exception parameter is the API field name, not the DB one'
453
    );
454
};
455
388
subtest "Test update method" => sub {
456
subtest "Test update method" => sub {
389
    plan tests => 6;
457
    plan tests => 6;
390
458
391
- 

Return to bug 23893