~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/template/tag_helper_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 content_tag("a", "Create", "href" => "create").html_safe?
38
 
    assert_equal content_tag("a", "Create", "href" => "create"),
39
 
                 content_tag("a", "Create", :href => "create")
40
 
  end
41
 
 
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
46
 
  end
47
 
 
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
52
 
  end
53
 
 
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!" }
56
 
  end
57
 
 
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" }
61
 
  end
62
 
 
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") },
66
 
                 output_buffer
67
 
  end
68
 
 
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
73
 
  end
74
 
 
75
 
  def test_cdata_section
76
 
    assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
77
 
  end
78
 
  
79
 
  def test_escape_once
80
 
    assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3')
81
 
  end
82
 
  
83
 
  def test_double_escaping_attributes
84
 
    ['1&amp;2', '1 &lt; 2', '&#8220;test&#8220;'].each do |escaped|
85
 
      assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped)
86
 
    end
87
 
  end
88
 
  
89
 
  def test_skip_invalid_escaped_attributes
90
 
    ['&1;', '&#1dfa3;', '& #123;'].each do |escaped|
91
 
      assert_equal %(<a href="#{escaped.gsub /&/, '&amp;'}" />), tag('a', :href => escaped)
92
 
    end
93
 
  end
94
 
 
95
 
  def test_disable_escaping
96
 
    assert_equal '<a href="&amp;" />', tag('a', { :href => '&amp;' }, false, false)
97
 
  end
98
 
end