# # File:: test_HTMLProcessor.rb # Author:: wkm # Copyright:: 2009 # License:: GPL # # Unit tests for the HTMLProcessor # $:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'test/unit' require 'sitefuel/processors/HTMLProcessor' require 'sitefuel/extensions/StringFormatting' include SiteFuel::Processor class TestHTMLProcessor < Test::Unit::TestCase def test_file_extensions # negative tests assert_equal false, HTMLProcessor.processes_file?("testhtml") assert_equal false, HTMLProcessor.processes_file?("testhtm") assert_equal false, HTMLProcessor.processes_file?("testHTML") assert_equal false, HTMLProcessor.processes_file?("test.html.foo") assert_equal false, HTMLProcessor.processes_file?("test.htm.foo") # positive tests assert HTMLProcessor.processes_file?("test.html") assert HTMLProcessor.processes_file?("test.htm") assert HTMLProcessor.processes_file?("test.HTML") assert HTMLProcessor.processes_file?("test.HtMl") assert HTMLProcessor.processes_file?("test.hTm") end def test_name assert_equal "HTML", HTMLProcessor.processor_name end def test_beautify_quotes assert_equal( %q{
“Really?” Alice asked.
“Yes. Just yesterday.” said Bob.
"Really?" Alice asked.
"Yes. Just yesterday." said Bob.}
)
)
assert_equal(
%q{
This was Alice’s car; she bought it from the Hoovers.
}, HTMLProcessor.filter_string( :beautify_quotes, %q{This was Alice's car; she bought it from the Hoovers.
} ) ) end def test_beautify_dashes assert_equal( %q{Alice—having just finished—shouted
}, HTMLProcessor.filter_string( :beautify_dashes, %q{Alice---having just finished---shouted
} ) ) assert_equal( %q{See ppg. 12–15
}, HTMLProcessor.filter_string( :beautify_dashes, %q{See ppg. 12--15
} ) ) assert_equal( %q{These--are left alone
}, HTMLProcessor.filter_string( :beautify_dashes, %q{These--are left alone
} ) ) # test --'s use as a filler for "bad words" assert_equal( %q{f––
}, HTMLProcessor.filter_string( :beautify_dashes, %q{f----
} ) ) end def test_beautify_arrows assert_equal( %q{a → b ← c ↔ d
}, HTMLProcessor.filter_string( :beautify_arrows, %q{a --> b <-- c <-> d
} ) ) assert_equal( %q{a ⇒ b ⇐ c ⇔ d
}, HTMLProcessor.filter_string( :beautify_arrows, %q{a ==> b <== c <=> d
} ) ) end def test_beautify_symbols assert_equal %q{™
}, HTMLProcessor.filter_string(:beautify_symbols, %q{(tm)
}) assert_equal %q{©
}, HTMLProcessor.filter_string(:beautify_symbols, %q{(c)
}) assert_equal %q{®
}, HTMLProcessor.filter_string(:beautify_symbols, %q{(r)
}) assert_equal( %q{Hello… Hi… And finally … that was it.
}, HTMLProcessor.filter_string( :beautify_symbols, %q{Hello... Hi... And finally ... that was it.
} ) ) end def test_traverse modifiable_tags = %w{h1 h2 h3 h4 h5 h6 p b i ul a li td th} unmodifiable_tags = %w{pre code html head} # test tags which should be modified modifiable_tags.each do |tag| assert_equal "<#{tag}>™#{tag}>", HTMLProcessor.filter_string(:beautify_symbols, "<#{tag}>(tm)#{tag}>") end # test tags which should be unmodified unmodifiable_tags.each do |tag| assert_equal "<#{tag}>(tm)#{tag}>", HTMLProcessor.filter_string(:beautify_symbols, "<#{tag}>(tm)#{tag}>") end end def test_embedded_css assert_equal( %q{}, HTMLProcessor.filter_string(:minify_styles, <<-END END ).strip ) end def test_embedded_javascript assert_equal( "", HTMLProcessor.filter_string(:minify_javascript, %q{