Modifying Members : Add Mod and GetMember
[koha-equinox.git] / t / lib / KohaTest / Acquisition / GetLateOrders.pm
1 package KohaTest::Acquisition::GetLateOrders;
2 use base qw( KohaTest::Acquisition );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::Acquisition;
10 use C4::Context;
11 use C4::Members;
12
13 =head3 no_orders
14
15 =cut
16
17 sub no_orders : Test( 1 ) {
18     my $self = shift;
19
20     my @orders = GetLateOrders( 1 );
21     is( scalar @orders, 0, 'There are no orders, so we found 0.' ) 
22       or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
23
24 }
25
26 =head3 one_order
27
28 =cut
29
30 sub one_order : Test( 29 ) {
31     my $self = shift;
32
33     my ( $basketid, $ordernumber ) = $self->create_new_basket();
34     ok( $basketid, 'a new basket was created' );
35     ok( $ordernumber, 'the basket has an order in it.' );
36     # we need this basket to be closed.
37     CloseBasket( $basketid );
38     
39     my @orders = GetLateOrders( 0 );
40
41     {
42         my @orders = GetLateOrders( 0 );
43         is( scalar @orders, 1, 'An order closed today is 0 days late.' ) 
44           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
45     }
46     {
47         my @orders = GetLateOrders( 1 );
48         is( scalar @orders, 0, 'An order closed today is not 1 day late.' ) 
49           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
50     }
51     {
52         my @orders = GetLateOrders( -1 );
53         is( scalar @orders, 1, 'an order closed today is -1 day late.' ) 
54           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
55     }
56
57     # provide some vendor information
58     {
59         my @orders = GetLateOrders( 0, $self->{'booksellerid'} );
60         is( scalar @orders, 1, 'We found this late order with the right supplierid.' ) 
61           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
62     }
63     {
64         my @orders = GetLateOrders( 0, $self->{'booksellerid'} + 1 );
65         is( scalar @orders, 0, 'We found no late orders with the wrong supplierid.' ) 
66           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
67     }
68
69     # provide some branch information
70     my $member = GetMember( borrowernumber=>$self->{'memberid'} );
71     # diag( Data::Dumper->Dump( [ $member ], [ 'member' ] ) );
72     {
73         my @orders = GetLateOrders( 0, $self->{'booksellerid'}, $member->{'branchcode'} );
74         is( scalar @orders, 1, 'We found this late order with the right branchcode.' ) 
75           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
76     }
77     {
78         my @orders = GetLateOrders( 0, $self->{'booksellerid'}, 'This is not the branch' );
79         is( scalar @orders, 0, 'We found no late orders with the wrong branchcode.' ) 
80           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
81     }
82
83     # set up some things necessary to make GetLateOrders use the IndependantBranches
84     $self->enable_independant_branches();    
85
86     {
87         my @orders = GetLateOrders( 0, $self->{'booksellerid'}, $member->{'branchcode'} );
88         is( scalar @orders, 1, 'We found this late order with the right branchcode.' ) 
89           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
90     }
91     {
92         my @orders = GetLateOrders( 0, $self->{'booksellerid'}, 'This is not the branch' );
93         is( scalar @orders, 0, 'We found no late orders with the wrong branchcode.' ) 
94           or diag( Data::Dumper->Dump( [ \@orders ], [ 'orders' ] ) );
95     }
96
97     # reset that.
98     $self->disable_independant_branches();    
99
100 }
101
102
103
104
105
106 1;