#! perl -w use strict; use warnings; use Test::More; use Tripletail '/dev/null'; plan tests => +1 # 01. +1 # 02. +1 # 03. +1 # 04a. +1 # 04b. +1 # 04c. +1 # 04d. +1 # 05. ; &test01_text(); &test02_textarea(); &test03_checkbox(); &test04a_select_dropdown(); &test04b_select_dropdown_few(); &test04c_select_dropdown_empty(); &test04d_select_dropdown_none(); &test05_select_multisel(); sub test01_text { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{
\n}; my $form = $TL->newForm({ txt => [1, 2], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'text with multi values, set on each tags'); } sub test02_textarea { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{
\n}; my $form = $TL->newForm({ tea => [3, 4], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'textarea with multi values, set on each tags'); } sub test03_checkbox { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{\n}; $html .= qq{
\n}; my $form = $TL->newForm({ chk => [9, 10], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{\n}; $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'checkbox with multi values'); } sub test04a_select_dropdown { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; for (1..2) { $html .= qq{\n}; } $html .= qq{
\n}; my $form = $TL->newForm({ sel => [5, 6], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; for my $i (1..2) { my $five_selected = $i == 1 ? ' selected="selected"' : ''; my $six_selected = $i == 2 ? ' selected="selected"' : ''; my $x_selected = ''; my $y_selected = ''; $exp .= qq{\n}; } $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'select as drodown form'); } sub test04b_select_dropdown_few { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; for (1..2) { $html .= qq{\n}; } $html .= qq{
\n}; my $form = $TL->newForm({ sel => [5], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; for my $i (1..2) { # 1st => "5" (five). # 2nd => "" (none). my $five_selected = $i == 1 ? ' selected="selected"' : ''; my $six_selected = ''; my $x_selected = ''; my $y_selected = ''; my $none_selected = $i == 2 ? ' selected="selected"' : ''; $exp .= qq{\n}; } $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'select as drodown form with few set value'); } sub test04c_select_dropdown_empty { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; for (1..2) { $html .= qq{\n}; } $html .= qq{
\n}; my $form = $TL->newForm({ sel => [], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; for my $i (1..2) { # empty value is treated as no value by $TL::Form. # 1st => "y" [keep]. # 2nd => "y" [keep]. my $five_selected = ''; my $six_selected = ''; my $x_selected = ''; my $y_selected = ' selected="selected"'; my $none_selected = ''; $exp .= qq{\n}; } $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'select as drodown form with empty set value'); } sub test04d_select_dropdown_none { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; for (1..2) { $html .= qq{\n}; } $html .= qq{
\n}; my $form = $TL->newForm({ }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; for my $i (1..2) { # 1st => "y" (y) [keep]. # 2nd => "y" (y) [keep]. my $five_selected = ''; my $six_selected = ''; my $x_selected = ''; my $y_selected = ' selected="selected"'; my $none_selected = ''; $exp .= qq{\n}; } $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'select as drodown form without value'); } sub test05_select_multisel { my $html = ""; $html .= qq{\n}; $html .= qq{
\n}; for (1..2) { $html .= qq{\n}; } $html .= qq{
\n}; my $form = $TL->newForm({ sel => [5, 6], }); my $tmpl = $TL->newTemplate->setTemplate($html); $tmpl->setForm($form); my $exp = ""; $exp .= qq{\n}; $exp .= qq{
\n}; for my $i (1..2) { my $five_selected = ' selected="selected"'; my $six_selected = ' selected="selected"'; $exp .= qq{\n}; } $exp .= qq{
\n}; is($tmpl->toStr(), $exp, 'select as mutl-select list'); }