Sha256: 9fd6f8790bb4d39af7ebb5dfd803f3572cadd13b81feca86b9e31ab2eb951a5c

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

#!/usr/bin/env ruby

require 'helper'
require 'erb'
require 'w3c_validators'

class ValidateFixtures < Test::Unit::TestCase
  include W3CValidators

  def setup
    @v = MarkupValidator.new
    sleep 1 # delay per WC3 request
  end

  HTML_4_0_TEMPLATE = <<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title><%= test_name %></title>
</head>
<body>
<%= content %>
</body>
</html>
EOD
  XHTML_1_0_TEMPLATE = <<EOD
<!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" xml:lang="en" lang="en">
<head>
<title><%= test_name %></title>
</head>
<body>
<%= content %>
</body>
</html>
EOD
  
  fixtures.each do |name, doc|
   if doc['html'] && (doc['valid_html'].nil? || doc['valid_html'])
     define_method("test_html_output_validity_of_#{name}") do
       assert_produces_valid_html(name, doc['html'])
     end
     define_method("test_xhtml_output_validity_of_#{name}") do
       assert_produces_valid_xhtml(name, doc['html'])
     end
   end
  end
  
  private
  def assert_produces_valid_html(test_name, content)
    body = ERB.new(HTML_4_0_TEMPLATE, nil,'-%').result(binding)    
    assert_validates(body)
  end

  def assert_produces_valid_xhtml(test_name, content)
    body = ERB.new(XHTML_1_0_TEMPLATE, nil,'-%').result(binding)    
    assert_validates(body)
  end
  
  def assert_validates(body)
    results = @v.validate_text(body)
    errors = results.errors
    warnings = results.warnings.reject {|w| w.message_id == "247" } # NET-enabling start-tag requires SHORTTAG YES.
    
    assert(errors.empty?, "Validator errors: \n" +
      errors.collect {|e| "'#{e.to_s}'"}.join("\n"))
    
    assert(warnings.empty?, "Validator warnings: \n" +
      warnings.collect {|w| "'#{w.to_s}'"}.join("\n"))
  end
  
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
RedCloth-4.0.3-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.0.1 test/validate_fixtures.rb
RedCloth-4.0.0-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.0.0 test/validate_fixtures.rb
RedCloth-4.0.1-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.0.2 test/validate_fixtures.rb
RedCloth-4.0.2-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.0.3 test/validate_fixtures.rb
RedCloth-4.1.0-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.1.1-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.1.1-universal-java test/validate_fixtures.rb
RedCloth-4.0.4 test/validate_fixtures.rb
RedCloth-4.1.0-universal-java test/validate_fixtures.rb
RedCloth-4.0.4-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.1.0 test/validate_fixtures.rb
RedCloth-4.1.1 test/validate_fixtures.rb