|
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 732-737
subtest 'C4::Items::_build_default_values_for_mod_marc' => sub {
Link Here
|
| 732 |
$schema->storage->txn_rollback; |
732 |
$schema->storage->txn_rollback; |
| 733 |
}; |
733 |
}; |
| 734 |
|
734 |
|
|
|
735 |
subtest '_mod_item_dates' => sub { |
| 736 |
plan tests => 11; |
| 737 |
|
| 738 |
is( C4::Items::_mod_item_dates(), undef, 'Call without parameters' ); |
| 739 |
is( C4::Items::_mod_item_dates(1), undef, 'Call without hashref' ); |
| 740 |
|
| 741 |
my $orgitem; |
| 742 |
my $item = { |
| 743 |
itemcallnumber => 'V II 149 1963', |
| 744 |
barcode => '109304', |
| 745 |
}; |
| 746 |
$orgitem = { %$item }; |
| 747 |
C4::Items::_mod_item_dates($item); |
| 748 |
is_deeply( $item, $orgitem, 'No dates passed to _mod_item_dates' ); |
| 749 |
|
| 750 |
# add two correct dates |
| 751 |
t::lib::Mocks::mock_preference('dateformat', 'us'); |
| 752 |
$item->{dateaccessioned} = '01/31/2016'; |
| 753 |
$item->{onloan} = $item->{dateaccessioned}; |
| 754 |
$orgitem = { %$item }; |
| 755 |
C4::Items::_mod_item_dates($item); |
| 756 |
is( $item->{dateaccessioned}, '2016-01-31', 'dateaccessioned is fine' ); |
| 757 |
is( $item->{onloan}, '2016-01-31', 'onloan is fine too' ); |
| 758 |
|
| 759 |
|
| 760 |
# add some invalid dates |
| 761 |
$item->{notexistingcolumndate} = '13/1/2015'; # wrong format |
| 762 |
$item->{anotherdate} = 'tralala'; # even worse |
| 763 |
$item->{myzerodate} = '0000-00-00'; # wrong too |
| 764 |
C4::Items::_mod_item_dates($item); |
| 765 |
is( $item->{notexistingcolumndate}, undef, 'Invalid date became NULL' ); |
| 766 |
is( $item->{anotherdate}, undef, 'Second invalid date became NULL too' ); |
| 767 |
is( $item->{myzerodate}, undef, '0000-00-00 became NULL too' ); |
| 768 |
|
| 769 |
# check if itemlost_on was not touched |
| 770 |
$item->{itemlost_on} = '12345678'; |
| 771 |
$item->{withdrawn_on} = '12/31/2015 23:59:00'; |
| 772 |
$orgitem = { %$item }; |
| 773 |
C4::Items::_mod_item_dates($item); |
| 774 |
is_deeply( $item, $orgitem, 'Colums with _on are not touched' ); |
| 775 |
|
| 776 |
t::lib::Mocks::mock_preference('dateformat', 'metric'); |
| 777 |
$item->{dateaccessioned} = '01/31/2016'; #wrong |
| 778 |
$item->{yetanotherdatetime} = '20/01/2016 13:58:00'; #okay |
| 779 |
C4::Items::_mod_item_dates($item); |
| 780 |
is( $item->{dateaccessioned}, undef, 'dateaccessioned wrong format' ); |
| 781 |
is( $item->{yetanotherdatetime}, '2016-01-20 13:58:00', |
| 782 |
'yetanotherdatetime is ok' ); |
| 783 |
}; |
| 784 |
|
| 735 |
# Helper method to set up a Biblio. |
785 |
# Helper method to set up a Biblio. |
| 736 |
sub get_biblio { |
786 |
sub get_biblio { |
| 737 |
my ( $frameworkcode ) = @_; |
787 |
my ( $frameworkcode ) = @_; |
| 738 |
- |
|
|