require "#{File.dirname(__FILE__)}/../abstract_unit" class TagHelperTest < Test::Unit::TestCase include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TextHelper include ActionView::Helpers::CaptureHelper def test_tag assert_equal "
", tag("br") assert_equal "
", tag(:br, :clear => "left") assert_equal "
", tag("br", nil, true) end def test_tag_options assert_match /\A

\z/, tag("p", "class" => "show", :class => "elsewhere") end def test_tag_options_rejects_nil_option assert_equal "

", tag("p", :ignored => nil) end def test_tag_options_accepts_blank_option assert_equal "

", tag("p", :included => '') end def test_tag_options_converts_boolean_option assert_equal '

', tag("p", :disabled => true, :multiple => true, :readonly => true) end def test_content_tag assert_equal "Create", content_tag("a", "Create", "href" => "create") assert_equal content_tag("a", "Create", "href" => "create"), content_tag("a", "Create", :href => "create") end def test_content_tag_with_block _erbout = '' content_tag(:div) { _erbout.concat "Hello world!" } assert_dom_equal "

Hello world!
", _erbout end def test_content_tag_with_block_and_options _erbout = '' content_tag(:div, :class => "green") { _erbout.concat "Hello world!" } assert_dom_equal %(
Hello world!
), _erbout end def test_content_tag_with_block_and_options_outside_of_action_view assert_equal content_tag("a", "Create", :href => "create"), content_tag("a", "href" => "create") { "Create" } end def test_cdata_section assert_equal "]]>", cdata_section("") end def test_escape_once assert_equal '1 < 2 & 3', escape_once('1 < 2 & 3') end def test_double_escaping_attributes ['1&2', '1 < 2', '“test“'].each do |escaped| assert_equal %(), tag('a', :href => escaped) end end def test_skip_invalid_escaped_attributes ['&1;', 'dfa3;', '& #123;'].each do |escaped| assert_equal %(), tag('a', :href => escaped) end end end