Sha256: b4df0e390087fe4186df7ff2fd737168f4874ff627fda3a6d97e3cf0bc1f3b3b

Contents?: true

Size: 1.88 KB

Versions: 27

Compression:

Stored size: 1.88 KB

Contents

#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '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

27 entries across 27 versions & 3 rubygems

Version Path
BBRedCloth-0.9.0.alpha1 test/validate_fixtures.rb
jeremy-RedCloth-4.1.1 test/validate_fixtures.rb
BBRedCloth-0.8.8 test/validate_fixtures.rb
BBRedCloth-0.8.7 test/validate_fixtures.rb
BBRedCloth-0.8.6 test/validate_fixtures.rb
BBRedCloth-0.8.5 test/validate_fixtures.rb
BBRedCloth-0.8.4 test/validate_fixtures.rb
BBRedCloth-0.8.3 test/validate_fixtures.rb
BBRedCloth-0.8.2 test/validate_fixtures.rb
BBRedCloth-0.8.1 test/validate_fixtures.rb
RedCloth-4.2.4-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.2.4-x86-mingw32 test/validate_fixtures.rb
RedCloth-4.2.4-java test/validate_fixtures.rb
RedCloth-4.2.4 test/validate_fixtures.rb
RedCloth-4.2.4.pre3-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.2.4.pre3-x86-mingw32 test/validate_fixtures.rb
RedCloth-4.2.4.pre3-java test/validate_fixtures.rb
RedCloth-4.2.4.pre3 test/validate_fixtures.rb
RedCloth-4.2.4.pre2-x86-mswin32-60 test/validate_fixtures.rb
RedCloth-4.2.4.pre2-x86-mingw32 test/validate_fixtures.rb