1
require 'abstract_unit'
3
class TagHelperTest < ActionView::TestCase
4
tests ActionView::Helpers::TagHelper
7
assert_equal "<br />", tag("br")
8
assert_equal "<br clear=\"left\" />", tag(:br, :clear => "left")
9
assert_equal "<br>", tag("br", nil, true)
13
str = tag("p", "class" => "show", :class => "elsewhere")
14
assert_match /class="show"/, str
15
assert_match /class="elsewhere"/, str
18
def test_tag_options_rejects_nil_option
19
assert_equal "<p />", tag("p", :ignored => nil)
22
def test_tag_options_accepts_false_option
23
assert_equal "<p value=\"false\" />", tag("p", :value => false)
26
def test_tag_options_accepts_blank_option
27
assert_equal "<p included=\"\" />", tag("p", :included => '')
30
def test_tag_options_converts_boolean_option
31
assert_equal '<p disabled="disabled" multiple="multiple" readonly="readonly" />',
32
tag("p", :disabled => true, :multiple => true, :readonly => true)
36
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
37
assert content_tag("a", "Create", "href" => "create").html_safe?
38
assert_equal content_tag("a", "Create", "href" => "create"),
39
content_tag("a", "Create", :href => "create")
42
def test_content_tag_with_block_in_erb
43
__in_erb_template = ''
44
content_tag(:div) { concat "Hello world!" }
45
assert_dom_equal "<div>Hello world!</div>", output_buffer
48
def test_content_tag_with_block_and_options_in_erb
49
__in_erb_template = ''
50
content_tag(:div, :class => "green") { concat "Hello world!" }
51
assert_dom_equal %(<div class="green">Hello world!</div>), output_buffer
54
def test_content_tag_with_block_and_options_out_of_erb
55
assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, :class => "green") { "Hello world!" }
58
def test_content_tag_with_block_and_options_outside_out_of_erb
59
assert_equal content_tag("a", "Create", :href => "create"),
60
content_tag("a", "href" => "create") { "Create" }
63
def test_content_tag_nested_in_content_tag_out_of_erb
64
assert_equal content_tag("p", content_tag("b", "Hello")),
65
content_tag("p") { content_tag("b", "Hello") },
69
def test_content_tag_nested_in_content_tag_in_erb
70
__in_erb_template = true
71
content_tag("p") { concat content_tag("b", "Hello") }
72
assert_equal '<p><b>Hello</b></p>', output_buffer
75
def test_cdata_section
76
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
80
assert_equal '1 < 2 & 3', escape_once('1 < 2 & 3')
83
def test_double_escaping_attributes
84
['1&2', '1 < 2', '“test“'].each do |escaped|
85
assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped)
89
def test_skip_invalid_escaped_attributes
90
['&1;', 'dfa3;', '& #123;'].each do |escaped|
91
assert_equal %(<a href="#{escaped.gsub /&/, '&'}" />), tag('a', :href => escaped)
95
def test_disable_escaping
96
assert_equal '<a href="&" />', tag('a', { :href => '&' }, false, false)