HTML-GUI
view release on metacpan or search on metacpan
t/03-screen.t view on Meta::CPAN
ok($yamlString, "check the YAML serialization");
is($yamlString,q~---
childs:
-
constraints:
- integer
- required
id: bla
type: text
value: 1
-
constraints:
- integer
- required
id: bli
type: text
value: 2
-
id: textObject
type: text
value: 2
id: my_screen
type: screen
~);
my $widgetCopy = HTML::GUI::widget->instantiateFromYAML($yamlString);
ok ($widgetCopy,"The instantation from YAML works");
my $originalDump = Dump $screen;
my $copyDump = Dump $widgetCopy;
#after a serialization/deserialization round-trip
#everything should be identical
is($originalDump,$copyDump,"after a serialization and deserialization, we have a copy that only differs from the errors");
my $tempFile = File::Temp->new(SUFFIX => '.yaml');
ok($tempFile,'We need a temp file');
#try to save in a file and read it
ok($screen->writeToFile($tempFile->filename),"save the widget in a file");
my $screenFromFile = HTML::GUI::widget->instantiateFromFile($tempFile->filename);
ok($screenFromFile,"load a screen widget from a file with an absolute path");
my $dirName = $tempFile->filename;
$dirName =~ s/[^\/]*\.yaml//;
ok($dirName,"Extract the directory name of the temp file");
my $fileName = $tempFile->filename;
$fileName =~ s/\Q$dirName\E//;
ok($dirName,"Extract the filename of the temp file");
$screenFromFile = HTML::GUI::widget->instantiateFromFile($fileName,$dirName);
ok($screenFromFile,"load a screen widget from a file from a root path and a relative filename");
#the path of the widget copy is the name of the temp file
#we modify it in order to have all the propeties identical
$screenFromFile->setProp({path=>'/'});
is($screenFromFile->getHtml(),
q~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>HTML-GUI-Widget</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<link rel="stylesheet" type="text/css" href="/static/css/base.css" />
</head>
<body>
<form action="/" method="post"><p class="float"><input id="bla" name="bla" type="text" value="1"/></p><p class="float"><input id="bli" name="bli" type="text" value="2"/></p><p class="float"><input id="textObject" name="textObject" type="text" value...
</body>
</html>
~);
my $fromFileDump = Dump $screenFromFile;
is($fromFileDump,$copyDump,"after a serialization and deserialization, we have a copy");
#Now we want to test a bit more complex screen with containers containing containers
my $bigScreenDesc = q~
---
childs:
-
label: "Identité patient &"
type: header
-
childs:
-
constraints:
- integer
- required
id: bla
label: un premier " champ
size: 20
type: text
value: "je vais vous manger !! éà üù\"\"\"'"
-
constraints:
- integer
- required
id: bli0
label: champ [0]
size: 15
type: text
value: 0
-
constraints:
- integer
- required
id: bli1
label: champ [1]
size: 15
type: text
value: 1
t/03-screen.t view on Meta::CPAN
'textObject' => 2,
'bli4' => 4,
'bli7' => 7,
'bli8' => 8,
'bli3' => 3,
'bli6' => 6,
'bli1' => 1,
'bla' => "je vais vous manger !! \x{e9}\x{e0}\x{fc}\x{f9}\"\"\"'",
'monprenom' => 'Pierre-Paul-Jaccque',
'adr1' => '12, rue du garel',
'button2' => "Effa\x{e7}er \x{a3} et \x{20ac}?",
'bli0' => 0,
'button' => "A Table!! \x{e9}\x{e0}\x{fc}\x{f9}\"'",
'combo01' => 0
};
~;
#my $valueDump = Dump $valueHash;
is($valueDump,$expectedValueHashString,"we can get structured data from the screen");
$bigScreen->setValue($valueHash);
my $valueHash2 = $bigScreen->getValueHash();
my $valueDump2 = Dumper($valueHash2);
is($valueDump,$valueDump2,"we managed the structured data round trip");
my $smallScreenYAML = q~---
childs:
-
constraints:
- integer
- required
id: bla
type: text
value: 1
-
constraints:
- integer
- required
id: bli
type: text
value: 2
-
id: textObject
type: text
value: 2
-
btnAction: HTML::GUI::screen::btnTestFunction
id: button
type: button
value: A Table!! éà üù
id: my_screen
type: screen
~;
my $smallScreen = HTML::GUI::widget->instantiateFromYAML($smallScreenYAML);
#now we try to do a dummy action
ok(!$callFlag,"We didn't call the dummy function previously");
ok($smallScreen->processHttpRequest({button=>'"A Table!! éà üù\\"\'""'}),"We can call a dummy function");
ok($callFlag,"The btnTestFunction was really called");
$smallScreen->error("This is a dummy message for the violation of a business rule with special caracters [éà üù]");
my $smallScreenHTML = q~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>HTML-GUI-Widget</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<link rel="stylesheet" type="text/css" href="/static/css/base.css" />
</head>
<body>
<form action="/" method="post"><div class="errorList"><h2 class="errorList">Some errors occured.</h2><dl class="errorList"><dt>General</dt><dd>This is a dummy message for the violation of a business rule with special caracters [éà üù]</dd></dl><...
</body>
</html>
~;
is($smallScreen->getHtml(),$smallScreenHTML,"The specialised error function generates the HTML we expect.");
( run in 0.651 second using v1.01-cache-2.11-cpan-b50b6a40fd4 )