Froze rails gems
[depot.git] / vendor / rails / actionpack / test / template / tag_helper_test.rb
1 require 'abstract_unit'
2
3 class TagHelperTest < ActionView::TestCase
4 tests ActionView::Helpers::TagHelper
5
6 def test_tag
7 assert_equal "<br />", tag("br")
8 assert_equal "<br clear=\"left\" />", tag(:br, :clear => "left")
9 assert_equal "<br>", tag("br", nil, true)
10 end
11
12 def test_tag_options
13 str = tag("p", "class" => "show", :class => "elsewhere")
14 assert_match /class="show"/, str
15 assert_match /class="elsewhere"/, str
16 end
17
18 def test_tag_options_rejects_nil_option
19 assert_equal "<p />", tag("p", :ignored => nil)
20 end
21
22 def test_tag_options_accepts_false_option
23 assert_equal "<p value=\"false\" />", tag("p", :value => false)
24 end
25
26 def test_tag_options_accepts_blank_option
27 assert_equal "<p included=\"\" />", tag("p", :included => '')
28 end
29
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)
33 end
34
35 def test_content_tag
36 assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
37 assert_equal content_tag("a", "Create", "href" => "create"),
38 content_tag("a", "Create", :href => "create")
39 end
40
41 def test_content_tag_with_block_in_erb
42 __in_erb_template = ''
43 content_tag(:div) { concat "Hello world!" }
44 assert_dom_equal "<div>Hello world!</div>", output_buffer
45 end
46
47 def test_content_tag_with_block_and_options_in_erb
48 __in_erb_template = ''
49 content_tag(:div, :class => "green") { concat "Hello world!" }
50 assert_dom_equal %(<div class="green">Hello world!</div>), output_buffer
51 end
52
53 def test_content_tag_with_block_and_options_out_of_erb
54 assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, :class => "green") { "Hello world!" }
55 end
56
57 def test_content_tag_with_block_and_options_outside_out_of_erb
58 assert_equal content_tag("a", "Create", :href => "create"),
59 content_tag("a", "href" => "create") { "Create" }
60 end
61
62 def test_content_tag_nested_in_content_tag_out_of_erb
63 assert_equal content_tag("p", content_tag("b", "Hello")),
64 content_tag("p") { content_tag("b", "Hello") },
65 output_buffer
66 end
67
68 def test_content_tag_nested_in_content_tag_in_erb
69 __in_erb_template = true
70 content_tag("p") { concat content_tag("b", "Hello") }
71 assert_equal '<p><b>Hello</b></p>', output_buffer
72 end
73
74 def test_cdata_section
75 assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
76 end
77
78 def test_escape_once
79 assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3')
80 end
81
82 def test_double_escaping_attributes
83 ['1&amp;2', '1 &lt; 2', '&#8220;test&#8220;'].each do |escaped|
84 assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped)
85 end
86 end
87
88 def test_skip_invalid_escaped_attributes
89 ['&1;', '&#1dfa3;', '& #123;'].each do |escaped|
90 assert_equal %(<a href="#{escaped.gsub /&/, '&amp;'}" />), tag('a', :href => escaped)
91 end
92 end
93
94 def test_disable_escaping
95 assert_equal '<a href="&amp;" />', tag('a', { :href => '&amp;' }, false, false)
96 end
97 end