aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2006-02-05 13:45:32 +0000
committerdakkar <dakkar@luxion>2006-02-05 13:45:32 +0000
commit0202ee945a19bcb6e497f0200f096de16db845f4 (patch)
treea34aa0f8939541247e8577dff4165227708017db /t
parentstep di split lingue per ReST (diff)
downloadWebCoso-0202ee945a19bcb6e497f0200f096de16db845f4.tar.gz
WebCoso-0202ee945a19bcb6e497f0200f096de16db845f4.tar.bz2
WebCoso-0202ee945a19bcb6e497f0200f096de16db845f4.zip
step per parsare ReST in un dom XML
git-svn-id: svn://luxion/repos/WebCoso/trunk@154 fcb26f47-9200-0410-b104-b98ab5b095f3
Diffstat (limited to 't')
-rw-r--r--t/steps/rest-xml.t99
1 files changed, 99 insertions, 0 deletions
diff --git a/t/steps/rest-xml.t b/t/steps/rest-xml.t
new file mode 100644
index 0000000..6ee8fa2
--- /dev/null
+++ b/t/steps/rest-xml.t
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+use utf8;
+use strict;
+use warnings;
+use Path::Class;
+use Test::More 'no_plan';
+use Test::Differences;
+use Encode;
+use WebCoso::Resource;
+
+BEGIN {use_ok('WebCoso::Step::ReST::ToXml')}
+my $step=WebCoso::Step::ReST::ToXml->new();
+
+sub make_res {
+ my $resource=WebCoso::Resource->new();
+ # serve solo per il path
+ $resource->set_property({filename=>'/tmp/mydoc.rest.txt'},datastream=>undef);
+ if (@_==1) { # monolingua
+ $resource->set_property(rstdoc=>$_[0]);
+ }
+ else { # multilingua
+ my %rst_doc=@_;
+ while (my ($lang,$str)=each %rst_doc) {
+ $resource->set_property(
+ {language=>$lang},
+ rstdoc=>$str
+ );
+ }
+ }
+
+ return $resource;
+}
+
+my $resource=make_res(<<'END_REST');
+Documento
+=========
+
+paragrafo àè
+END_REST
+
+$step->process($resource,'gen');
+ok(!defined $resource->get_property('xmldom'),'no action on second pass');
+
+$step->process($resource,'meta');
+my $dom=$resource->get_property('xmldom');
+isa_ok($dom,'XML::LibXML::Document','parsed ok on first pass');
+
+is($dom->findvalue('/document/@source'),
+ '/tmp/mydoc.rest.txt',
+ 'source path');
+is($dom->findvalue('/document/title'),
+ 'Documento',
+ 'title');
+is($dom->findvalue('count(/document/paragraph)'),
+ 1,
+ '1 paragraph');
+is($dom->findvalue('/document/paragraph'),
+ 'paragrafo àè',
+ 'paragraph content (unicode)');
+
+$resource=make_res(it=><<'END_REST_IT',en=><<'END_REST_EN');
+Documento
+=========
+
+paragrafo
+END_REST_IT
+Document
+========
+
+paragraph
+END_REST_EN
+
+$step->process($resource,'meta');
+$dom=$resource->get_property({language=>'it'},'xmldom');
+isa_ok($dom,'XML::LibXML::Document','parsed it');
+
+is($dom->findvalue('/document/@source'),
+ '/tmp/mydoc.rest.txt',
+ 'source path');
+is($dom->findvalue('/document/title'),
+ 'Documento',
+ 'title');
+is($dom->findvalue('/document/paragraph'),
+ 'paragrafo',
+ 'paragraph content');
+
+$dom=$resource->get_property({language=>'en'},'xmldom');
+isa_ok($dom,'XML::LibXML::Document','parsed en');
+
+is($dom->findvalue('/document/@source'),
+ '/tmp/mydoc.rest.txt',
+ 'source path');
+is($dom->findvalue('/document/title'),
+ 'Document',
+ 'title');
+is($dom->findvalue('/document/paragraph'),
+ 'paragraph',
+ 'paragraph content');
+