From 5db9ddaf4730df42882b4044e98b99765f3c2f05 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 21 Jan 2008 11:59:55 -0600 Subject: [PATCH] Fix Busted Functional Tests Fix the functional tests busted by Revision 212. Sync with latest HTML5lib. --- test/functional/admin_controller_test.rb | 5 +++++ test/functional/file_controller_test.rb | 5 +++++ test/functional/wiki_controller_test.rb | 5 +++++ test/test_helper.rb | 10 +++++++-- .../plugins/HTML5lib/lib/html5/inputstream.rb | 9 +++++--- vendor/plugins/HTML5lib/lib/html5/sniffer.rb | 12 +++++----- .../plugins/HTML5lib/lib/html5/tokenizer.rb | 6 ++++- vendor/plugins/HTML5lib/test/test_lxp.rb | 6 ++++- .../plugins/HTML5lib/test/test_sanitizer.rb | 4 ++-- .../plugins/HTML5lib/test/test_serializer.rb | 3 +-- vendor/plugins/HTML5lib/test/test_stream.rb | 22 +++++++++++++------ vendor/plugins/HTML5lib/test19.rb | 10 ++++----- 12 files changed, 67 insertions(+), 30 deletions(-) diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 0d438599..0656f815 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -13,6 +13,11 @@ class AdminControllerTest < Test::Unit::TestCase @controller = AdminController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + class << @request.session + attr_accessor :dbman + end + # simulate a cookie session store + @request.session.dbman = FakeSessionDbMan @wiki = Wiki.new @oak = pages(:oak) @elephant = pages(:elephant) diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index ff64282c..6a05b0d8 100755 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -15,6 +15,11 @@ class FileControllerTest < Test::Unit::TestCase @controller = FileController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + class << @request.session + attr_accessor :dbman + end + # simulate a cookie session store + @request.session.dbman = FakeSessionDbMan @web = webs(:test_wiki) @wiki = Wiki.new WikiFile.delete_all diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 047eff77..f49cbc52 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -20,6 +20,11 @@ class WikiControllerTest < Test::Unit::TestCase @controller = WikiController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + class << @request.session + attr_accessor :dbman + end + # simulate a cookie session store + @request.session.dbman = FakeSessionDbMan @wiki = Wiki.new @web = webs(:test_wiki) @home = @page = pages(:home_page) diff --git a/test/test_helper.rb b/test/test_helper.rb index e5ffb738..0cecb06a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,10 +8,16 @@ require 'application' require 'test/unit' require 'active_record/fixtures' require 'action_controller/test_process' -#require 'action_web_service/test_invoke' -#require 'breakpoint' require 'wiki_content' require 'url_generator' +require 'digest/sha1' + +# simulates cookie session store +class FakeSessionDbMan + def self.generate_digest(data) + Digest::SHA1.hexdigest("secure") + end +end Test::Unit::TestCase.pre_loaded_fixtures = false Test::Unit::TestCase.use_transactional_fixtures = true diff --git a/vendor/plugins/HTML5lib/lib/html5/inputstream.rb b/vendor/plugins/HTML5lib/lib/html5/inputstream.rb index d63477cd..6864d482 100755 --- a/vendor/plugins/HTML5lib/lib/html5/inputstream.rb +++ b/vendor/plugins/HTML5lib/lib/html5/inputstream.rb @@ -281,7 +281,11 @@ module HTML5 @tell += 1 if @buffer[@tell] == "\n" c = "\n" when "\x80" .. "\x9F" - c = ''.force_encoding('UTF-8') << ENTITIES_WINDOWS1252[c.ord-0x80] + c = ENTITIES_WINDOWS1252[c.ord-0x80].chr('utf-8') + when "\xA0" .. "\xFF" + if c.encoding == Encoding::ASCII_8BIT + c = c.encode('utf-8','iso-8859-1') + end end if c == "\x0D" @@ -299,8 +303,7 @@ module HTML5 @col += 1 end - # binary utf-8 - c.ord > 126 ? [c.ord].pack('U') : c + c when 0x01..0x7F if c == 0x0D diff --git a/vendor/plugins/HTML5lib/lib/html5/sniffer.rb b/vendor/plugins/HTML5lib/lib/html5/sniffer.rb index 5e52c2c7..6d564fdf 100644 --- a/vendor/plugins/HTML5lib/lib/html5/sniffer.rb +++ b/vendor/plugins/HTML5lib/lib/html5/sniffer.rb @@ -7,9 +7,9 @@ module Sniffer while pos < s.length case s[pos] - when 0x09, 0x20, 0x0A, 0x0D # tab, space, LF, CR + when ?\t, ?\ , ?\n, ?\r # 0x09, 0x20, 0x0A, 0x0D == tab, space, LF, CR pos += 1 - when 0x3C # "<" + when ?< # 0x3C pos += 1 if s[pos..pos+2] == "!--" # [0x21, 0x2D, 0x2D] pos += 3 @@ -17,13 +17,13 @@ module Sniffer pos += 1 end pos += 3 - elsif s[pos] == 0x21 # "!" + elsif s[pos] == ?! # 0x21 pos += 1 - until s[pos] == 0x3E or pos >= s.length # ">" + until s[pos] == ?> or pos >= s.length # 0x3E pos += 1 end pos += 1 - elsif s[pos] == 0x3F # "?" + elsif s[pos] == ?? # 0x3F until s[pos..pos+1] == "?>" or pos >= s.length # [0x3F, 0x3E] pos += 1 end @@ -42,4 +42,4 @@ module Sniffer "text/html" end end -end \ No newline at end of file +end diff --git a/vendor/plugins/HTML5lib/lib/html5/tokenizer.rb b/vendor/plugins/HTML5lib/lib/html5/tokenizer.rb index 0bd97c52..dd33e841 100644 --- a/vendor/plugins/HTML5lib/lib/html5/tokenizer.rb +++ b/vendor/plugins/HTML5lib/lib/html5/tokenizer.rb @@ -118,7 +118,11 @@ module HTML5 end if 0 < charAsInt and charAsInt <= 1114111 and not (55296 <= charAsInt and charAsInt <= 57343) - char = [charAsInt].pack('U') + if String.method_defined? :force_encoding + char = charAsInt.chr('utf-8') + else + char = [charAsInt].pack('U') + end else char = [0xFFFD].pack('U') @token_queue << {:type => :ParseError, :data => "cant-convert-numeric-entity", :datavars => {"charAsInt" => charAsInt}} diff --git a/vendor/plugins/HTML5lib/test/test_lxp.rb b/vendor/plugins/HTML5lib/test/test_lxp.rb index 0fada8ae..e2f1ca2c 100755 --- a/vendor/plugins/HTML5lib/test/test_lxp.rb +++ b/vendor/plugins/HTML5lib/test/test_lxp.rb @@ -9,7 +9,11 @@ def assert_xml_equal(input, expected=nil, parser=HTML5::XMLParser) document = parser.parse(input.chomp, :lowercase_attr_name => false, :lowercase_element_name => false).root if not expected expected = input.chomp.gsub(XMLELEM,&sortattrs) - expected = expected.gsub(/&#(\d+);/) {[$1.to_i].pack('U')} + if expected.respond_to? :force_encoding + expected = expected.gsub(/&#(\d+);/) {$1.to_i.chr('utf-8')} + else + expected = expected.gsub(/&#(\d+);/) {[$1.to_i].pack('U')} + end output = document.to_s.gsub(/'/,'"').gsub(XMLELEM,&sortattrs) assert_equal(expected, output) else diff --git a/vendor/plugins/HTML5lib/test/test_sanitizer.rb b/vendor/plugins/HTML5lib/test/test_sanitizer.rb index d53df925..acc3fa67 100644 --- a/vendor/plugins/HTML5lib/test/test_sanitizer.rb +++ b/vendor/plugins/HTML5lib/test/test_sanitizer.rb @@ -12,11 +12,11 @@ class SanitizeTest < Test::Unit::TestCase include HTML5 def sanitize_xhtml stream - XHTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s + XHTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).join end def sanitize_html stream - HTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s + HTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).join end def sanitize_rexml stream diff --git a/vendor/plugins/HTML5lib/test/test_serializer.rb b/vendor/plugins/HTML5lib/test/test_serializer.rb index 9a0d0198..29781228 100644 --- a/vendor/plugins/HTML5lib/test/test_serializer.rb +++ b/vendor/plugins/HTML5lib/test/test_serializer.rb @@ -50,7 +50,7 @@ class Html5SerializeTestcase < Test::Unit::TestCase flunk("Expected: #{expected.inspect}, Received: #{result.inspect}") end - return if test_name == 'optionaltags' + next if test_name == 'optionaltags' result = HTML5::XHTMLSerializer. serialize(JsonWalker.new(test["input"]), (test["options"] || {})) @@ -60,7 +60,6 @@ class Html5SerializeTestcase < Test::Unit::TestCase elsif !expected.include?(result) flunk("Expected: #{expected.inspect}, Received: #{result.inspect}") end - end end diff --git a/vendor/plugins/HTML5lib/test/test_stream.rb b/vendor/plugins/HTML5lib/test/test_stream.rb index 40955bd7..d5d6740e 100755 --- a/vendor/plugins/HTML5lib/test/test_stream.rb +++ b/vendor/plugins/HTML5lib/test/test_stream.rb @@ -5,6 +5,14 @@ require 'html5/inputstream' class HTMLInputStreamTest < Test::Unit::TestCase include HTML5 + def getc stream + if String.method_defined? :force_encoding + stream.char.force_encoding('binary') + else + stream.char + end + end + def test_char_ascii stream = HTMLInputStream.new("'", :encoding=>'ascii') assert_equal('ascii', stream.char_encoding) @@ -13,23 +21,23 @@ class HTMLInputStreamTest < Test::Unit::TestCase def test_char_null stream = HTMLInputStream.new("\x00") - assert_equal("\xef\xbf\xbd", stream.char) + assert_equal("\xef\xbf\xbd", getc(stream)) end def test_char_utf8 stream = HTMLInputStream.new("\xe2\x80\x98", :encoding=>'utf-8') assert_equal('utf-8', stream.char_encoding) - assert_equal("\xe2\x80\x98", stream.char) + assert_equal("\xe2\x80\x98", getc(stream)) end def test_char_win1252 stream = HTMLInputStream.new("\xa2\xc5\xf1\x92\x86") assert_equal('windows-1252', stream.char_encoding) - assert_equal("\xc2\xa2", stream.char) - assert_equal("\xc3\x85", stream.char) - assert_equal("\xc3\xb1", stream.char) - assert_equal("\xe2\x80\x99", stream.char) - assert_equal("\xe2\x80\xa0", stream.char) + assert_equal("\xc2\xa2", getc(stream)) + assert_equal("\xc3\x85", getc(stream)) + assert_equal("\xc3\xb1", getc(stream)) + assert_equal("\xe2\x80\x99", getc(stream)) + assert_equal("\xe2\x80\xa0", getc(stream)) end def test_bom diff --git a/vendor/plugins/HTML5lib/test19.rb b/vendor/plugins/HTML5lib/test19.rb index 69ebe77c..d00b8039 100644 --- a/vendor/plugins/HTML5lib/test19.rb +++ b/vendor/plugins/HTML5lib/test19.rb @@ -13,20 +13,18 @@ require 'test/test_cli' require 'test/test_input_stream' -# incompatible encoding regexp match -# require 'test/test_lxp' +require 'test/test_lxp' require 'test/test_parser' # warning: method redefined; discarding old test # warning: instance variable @expanded_name not initialized +# SimpleDelegator.class # require 'test/test_sanitizer' -# warning: instance variable @delegate_sd_obj not initialized -# require 'test/test_serializer' +require 'test/test_serializer' -# undebugged -# require 'test/test_sniffer' +require 'test/test_sniffer' require 'test/test_stream'