| 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 | -  |  |  |