diff options
Diffstat (limited to 't')
-rw-r--r-- | t/04-template-handling.t | 23 | ||||
-rw-r--r-- | t/62-api.t | 17 | ||||
-rw-r--r-- | t/data/62-request-data | 95 |
3 files changed, 133 insertions, 2 deletions
diff --git a/t/04-template-handling.t b/t/04-template-handling.t index 7043f53f..38dcac37 100644 --- a/t/04-template-handling.t +++ b/t/04-template-handling.t @@ -421,6 +421,29 @@ is(grep (/value="1" selected/, @output), 0, 'Select box Value 1 unselected'); is(grep (/value="1000" selected/, @output), 1, 'Select box Value 1000 selected'); is(grep (/<td class="description">dtest1/, @output), 1, 'Contact description shows'); +# bulk payment template tests +my $payment = LedgerSMB->new(); +$payment->merge({ + contact_1 => 1, source_1 => 1, action=>'dispay_payments', id_1 => 1, + id_1_1 => 1, + contact_invoices => [{contact_id => 1, invoices =>[[101, 101, "2009-01-01", 1000, 0, 0, 1000, 0, + 'test']]}]}); + +my $payment_template = LedgerSMB::Template->new( + path => 'UI/payments', + template => 'payments_detail', + format => 'HTML', + no_auto_output => 1, + output_file => 'payment_test1' +); + +$payment_template->render($payment); +my @output = get_output_line_array($payment_template); +cmp_ok(grep(/101<\/td>/, @output), '>', 0, 'Invoice row exists'); +is(grep(/name="payment_101"/, @output), 0, 'Invoice locked'); +is(grep(/Locked by/, @output), 1, 'Invoice locked label shown'); + + # LPR PRinting Tests use LedgerSMB::Sysconfig; %LedgerSMB::Sysconfig::printer = ('test' => 'cat > t/var/04-lpr-test'); @@ -79,13 +79,20 @@ for my $test (@$test_request_data){ } package LedgerSMB::Template; - +use Test::More; # Don't render templates. Just return so we can run tests on data structures. sub render { my ($self, $data) = @_; if (ref $data->{_test_cases} eq 'CODE'){ $data->{_test_cases}($data); } + if ($data->{_error_test}){ + cmp_ok($data->{_died}, '==', '1', + "$data->{_test_id} died as expected"); + } else { + ok(!defined $data->{_died}, + "$data->{_test_id} did not error"); + } return 1; } @@ -103,3 +110,11 @@ sub _load_script { do "bin/io.pl"; do "bin/$1[0]"; } + +package LedgerSMB; + +sub error { + my $self = shift; + $self->{_error} = shift; + $self->{_died} = 1; +} diff --git a/t/data/62-request-data b/t/data/62-request-data index bb5e7747..58a52297 100644 --- a/t/data/62-request-data +++ b/t/data/62-request-data @@ -50,10 +50,72 @@ our $test_request_data = [ 'module' => 'vouchers.pl', }, { + '_test_id' => 'Payment source start error', + '_codebase' => 'new', + '_error_test' => 1, + 'account_class' => 1, + 'module' => 'payment.pl', + 'action' => 'display_payments', + 'approved' => 0, + 'currency' => 'USD', + 'datepaid' => '2008-07-22', + }, + { + '_test_id' => 'Payment source numbering', + '_codebase' => 'new', + '_error_test' => 1, + 'account_class' => 1, + 'start_source' => 1, + 'module' => 'payment.pl', + 'action' => 'update_payments', + 'approved' => 0, + 'currency' => 'USD', + 'datepaid' => '2008-07-22', + 'id_1' => 1, + 'id_3' => 3, + '_exec_override' => { + 'payment_get_all_contact_invoices' => sub { + my $self = shift; + $retval = [ { contact_id => 1, + total_due => Math::BigFloat->new(1000), + econtrol_code => 'TEST1', + eca_description => 'test', + contact_name => 'test', + account_number => 'test', + invoices => '{{"100","101","2009-01-01",1000,1000}}', + has_vouchers => 0, + } , + { + contact_id => 2, + total_due => Math::BigFloat->new(1000), + econtrol_code => 'TEST1', + eca_description => 'test', + contact_name => 'test', + account_number => 'test', + invoices => '{{101,101,2009-01-01,1000,1000}}', + has_vouchers => 0, + } , + { + contact_id => 3, + total_due => Math::BigFloat->new(1000), + econtrol_code => 'TEST1', + eca_description => 'test', + contact_name => 'test', + account_number => 'test', + invoices => '{{102,101,2009-01-01,1000,1000}}', + has_vouchers => 0, + } ]; + $self->{contact_invoices} = $retval; + $self->debug({'file' => '/tmp/test2'}); + return @$retval; + } + } + }, + { '_test_id' => 'Payment print total', '_codebase' => 'new', 'action' => 'print', - 'approved' => 0, + 'approved' => 0, 'currency' => 'USD', 'datepaid' => '2008-07-22', 'contact_1' => '25', @@ -93,6 +155,7 @@ our $test_request_data = [ 'multiple' => 1, }, + ]; our $pre_test_subs = { @@ -138,6 +201,21 @@ our $api_test_cases = { }), 'eq', '105900.00', 'Printed amount is correct' ); + }, + 'Payment source start error' => sub { + my $self = shift; + cmp_ok($self->{_error}, 'eq', 'No source start defined!', + "Payment source start error: error correct"); + }, + 'Payment source numbering' => sub { + my $self = shift; + $self->debug({file => '/tmp/test'}); + ok(defined $self->{source_1}, + "$self->{_test_id} source 1 defined"); + cmp_ok($self->{source_2}, 'eq', '', + "$self->{_test_id} source 2 not found"); + ok(defined $self->{source_3}, + "$self->{_test_id} source 3 defined"); } }; @@ -145,3 +223,18 @@ opendir (D62, 't/data/62.d'); for my $testfile (readdir(D62)){ do "t/data/62.d/$testfile"; }; + +# Overridden methods in classes for tests. + +package LedgerSMB::DBObject::Payment; +sub exec_method { + my $self = shift; + my %args = @_; + my $funcname = $args{funcname}; + if (ref $self->{_exec_override} eq 'HASH'){ + if ($self->{_exec_override}->{"$funcname"}){ + return $self->{_exec_override}->{"$args{funcname}"}($self); + } + } + LedgerSMB::DBObject::exec_method($self, @_); +} |