bug 2295 [3/4]: moving C4::Items tests into t/lib/KohaTest
[koha.git] / t / lib / KohaTest / Items / SetDefaults.pm
1 package KohaTest::Items::SetDefaults;
2 use base qw( KohaTest::Items );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::Items;
10
11 =head2 STARTUP METHODS
12
13 These get run once, before the main test methods in this module
14
15 =cut
16
17 =head2 TEST METHODS
18
19 standard test methods
20
21 =head3 
22
23
24 =cut
25
26 sub add_some_items : Test( 3 ) {
27
28     my $item_to_add_1 = { itemnotes => 'newitem', };
29
30     C4::Items::_set_defaults_for_add($item_to_add_1);
31     ok( exists $item_to_add_1->{'dateaccessioned'}, 'dateaccessioned added to new item' );
32     like( $item_to_add_1->{'dateaccessioned'}, qr/^\d\d\d\d-\d\d-\d\d$/, 'new dateaccessioned is dddd-dd-dd' );
33     is( $item_to_add_1->{'itemnotes'}, 'newitem', 'itemnotes not clobbered' );
34
35 }
36
37 sub undefined : Test( 4 ) {
38     my $item_add_fixes_1 = {
39         notforloan => undef,
40         damaged    => undef,
41         wthdrawn   => undef,
42         itemlost   => undef,
43     };
44
45     C4::Items::_set_defaults_for_add($item_add_fixes_1);
46     is( $item_add_fixes_1->{'notforloan'}, 0, 'null notforloan fixed during add' );
47     is( $item_add_fixes_1->{'damaged'},    0, 'null damaged fixed during add' );
48     is( $item_add_fixes_1->{'wthdrawn'},   0, 'null wthdrawn fixed during add' );
49     is( $item_add_fixes_1->{'itemlost'},   0, 'null itemlost fixed during add' );
50 }
51
52 sub empty_gets_fixed : Test( 4 ) {
53
54     my $item_add_fixes_2 = {
55         notforloan => '',
56         damaged    => '',
57         wthdrawn   => '',
58         itemlost   => '',
59     };
60
61     C4::Items::_set_defaults_for_add($item_add_fixes_2);
62     is( $item_add_fixes_2->{'notforloan'}, 0, 'empty notforloan fixed during add' );
63     is( $item_add_fixes_2->{'damaged'},    0, 'empty damaged fixed during add' );
64     is( $item_add_fixes_2->{'wthdrawn'},   0, 'empty wthdrawn fixed during add' );
65     is( $item_add_fixes_2->{'itemlost'},   0, 'empty itemlost fixed during add' );
66
67 }
68
69 sub do_not_clobber : Test( 4 ) {
70
71     my $item_add_fixes_3 = {
72         notforloan => 1,
73         damaged    => 2,
74         wthdrawn   => 3,
75         itemlost   => 4,
76     };
77
78     C4::Items::_set_defaults_for_add($item_add_fixes_3);
79     is( $item_add_fixes_3->{'notforloan'}, 1, 'do not clobber notforloan during mod' );
80     is( $item_add_fixes_3->{'damaged'},    2, 'do not clobber damaged during mod' );
81     is( $item_add_fixes_3->{'wthdrawn'},   3, 'do not clobber wthdrawn during mod' );
82     is( $item_add_fixes_3->{'itemlost'},   4, 'do not clobber itemlost during mod' );
83
84 }
85
86 1;