def test_select_widget
build_page{|src_output, map_output, xml_output|
src_output.print "class MainPage < WPM::PageContext\n"
src_output.print " def init_context\n"
src_output.print " @list = %w[ foo bar baz ]\n"
src_output.print " @selected = 'bar'\n"
src_output.print " end\n"
src_output.print "\n"
src_output.print " attr_reader :list\n"
src_output.print " attr_accessor :selected\n"
src_output.print "end\n"
map_output.print "<?xml version=\"1.0\"?>\n"
map_output.print "<map xmlns=\"http://www.freedom.ne.jp/toki/ruby/PageMaker/Map\">\n"
map_output.print "\n"
map_output.print "<form name=\"Form\">\n"
map_output.print "</form>\n"
map_output.print "\n"
map_output.print "<select name=\"Select\">\n"
map_output.print "<list type=\"accessor\">list</list>\n"
map_output.print "<selected type=\"accessor\">selected</selected>\n"
map_output.print "</select>\n"
map_output.print "\n"
map_output.print "</map>\n"
xml_output.print "<?xml version=\"1.0\"?>\n"
xml_output.print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:pm=\"http://www.freedom.ne.jp/toki/ruby/PageMaker\">\n"
xml_output.print "<head><title>test of SelectWidget</title></head>\n"
xml_output.print "<body>\n"
xml_output.print "<pm:widget name=\"Form\">\n"
xml_output.print "<p>\n"
xml_output.print "<pm:widget name=\"Select\" />\n"
xml_output.print "</p>\n"
xml_output.print "</pm:widget>\n"
xml_output.print "</body>\n"
xml_output.print "</html>\n"
}
dst = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
dst += "<head><title>test of SelectWidget</title></head>\n"
dst += "<body>\n"
dst += "<form id=\"MainPage.Form.0\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">"
dst += "<div style=\"display: none\"><input type=\"hidden\" name=\"_wpm_submit_\" value=\"MainPage.Form.0\" /></div>\n"
dst += "<p>\n"
dst += "<select id=\"MainPage.Select.0\" name=\"MainPage.Select.0\">"
dst += "<option value=\"foo\">foo</option>"
dst += "<option value=\"bar\" selected=\"selected\">bar</option>"
dst += "<option value=\"baz\">baz</option>"
dst += "</select>\n"
dst += "</p>\n"
dst += "</form>\n"
dst += "</body>\n"
dst += "</html>"
assert_equal(dst, run_page)
assert_equal(1, @params_call)
assert_equal(0, @page_path_call)
assert_equal('bar', @page.context.selected)
@page.clear
@params['MainPage.Select.0'] = 'baz'
dst = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
dst += "<head><title>test of SelectWidget</title></head>\n"
dst += "<body>\n"
dst += "<form id=\"MainPage.Form.0\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">"
dst += "<div style=\"display: none\"><input type=\"hidden\" name=\"_wpm_submit_\" value=\"MainPage.Form.0\" /></div>\n"
dst += "<p>\n"
dst += "<select id=\"MainPage.Select.0\" name=\"MainPage.Select.0\">"
dst += "<option value=\"foo\">foo</option>"
dst += "<option value=\"bar\">bar</option>"
dst += "<option value=\"baz\" selected=\"selected\">baz</option>"
dst += "</select>\n"
dst += "</p>\n"
dst += "</form>\n"
dst += "</body>\n"
dst += "</html>"
assert_equal(dst, run_page)
assert_equal(2, @params_call)
assert_equal(0, @page_path_call)
assert_equal('baz', @page.context.selected)
end