summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-06-05 01:05:12 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-06-05 01:05:12 +0000
commit501ac60d3a4a6d438ba93495d6be379afc5ec44a (patch)
tree2392ceddd558a40bc4b96982cd06dd722bbd7a21 /t
parent6fb2b8d80595bde410e71deab19474596287eba4 (diff)
More tests and PDF support now works with XeTeX and preliminary escaping
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1255 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 't')
-rw-r--r--t/01-load.t3
-rw-r--r--t/04-template-handling.t120
-rw-r--r--t/99-versioning.t39
-rw-r--r--t/data/04-template.txt2
4 files changed, 115 insertions, 49 deletions
diff --git a/t/01-load.t b/t/01-load.t
index ac7c970d..7a0aaf62 100644
--- a/t/01-load.t
+++ b/t/01-load.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 35;
use_ok('LedgerSMB');
use_ok('LedgerSMB::AA');
@@ -36,6 +36,7 @@ use_ok('LedgerSMB::Template');
use_ok('LedgerSMB::Template::HTML');
use_ok('LedgerSMB::Template::PDF');
use_ok('LedgerSMB::Template::PS');
+use_ok('LedgerSMB::Template::TXT');
use_ok('LedgerSMB::User');
SKIP: {
diff --git a/t/04-template-handling.t b/t/04-template-handling.t
index 1f05a266..a8b20c27 100644
--- a/t/04-template-handling.t
+++ b/t/04-template-handling.t
@@ -18,6 +18,9 @@ use LedgerSMB::Sysconfig;
use LedgerSMB::Locale;
use LedgerSMB::Template;
use LedgerSMB::Template::HTML;
+use LedgerSMB::Template::PS;
+use LedgerSMB::Template::PDF;
+use LedgerSMB::Template::TXT;
$LedgerSMB::Sysconfig::tempdir = 't/var';
@@ -31,6 +34,10 @@ my $locale;
$locale = LedgerSMB::Locale->get_handle('fr');
+##############
+## AM tests ##
+##############
+
# AM->check_template_name checks
# check_template operates by calling $form->error if the checks fail
$form = new Form;
@@ -116,7 +123,10 @@ is(join("\n", @r), $form->{body}, 'AM, save_template: Good save');
is(unlink($form->{file}), 1, 'AM, save_template: removing testfile');
ok(!-e $form->{file}, 'AM, save_template: testfile removed');
-# LedgerSMB::Template::HTML checks
+######################################
+## LedgerSMB::Template::HTML checks ##
+######################################
+
is(LedgerSMB::Template::HTML::get_template('04-template'), '04-template.html',
'HTML, get_template: Returned correct template file name');
is(LedgerSMB::Template::HTML::preprocess('04-template'), '04-template',
@@ -137,6 +147,10 @@ is_deeply(LedgerSMB::Template::HTML::preprocess({'fruit' => '&veggies',
is(LedgerSMB::Template::HTML::postprocess({outputfile => '04-template'}),
'04-template.html', 'HTML, postprocess: Return output filename');
+####################
+## Template tests ##
+####################
+
# Template->new
$myconfig = {'templates' => 't/data'};
throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => 'x/0')}
@@ -159,36 +173,15 @@ is($template->{include_path}, 't/data/de;t/data',
'Template, new: Object creation with valid language has good include_path');
$template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'language' => 'de',
- 'path' => 't/data');
+ 'path' => 't/data', 'outputfile' => 'test');
ok(defined $template,
'Template, new: Object creation with valid language and path');
isa_ok($template, 'LedgerSMB::Template',
'Template, new: Object creation with valid language and path');
is($template->{include_path}, 't/data',
'Template, new: Object creation with valid path overrides language');
-
-$template = undef;
-$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'HTML',
- 'template' => '04-template');
-ok(defined $template,
- 'Template, new: Object creation with format and template');
-isa_ok($template, 'LedgerSMB::Template',
- 'Template, new: Object creation with format and template');
-is($template->{include_path}, 't/data',
- 'Template, new: Object creation with format and template');
-is($template->render({'login' => 'foo&bar'}), 't/var/04-template-output.html',
- 'Template, render: Simple HTML template, default filename');
-ok(-e 't/var/04-template-output.html', 'Template, render (HTML): File created');
-open($FH, '<', 't/var/04-template-output.html');
-@r = <$FH>;
-close($FH);
-chomp(@r);
-is(join("\n", @r), "I am a template.\nLook at me foo&amp;bar.",
- 'Template, render (HTML): Simple HTML template, correct output');
-is(unlink('t/var/04-template-output.html'), 1,
- 'Template, render: removing testfile');
-ok(!-e 't/var/04-template-output.html',
- 'Template, render (HTML): testfile removed');
+is($template->{outputfile}, 't/var/test',
+ 'Template, new: Object creation with filename is correct');
$template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'HTML',
@@ -214,17 +207,21 @@ ok(defined $template,
throws_ok{$template->render({'login' => 'foo'})} qr/Can't locate/,
'Template, render: Invalid format caught';
+#####################
+## Rendering tests ##
+#####################
+
$template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'PDF',
'template' => '04-template');
ok(defined $template,
- 'Template, new: Object creation with format and template');
+ 'Template, new (PDF): Object creation with format and template');
isa_ok($template, 'LedgerSMB::Template',
- 'Template, new: Object creation with format and template');
+ 'Template, new (PDF): Object creation with format and template');
is($template->{include_path}, 't/data',
- 'Template, new: Object creation with format and template');
-is($template->render({'login' => 'foo\&bar'}), 't/var/04-template-output.pdf',
- 'Template, render: Simple PDF template, default filename');
+ 'Template, new (PDF): Object creation with format and template');
+is($template->render({'login' => 'foo&bar'}), 't/var/04-template-output.pdf',
+ 'Template, render (PDF): Simple PDF template, default filename');
ok(-e 't/var/04-template-output.pdf', 'Template, render (PDF): File created');
is(unlink('t/var/04-template-output.pdf'), 1,
'Template, render (PDF): removing testfile');
@@ -235,26 +232,61 @@ $template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'PS',
'template' => '04-template');
ok(defined $template,
- 'Template, new: Object creation with format and template');
+ 'Template, new (PS): Object creation with format and template');
isa_ok($template, 'LedgerSMB::Template',
- 'Template, new: Object creation with format and template');
+ 'Template, new (PS): Object creation with format and template');
is($template->{include_path}, 't/data',
- 'Template, new: Object creation with format and template');
+ 'Template, new (PS): Object creation with format and template');
is($template->render({'login' => 'foo\&bar'}), 't/var/04-template-output.ps',
- 'Template, render: Simple Postscript template, default filename');
+ 'Template, render (PS): Simple Postscript template, default filename');
ok(-e 't/var/04-template-output.ps', 'Template, render (PS): File created');
is(unlink('t/var/04-template-output.ps'), 1,
'Template, render (PS): removing testfile');
ok(!-e 't/var/04-template-output.ps',
'Template, render (PS): testfile removed');
-##open($FH, '<', 't/var/04-template-output.html');
-##@r = <$FH>;
-##close($FH);
-##chomp(@r);
-##is(join("\n", @r), "I am a template.\nLook at me foo&amp;bar.",
-## 'Template, render (HTML): Simple HTML template, correct output');
-##is(unlink('t/var/04-template-output.html'), 1,
-## 'Template, render: removing testfile');
-##ok(!-e 't/var/04-template-output.html',
-## 'Template, render (HTML): testfile removed');
+$template = undef;
+$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'TXT',
+ 'template' => '04-template');
+ok(defined $template,
+ 'Template, new (TXT): Object creation with format and template');
+isa_ok($template, 'LedgerSMB::Template',
+ 'Template, new (TXT): Object creation with format and template');
+is($template->{include_path}, 't/data',
+ 'Template, new (TXT): Object creation with format and template');
+is($template->render({'login' => 'foo&bar'}), 't/var/04-template-output.txt',
+ 'Template, render: Simple text template, default filename');
+ok(-e 't/var/04-template-output.txt', 'Template, render (TXT): File created');
+open($FH, '<', 't/var/04-template-output.txt');
+@r = <$FH>;
+close($FH);
+chomp(@r);
+is(join("\n", @r), "I am a template.\nLook at me foo&bar.",
+ 'Template, render (TXT): Simple TXT template, correct output');
+is(unlink('t/var/04-template-output.txt'), 1,
+ 'Template, render (TXT): removing testfile');
+ok(!-e 't/var/04-template-output.html',
+ 'Template, render (TXT): testfile removed');
+
+$template = undef;
+$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'HTML',
+ 'template' => '04-template');
+ok(defined $template,
+ 'Template, new (HTML): Object creation with format and template');
+isa_ok($template, 'LedgerSMB::Template',
+ 'Template, new (HTML): Object creation with format and template');
+is($template->{include_path}, 't/data',
+ 'Template, new (HTML): Object creation with format and template');
+is($template->render({'login' => 'foo&bar'}), 't/var/04-template-output.html',
+ 'Template, render (HTML): Simple HTML template, default filename');
+ok(-e 't/var/04-template-output.html', 'Template, render (HTML): File created');
+open($FH, '<', 't/var/04-template-output.html');
+@r = <$FH>;
+close($FH);
+chomp(@r);
+is(join("\n", @r), "I am a template.\nLook at me foo&amp;bar.",
+ 'Template, render (HTML): Simple HTML template, correct output');
+is(unlink('t/var/04-template-output.html'), 1,
+ 'Template, render (HTML): removing testfile');
+ok(!-e 't/var/04-template-output.html',
+ 'Template, render (HTML): testfile removed');
diff --git a/t/99-versioning.t b/t/99-versioning.t
index d1b833c5..3259e07d 100644
--- a/t/99-versioning.t
+++ b/t/99-versioning.t
@@ -33,13 +33,44 @@ chomp $ver;
is($lsmb->{version}, $ver, 'LedgerSMB version matches VERSION');
is($form->{version}, $ver, 'Form version matches VERSION');
+my @dparts;
+my @lparts;
+my $age;
SKIP: {
skip 'LedgerSMB is trunk', 1 if $lsmb->{version} =~ /trunk$/i;
- cmp_ok($lsmb->{version}, 'ge', $lsmb->{dbversion},
- 'lsmb: version >= dbversion');
+ @dparts = split /\./, $lsmb->{dbversion};
+ @lparts = split /\./, $lsmb->{version};
+ $age = 0;
+ foreach my $dpart (@dparts) {
+ my $lpart = shift @lparts;
+ if (!defined $lpart) {
+ $age = 1;
+ last;
+ } elsif ($lpart > $dpart) {
+ last;
+ } elsif ($dpart > $lpart) {
+ $age = 1;
+ last;
+ }
+ }
+ ok($age == 0, 'lsmb: version >= dbversion');
}
SKIP: {
skip 'Form is trunk', 1 if $form->{version} =~ /trunk$/i;
- cmp_ok($form->{version}, 'ge', $form->{dbversion},
- 'form: version >= dbversion');
+ @dparts = split /\./, $form->{dbversion};
+ @lparts = split /\./, $form->{version};
+ $age = 0;
+ foreach my $dpart (@dparts) {
+ my $lpart = shift @lparts;
+ if (!defined $lpart) {
+ $age = 1;
+ last;
+ } elsif ($lpart > $dpart) {
+ last;
+ } elsif ($dpart > $lpart) {
+ $age = 1;
+ last;
+ }
+ }
+ ok($age == 0, 'form: version >= dbversion');
}
diff --git a/t/data/04-template.txt b/t/data/04-template.txt
new file mode 100644
index 00000000..3b236040
--- /dev/null
+++ b/t/data/04-template.txt
@@ -0,0 +1,2 @@
+I am a template.
+Look at me <?lsmb login ?>.