[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1255] trunk



Revision: 1255
          http://svn.sourceforge.net/ledger-smb/?rev=1255&view=rev
Author:   tetragon
Date:     2007-06-04 18:05:12 -0700 (Mon, 04 Jun 2007)

Log Message:
-----------
More tests and PDF support now works with XeTeX and preliminary escaping

Modified Paths:
--------------
    trunk/LedgerSMB/Template/PDF.pm
    trunk/LedgerSMB/Template/TXT.pm
    trunk/t/01-load.t
    trunk/t/04-template-handling.t
    trunk/t/99-versioning.t

Added Paths:
-----------
    trunk/t/data/04-template.txt

Modified: trunk/LedgerSMB/Template/PDF.pm
===================================================================
--- trunk/LedgerSMB/Template/PDF.pm	2007-06-04 22:58:22 UTC (rev 1254)
+++ trunk/LedgerSMB/Template/PDF.pm	2007-06-05 01:05:12 UTC (rev 1255)
@@ -45,12 +45,27 @@
 	my $name = shift;
 	return "${name}.tex";
 }
+
 sub preprocess {
 	my $rawvars = shift;
 	my $vars;
 	my $type = ref $rawvars;
-	#XXX Fix escaping
-	return $rawvars;
+
+	if ($type eq 'ARRAY') {
+		for (@{$rawvars}) {
+			push @{$vars}, preprocess($_);
+		}
+	} elsif ($type eq 'HASH') {
+		for ( keys %{$rawvars} ) {
+			$vars->{$_} = preprocess($rawvars->{$_});
+		}
+	} else {
+		#XXX Fix escaping
+		$rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
+		$rawvars =~ s/"(.*)"/``$1''/gs;
+		return $rawvars;
+	}
+	return $vars;
 }
 
 sub process {
@@ -63,12 +78,12 @@
 		INCLUDE_PATH => $parent->{include_path},
 		START_TAG => quotemeta('<?lsmb'),
 		END_TAG => quotemeta('?>'),
-		DELIMITER => ';',
+		DELIMITER => ';'
 		}) || throw Error::Simple Template::Latex->error(); 
 
 	if (not $template->process(
 		get_template($parent->{template}), 
-		$cleanvars, "$parent->{outputfile}.pdf", binmode => ':utf8')) {
+		$cleanvars, "$parent->{outputfile}.pdf", binmode => 1)) {
 		throw Error::Simple $template->error();
 	}
 	$parent->{mimetype} = 'application/pdf';

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2007-06-04 22:58:22 UTC (rev 1254)
+++ trunk/LedgerSMB/Template/TXT.pm	2007-06-05 01:05:12 UTC (rev 1255)
@@ -13,7 +13,7 @@
 
 =item preprocess ($vars)
 
-Currently does nothing.
+Returns $vars.
 
 =item process ($parent, $cleanvars)
 
@@ -21,7 +21,7 @@
 
 =item postprocess ($parent)
 
-Currently does nothing.
+Returns the output filename.
 
 =back
 
@@ -48,10 +48,7 @@
 
 sub preprocess {
     my $rawvars = shift;
-    my $vars;
-    my $type = ref $rawvars;
-
-    return $vars;
+    return $rawvars;
 }
 
 sub process {

Modified: trunk/t/01-load.t
===================================================================
--- trunk/t/01-load.t	2007-06-04 22:58:22 UTC (rev 1254)
+++ trunk/t/01-load.t	2007-06-05 01:05:12 UTC (rev 1255)
@@ -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::HTML');
 use_ok('LedgerSMB::Template::PDF');
 use_ok('LedgerSMB::Template::PS');
+use_ok('LedgerSMB::Template::TXT');
 use_ok('LedgerSMB::User');
 
 SKIP: {

Modified: trunk/t/04-template-handling.t
===================================================================
--- trunk/t/04-template-handling.t	2007-06-04 22:58:22 UTC (rev 1254)
+++ trunk/t/04-template-handling.t	2007-06-05 01:05:12 UTC (rev 1255)
@@ -18,6 +18,9 @@
 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 @@
 
 $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(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(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,39 +173,18 @@
 	'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');
+is($template->{outputfile}, 't/var/test',
+	'Template, new: Object creation with filename is correct');
 
 $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');
..hidden.. = <$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' => 'HTML', 
 	'template' => '04-template', 'locale' => $locale);
 ok(defined $template, 
 	'Template, new: Object creation with locale');
@@ -214,17 +207,21 @@
 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 = 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');
..hidden.. = <$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');
..hidden.. = <$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');
..hidden.. = <$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');

Modified: trunk/t/99-versioning.t
===================================================================
--- trunk/t/99-versioning.t	2007-06-04 22:58:22 UTC (rev 1254)
+++ trunk/t/99-versioning.t	2007-06-05 01:05:12 UTC (rev 1255)
@@ -33,13 +33,44 @@
 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');
 }

Added: trunk/t/data/04-template.txt
===================================================================
--- trunk/t/data/04-template.txt	                        (rev 0)
+++ trunk/t/data/04-template.txt	2007-06-05 01:05:12 UTC (rev 1255)
@@ -0,0 +1,2 @@
+I am a template.
+Look at me <?lsmb login ?>.


Property changes on: trunk/t/data/04-template.txt
___________________________________________________________________
Name: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.