w3c_validators 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +14 -2
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/{README.rdoc → README.md} +41 -29
- data/Rakefile +64 -0
- data/lib/w3c_validators.rb +2 -1
- data/lib/w3c_validators/css_validator.rb +23 -16
- data/lib/w3c_validators/feed_validator.rb +4 -4
- data/lib/w3c_validators/markup_validator.rb +29 -29
- data/lib/w3c_validators/message.rb +6 -2
- data/lib/w3c_validators/nu_validator.rb +2 -2
- data/lib/w3c_validators/validator.rb +48 -43
- data/lib/w3c_validators/version.rb +3 -0
- data/test/fixtures/bootstrap.min.css +6 -0
- data/test/fixtures/invalid_css.css +2 -0
- data/test/fixtures/invalid_encoding.html +10 -0
- data/test/fixtures/invalid_feed.xml +19 -0
- data/test/fixtures/invalid_html5.html +16 -0
- data/test/fixtures/invalid_markup.html +11 -0
- data/test/fixtures/valid_css.css +2 -0
- data/test/fixtures/valid_feed.xml +20 -0
- data/test/fixtures/valid_html5.html +16 -0
- data/test/fixtures/valid_markup.html +11 -0
- data/test/http_recording/css_context.yml +72 -0
- data/test/http_recording/css_overriding_css_profile.yml +66 -0
- data/test/http_recording/css_skippedstring.yml +72 -0
- data/test/http_recording/css_validating_big_file.yml +1423 -0
- data/test/http_recording/css_validating_file.yml +72 -0
- data/test/http_recording/css_validating_text.yml +66 -0
- data/test/http_recording/css_validating_text_via_file.yml +72 -0
- data/test/http_recording/css_validating_uri.yml +65 -0
- data/test/http_recording/css_vendor_extensions_as_errors.yml +65 -0
- data/test/http_recording/css_vendor_extensions_as_warnings.yml +62 -0
- data/test/http_recording/css_vendor_extensions_default.yml +62 -0
- data/test/http_recording/feed_validating_file.yml +49 -0
- data/test/http_recording/feed_validating_text.yml +46 -0
- data/test/http_recording/feed_validating_text_via_file.yml +49 -0
- data/test/http_recording/feed_validating_uri_with_soap.yml +50 -0
- data/test/http_recording/html5_getting_request_data.yml +51 -0
- data/test/http_recording/html5_validating_uri.yml +74 -0
- data/test/http_recording/markup_debugging_uri.yml +83 -0
- data/test/http_recording/markup_overriding_charset.yml +125 -0
- data/test/http_recording/markup_overriding_charset_for_fallback_only.yml +76 -0
- data/test/http_recording/markup_overriding_doctype.yml +208 -0
- data/test/http_recording/markup_overriding_doctype_for_fallback_only.yml +84 -0
- data/test/http_recording/markup_validating_file.yml +93 -0
- data/test/http_recording/markup_validating_text.yml +67 -0
- data/test/http_recording/markup_validating_text_via_file.yml +93 -0
- data/test/http_recording/markup_validating_uri_with_head_request.yml +38 -0
- data/test/http_recording/markup_validating_uri_with_soap.yml +76 -0
- data/test/http_recording/markup_validator_abort.yml +50 -0
- data/test/http_recording/markup_validator_contains_details_of_error_conditions.yml +76 -0
- data/test/test_css_validator.rb +78 -17
- data/test/test_exceptions.rb +11 -8
- data/test/test_feed_validator.rb +42 -39
- data/test/test_helper.rb +7 -2
- data/test/test_html5_validator.rb +42 -34
- data/test/test_markup_validator.rb +75 -52
- data/test/test_proxy.rb +5 -2
- data/w3c_validators.gemspec +24 -0
- metadata +154 -68
data/test/test_exceptions.rb
CHANGED
@@ -14,22 +14,25 @@ class ExceptionTests < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_bad_validator_uri
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
VCR.turned_off do
|
18
|
+
WebMock.allow_net_connect!
|
19
|
+
['http://noexist/', 'http://noexist.badtld/',
|
20
|
+
'http://example.com/noexist'].each do |uri|
|
21
|
+
v = MarkupValidator.new(:validator_uri => uri)
|
22
|
+
assert_raise ValidatorUnavailable do
|
23
|
+
v.validate_text(@valid_fragment)
|
24
|
+
end
|
23
25
|
end
|
26
|
+
WebMock.disable_net_connect!
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
def test_bad_soap_response
|
28
|
-
|
31
|
+
omit("Pending, broken")
|
29
32
|
[].each do |uri|
|
30
33
|
v = MarkupValidator.new(:validator_uri => uri)
|
31
34
|
assert_raise ParsingError do
|
32
|
-
|
35
|
+
v.validate_text(@valid_fragment)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/test/test_feed_validator.rb
CHANGED
@@ -9,57 +9,60 @@ class FeedValidatorTests < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_validating_uri_with_soap
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
VCR.use_cassette('feed_validating_uri_with_soap') do
|
13
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_feed.xml')
|
14
|
+
assert_errors r, 1
|
15
|
+
assert_warnings r, 1
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_validating_file
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
VCR.use_cassette('feed_validating_file') do
|
21
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
|
22
|
+
r = @v.validate_file(file_path)
|
23
|
+
assert_errors r, 1
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def test_validating_text
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
<updated>2003-12-13T18:30:02Z</updated>
|
35
|
-
<author>
|
36
|
-
<email>johndoe@example.com</email>
|
37
|
-
</author>
|
38
|
-
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
|
39
|
-
<entry>
|
40
|
-
<title>Atom-Powered Robots Run Amok</title>
|
41
|
-
<link href="http://example.org/2003/12/13/atom03"/>
|
42
|
-
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
28
|
+
VCR.use_cassette('feed_validating_text') do
|
29
|
+
fragment = <<-EOT
|
30
|
+
<?xml version="1.0" encoding="utf-8"?>
|
31
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
32
|
+
<title>Example Feed</title>
|
33
|
+
<subtitle>A subtitle.</subtitle>
|
34
|
+
<link href="http://example.org/feed/" rel="self"/>
|
35
|
+
<link href="http://example.org/"/>
|
43
36
|
<updated>2003-12-13T18:30:02Z</updated>
|
44
|
-
<
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
<author>
|
38
|
+
<email>johndoe@example.com</email>
|
39
|
+
</author>
|
40
|
+
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
|
41
|
+
<entry>
|
42
|
+
<title>Atom-Powered Robots Run Amok</title>
|
43
|
+
<link href="http://example.org/2003/12/13/atom03"/>
|
44
|
+
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
45
|
+
<updated>2003-12-13T18:30:02Z</updated>
|
46
|
+
<summary>Some text.</summary>
|
47
|
+
</entry>
|
48
|
+
</feed>
|
49
|
+
EOT
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
r = @v.validate_text(fragment)
|
52
|
+
assert_equal 1, r.errors.length
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
|
54
57
|
def test_validating_text_via_file
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
VCR.use_cassette('feed_validating_text_via_file') do
|
59
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/invalid_feed.xml')
|
60
|
+
fh = File.new(file_path, 'r+')
|
61
|
+
r = @v.validate_file(fh)
|
62
|
+
fh.close
|
63
|
+
assert_errors r, 1
|
64
|
+
end
|
61
65
|
end
|
62
66
|
|
63
|
-
|
64
|
-
|
65
67
|
end
|
68
|
+
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
require 'iconv'
|
3
2
|
require 'rubygems'
|
4
3
|
require 'test/unit'
|
5
4
|
require 'w3c_validators'
|
5
|
+
require 'vcr'
|
6
|
+
|
7
|
+
VCR.configure do |config|
|
8
|
+
config.cassette_library_dir = "test/http_recording"
|
9
|
+
config.hook_into :webmock # or :fakeweb
|
10
|
+
end
|
6
11
|
|
7
12
|
class Test::Unit::TestCase
|
8
13
|
|
@@ -36,4 +41,4 @@ class Test::Unit::TestCase
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
|
-
end
|
44
|
+
end
|
@@ -9,50 +9,58 @@ class HTML5ValidatorTests < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_getting_request_data
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
VCR.use_cassette('html5_getting_request_data') do
|
13
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/valid_html5.html')
|
14
|
+
assert_equal :html5, r.doctype
|
15
|
+
assert_equal 'https://doc75.github.io/w3c_validators_tests/valid_html5.html', r.uri
|
16
|
+
assert_no_errors r
|
17
|
+
assert_no_warnings r
|
18
|
+
assert r.is_valid?
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def test_validating_uri
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
VCR.use_cassette('html5_validating_uri') do
|
24
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_html5.html')
|
25
|
+
assert_errors r, 2
|
26
|
+
assert_no_warnings r
|
27
|
+
assert !r.is_valid?
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def test_validating_file
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
omit('Pending, broken')
|
33
|
+
VCR.use_cassette('html5_validating_file') do
|
34
|
+
file = File.dirname(__FILE__) + '/fixtures/invalid_html5.html'
|
35
|
+
r = @v.validate_file(file)
|
36
|
+
assert_errors r, 1
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
def test_validating_text
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
<
|
40
|
-
<
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
omit('Pending, broken')
|
42
|
+
VCR.use_cassette('html5_validating_text') do
|
43
|
+
valid_fragment = <<-EOV
|
44
|
+
<!DOCTYPE html>
|
45
|
+
<html lang="en-ca">
|
46
|
+
<head>
|
47
|
+
<title>HTML 5 Example</title>
|
48
|
+
</head>
|
49
|
+
<body>
|
50
|
+
<!-- should have one error (missing </section>) -->
|
51
|
+
<p>This is a sample HTML 5 document.</p>
|
52
|
+
<section>
|
53
|
+
<h1>Example of paragraphs</h1>
|
54
|
+
This is the <em>first</em> paragraph in this example.
|
55
|
+
<p>This is the second.</p>
|
56
|
+
<p>Test<br>test</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
59
|
+
EOV
|
53
60
|
|
54
|
-
|
55
|
-
|
61
|
+
r = @v.validate_text(valid_fragment)
|
62
|
+
assert_errors r, 1
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
#def test_validating_text_via_file
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
require 'ruby-debug'
|
3
2
|
|
4
3
|
# Test cases for the MarkupValidator.
|
5
4
|
class MarkupValidatorTests < Test::Unit::TestCase
|
@@ -10,91 +9,115 @@ class MarkupValidatorTests < Test::Unit::TestCase
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def test_overriding_doctype
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
VCR.use_cassette('markup_overriding_doctype') do
|
13
|
+
@v.set_doctype!(:html32, false)
|
14
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup.html')
|
15
|
+
assert_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_overriding_doctype_for_fallback_only
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
VCR.use_cassette('markup_overriding_doctype_for_fallback_only') do
|
21
|
+
@v.set_doctype!(:html32, true)
|
22
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_1.html')
|
23
|
+
assert_not_equal '-//W3C//DTD HTML 3.2 Final//EN', r.doctype
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
def test_overriding_charset
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
VCR.use_cassette('markup_overriding_charset') do
|
29
|
+
@v.set_charset!(:utf_16, false)
|
30
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_2.html')
|
31
|
+
assert_equal 'utf-16', r.charset
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
def test_overriding_charset_for_fallback_only
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
VCR.use_cassette('markup_overriding_charset_for_fallback_only') do
|
37
|
+
@v.set_doctype!(:utf_16, true)
|
38
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/markup_overriding_charset_for_fallback_only.html')
|
39
|
+
assert_not_equal 'utf-16', r.charset
|
40
|
+
end
|
34
41
|
end
|
35
42
|
|
36
43
|
def test_validating_uri_with_head_request
|
37
|
-
|
38
|
-
|
44
|
+
VCR.use_cassette('markup_validating_uri_with_head_request') do
|
45
|
+
r = @v.validate_uri_quickly('https://doc75.github.io/w3c_validators_tests/invalid_markup_4.html')
|
46
|
+
assert_errors r, 1
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
50
|
def test_validating_uri_with_soap
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
VCR.use_cassette('markup_validating_uri_with_soap') do
|
52
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_5.html')
|
53
|
+
assert_errors r, 1
|
54
|
+
assert_no_warnings r
|
55
|
+
end
|
45
56
|
end
|
46
57
|
|
47
58
|
def test_debugging_uri
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
VCR.use_cassette('markup_debugging_uri') do
|
60
|
+
@v.set_debug!
|
61
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_6.html')
|
62
|
+
assert r.debug_messages.length > 0
|
63
|
+
end
|
51
64
|
end
|
52
65
|
|
53
66
|
def test_validating_file
|
54
|
-
|
55
|
-
|
56
|
-
|
67
|
+
VCR.use_cassette('markup_validating_file') do
|
68
|
+
file = File.dirname(__FILE__) + '/fixtures/invalid_markup.html'
|
69
|
+
r = @v.validate_file(file)
|
70
|
+
assert_errors r, 1
|
57
71
|
|
58
|
-
|
72
|
+
assert r.uri =~ /fixtures\/invalid_markup\.html$/
|
73
|
+
end
|
59
74
|
end
|
60
75
|
|
61
76
|
def test_validating_text
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
77
|
+
VCR.use_cassette('markup_validating_text') do
|
78
|
+
valid_fragment = <<-EOV
|
79
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
80
|
+
<title>Test</title>
|
81
|
+
<body>
|
82
|
+
<div class="example">This is a test</div>
|
83
|
+
</body>
|
84
|
+
EOV
|
85
|
+
|
86
|
+
r = @v.validate_text(valid_fragment)
|
87
|
+
assert_no_errors r
|
88
|
+
assert_warnings r, 2
|
89
|
+
end
|
74
90
|
end
|
75
91
|
|
76
92
|
def test_validating_text_via_file
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
93
|
+
VCR.use_cassette('markup_validating_text_via_file') do
|
94
|
+
fh = File.new(File.dirname(__FILE__) + '/fixtures/invalid_markup.html', 'r+')
|
95
|
+
r = @v.validate_file(fh)
|
96
|
+
fh.close
|
97
|
+
assert_errors r, 1
|
98
|
+
end
|
81
99
|
end
|
82
100
|
|
83
101
|
|
84
102
|
def test_validator_abort
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
103
|
+
VCR.use_cassette('markup_validator_abort') do
|
104
|
+
@v.set_debug!
|
105
|
+
assert_nothing_raised do
|
106
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_encoding.html')
|
107
|
+
assert !r.is_valid?
|
108
|
+
assert_errors r, 1
|
109
|
+
assert_no_warnings r
|
110
|
+
end
|
91
111
|
end
|
92
112
|
end
|
93
113
|
|
94
|
-
def test_validator_contains_details_of_error_conditions
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
114
|
+
def test_validator_contains_details_of_error_conditions
|
115
|
+
VCR.use_cassette('markup_validator_contains_details_of_error_conditions') do
|
116
|
+
r = @v.validate_uri('https://doc75.github.io/w3c_validators_tests/invalid_markup_7.html')
|
117
|
+
assert_not_nil r.errors[0].col
|
118
|
+
assert_not_nil r.errors[0].line
|
119
|
+
assert_not_nil r.errors[0].message
|
120
|
+
end
|
99
121
|
end
|
100
122
|
end
|
123
|
+
|
data/test/test_proxy.rb
CHANGED
@@ -22,7 +22,10 @@ class ProxyTests < Test::Unit::TestCase
|
|
22
22
|
|
23
23
|
|
24
24
|
def test_validating_uri_with_head_request
|
25
|
-
|
26
|
-
|
25
|
+
omit("Pending, to prevent w3.org abuse")
|
26
|
+
VCR.use_cassette('markup_overriding_doctype') do
|
27
|
+
r = @v.validate_uri_quickly('https://doc75.github.io/w3c_validators_tests/invalid_markup_8.html')
|
28
|
+
assert_errors r, 1
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/w3c_validators/version.rb', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Dunae"]
|
6
|
+
gem.summary = "A Ruby wrapper for the World Wide Web Consortium’s online validation services."
|
7
|
+
gem.homepage = "https://github.com/w3c-validators/w3c_validators"
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split("\n")
|
10
|
+
gem.test_files = `git ls-files -- {test}/*`.split("\n")
|
11
|
+
gem.name = "w3c_validators"
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
gem.version = W3CValidators::VERSION
|
14
|
+
|
15
|
+
gem.required_ruby_version = '~>2.0'
|
16
|
+
|
17
|
+
gem.add_dependency 'nokogiri', '~> 1.6'
|
18
|
+
gem.add_dependency 'json', '~> 2.0'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'vcr'
|
22
|
+
gem.add_development_dependency 'webmock'
|
23
|
+
gem.add_development_dependency 'test-unit'
|
24
|
+
end
|