jakewendt-html_test 0.2.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.rdoc +37 -0
- data/Rakefile +45 -22
- data/VERSION +1 -1
- data/jakewendt-html_test.gemspec +10 -31
- data/lib/assertions.rb +6 -2
- data/lib/html_test.rb +8 -6
- data/lib/url_checker.rb +146 -141
- data/lib/validate_filter.rb +10 -3
- data/lib/validator.rb +7 -1
- data/script/rails +6 -0
- metadata +23 -58
- data/rails/init.rb +0 -1
- data/test/controller_test.rb +0 -120
- data/test/integration_test.rb +0 -73
- data/test/invalid.html +0 -15
- data/test/link_validator_test.rb +0 -141
- data/test/public/image.jpg +0 -0
- data/test/rhtml_template.rhtml +0 -1
- data/test/rxml_template.rxml +0 -2
- data/test/test_helper.rb +0 -61
- data/test/untidy.html +0 -19
- data/test/valid.html +0 -14
- data/test/valid_links.html +0 -22
- data/test/validate_all_test.rb +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 381eba33dcd5526ed109a48740e5729f6e273013
|
4
|
+
data.tar.gz: ddcda1e319cd7f54b0a51c60e053617aa140cc67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0df2dfc51a4aa429ce69624b784a52dc682d9db6da72b13b920d8fda91a20dc7f71f05b3850b72a0358dc3d4f81a445dde3734c4b4092a0485bd76398ee0d3d2
|
7
|
+
data.tar.gz: 3124f0b840e5f1dc1ecfeba3b07eac4da04781fcf18759e6dfe42aa4531fc0f8314741f72eb36f1f18ff9220f46289dd0988b5557c6f8a82062a35872251677e
|
data/README.rdoc
CHANGED
@@ -103,3 +103,40 @@ Peter Marklund (http://marklunds.com)
|
|
103
103
|
|
104
104
|
== License
|
105
105
|
Licensed under the same terms as Ruby on Rails.
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
== Gemified with Jeweler
|
113
|
+
|
114
|
+
vi Rakefile
|
115
|
+
rake version:write
|
116
|
+
|
117
|
+
rake version:bump:patch
|
118
|
+
rake version:bump:minor
|
119
|
+
rake version:bump:major
|
120
|
+
|
121
|
+
rake gemspec
|
122
|
+
|
123
|
+
rake install
|
124
|
+
rake release
|
125
|
+
|
126
|
+
== Testing
|
127
|
+
|
128
|
+
Since upgrading some apps to rails 3, I found that this gem has some issues.
|
129
|
+
So, I'm wrapping the repo code in a rails 3 app solely for testing.
|
130
|
+
During gem creation/installation only the necessary code will be included.
|
131
|
+
|
132
|
+
Features untested in rails 3 due to me not using them ...
|
133
|
+
|
134
|
+
* the tidy validator
|
135
|
+
* the check_urls option
|
136
|
+
* ActionController::Routing::Routes doesn't exist in Rails 3
|
137
|
+
* also note, Test::Unit::AssertionFailedError doesn't exist in Ruby 1.9
|
138
|
+
* replaced all with "MiniTest::Assertion"
|
139
|
+
* these assert_raises are wrapped around assertion that don't have a negative
|
140
|
+
* also, the gem now adds the Gemfile dependencies to it which isn't really true
|
141
|
+
|
142
|
+
|
data/Rakefile
CHANGED
@@ -1,25 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the html_test plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
14
4
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
HtmlTest::Application.load_tasks
|
8
|
+
|
9
|
+
#require 'rake'
|
10
|
+
#require 'rake/testtask'
|
11
|
+
##require 'rake/rdoctask'
|
12
|
+
#require 'rdoc/task'
|
13
|
+
#
|
14
|
+
#desc 'Default: run unit tests.'
|
15
|
+
#task :default => :test
|
16
|
+
|
17
|
+
#desc 'Test the html_test plugin.'
|
18
|
+
#Rake::TestTask.new(:test) do |t|
|
19
|
+
# t.libs << 'test'
|
20
|
+
# t.libs << 'lib'
|
21
|
+
# t.pattern = 'test/**/*_test.rb'
|
22
|
+
# t.verbose = true
|
23
|
+
#end
|
24
|
+
|
25
|
+
#desc 'Generate documentation for the html_test plugin.'
|
26
|
+
#Rake::RDocTask.new(:rdoc) do |rdoc|
|
27
|
+
# rdoc.rdoc_dir = 'rdoc'
|
28
|
+
# rdoc.title = 'HtmlTest'
|
29
|
+
# rdoc.options << '--line-numbers' << '--inline-source'
|
30
|
+
# rdoc.rdoc_files.include('README')
|
31
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
32
|
+
#end
|
23
33
|
|
24
34
|
begin
|
25
35
|
require 'jeweler'
|
@@ -27,12 +37,25 @@ begin
|
|
27
37
|
gem.name = "jakewendt-html_test"
|
28
38
|
gem.summary = %Q{Ruby on Rails plugin for HTML validation and link checking}
|
29
39
|
gem.description = %Q{Ruby on Rails plugin for HTML validation and link checking}
|
30
|
-
gem.email = "github@
|
40
|
+
gem.email = "github@jakewendt.com"
|
31
41
|
gem.homepage = "http://github.com/jakewendt/html_test"
|
32
42
|
gem.authors = ["Peter Marklund", "George 'Jake' Wendt"]
|
33
43
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
44
|
+
|
45
|
+
gem.files = FileList['**/*']
|
46
|
+
gem.files -= FileList['app/**/*']
|
47
|
+
gem.files -= FileList['config/**/*']
|
48
|
+
gem.files -= FileList['test/**/*']
|
49
|
+
gem.files -= FileList['log/**/*']
|
50
|
+
gem.files -= FileList['pkg/**/*']
|
51
|
+
gem.files -= FileList['**/versions/**/*']
|
52
|
+
gem.files -= FileList['*Gemfile*']
|
53
|
+
gem.files -= FileList['rails/init.rb*']
|
54
|
+
gem.files -= FileList['coverage/**/*']
|
34
55
|
end
|
35
56
|
Jeweler::GemcutterTasks.new
|
36
57
|
rescue LoadError
|
37
58
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
38
59
|
end
|
60
|
+
|
61
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.5
|
data/jakewendt-html_test.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "jakewendt-html_test"
|
8
|
+
s.version = "0.3.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Peter Marklund", "George 'Jake' Wendt"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2013-12-04"
|
13
|
+
s.description = "Ruby on Rails plugin for HTML validation and link checking"
|
14
|
+
s.email = "github@jakewendt.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
@@ -36,33 +36,12 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/url_selector.rb",
|
37
37
|
"lib/validate_filter.rb",
|
38
38
|
"lib/validator.rb",
|
39
|
-
"rails
|
40
|
-
"script/validate"
|
41
|
-
"test/controller_test.rb",
|
42
|
-
"test/integration_test.rb",
|
43
|
-
"test/invalid.html",
|
44
|
-
"test/link_validator_test.rb",
|
45
|
-
"test/public/image.jpg",
|
46
|
-
"test/rhtml_template.rhtml",
|
47
|
-
"test/rxml_template.rxml",
|
48
|
-
"test/test_helper.rb",
|
49
|
-
"test/untidy.html",
|
50
|
-
"test/valid.html",
|
51
|
-
"test/valid_links.html",
|
52
|
-
"test/validate_all_test.rb"
|
39
|
+
"script/rails",
|
40
|
+
"script/validate"
|
53
41
|
]
|
54
|
-
s.homepage =
|
42
|
+
s.homepage = "http://github.com/jakewendt/html_test"
|
55
43
|
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version =
|
57
|
-
s.summary =
|
58
|
-
|
59
|
-
if s.respond_to? :specification_version then
|
60
|
-
s.specification_version = 3
|
61
|
-
|
62
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
-
else
|
64
|
-
end
|
65
|
-
else
|
66
|
-
end
|
44
|
+
s.rubygems_version = "2.0.14"
|
45
|
+
s.summary = "Ruby on Rails plugin for HTML validation and link checking"
|
67
46
|
end
|
68
47
|
|
data/lib/assertions.rb
CHANGED
@@ -28,7 +28,9 @@ module Html
|
|
28
28
|
assert_message = "Validator #{t} failed"
|
29
29
|
assert_message << " for url #{url}" if url
|
30
30
|
assert_message << " with message '#{error}'"
|
31
|
-
|
31
|
+
|
32
|
+
# Why would I want to print this in the log file???
|
33
|
+
# Rails.logger.error(assert_message + " for response body:\n #{with_line_counts(body)}")
|
32
34
|
assert(error.nil?, assert_message)
|
33
35
|
end
|
34
36
|
end
|
@@ -42,7 +44,9 @@ module Html
|
|
42
44
|
def with_line_counts(body)
|
43
45
|
separator = ("-" * 40) + $/
|
44
46
|
body_counts = separator.dup
|
45
|
-
|
47
|
+
# string no longer responds to each_with_index in ruby 1.9.3
|
48
|
+
# body.each_with_index do |line, i|
|
49
|
+
body.split(/\n/).each_with_index do |line, i|
|
46
50
|
body_counts << sprintf("%4u %s", i+1, line) # Right align line numbers
|
47
51
|
end
|
48
52
|
body_counts << separator
|
data/lib/html_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
if !defined?(RAILS_ENV) || RAILS_ENV == 'test'
|
1
|
+
#if !defined?(RAILS_ENV) || RAILS_ENV == 'test'
|
2
|
+
if !defined?(RAILS_ENV) || RAILS_ENV == 'test' || Rails.env == 'test'
|
2
3
|
|
3
4
|
%w(validator assertions url_selector url_checker link_validator validate_filter).each do |file|
|
4
5
|
require File.join(File.dirname(__FILE__), file)
|
@@ -74,11 +75,15 @@ validators.each do |validator|
|
|
74
75
|
end
|
75
76
|
|
76
77
|
if validate
|
77
|
-
ApplicationController
|
78
|
+
# In Rails 3, ApplicationController not defined yet
|
79
|
+
# ApplicationController.validate_all = true
|
80
|
+
ActionController::Base.validate_all = true
|
78
81
|
# default is :tidy, but it doesn't really validate.
|
79
82
|
# I've purposely not closed tags and it doesn't complain.
|
80
83
|
# :w3c is ridiculously slow! even when used locally
|
81
|
-
ApplicationController.validators = [:w3c]
|
84
|
+
# ApplicationController.validators = [:w3c]
|
85
|
+
# In Rails 3, ApplicationController not defined yet
|
86
|
+
ActionController::Base.validators = [:w3c]
|
82
87
|
#ApplicationController.validators = [:tidy, :w3c]
|
83
88
|
Html::Test::Validator.verbose = false
|
84
89
|
Html::Test::Validator.revalidate_all = true
|
@@ -90,7 +95,4 @@ else
|
|
90
95
|
puts "NOT validating html at all"
|
91
96
|
end
|
92
97
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
98
|
end #if !defined?(RAILS_ENV) || RAILS_ENV == 'test'
|
data/lib/url_checker.rb
CHANGED
@@ -1,142 +1,147 @@
|
|
1
1
|
module Html
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
2
|
+
module Test
|
3
|
+
class InvalidUrl < RuntimeError; end
|
4
|
+
|
5
|
+
class UrlChecker
|
6
|
+
attr_accessor :request, :response, :params
|
7
|
+
|
8
|
+
include Html::Test::UrlSelector
|
9
|
+
|
10
|
+
def initialize(controller)
|
11
|
+
self.request = controller.request
|
12
|
+
self.response = controller.response
|
13
|
+
self.params = controller.params
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_urls_resolve
|
17
|
+
urls_to_check.each do |url|
|
18
|
+
check_url_resolves(url)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def check_redirects_resolve
|
23
|
+
redirect_url = response.headers['Location']
|
24
|
+
if response.status =~ /302/ && redirect_url.present?
|
25
|
+
check_url_resolves(redirect_url)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def urls_to_check
|
31
|
+
anchor_urls + image_urls + form_urls
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_url_resolves(url)
|
35
|
+
return if skip_url?(url, root_url) || external_http?(url, root_url)
|
36
|
+
url = strip_anchor(remove_query(make_absolute(url)))
|
37
|
+
return if public_file_exists?(url)
|
38
|
+
check_action_exists(url)
|
39
|
+
end
|
40
|
+
|
41
|
+
def root_url
|
42
|
+
request.protocol + request.host_with_port
|
43
|
+
end
|
44
|
+
|
45
|
+
def public_file_exists?(url)
|
46
|
+
public_path = File.join(rails_public_path, url)
|
47
|
+
File.exists?(public_path) || File.exists?(public_path + ".html")
|
48
|
+
end
|
49
|
+
|
50
|
+
def rails_public_path
|
51
|
+
File.join(Rails.root, "public")
|
52
|
+
end
|
53
|
+
|
54
|
+
# Make URLs absolute paths, i.e. relative to the site root
|
55
|
+
def make_absolute(url)
|
56
|
+
url = remove_host(url) if has_protocol?(url)
|
57
|
+
return url if url =~ %r{^/}
|
58
|
+
current_url = request.url || url_from_params
|
59
|
+
current_url = File.dirname(current_url) if current_url !~ %r{/$}
|
60
|
+
url = File.join(current_url, url)
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove_host(url)
|
64
|
+
url_no_host = url[%r{^[a-z]+://[^/]+(/.+)$}, 1]
|
65
|
+
url_no_host.blank? ? "/" : url_no_host
|
66
|
+
end
|
67
|
+
|
68
|
+
def remove_query(url)
|
69
|
+
url =~ /\?/ ? url[/^(.+?)\?/, 1] : url
|
70
|
+
end
|
71
|
+
|
72
|
+
def strip_anchor(url)
|
73
|
+
url =~ /\#/ ? url[/^(.+?)\#/, 1] : url
|
74
|
+
end
|
75
|
+
|
76
|
+
# Each URL is required to have at least one HTTP method for which there is a route with an action
|
77
|
+
def check_action_exists(url)
|
78
|
+
unless routes_from_url(url).any? { |route| route_has_action?(route) }
|
79
|
+
raise_invalid_url(url, "No action or template")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def route_has_action?(route)
|
84
|
+
controller = "#{route[:controller].camelize}Controller".constantize
|
85
|
+
controller.public_instance_methods.include?(route[:action]) || template_file_exists?(route, controller)
|
86
|
+
end
|
87
|
+
|
88
|
+
def template_file_exists?(route, controller)
|
89
|
+
# Workaround for Rails 1.2 that doesn't have the view_paths method
|
90
|
+
template_dirs = controller.respond_to?(:view_paths) ?
|
91
|
+
controller.view_paths : [controller.view_root]
|
92
|
+
template_dirs.each do |template_dir|
|
93
|
+
template_file = File.join(template_dir, controller.controller_path, "#{route[:action]}.*")
|
94
|
+
return true if !Dir.glob(template_file).empty?
|
95
|
+
end
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
99
|
+
# This is a special case where on my site I had a catch all route for 404s. If you have
|
100
|
+
# such a route, you can override this method and check for it, i.e. you could do something
|
101
|
+
# like this:
|
102
|
+
#
|
103
|
+
# if params[:action] == "rescue_404"
|
104
|
+
# raise Html::Test::InvalidUrl.new("Action rescue_404 invoked for url '#{url}'")
|
105
|
+
# end
|
106
|
+
def check_not_404(url, params)
|
107
|
+
# This method is unimplemented by default
|
108
|
+
end
|
109
|
+
|
110
|
+
def routes_from_url(url)
|
111
|
+
routes = [:get, :post, :put, :delete].map do |method|
|
112
|
+
begin
|
113
|
+
# Need to specify the method here for RESTful resource routes to work, i.e.
|
114
|
+
# for /posts/1 to be recognized as the show action etc.
|
115
|
+
|
116
|
+
|
117
|
+
# ActionController::Routing::Routes does not exist in Rails 3!
|
118
|
+
# fortunately, I don't use "check_urls" so not an issue right now.
|
119
|
+
|
120
|
+
params = ::ActionController::Routing::Routes.recognize_path(url, {:method => method})
|
121
|
+
check_not_404(url, params)
|
122
|
+
params
|
123
|
+
rescue
|
124
|
+
# Could not find a route with that method
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
end.compact
|
128
|
+
routes.present? ? routes : raise_invalid_url(url, "Cannot find a route")
|
129
|
+
end
|
130
|
+
|
131
|
+
def url_from_params(options = params)
|
132
|
+
return "/" if params.empty?
|
133
|
+
options[:controller] ||= params[:controller]
|
134
|
+
::ActionController::Routing::Routes.generate_extras(symbolize_hash(options))[0]
|
135
|
+
end
|
136
|
+
|
137
|
+
# Convert all keys in the hash to symbols. Not sure why this is needed.
|
138
|
+
def symbolize_hash(hash)
|
139
|
+
hash.keys.inject({}) { |h, k| h[k.to_sym] = hash[k]; h }
|
140
|
+
end
|
141
|
+
|
142
|
+
def raise_invalid_url(url, message)
|
143
|
+
raise(Html::Test::InvalidUrl.new("#{message} for url '#{url}' request_uri='#{request.url}' body='#{response.body}'"))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/validate_filter.rb
CHANGED
@@ -14,7 +14,9 @@ module Html
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def validate_page
|
17
|
-
url = request.request_uri
|
17
|
+
# url = request.request_uri
|
18
|
+
# no more request_uri in Rails 3
|
19
|
+
url = request.url
|
18
20
|
return if (!should_validate? || ValidateFilter.already_validated?(url))
|
19
21
|
# assert_validates(validators, response.body.strip, url, :verbose => true)
|
20
22
|
assert_validates(validators, response.body.strip, url )
|
@@ -39,8 +41,13 @@ module Html
|
|
39
41
|
|
40
42
|
# Override this method if you only want to validate a subset of pages
|
41
43
|
def should_validate?
|
42
|
-
response.status =~ /200/ &&
|
43
|
-
|
44
|
+
# response.status =~ /200/ &&
|
45
|
+
# (response.headers['Content-Type'] =~ /text\/html/i || response.body =~ /<html/)
|
46
|
+
# In rails 3,
|
47
|
+
# response.status is a Fixnum which would return nil in this match
|
48
|
+
# and response.headers['Content-Type'] is blank
|
49
|
+
response.status.to_s =~ /200/ &&
|
50
|
+
(response.content_type =~ /text\/html/i || response.body =~ /<html/)
|
44
51
|
end
|
45
52
|
|
46
53
|
# Used in testing (of html_test_extension plugin)
|
data/lib/validator.rb
CHANGED
@@ -57,7 +57,13 @@ module Html
|
|
57
57
|
# Reference in the stylesheets
|
58
58
|
response.body.sub!(%r{@import "./base.css"}, %Q{@import "#{File.dirname(w3c_url)}/base.css"})
|
59
59
|
response_file = find_unique_path(File.join(tmp_dir, "w3c_response.html"))
|
60
|
-
|
60
|
+
|
61
|
+
# open(response_file, "w" ) { |f| f.puts(response.body) }
|
62
|
+
# I was getting many errors like ... (in ruby 1.9.3 and rails 3)
|
63
|
+
# Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8
|
64
|
+
# adding force_encoding('UTF-8') seems to fix this.
|
65
|
+
open(response_file, "w" ) { |f| f.puts(response.body.force_encoding('UTF-8')) }
|
66
|
+
|
61
67
|
"W3C status #{status}. Response from W3C was written to the file #{response_file}"
|
62
68
|
else
|
63
69
|
nil
|
data/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
metadata
CHANGED
@@ -1,34 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jakewendt-html_test
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.5
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Peter Marklund
|
14
8
|
- George 'Jake' Wendt
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2011-08-10 00:00:00 -07:00
|
20
|
-
default_executable:
|
12
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
21
13
|
dependencies: []
|
22
|
-
|
23
14
|
description: Ruby on Rails plugin for HTML validation and link checking
|
24
|
-
email: github@
|
15
|
+
email: github@jakewendt.com
|
25
16
|
executables: []
|
26
|
-
|
27
17
|
extensions: []
|
28
|
-
|
29
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
30
19
|
- README.rdoc
|
31
|
-
files:
|
20
|
+
files:
|
32
21
|
- README.rdoc
|
33
22
|
- Rakefile
|
34
23
|
- VERSION
|
@@ -49,53 +38,29 @@ files:
|
|
49
38
|
- lib/url_selector.rb
|
50
39
|
- lib/validate_filter.rb
|
51
40
|
- lib/validator.rb
|
52
|
-
- rails
|
41
|
+
- script/rails
|
53
42
|
- script/validate
|
54
|
-
- test/controller_test.rb
|
55
|
-
- test/integration_test.rb
|
56
|
-
- test/invalid.html
|
57
|
-
- test/link_validator_test.rb
|
58
|
-
- test/public/image.jpg
|
59
|
-
- test/rhtml_template.rhtml
|
60
|
-
- test/rxml_template.rxml
|
61
|
-
- test/test_helper.rb
|
62
|
-
- test/untidy.html
|
63
|
-
- test/valid.html
|
64
|
-
- test/valid_links.html
|
65
|
-
- test/validate_all_test.rb
|
66
|
-
has_rdoc: true
|
67
43
|
homepage: http://github.com/jakewendt/html_test
|
68
44
|
licenses: []
|
69
|
-
|
45
|
+
metadata: {}
|
70
46
|
post_install_message:
|
71
47
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
48
|
+
require_paths:
|
74
49
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
none: false
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
93
60
|
requirements: []
|
94
|
-
|
95
61
|
rubyforge_project:
|
96
|
-
rubygems_version:
|
62
|
+
rubygems_version: 2.0.14
|
97
63
|
signing_key:
|
98
|
-
specification_version:
|
64
|
+
specification_version: 4
|
99
65
|
summary: Ruby on Rails plugin for HTML validation and link checking
|
100
66
|
test_files: []
|
101
|
-
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'jakewendt-html_test' if RAILS_ENV == 'test'
|
data/test/controller_test.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "..", "test", "test_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
3
|
-
|
4
|
-
ActionController::Routing::Routes.draw do |map|
|
5
|
-
map.connect 'test/:action', :controller => 'test'
|
6
|
-
end
|
7
|
-
|
8
|
-
class Html::Test::ControllerTest < ActionController::TestCase
|
9
|
-
def setup
|
10
|
-
@controller = TestController.new
|
11
|
-
@request = ActionController::TestRequest.new
|
12
|
-
@response = ActionController::TestResponse.new
|
13
|
-
|
14
|
-
ActionController::Base.validate_all = false
|
15
|
-
ActionController::Base.check_urls = true
|
16
|
-
ActionController::Base.check_redirects = true
|
17
|
-
Html::Test::Validator.tidy_ignore_list = []
|
18
|
-
Html::Test::UrlChecker.any_instance.stubs(:rails_public_path).returns(File.join(File.dirname(__FILE__), "public"))
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_assert_validates_success
|
22
|
-
get :valid
|
23
|
-
assert_response :success
|
24
|
-
assert_validates # Should validate tidy, w3c, and xmllint
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_assert_tidy_failure
|
28
|
-
get :untidy
|
29
|
-
assert_response :success
|
30
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
31
|
-
assert_tidy
|
32
|
-
end
|
33
|
-
assert_w3c
|
34
|
-
assert_xmllint
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_assert_w3c_failure
|
38
|
-
get :invalid
|
39
|
-
assert_response :success
|
40
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
41
|
-
assert_w3c
|
42
|
-
end
|
43
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
44
|
-
assert_xmllint
|
45
|
-
end
|
46
|
-
assert_tidy
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_url_no_route
|
50
|
-
assert_raise(Html::Test::InvalidUrl) do
|
51
|
-
get :url_no_route
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_url_no_action
|
56
|
-
assert_raise(Html::Test::InvalidUrl) do
|
57
|
-
get :url_no_action
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# TODO: figure out why those tests don't work
|
62
|
-
# def test_url_rhtml_template_exists
|
63
|
-
# get :rhtml_template
|
64
|
-
# end
|
65
|
-
|
66
|
-
# def test_url_rxml_template_exists
|
67
|
-
# get :rxml_template
|
68
|
-
# end
|
69
|
-
|
70
|
-
def test_url_action_no_template
|
71
|
-
get :action_no_template
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_redirect_no_action
|
75
|
-
assert_raise(Html::Test::InvalidUrl) do
|
76
|
-
get :redirect_no_action
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_redirect_valid_action
|
81
|
-
get :redirect_valid_action
|
82
|
-
assert_response :redirect
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_redirect_external
|
86
|
-
get :redirect_external
|
87
|
-
assert_response :redirect
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_redirect_valid_with_host
|
91
|
-
get :redirect_valid_with_host
|
92
|
-
assert_response :redirect
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_image_file_exists
|
96
|
-
get :image_file_exists
|
97
|
-
assert_response :success
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_image_does_not_exist
|
101
|
-
assert_raise(Html::Test::InvalidUrl) do
|
102
|
-
get :image_file_does_not_exist
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_urls_to_resolve
|
107
|
-
checker = Html::Test::UrlChecker.new(@controller)
|
108
|
-
checker.stubs(:response_body).returns(<<-HTML
|
109
|
-
<a href="anchor_url">hej</a>
|
110
|
-
Some text and <div>markup</div>
|
111
|
-
<img src="image_url"/>
|
112
|
-
Some more text
|
113
|
-
<form action="form_url">
|
114
|
-
Some text
|
115
|
-
</form>
|
116
|
-
HTML
|
117
|
-
)
|
118
|
-
assert_equal(%w(anchor_url form_url image_url), checker.send(:urls_to_check).sort)
|
119
|
-
end
|
120
|
-
end
|
data/test/integration_test.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "..", "test", "test_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
3
|
-
|
4
|
-
ActionController::Routing::Routes.draw do |map|
|
5
|
-
map.connect 'test/:action', :controller => 'test'
|
6
|
-
end
|
7
|
-
ApplicationController.validate_all = false
|
8
|
-
ApplicationController.check_urls = true
|
9
|
-
ApplicationController.check_redirects = true
|
10
|
-
|
11
|
-
class Html::Test::IntegrationTest < ActionController::IntegrationTest
|
12
|
-
def test_assert_valides_invokes_all
|
13
|
-
get('/test/valid')
|
14
|
-
assert_response :success
|
15
|
-
|
16
|
-
[:tidy_errors, :w3c_errors, :xmllint_errors].each do |method|
|
17
|
-
Html::Test::Validator.expects(method).with(@response.body)
|
18
|
-
end
|
19
|
-
assert_validates
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_assert_tidy_invoked
|
23
|
-
get('/test/valid')
|
24
|
-
assert_response :success
|
25
|
-
Html::Test::Validator.expects(:tidy_errors).with(@response.body)
|
26
|
-
assert_tidy
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_assert_valid_success
|
30
|
-
get('/test/valid')
|
31
|
-
assert_response :success
|
32
|
-
assert_validates
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_assert_tidy_failure
|
36
|
-
file_string = TestController.test_file_string(:untidy)
|
37
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
38
|
-
assert_tidy(file_string)
|
39
|
-
end
|
40
|
-
assert_w3c(file_string)
|
41
|
-
assert_xmllint(file_string)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_assert_w3c_failure
|
45
|
-
file_string = TestController.test_file_string(:invalid)
|
46
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
47
|
-
assert_w3c(file_string)
|
48
|
-
end
|
49
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
50
|
-
assert_xmllint(file_string)
|
51
|
-
end
|
52
|
-
assert_raise(Test::Unit::AssertionFailedError) do
|
53
|
-
Html::Test::Validator.expects(:dtd).returns("doctype")
|
54
|
-
assert_xmllint(file_string)
|
55
|
-
end
|
56
|
-
assert_tidy(file_string)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_url_no_route
|
60
|
-
TestController.any_instance.expects(:rescue_action).with() { |e| e.class == Html::Test::InvalidUrl }
|
61
|
-
get '/test/url_no_route'
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_url_no_route_relative
|
65
|
-
TestController.any_instance.expects(:rescue_action).with() { |e| e.class == Html::Test::InvalidUrl }
|
66
|
-
get '/test/url_no_route_relative'
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_redirect_valid_action
|
70
|
-
get '/test/redirect_valid_action'
|
71
|
-
assert_response :redirect
|
72
|
-
end
|
73
|
-
end
|
data/test/invalid.html
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
6
|
-
<title>A perfectly invalid document</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<h1>This is a perfectly invalid XHTML 1 document</h1>
|
10
|
-
|
11
|
-
Here are some unquoted chars: <>
|
12
|
-
|
13
|
-
Tidy may not complain about this document, but that's just crazy.
|
14
|
-
</body>
|
15
|
-
</html>
|
data/test/link_validator_test.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "..", "test", "test_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
# Stub out the HTTP requests
|
6
|
-
module Net
|
7
|
-
class HTTP
|
8
|
-
@@test_requests = []
|
9
|
-
cattr_accessor :test_requests
|
10
|
-
|
11
|
-
@@test_with_links = false
|
12
|
-
cattr_accessor :test_with_links
|
13
|
-
|
14
|
-
def self.get_response(uri)
|
15
|
-
self.test_requests << uri.to_s
|
16
|
-
|
17
|
-
if uri.path =~ /valid_links/ or test_with_links
|
18
|
-
file = :valid_links
|
19
|
-
else
|
20
|
-
file = :valid
|
21
|
-
end
|
22
|
-
test_with_links = false
|
23
|
-
return OpenStruct.new({
|
24
|
-
:body => TestController.test_file_string(file),
|
25
|
-
:code => "200",
|
26
|
-
:header => {'content-type' => 'text/html'}
|
27
|
-
})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Html::Test::LinkValidatorTest < Test::Unit::TestCase
|
33
|
-
def setup
|
34
|
-
Net::HTTP.test_requests = []
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_parse_command_line
|
38
|
-
# Missing URL
|
39
|
-
assert_raise(RuntimeError) { Html::Test::LinkValidator.parse_command_line(["--no-follow"]) }
|
40
|
-
|
41
|
-
# Missing skip patterns
|
42
|
-
options_no_skip = ["http://my.url.com", "--no-follow", "--validators", "w3c,tidy,xmllint",
|
43
|
-
"--no-external", "--dtd", "some.dtd", "--only", "some/url", "--skip"]
|
44
|
-
assert_raise(OptionParser::MissingArgument) do
|
45
|
-
Html::Test::LinkValidator.parse_command_line(options_no_skip.dup)
|
46
|
-
end
|
47
|
-
|
48
|
-
# All options - valid
|
49
|
-
assert_equal({
|
50
|
-
:follow_links => false,
|
51
|
-
:validators => ["w3c", "tidy", "xmllint"],
|
52
|
-
:follow_external => false,
|
53
|
-
:dtd => "some.dtd",
|
54
|
-
:only_pattern => Regexp.new("some/url"),
|
55
|
-
:skip_patterns => [/pattern1/, /pattern2/]
|
56
|
-
}, Html::Test::LinkValidator.parse_command_line(options_no_skip << "pattern1,pattern2"))
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_default_options
|
60
|
-
url = "http://localhost:3000"
|
61
|
-
validator = Html::Test::LinkValidator.new(url)
|
62
|
-
|
63
|
-
assert_equal url, Net::HTTP.test_requests.first
|
64
|
-
assert_equal 1, Net::HTTP.test_requests.size
|
65
|
-
|
66
|
-
assert validator.options[:follow_links]
|
67
|
-
assert_equal ['tidy'], validator.options[:validators]
|
68
|
-
assert_equal [], validator.options[:skip_patterns]
|
69
|
-
assert_nil validator.options[:only_pattern]
|
70
|
-
assert validator.options[:follow_external]
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_quiet
|
74
|
-
validator = Html::Test::LinkValidator.new("http://my.cool.site", {:quiet => true})
|
75
|
-
# Even in quiet mode the log should be populated
|
76
|
-
assert_match /my\.cool\.site/, validator.log
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_link_follow_page
|
80
|
-
validator = Html::Test::LinkValidator.new("http://site.com/dir/valid_links")
|
81
|
-
# All links visited
|
82
|
-
assert_equal(["http://site.com/dir/valid_links",
|
83
|
-
"http://site.com/link1",
|
84
|
-
"http://site.com/dir/link2",
|
85
|
-
"http://site.com/dir/foobar/link3",
|
86
|
-
"http://foobar.com/external"].sort,
|
87
|
-
Net::HTTP.test_requests.sort)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_link_follow_root
|
91
|
-
%w(http://site.com http://site.com/).each do |url|
|
92
|
-
Net::HTTP.test_requests = []
|
93
|
-
Net::HTTP.test_with_links = true
|
94
|
-
validator = Html::Test::LinkValidator.new(url)
|
95
|
-
# All links visited
|
96
|
-
assert_equal([url,
|
97
|
-
"http://site.com/link1",
|
98
|
-
"http://site.com/link2",
|
99
|
-
"http://site.com/foobar/link3",
|
100
|
-
"http://foobar.com/external"].sort,
|
101
|
-
Net::HTTP.test_requests.sort)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_link_follow_dir
|
106
|
-
Net::HTTP.test_with_links = true
|
107
|
-
validator = Html::Test::LinkValidator.new("http://site.com/dir/")
|
108
|
-
# All links visited
|
109
|
-
assert_equal(["http://site.com/dir/",
|
110
|
-
"http://site.com/link1",
|
111
|
-
"http://site.com/dir/link2",
|
112
|
-
"http://site.com/dir/foobar/link3",
|
113
|
-
"http://foobar.com/external"].sort,
|
114
|
-
Net::HTTP.test_requests.sort)
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_skip_patterns
|
118
|
-
url = "http://my.cool.site/valid_links"
|
119
|
-
validator = Html::Test::LinkValidator.new(url,
|
120
|
-
{:skip_patterns => [/link[12]/, /http/]})
|
121
|
-
assert_equal [url, "http://my.cool.site/foobar/link3"].sort,
|
122
|
-
Net::HTTP.test_requests.sort
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_only_pattern
|
126
|
-
url = "http://my.cool.site/dir/valid_links"
|
127
|
-
validator = Html::Test::LinkValidator.new(url, {:only_pattern => /link[12]/})
|
128
|
-
assert_equal [url, "http://my.cool.site/link1", "http://my.cool.site/dir/link2"].sort,
|
129
|
-
Net::HTTP.test_requests.sort
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_follow_external_false
|
133
|
-
Net::HTTP.test_with_links = true
|
134
|
-
validator = Html::Test::LinkValidator.new("http://site.com/dir/", {:follow_external => false})
|
135
|
-
assert_equal(["http://site.com/dir/",
|
136
|
-
"http://site.com/link1",
|
137
|
-
"http://site.com/dir/link2",
|
138
|
-
"http://site.com/dir/foobar/link3"].sort,
|
139
|
-
Net::HTTP.test_requests.sort)
|
140
|
-
end
|
141
|
-
end
|
data/test/public/image.jpg
DELETED
File without changes
|
data/test/rhtml_template.rhtml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Some contents
|
data/test/rxml_template.rxml
DELETED
data/test/test_helper.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
class TestController < ActionController::Base
|
2
|
-
prepend_view_path(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
layout nil
|
5
|
-
def valid; render :file => TestController.test_file(:valid) end
|
6
|
-
def untidy; render :file => TestController.test_file(:untidy) end
|
7
|
-
def invalid; render :file => TestController.test_file(:invalid) end
|
8
|
-
|
9
|
-
def url_no_route
|
10
|
-
render :text => %Q{<a href="/norouteforthisurl">No route</a>}
|
11
|
-
end
|
12
|
-
|
13
|
-
def url_no_route_relative
|
14
|
-
render :text => %Q{<a href="norouteforthisurl">No route</a>}
|
15
|
-
end
|
16
|
-
|
17
|
-
def url_no_action
|
18
|
-
render :text => %Q{<a href="/test/thisactiondoesnotexist">no action</a>}
|
19
|
-
end
|
20
|
-
|
21
|
-
def action_no_template
|
22
|
-
render :text => %Q{<a href="/test/valid">valid</a>}
|
23
|
-
end
|
24
|
-
|
25
|
-
def redirect_no_action
|
26
|
-
redirect_to :action => 'thisactiondoesnotexist'
|
27
|
-
end
|
28
|
-
|
29
|
-
def redirect_valid_action
|
30
|
-
redirect_to :action => 'valid'
|
31
|
-
end
|
32
|
-
|
33
|
-
def redirect_external
|
34
|
-
redirect_to "http://google.com/foobar"
|
35
|
-
end
|
36
|
-
|
37
|
-
def redirect_valid_with_host
|
38
|
-
redirect_to "http://test.host/test/valid"
|
39
|
-
end
|
40
|
-
|
41
|
-
def image_file_exists
|
42
|
-
render :text => %Q{<img src="/image.jpg?23049829034"/>}
|
43
|
-
end
|
44
|
-
|
45
|
-
def image_file_does_not_exist
|
46
|
-
render :text => %Q{<img src="/image2.jpg?23049829034"/>}
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.test_file(action)
|
50
|
-
File.join(File.dirname(__FILE__), "#{action}.html")
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.test_file_string(action)
|
54
|
-
IO.read(test_file(action))
|
55
|
-
end
|
56
|
-
|
57
|
-
# Re-raise errors caught by the controller.
|
58
|
-
def rescue_action(e)
|
59
|
-
raise e
|
60
|
-
end
|
61
|
-
end
|
data/test/untidy.html
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
6
|
-
<title>A perfectly valid untidy document</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<h1>This is a perfectly valid but untidy XHTML 1 document</h1>
|
10
|
-
|
11
|
-
<table>
|
12
|
-
<tr>
|
13
|
-
<td>
|
14
|
-
A table with no summary attribute. Tidy will kill us for this.
|
15
|
-
</td>
|
16
|
-
</tr>
|
17
|
-
</table>
|
18
|
-
</body>
|
19
|
-
</html>
|
data/test/valid.html
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
6
|
-
<title>A perfectly valid document</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<h1>This is a perfectly valid XHTML 1 document</h1>
|
10
|
-
<p>
|
11
|
-
Here is some text.
|
12
|
-
</p>
|
13
|
-
</body>
|
14
|
-
</html>
|
data/test/valid_links.html
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
6
|
-
<title>A perfectly valid document</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<h1>This is a perfectly valid XHTML 1 document</h1>
|
10
|
-
<p>
|
11
|
-
Here is some text.
|
12
|
-
</p>
|
13
|
-
<ul>
|
14
|
-
<li><a href="/link1">Link 1</a></li>
|
15
|
-
<li><a href="link2">Link 2</a></li>
|
16
|
-
<li><a href="link2">Link 2</a></li>
|
17
|
-
<li><a href="link2#comments">Link 2</a></li>
|
18
|
-
<li><a href="foobar/link3">Link 3</a></li>
|
19
|
-
<li><a href="http://foobar.com/external">External Link</a></li>
|
20
|
-
</ul>
|
21
|
-
</body>
|
22
|
-
</html>
|
data/test/validate_all_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "..", "test", "test_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
3
|
-
|
4
|
-
class Html::Test::ValidateAllTest < ActionController::TestCase
|
5
|
-
def setup
|
6
|
-
@controller = TestController.new
|
7
|
-
@request = ActionController::TestRequest.new
|
8
|
-
@response = ActionController::TestResponse.new
|
9
|
-
ApplicationController.validate_all = true
|
10
|
-
ApplicationController.validators = [:tidy]
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_validate_all
|
14
|
-
assert_raise(Test::Unit::AssertionFailedError) { get :untidy }
|
15
|
-
end
|
16
|
-
end
|