start of test suite for C4::Items
[koha.git] / t / Items.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 28;
7 BEGIN {
8         use_ok('C4::Items');
9 }
10
11 my $item_mod_fixes_1 = {
12     notforloan => undef,
13     damaged    => undef,
14     wthdrawn   => undef,
15     itemlost   => undef,
16 };
17
18 my $item_mod_fixes_2 = {
19     notforloan => '',
20     damaged    => '',
21     wthdrawn   => '',
22     itemlost   => '',
23 };
24
25 my $item_mod_fixes_3 = {
26     notforloan => 1,
27     damaged    => 2,
28     wthdrawn   => 3,
29     itemlost   => 4,
30 };
31
32 C4::Items::_do_column_fixes_for_mod($item_mod_fixes_1);
33 is($item_mod_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during mod');
34 is($item_mod_fixes_1->{'damaged'}, 0, 'null damaged fixed during mod');
35 is($item_mod_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during mod');
36 is($item_mod_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during mod');
37
38 C4::Items::_do_column_fixes_for_mod($item_mod_fixes_2);
39 is($item_mod_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during mod');
40 is($item_mod_fixes_2->{'damaged'}, 0, 'empty damaged fixed during mod');
41 is($item_mod_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during mod');
42 is($item_mod_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during mod');
43
44 C4::Items::_do_column_fixes_for_mod($item_mod_fixes_3);
45 is($item_mod_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod');
46 is($item_mod_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod');
47 is($item_mod_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod');
48 is($item_mod_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod');
49
50 my $item_to_add_1 = {
51     itemnotes => 'newitem',
52 };
53
54 C4::Items::_set_defaults_for_add($item_to_add_1);
55 ok(exists $item_to_add_1->{'dateaccessioned'}, 'dateaccessioned added to new item');
56 like($item_to_add_1->{'dateaccessioned'}, qr/^\d\d\d\d-\d\d-\d\d$/ , 'new dateaccessioned is dddd-dd-dd');
57 is($item_to_add_1->{'itemnotes'}, 'newitem', 'itemnotes not clobbered');
58
59 my $item_add_fixes_1 = {
60     notforloan => undef,
61     damaged    => undef,
62     wthdrawn   => undef,
63     itemlost   => undef,
64 };
65
66 my $item_add_fixes_2 = {
67     notforloan => '',
68     damaged    => '',
69     wthdrawn   => '',
70     itemlost   => '',
71 };
72
73 my $item_add_fixes_3 = {
74     notforloan => 1,
75     damaged    => 2,
76     wthdrawn   => 3,
77     itemlost   => 4,
78 };
79
80 C4::Items::_set_defaults_for_add($item_add_fixes_1);
81 is($item_add_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during add');
82 is($item_add_fixes_1->{'damaged'}, 0, 'null damaged fixed during add');
83 is($item_add_fixes_1->{'wthdrawn'}, 0, 'null wthdrawn fixed during add');
84 is($item_add_fixes_1->{'itemlost'}, 0, 'null itemlost fixed during add');
85
86 C4::Items::_set_defaults_for_add($item_add_fixes_2);
87 is($item_add_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during add');
88 is($item_add_fixes_2->{'damaged'}, 0, 'empty damaged fixed during add');
89 is($item_add_fixes_2->{'wthdrawn'}, 0, 'empty wthdrawn fixed during add');
90 is($item_add_fixes_2->{'itemlost'}, 0, 'empty itemlost fixed during add');
91
92 C4::Items::_set_defaults_for_add($item_add_fixes_3);
93 is($item_add_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod');
94 is($item_add_fixes_3->{'damaged'}, 2, 'do not clobber damaged during mod');
95 is($item_add_fixes_3->{'wthdrawn'}, 3, 'do not clobber wthdrawn during mod');
96 is($item_add_fixes_3->{'itemlost'}, 4, 'do not clobber itemlost during mod');
97