Lines 26-32
use Koha::Library;
Link Here
|
26 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
27 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
28 |
|
28 |
|
29 |
use Test::More tests => 10; |
29 |
use Test::More tests => 11; |
30 |
|
30 |
|
31 |
use Test::Warn; |
31 |
use Test::Warn; |
32 |
|
32 |
|
Lines 666-671
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
666 |
$schema->storage->txn_rollback; |
666 |
$schema->storage->txn_rollback; |
667 |
}; |
667 |
}; |
668 |
|
668 |
|
|
|
669 |
subtest '_mod_item_dates' => sub { |
670 |
plan tests => 11; |
671 |
|
672 |
is( C4::Items::_mod_item_dates(), undef, 'Call without parameters' ); |
673 |
is( C4::Items::_mod_item_dates(1), undef, 'Call without hashref' ); |
674 |
|
675 |
my $orgitem; |
676 |
my $item = { |
677 |
itemcallnumber => 'V II 149 1963', |
678 |
barcode => '109304', |
679 |
}; |
680 |
$orgitem = { %$item }; |
681 |
C4::Items::_mod_item_dates($item); |
682 |
is_deeply( $item, $orgitem, 'No dates passed to _mod_item_dates' ); |
683 |
|
684 |
# add two correct dates |
685 |
t::lib::Mocks::mock_preference('dateformat', 'us'); |
686 |
$item->{dateaccessioned} = '01/31/2016'; |
687 |
$item->{onloan} = $item->{dateaccessioned}; |
688 |
$orgitem = { %$item }; |
689 |
C4::Items::_mod_item_dates($item); |
690 |
is( $item->{dateaccessioned}, '2016-01-31', 'dateaccessioned is fine' ); |
691 |
is( $item->{onloan}, '2016-01-31', 'onloan is fine too' ); |
692 |
|
693 |
|
694 |
# add some invalid dates |
695 |
$item->{notexistingcolumndate} = '13/1/2015'; # wrong format |
696 |
$item->{anotherdate} = 'tralala'; # even worse |
697 |
$item->{myzerodate} = '0000-00-00'; # wrong too |
698 |
C4::Items::_mod_item_dates($item); |
699 |
is( $item->{notexistingcolumndate}, undef, 'Invalid date became NULL' ); |
700 |
is( $item->{anotherdate}, undef, 'Second invalid date became NULL too' ); |
701 |
is( $item->{myzerodate}, undef, '0000-00-00 became NULL too' ); |
702 |
|
703 |
# check if itemlost_on was not touched |
704 |
$item->{itemlost_on} = '12345678'; |
705 |
$item->{withdrawn_on} = '12/31/2015 23:59:00'; |
706 |
$orgitem = { %$item }; |
707 |
C4::Items::_mod_item_dates($item); |
708 |
is_deeply( $item, $orgitem, 'Colums with _on are not touched' ); |
709 |
|
710 |
t::lib::Mocks::mock_preference('dateformat', 'metric'); |
711 |
$item->{dateaccessioned} = '01/31/2016'; #wrong |
712 |
$item->{yetanotherdatetime} = '20/01/2016 13:58:00'; #okay |
713 |
C4::Items::_mod_item_dates($item); |
714 |
is( $item->{dateaccessioned}, undef, 'dateaccessioned wrong format' ); |
715 |
is( $item->{yetanotherdatetime}, '2016-01-20 13:58:00', |
716 |
'yetanotherdatetime is ok' ); |
717 |
}; |
718 |
|
669 |
# Helper method to set up a Biblio. |
719 |
# Helper method to set up a Biblio. |
670 |
sub get_biblio { |
720 |
sub get_biblio { |
671 |
my ( $frameworkcode ) = @_; |
721 |
my ( $frameworkcode ) = @_; |
672 |
- |
|
|