6 use Test
::More tests
=> 49;
9 use_ok
('C4::Acquisition');
11 my $module = new Test
::MockModule
('C4::Context');
12 $module->mock('_new_dbh', sub {
13 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
14 || die "Cannot create handle: $DBI::errstr\n";
18 my $dbh = C4
::Context
->dbh;
20 # We need to add a resultset to avoid DBI fail
21 # ("DBI bind_columns: invalid number of arguments...")
23 [qw(one two three four)],
27 $dbh->{mock_add_resultset
} = $rs;
28 my @invoices = C4
::Acquisition
::GetInvoices
(
29 supplierid
=> "supplierid",
30 invoicenumber
=> "invoicenumber",
31 suppliername
=> "suppliername",
32 shipmentdatefrom
=> "shipmentdatefrom",
33 shipmentdateto
=> "shipmentdateto",
34 billingdatefrom
=> "billingdatefrom",
35 billingdateto
=> "billingdateto",
36 isbneanissn
=> "isbneanissn",
39 publisher
=> "publisher",
40 publicationyear
=> "publicationyear",
41 branchcode
=> "branchcode",
43 my $history = $dbh->{mock_all_history
};
45 is
(scalar(@
$history), 1);
46 my @bound_params = @
{ $history->[0]->{bound_params
} };
47 is
(scalar(@bound_params), 15);
48 is
($bound_params[0], 'supplierid');
49 is
($bound_params[1], '%invoicenumber%');
50 is
($bound_params[2], '%suppliername%');
51 is
($bound_params[3], 'shipmentdatefrom');
52 is
($bound_params[4], 'shipmentdateto');
53 is
($bound_params[5], 'billingdatefrom');
54 is
($bound_params[6], 'billingdateto');
55 is
($bound_params[7], 'isbneanissn');
56 is
($bound_params[8], 'isbneanissn');
57 is
($bound_params[9], 'isbneanissn');
58 is
($bound_params[10], 'title');
59 is
($bound_params[11], 'author');
60 is
($bound_params[12], 'publisher');
61 is
($bound_params[13], 'publicationyear');
62 is
($bound_params[14], 'branchcode');
64 $dbh->{mock_clear_history
} = 1;
65 $dbh->{mock_add_resultset
} = $rs;
67 $history = $dbh->{mock_all_history
};
68 is
(scalar(@
$history), 1);
69 @bound_params = @
{ $history->[0]->{bound_params
} };
70 is
(scalar(@bound_params), 1);
71 is
($bound_params[0], 42);
73 $dbh->{mock_clear_history
} = 1;
74 $dbh->{mock_add_resultset
} = $rs;
75 $dbh->{mock_add_resultset
} = $rs;
76 my $invoice = GetInvoiceDetails
(42);
77 $history = $dbh->{mock_all_history
};
78 is
(scalar(@
$history), 2);
79 @bound_params = @
{ $history->[0]->{bound_params
} };
80 is
(scalar(@bound_params), 1);
81 is
($bound_params[0], 42);
82 @bound_params = @
{ $history->[1]->{bound_params
} };
83 is
(scalar(@bound_params), 1);
84 is
($bound_params[0], 42);
85 ok
(exists $invoice->{orders
});
87 $dbh->{mock_clear_history
} = 1;
88 is
(AddInvoice
(booksellerid
=> 1), undef); # Fails because of a missing parameter
89 $history = $dbh->{mock_all_history
};
90 is
(scalar(@
$history), 0);
92 $dbh->{mock_clear_history
} = 1;
93 AddInvoice
(invoicenumber
=> 'invoice', booksellerid
=> 1, unknown
=> "unknown");
94 $history = $dbh->{mock_all_history
};
95 is
(scalar(@
$history), 1);
96 @bound_params = @
{ $history->[0]->{bound_params
} };
97 is
(scalar(@bound_params), 2);
98 ok
(grep /^1$/, @bound_params);
99 ok
(grep /^invoice$/, @bound_params);
100 ok
(not grep /unknown/, @bound_params);
102 $dbh->{mock_clear_history
} = 1;
103 is
(ModInvoice
(booksellerid
=> 1), undef); # Fails because of a missing parameter
104 $history = $dbh->{mock_all_history
};
105 is
(scalar(@
$history), 0);
107 $dbh->{mock_clear_history
} = 1;
108 ModInvoice
(invoiceid
=> 3, invoicenumber
=> 'invoice', unknown
=> "unknown");
109 $history = $dbh->{mock_all_history
};
110 is
(scalar(@
$history), 1);
111 @bound_params = @
{ $history->[0]->{bound_params
} };
112 is
(scalar(@bound_params), 2);
113 ok
(grep /^3$/, @bound_params);
114 ok
(grep /^invoice$/, @bound_params);
115 ok
(not grep /unknown/, @bound_params);
117 $dbh->{mock_clear_history
} = 1;
119 $history = $dbh->{mock_all_history
};
120 is
(scalar(@
$history), 1);
121 @bound_params = @
{ $history->[0]->{bound_params
} };
122 is
(scalar(@bound_params), 1);
123 is
($bound_params[0], 42);
125 $dbh->{mock_clear_history
} = 1;
127 $history = $dbh->{mock_all_history
};
128 is
(scalar(@
$history), 1);
129 @bound_params = @
{ $history->[0]->{bound_params
} };
130 is
(scalar(@bound_params), 1);
131 is
($bound_params[0], 42);
132 my $checkordersrs = [
137 $dbh->{mock_add_resultset
} = $checkordersrs;
138 is
(DelInvoice
(42), undef, "Invoices with items don't get deleted");
150 $dbh->{mock_add_resultset
} = $checkordersrs;
151 $dbh->{mock_add_resultset
} = $deleters;
152 ok
(DelInvoice
(42), "Invoices without items do get deleted");