#!perl -w # Form-related tests for CGI.pm # If you are adding or updated tests, please put tests for each methods in # their own file, rather than growing this file any larger. use Test::More 'no_plan'; use CGI (':standard','-no_debug','-tabindex'); my $CRLF = "\015\012"; if ($^O eq 'VMS') { $CRLF = "\n"; # via web server carriage is inserted automatically } if (ord("\t") != 9) { # EBCDIC? $CRLF = "\r\n"; } # Set up a CGI environment $ENV{REQUEST_METHOD} = 'GET'; $ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull'; $ENV{PATH_INFO} = '/somewhere/else'; $ENV{PATH_TRANSLATED} = '/usr/local/somewhere/else'; $ENV{SCRIPT_NAME} ='/cgi-bin/foo.cgi'; $ENV{SERVER_PROTOCOL} = 'HTTP/1.0'; $ENV{SERVER_PORT} = 8080; $ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; is(start_form(-action=>'foobar',-method=>'get'), qq(
\n), "start_form()"); is(submit(), qq(), "submit()"); is(submit(-name => 'foo', -value => 'bar'), qq(), "submit(-name,-value)"); is(submit({-name => 'foo', -value => 'bar'}), qq(), "submit({-name,-value})"); is(textfield(-name => 'weather'), qq(), "textfield({-name})"); is(textfield(-name => 'weather', -value => 'nice'), qq(), "textfield({-name,-value})"); is(textfield(-name => 'weather', -value => 'nice', -override => 1), qq(), "textfield({-name,-value,-override})"); is(checkbox(-name => 'weather', -value => 'nice'), qq(), "checkbox()"); is(checkbox(-name => 'weather', -value => 'nice', -label => 'forecast'), qq(), "checkbox()"); is(checkbox(-name => 'weather', -value => 'nice', -label => 'forecast', -checked => 1, -override => 1), qq(), "checkbox()"); is(checkbox(-name => 'weather', -value => 'dull', -label => 'forecast'), qq(), "checkbox()"); is(radio_group(-name => 'game'), qq( ), 'radio_group()'); is(radio_group(-name => 'game', -labels => {'chess' => 'ping pong'}), qq( ), 'radio_group()'); is(checkbox_group(-name => 'game', -Values => [qw/checkers chess cribbage/]), qq( ), 'checkbox_group()'); is(checkbox_group(-name => 'game', '-values' => [qw/checkers chess cribbage/], '-defaults' => ['cribbage'], -override=>1), qq( ), 'checkbox_group()'); is(popup_menu(-name => 'game', '-values' => [qw/checkers chess cribbage/], -default => 'cribbage', -override => 1), '', 'popup_menu()'); is(scrolling_list(-name => 'game', '-values' => [qw/checkers chess cribbage/], -default => 'cribbage', -override=>1), '', 'scrolling_list()'); is(checkbox_group(-name => 'game', -Values => [qw/checkers chess cribbage/], -disabled => ['checkers']), qq( ), 'checkbox_group()'); my $optgroup = optgroup(-name=>'optgroup_name', -Values => ['moe','catch'], -attributes=>{'catch'=>{'class'=>'red'}}); is($optgroup, qq( ), 'optgroup()'); is(popup_menu(-name=>'menu_name', -Values=>[qw/eenie meenie minie/, $optgroup], -labels=>{'eenie'=>'one', 'meenie'=>'two', 'minie'=>'three'}, -default=>'meenie'), qq(), 'popup_menu() + optgroup()'); is(scrolling_list(-name=>'menu_name', -Values=>[qw/eenie meenie minie/, $optgroup], -labels=>{'eenie'=>'one', 'meenie'=>'two', 'minie'=>'three'}, -default=>'meenie'), qq(), 'scrolling_list() + optgroup()'); # ---------- START 22046 ---------- # The following tests were added for # https://rt.cpan.org/Public/Bug/Display.html?id=22046 # SHCOREY at cpan.org # Saved whether working with XHTML because need to test both # with it and without. my $saved_XHTML = $CGI::XHTML; # set XHTML $CGI::XHTML = 1; is(start_form("GET","/foobar"), qq{ }, 'start_form() + XHTML'); is(start_form("GET", "/foobar",&CGI::URL_ENCODED), qq{ }, 'start_form() + XHTML + URL_ENCODED'); is(start_form("GET", "/foobar",&CGI::MULTIPART), qq{ }, 'start_form() + XHTML + MULTIPART'); is(start_multipart_form("GET", "/foobar"), qq{ }, 'start_multipart_form() + XHTML'); is(start_multipart_form("GET", "/foobar","name=\"foobar\""), qq{ }, 'start_multipart_form() + XHTML + additional args'); # set no XHTML $CGI::XHTML = 0; is(start_form("GET","/foobar"), qq{ }, 'start_form() + NO_XHTML'); is(start_form("GET", "/foobar",&CGI::URL_ENCODED), qq{ }, 'start_form() + NO_XHTML + URL_ENCODED'); is(start_form("GET", "/foobar",&CGI::MULTIPART), qq{ }, 'start_form() + NO_XHTML + MULTIPART'); is(start_multipart_form("GET", "/foobar"), qq{ }, 'start_multipart_form() + NO_XHTML'); is(start_multipart_form("GET", "/foobar","name=\"foobar\""), qq{ }, 'start_multipart_form() + NO_XHTML + additional args'); # restoring value $CGI::XHTML = $saved_XHTML;