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