Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

No commit message

  • Loading branch information...
commit b39249cd3539dea8da15e5adcdfddd7aff8cdeee 1 parent 2463484
@alexdunae authored
View
40 LICENSE
@@ -1,9 +1,8 @@
-= Ruby HTML Validator License
+= W3C Validators License
-Copyright (c) 2007 Alex Dunae
-
-Premailer is copyrighted free software by Alex Dunae (http://dunae.ca/).
-You can redistribute it and/or modify it under the conditions below:
+W3C Validators is copyrighted free software by Alex Dunae (http://dunae.ca/).
+You can redistribute it and/or modify it under either the terms of the GPL
+or the conditions below:
1. You may make and give away verbatim copies of the source form of the
software without restriction, provided that you duplicate all of the
@@ -14,8 +13,8 @@ You can redistribute it and/or modify it under the conditions below:
a) place your modifications in the Public Domain or otherwise
make them Freely Available, such as by posting said
- modifications to the internet or an equivalent medium, or by
- allowing the author to include your modifications in the software.
+ modifications to Usenet or an equivalent medium, or by allowing
+ the author to include your modifications in the software.
b) use the modified software only within your corporation or
organization.
@@ -25,10 +24,28 @@ You can redistribute it and/or modify it under the conditions below:
d) make other distribution arrangements with the author.
- 3. You may modify and include the part of the software into any other
- software (possibly commercial) as long as clear acknowledgement or
- a link back to the original software (http://code.dunae.ca/html_validator/)
- is provided.
+ 3. You may distribute the software in object code or executable
+ form, provided that you do at least ONE of the following:
+
+ a) distribute the executables and library files of the software,
+ together with instructions (in the manual page or equivalent)
+ on where to get the original distribution.
+
+ b) accompany the distribution with the machine-readable source of
+ the software.
+
+ c) give non-standard executables non-standard names, with
+ instructions on where to get the original software distribution.
+
+ d) make other distribution arrangements with the author.
+
+ 4. You may modify and include the part of the software into any other
+ software (possibly commercial). But some files in the distribution
+ are not written by the author, so that they are not under this terms.
+
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
+ files under the ./missing directory. See each file for the copying
+ condition.
5. The scripts and library files supplied as input to or produced as
output from the software do not automatically fall under the
@@ -40,3 +57,4 @@ You can redistribute it and/or modify it under the conditions below:
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
+
View
41 README
@@ -0,0 +1,41 @@
+= W3C Validators README
+
+W3C Validators is a Ruby wrapper for the World Wide Web Consortium's online
+validation service.
+
+It currently only supports the markup validator (http://validator.w3.org/);
+support for the CSS and feed validators is pending.
+
+=== Installation
+
+ gem install w3c_validators
+
+=== Example
+
+ require 'w3c_validators'
+
+ # set a custom validation host
+ @validator = MarkupValidator.new(:validator_uri => 'http://validator.localhost/check')
+
+ # override the DOCTYPE
+ @validator.set_doctype!(:html32)
+
+ # turn on debugging messages
+ @validator.set_debug!(true)
+
+ results = @validator.validate_uri('http://example.com/invalid.html')
+
+ if results.errors.length > 0
+ results.errors.each do |err|
+ puts err.to_s
+ end
+ else
+ puts 'Valid!'
+ end
+
+=== Credits and code
+
+Documentation and the source code are available at http://code.dunae.ca/w3c_validators/.
+
+Written by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007.
+
View
67 lib/markup_validator/constants.rb
@@ -0,0 +1,67 @@
+module W3CValidators
+ DOCTYPES = { :xhtml10_strict => 'XHTML 1.0 Strict',
+ :xhtml10_transitional => 'XHTML 1.0 Transitional',
+ :xhtml10_frameset => 'XHTML 1.0 Frameset',
+ :xhtml401_strict => 'HTML 4.01 Strict',
+ :xhtml401_transitional => 'HTML 4.01 Transitional',
+ :xhtml401_framest => 'HTML 4.01 Frameset',
+ :html32 => 'HTML 3.2',
+ :html20 => 'HTML 2.0',
+ :iso_html => 'ISO/IEC 15445:2000 ("ISO HTML")',
+ :xhtml11 => 'XHTML 1.1',
+ :xhtml_basic10 => 'XHTML Basic 1.0',
+ :xhtml_print10 => 'XHTML-Print 1.0',
+ :xhtml11_plus_mathml20 => 'XHTML 1.1 plus MathML 2.0',
+ :xhtml11_plus_mathml20_plus_svg11 => 'XHTML 1.1 plus MathML 2.0 plus SVG 1.1',
+ :mathml20=> 'MathML 2.0',
+ :svg10 => 'SVG 1.0',
+ :svg11 => 'SVG 1.1',
+ :svg11tiny => 'SVG 1.1 Tiny',
+ :svg11_basic => 'SVG 1.1 Basic',
+ :smil10 => 'SMIL 1.0',
+ :smil20 => 'SMIL 2.0'
+ }
+
+ CHARSETS = { :utf_8 => 'utf-8',
+ :utf_16 => 'utf-16',
+ :iso_8859_1 => 'iso-8859-1',
+ :iso_8859_2 => 'iso-8859-2',
+ :iso_8859_3 => 'iso-8859-3',
+ :iso_8859_4 => 'iso-8859-4',
+ :iso_8859_5 => 'iso-8859-5',
+ :iso_8859_6i => 'iso-8859-6-i',
+ :iso_8859_7 => 'iso-8859-7',
+ :iso_8859_8 => 'iso-8859-8',
+ :iso_8859_8i => 'iso-8859-8-i',
+ :iso_8859_9 => 'iso-8859-9',
+ :iso_8859_10 => 'iso-8859-10',
+ :iso_8859_11 => 'iso-8859-11',
+ :iso_8859_13 => 'iso-8859-13',
+ :iso_8859_14 => 'iso-8859-14',
+ :iso_8859_15 => 'iso-8859-15',
+ :iso_8859_16 => 'iso-8859-16',
+ :us_ascci => 'us-ascii',
+ :euc_jp => 'euc-jp',
+ :shift_jis => 'shift_jis',
+ :iso_2022_hp => 'iso-2022-jp',
+ :euc_jr => 'euc-kr',
+ :ksk_5601 => 'ksc_5601',
+ :gb_2312 => 'gb2312',
+ :gb_18030 => 'gb18030',
+ :big5 => 'big5',
+ :big5_hkscs => 'big5-HKSCS',
+ :tis_620 => 'tis-620',
+ :koi8_r => 'koi8-r',
+ :koi8_u => 'koi8-u',
+ :iso_ir_111 => 'iso-ir-111',
+ :macintosh => 'macintosh',
+ :windows_1250 => 'windows-1250',
+ :windows_1251 => 'windows-1251',
+ :windows_1252 => 'windows-1252',
+ :windows_1253 => 'windows-1253',
+ :windows_1254 => 'windows-1254',
+ :windows_1255 => 'windows-1255',
+ :windows_1256 => 'windows-1256',
+ :windows_1257 => 'windows-1257'
+ }
+end
View
4 lib/markup_validator/exceptions.rb
@@ -0,0 +1,4 @@
+module W3CValidators
+ class ValidatorUnavailable < RuntimeError; end
+ class ParsingError < RuntimeError; end
+end
View
194 lib/markup_validator/markup_validator.rb
@@ -2,46 +2,76 @@
require 'net/http'
require 'uri'
require 'rexml/document'
+require 'logger'
module W3CValidators
class MarkupValidator
- USER_AGENT = 'Ruby HTML Validator/0.9 (http://code.dunae.ca/html_validator/)'
- VERSION = '0.9'
+ USER_AGENT = 'Ruby W3C Validator/0.9 (http://code.dunae.ca/w3c_validators/)'
+ VERSION = '0.9.0'
VALIDATOR_URI = 'http://validator.w3.org/check'
HEAD_STATUS_HEADER = 'X-W3C-Validator-Status'
HEAD_ERROR_COUNT_HEADER = 'X-W3C-Validator-Errors'
SOAP_OUTPUT_PARAM = 'soap12'
- #DEFAULT_OPTIONS = {:doctype => nil, :verbose => false, :debug => false,
- # :ss => false, :outline => false}
-
- attr_reader :results
+ attr_reader :results, :validator_uri
# Create a new instance of the MarkupValidator.
#
# ==== Options
# The +options+ hash allows you to set request parameters (see http://validator.w3.org/docs/api.html#requestformat)
- # quickly. Request parameters can also be set using set_charset! and set_doctype!.
+ # quickly. Request parameters can also be set using set_charset!, set_debug! and set_doctype!.
+ #
+ # You can pass in your own validator's URI (i.e. <tt>MarkupValidator.new({:validator_uri => 'http://validator.localhost/check'})</tt>).
def initialize(options = {})
+ if options[:validator_uri]
+ @validator_uri = URI.parse(options[:validator_uri])
+ options.delete(options[:validator_uri])
+ else
+ @validator_uri = URI.parse(VALIDATOR_URI)
+ end
@options = options
- @validator_uri = URI.parse(VALIDATOR_URI)
end
# Specify the character encoding to use when parsing the document.
#
- # When +only_as_fallback+ is +true+, the given encoding will only be used as a fallback value,
- # in case the +charset+ is absent or unrecognized.
+ # When +only_as_fallback+ is +true+, the given encoding will only be
+ # used as a fallback value, in case the +charset+ is absent or unrecognized.
+ #
+ # +charset+ can be a string (e.g. <tt>set_charset!('utf-8')</tt>) or
+ # a symbol (e.g. <tt>set_charset!(:utf_8)</tt>) from the W3CValidators::CHARSETS hash.
+ #
+ # Has no effect when using validate_uri_quickly.
def set_charset!(charset, only_as_fallback = false)
+ if charset.kind_of?(Symbol)
+ if CHARSETS.has_key?(charset)
+ charset = CHARSETS[charset]
+ else
+ return
+ end
+ end
@options[:charset] = charset
@options[:fbc] = only_as_fallback
end
# Specify the Document Type (+DOCTYPE+) to use when parsing the document.
#
- # When +only_as_fallback+ is +true+, the given document type will only be used as a fallback value,
- # in case the document's +DOCTYPE+ declaration is missing or unrecognized.
+ # When +only_as_fallback+ is +true+, the given document type will only be
+ # used as a fallback value, in case the document's +DOCTYPE+ declaration
+ # is missing or unrecognized.
+ #
+ # +doctype+ can be a string (e.g. <tt>set_doctype!('HTML 3.2')</tt>) or
+ # a symbol (e.g. <tt>set_doctype!(:html32)</tt>) from the W3CValidators::DOCTYPES hash.
+ #
+ # Has no effect when using validate_uri_quickly.
def set_doctype!(doctype, only_as_fallback = false)
+ if doctype.kind_of?(Symbol)
+ if DOCTYPES.has_key?(doctype)
+ doctype = DOCTYPES[doctype]
+ else
+ return
+ end
+ end
@options[:doctype] = doctype
@options[:fbd] = only_as_fallback
end
@@ -50,24 +80,24 @@ def set_doctype!(doctype, only_as_fallback = false)
# and validation process (such as parser used, parse mode, etc.).
#
# Debugging information is stored in the Results +debug_messages+ hash. Custom debugging messages can be set with Results#add_debug_message.
+ #
+ # Has no effect when using validate_uri_quickly.
def set_debug!(debug = true)
@options[:debug] = debug
end
-
- # Validate the markup of an URI.
- #
- # By setting +quick+ to +true+ the URI is validated using a +HEAD+ request
- # and only returns an error count, not full error messages.
+ # Validate the markup of an URI using a +SOAP+ request.
#
# Returns W3CValidators::Results.
- def validate_uri(uri, quick = false)
- return validate({:uri => uri}, quick)
- #if quick
- # return quick_validate({:uri => uri})
- #else
- # return validate({:uri => uri})
- #end
+ def validate_uri(uri)
+ return validate({:uri => uri}, false)
+ end
+
+ # Validate the markup of an URI using a +HEAD+ request.
+ #
+ # Returns W3CValidators::Results with an error count, not full error messages.
+ def validate_uri_quickly(uri)
+ return validate({:uri => uri}, true)
end
# Validate the markup of a fragment.
@@ -79,69 +109,68 @@ def validate_fragment(fragment)
# Validate the markup of a local file.
#
- # +file_path+ must be the fully-expanded path to an HTML file.
+ # +file_path+ must be the fully-expanded path to the file.
#
# Returns W3CValidators::Results.
#--
# TODO: needs error handling
#++
def validate_file(file_path)
- begin
- fh = File.new(file_path, 'r+')
- markup_src = fh.read
- fh.close
- return validate({:uploaded_file => markup_src}, false)
- end
+ fh = File.new(file_path, 'r+')
+ markup_src = fh.read
+ fh.close
+ return validate({:uploaded_file => markup_src}, false)
end
-
protected
# Perform a validation request.
#
# Returns W3CValidators::Results.
- def validate(options, quick = false) # :nodoc:
+ def validate(options, quick = false)
options = create_request_options(options, false)
response = nil
results = nil
- if quick # perform a HEAD request
- raise ArgumentError, "a URI must be provided for HEAD requests." unless options[:uri]
- query = create_query_string_data(options)
-
+ begin
Net::HTTP.start(@validator_uri.host, @validator_uri.port) do |http|
- response = http.request_head(@validator_uri.path + '?' + query)
- end
-
- results = parse_head_response(response, options[:uri])
- else # perform a SOAP request
- if options.has_key?(:uri) # send a GET request
- query = create_query_string_data(options)
-
- Net::HTTP.start(@validator_uri.host, @validator_uri.port) do |http|
- response = http.get(@validator_uri.path + '?' + query).body
- end
- else # send a multipart form request
- query, boundary = create_multipart_data(options)
- Net::HTTP.start(@validator_uri.host, @validator_uri.port) do |http|
- response = http.post2("/check", query, "Content-type" => "multipart/form-data; boundary=" + boundary).body
+ if quick
+ # perform a HEAD request
+ raise ArgumentError, "a URI must be provided for HEAD requests." unless options[:uri]
+ query = create_query_string_data(options)
+ response = http.request_head(@validator_uri.path + '?' + query)
+ results = parse_head_response(response, options[:uri])
+ else
+ # perform a SOAP request
+ if options.has_key?(:uri) or options.has_key?(:fragment)
+ # send a GET request
+ query = create_query_string_data(options)
+ response = http.get(@validator_uri.path + '?' + query)
+ else
+ # send a multipart form request
+ query, boundary = create_multipart_data(options)
+ response = http.post2("/check", query, "Content-type" => "multipart/form-data; boundary=" + boundary)
+ end
+ response.value
+ results = parse_soap_response(response.body)
end
end
- results = parse_soap_response(response)
+ rescue Exception => e
+ handle_exception e
end
-
@results = results
end
- # Parse the SOAP XML response into W3CValidators::Results.
+ # Parse the SOAP XML response.
#
# +response+ must be a Net::HTTPResponse.
#
- # Returns Results.
- #--
- # TODO: add support for m:debug options
- #++
+ # Returns W3CValidators::Results.
def parse_soap_response(response)
- doc = REXML::Document.new(response)
+ begin
+ doc = REXML::Document.new(response)
+ rescue Exception => e
+ handle_exception e
+ end
result_params = {}
{:doctype => 'm:doctype', :uri => 'm:uri', :charset => 'm:charset',
@@ -151,8 +180,6 @@ def parse_soap_response(response)
end
end
- puts result_params.inspect
-
results = Results.new(result_params)
{:warning => 'm:warnings/m:warninglist/m:warning', :error => 'm:errors/m:errorlist/m:error'}.each do |local_type, remote_type|
@@ -191,6 +218,7 @@ def parse_head_response(response, validated_uri = nil) # :nodoc:
# Perform sanity checks on request params
def create_request_options(options, quick) # :nodoc:
options = @options.merge(options)
+
options[:output] = SOAP_OUTPUT_PARAM unless quick
@@ -210,10 +238,10 @@ def create_request_options(options, quick) # :nodoc:
options[k] = options[k] ? 1 : 0
end
end
+
options
end
-
def create_multipart_data(options) # :nodoc:
boundary = '349832898984244898448024464570528145'
params = []
@@ -246,5 +274,45 @@ def create_query_string_data(options) # :nodoc:
qs
end
+ private
+ #--
+ # Big thanks to ara.t.howard and Joel VanderWerf on Ruby-Talk for the exception handling help.
+ #++
+ def handle_exception(e, msg = '')
+ case e
+ when Net::HTTPServerException
+ msg = "unable to connect to the validator at #{@validator_uri} (response was #{e.message})."
+ raise ValidatorUnavailable, msg, caller
+ when REXML::ParseException
+ msg = "unable to parse the response from the validator."
+ raise ParsingError, msg, caller
+ else
+ raise e
+ end
+
+ if e.respond_to?(:error_handler_before)
+ fcall(e, :error_handler_before, self)
+ end
+
+ if e.respond_to?(:error_handler_instead)
+ fcall(e, :error_handler_instead, self)
+ else
+ if e.respond_to? :status
+ exit_status(( e.status ))
+ end
+
+ if SystemExit === e
+ stderr.puts e.message unless(SystemExit === e and e.message.to_s == 'exit') ### avoids double message for abort('message')
+ end
+ end
+
+ if e.respond_to?(:error_handler_after)
+ fcall(e, :error_handler_after, self)
+ end
+
+ exit_status(( exit_failure )) if exit_status == exit_success
+ exit_status(( Integer(exit_status) rescue(exit_status ? 0 : 1) ))
+ exit exit_status
+ end
end
end
View
8 lib/markup_validator/message.rb
@@ -14,13 +14,13 @@ def initialize(message_type, options = {})
@message_id = options[:messageid]
end
+ def is_debug?
+ @type == :debug
+ end
+
def is_error?
@type == :error
end
-
- def is_warning?
- @type == :warning
- end
def to_s
return '' unless @message and not @message.empty?
View
37 lib/w3c_validators.rb
@@ -1,38 +1,5 @@
require 'lib/markup_validator/markup_validator'
+require 'lib/markup_validator/exceptions'
+require 'lib/markup_validator/constants'
require 'lib/markup_validator/results'
require 'lib/markup_validator/message'
-
-module W3CValidators
-
- # Validate an URL against the W3C validator.
- #
- # This method provides a quick validation but does not return any error details.
- #
- # ==== Example
- # v = HTMLValidator.validate('http://example.com/test.html')
- #
- # puts v.errors.length
- # => 5
- #
- # puts v.errors[0].to_s
- # => "ERROR: line 6, col 73: end tag for "link" omitted, but OMITTAG NO was specified"
- def self.validate_markup(url, options={})
- MarkupValidator.validate(url, options)
- end
-
- # Validate an URL against the W3C validator using an HTTP HEAD request.
- #
- # This method provides a quick validation but does not return any error or warning details.
- #
- # ==== Example
- # v = HTMLValidator.quick_validate('http://example.com/test.html')
- #
- # puts v.errors.length
- # => 5
- #
- # puts v.errors[0].explanation
- # => nil
- def self.quick_validate(url, options={})
- Validator.quick_validate(url, options)
- end
-end
View
22 rakefile.rb
@@ -9,6 +9,7 @@
desc 'Check a file against the W3C\'s markup validation service.'
task :validate do
+
url = ENV['url']
if !url or url.empty?
@@ -18,21 +19,10 @@
v = MarkupValidator.new
- #results = v.validate_file('test.html', false)
-
results = v.validate_uri(url, false)
- puts "ERRORS?"
- puts results.errors.length
-
- puts "WARNINGS?"
- puts results.warnings.length
-
- puts results.errors[0].to_s
+ puts "Errors:" + results.errors.length.to_s
- #results.errors.each do |err|
- #puts "ERROR: #{err.line}: #{err.source}"
- # puts err.to_s
- #end
+ puts "Warnings: " + results.warnings.length.to_s
puts "DOCTYPE: #{results.doctype}"
puts "Validity: #{results.validity}"
@@ -47,14 +37,14 @@
end
-desc 'Generate documentation for the HTMLalidator.'
+desc 'Generate documentation for the W3C Validators.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
- rdoc.title = 'HTMLValidator'
+ rdoc.title = 'Ruby W3C Validators'
rdoc.options << '--all'
rdoc.options << '--inline-source'
rdoc.options << '--line-numbers'
- #rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('LICENSE')
#rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('lib/*.rb')
View
38 test.html
@@ -1,38 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca" lang="en-ca">
-<head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <title>Alex Dunae - dunae.ca</title>
- <link rel="openid.server" href="http://dunae.ca/openid/MyID.config.php">
- <link rel="openid.delegate" href="http://dunae.ca/openid/MyID.config.php">
- <link rel="stylesheet" type="text/css" href="http://code.dunae.ca/screen.css" />
-</head>
-<body>
-<div id="container">
-
- <h1 id="header"><a href="http://dunae.ca/">dunae.ca</a></h1>
- <div id="content">
- <p>Not much to see here right now.</p>
-
- <p>Some of my recent web work includes:
- <ul>
- <li><a href="http://cymc.ca/">Comox Valley Youth Music Centre</a></li>
- <li><a href="http://denisebrynelsen.ca/">Denise Brynelsen, Sunshine Coast Realty</a></li>
-
- <li><a href="http://jackson2bears.net/">jackson2bears</a></li>
- <li><a href="http://www.cumberlandvillageworks.com/">Cumberland Village Works</a></li>
- <li><a href="http://www.squeegeeville.com/">Squeegeeville</a></li>
- </ul></p>
-
- <p>You can read a bit of my copy writing <a href="http://www.surfsinn.ca/tofino-ucluelet-guesthouse/">here</a>.</p>
-
- <p>You may want to look at some <a href="http://code.dunae.ca/">code I have written</a>.</p>
-
- <p>This portfolio currently takes back seat to a new house, a new rabbit and actual work. Writing and print work will eventually be on display, too.</p>
-
- <p>Feel free to get in touch: 250-885-6744</code>.</p>
- </div>
-
-</div>
-</body>
-</html>
View
11 test/fixtures/invalid.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca" lang="en-ca">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title>W3C Validators -- Invalid Test Page </title>
+</head>
+<body>
+<p unknown="true">Invalid!</p>
+<!-- 1 error; 0 warnings -->
+</body>
+</html>
View
11 test/fixtures/valid.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca" lang="en-ca">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title>W3C Validators -- Valid Test Page </title>
+</head>
+<body>
+<p>Valid!</p>
+<!-- 0 errors; 0 warnings -->
+</body>
+</html>
View
82 test/test_html_validator.rb
@@ -1,77 +1,71 @@
require File.dirname(__FILE__) + '/test_helper'
-# Test cases for the CssParser.
+# Test cases for the MarkupValidator.
class MarkupValidatorTests < Test::Unit::TestCase
-include W3CValidators
+ include W3CValidators
def setup
@v = MarkupValidator.new
-
- @valid_fragment = <<-EOV
- <div class="example">This is a test</div>
- EOV
-
- @invalid_fragment = <<-EOI
- <div class="example>This is a test
- EOI
-
- end
-
- def test_converting_boolean_params_to_integers
- return
end
def test_overriding_doctype
- doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- @v.set_doctype!(doctype, false)
- r = @v.validate_uri('http://dunae.ca/', true)
- flunk
- assert_equal doctype, r.doctype
- return
+ @v.set_doctype!(:html32, false)
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
end
def test_overriding_doctype_for_fallback_only
- doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- @v.set_doctype!(doctype, true)
- r = @v.validate_uri('http://dunae.ca/', true)
- assert_not_equal doctype, r.doctype
- return
+ @v.set_doctype!(:html32, true)
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_not_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
end
-
+
def test_overriding_charset
- return
+ @v.set_charset!(:utf_16, false)
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_equal 'utf-16', r.charset
+ end
+
+ def test_overriding_charset_for_fallback_only
+ @v.set_doctype!(:utf_16, true)
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_not_equal 'utf-16', r.charset
end
def test_validating_uri_with_head_request
- r = @v.validate_uri('http://dunae.ca/', true)
- assert_equal 11, r.errors.length
+ r = @v.validate_uri_quickly('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_equal 1, r.errors.length
assert_equal 0, r.warnings.length
end
def test_validating_uri_with_soap
- r = @v.validate_uri('http://dunae.ca/', false)
- assert_equal 11, r.errors.length
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
+ assert_equal 1, r.errors.length
assert_equal 0, r.warnings.length
end
def test_debugging_uri
@v.set_debug!
- r = @v.validate_uri('http://dunae.ca/', false)
+ r = @v.validate_uri('http://code.dunae.ca/w3c_validators/test/invalid.html')
assert r.debug_messages.length > 0
end
- def test_validating_file_with_soap
- return
+ def test_validating_file
+ file = File.dirname(__FILE__) + '/fixtures/invalid.html'
+ r = @v.validate_file(file)
+ assert_equal 1, r.errors.length
end
- def test_validating_fragment_with_soap
- return
- r = @v.validate_fragment(@valid_fragment, false)
- puts @valid_fragment
- r.errors.each do |err|
- puts err.to_s
- end
-
+ def test_validating_fragment
+ valid_fragment = <<-EOV
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+ <title>Test</title>
+ <body>
+ <div class="example">This is a test</div>
+ </body>
+ EOV
+
+ r = @v.validate_fragment(valid_fragment)
assert_equal 0, r.errors.length
-
+ assert_equal 0, r.warnings.length
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.