Methods
T
Instance Public methods
test_find_all()
# File actionpack/test/template/html-scanner/document_test.rb, line 30
  def test_find_all
    doc = HTML::Document.new "      <html>
        <body>
          <p class="test"><img src="hello.gif"></p>
          <div class="foo">
            <p class="test">something</p>
            <p>here is <em class="test">more</em></p>
          </div>
        </body>
      </html>
".strip
    all = doc.find_all :attributes => { :class => "test" }
    assert_equal 3, all.length
    assert_equal [ "p", "p", "em" ], all.map { |n| n.name }
  end
test_find_empty_tag()
# File actionpack/test/template/html-scanner/document_test.rb, line 115
def test_find_empty_tag
  doc = HTML::Document.new("<div id='map'></div>")
  assert_nil doc.find(:tag => "div", :attributes => { :id => "map" }, :content => /./)
  assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => /\A\Z/)
  assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => /^$/)
  assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => "")
  assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => nil)
end
test_find_img()
# File actionpack/test/template/html-scanner/document_test.rb, line 19
  def test_find_img
    doc = HTML::Document.new "      <html>
        <body>
          <p><img src="hello.gif"></p>
        </body>
      </html>
".strip
    assert doc.find(:tag=>"img", :attributes=>{"src"=>"hello.gif"})
  end
test_find_with_text()
# File actionpack/test/template/html-scanner/document_test.rb, line 47
  def test_find_with_text
    doc = HTML::Document.new "      <html>
        <body>
          <p>Some text</p>
        </body>
      </html>
".strip
    assert doc.find(:content => "Some text")
    assert doc.find(:tag => "p", :child => { :content => "Some text" })
    assert doc.find(:tag => "p", :child => "Some text")
    assert doc.find(:tag => "p", :content => "Some text")
  end
test_handle_doctype()
# File actionpack/test/template/html-scanner/document_test.rb, line 4
  def test_handle_doctype
    doc = nil
    assert_nothing_raised do
      doc = HTML::Document.new "        <!DOCTYPE "blah" "blah" "blah">
        <html>
        </html>
".strip
    end
    assert_equal 3, doc.root.children.length
    assert_equal %Q{<!DOCTYPE "blah" "blah" "blah">}, doc.root.children[0].content
    assert_match %r{\s+}m, doc.root.children[1].content
    assert_equal "html", doc.root.children[2].name
  end
test_invalid_document_raises_exception_when_strict()
# File actionpack/test/template/html-scanner/document_test.rb, line 136
def test_invalid_document_raises_exception_when_strict
  assert_raise RuntimeError do
    HTML::Document.new("<html>
      <table>
        <tr>
          <td style=\"color: #FFFFFF; height: 17px; onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" style=\"cursor:pointer; height: 17px;\"; nowrap onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" onmouseout=\"this.bgColor='#0066cc'; this.style.color='#FFFFFF'\" onmouseover=\"this.bgColor='#ffffff'; this.style.color='#0033cc'\">About Us</td>
        </tr>
      </table>
    </html>", true)
  end
end
test_parse_cdata()
# File actionpack/test/template/html-scanner/document_test.rb, line 97
  def test_parse_cdata
    doc = HTML::Document.new("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title><![CDATA[<br>]]></title>
   </head>
  <body>
    <p>this document has &lt;br&gt; for a title</p>
  </body>
</html>
")

    assert_nil doc.find(:tag => "title", :descendant => { :tag => "br" })
    assert doc.find(:tag => "title", :child => "<br>")
  end
test_parse_document()
# File actionpack/test/template/html-scanner/document_test.rb, line 66
  def test_parse_document
    doc = HTML::Document.new("      <div>
        <h2>blah</h2>
        <table>
        </table>
      </div>
")
    assert_not_nil doc.find(:tag => "div", :children => { :count => 1, :only => { :tag => "table" } })
  end
test_parse_invalid_document()
# File actionpack/test/template/html-scanner/document_test.rb, line 124
def test_parse_invalid_document
  assert_nothing_raised do
    HTML::Document.new("<html>
      <table>
        <tr>
          <td style=\"color: #FFFFFF; height: 17px; onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" style=\"cursor:pointer; height: 17px;\"; nowrap onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" onmouseout=\"this.bgColor='#0066cc'; this.style.color='#FFFFFF'\" onmouseover=\"this.bgColor='#ffffff'; this.style.color='#0033cc'\">About Us</td>
        </tr>
      </table>
    </html>")
  end
end
test_parse_xml()
# File actionpack/test/template/html-scanner/document_test.rb, line 61
def test_parse_xml
  assert_nothing_raised { HTML::Document.new("<tags><tag/></tags>", true, true) }
  assert_nothing_raised { HTML::Document.new("<outer><link>something</link></outer>", true, true) }
end
test_tag_nesting_nothing_to_s()
# File actionpack/test/template/html-scanner/document_test.rb, line 77
def test_tag_nesting_nothing_to_s
  doc = HTML::Document.new("<tag></tag>")
  assert_equal "<tag></tag>", doc.root.to_s
end
test_tag_nesting_space_to_s()
# File actionpack/test/template/html-scanner/document_test.rb, line 82
def test_tag_nesting_space_to_s
  doc = HTML::Document.new("<tag> </tag>")
  assert_equal "<tag> </tag>", doc.root.to_s
end
test_tag_nesting_tag_to_s()
# File actionpack/test/template/html-scanner/document_test.rb, line 92
def test_tag_nesting_tag_to_s
  doc = HTML::Document.new("<tag><nested /></tag>")
  assert_equal "<tag><nested /></tag>", doc.root.to_s
end
test_tag_nesting_text_to_s()
# File actionpack/test/template/html-scanner/document_test.rb, line 87
def test_tag_nesting_text_to_s
  doc = HTML::Document.new("<tag>text</tag>")
  assert_equal "<tag>text</tag>", doc.root.to_s
end