mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-12 18:40:57 +00:00
Add tests for encoded anchors for file: and http:
I started with a test of urlencoded anchors, assuming at the URL might have a urlencoded anchor, but the actual anchor in the HTML would NOT be urlencoded.
This commit is contained in:
parent
33036803b0
commit
2d1bf6ef98
5 changed files with 143 additions and 9 deletions
|
|
@ -7,7 +7,7 @@ url http_anchor.html#bad
|
|||
cache key http://localhost:%(port)d/%(datadir)s/http_anchor.html#bad
|
||||
real url http://localhost:%(port)d/%(datadir)s/http_anchor.html#bad
|
||||
name a_bad
|
||||
warning Anchor `bad' not found. Available anchors: `good'.
|
||||
warning Anchor `bad' (decoded: `bad') not found. Available anchors: `good'.
|
||||
valid
|
||||
|
||||
url http_anchor.html#good
|
||||
|
|
|
|||
25
tests/checker/data/urlencoding_anchor.html
Normal file
25
tests/checker/data/urlencoding_anchor.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!-- targets -->
|
||||
<a name="good">Good target</a>
|
||||
<a name="with_pipes_|_and_parentheses_(and—em-dashes)">Needs-encoded target #1</a>
|
||||
<a name="another_with_pipes_|_and_parentheses_(and—em-dashes)">Needs-encoded target #2</a>
|
||||
<a name="partially_|_(encoded_em—dash)">Target for partially-encoded testing</a>
|
||||
|
||||
<!-- simple anchors -->
|
||||
<a href="urlencoding_anchor.html">No anchor, will not be tested</a>
|
||||
<a href="urlencoding_anchor.html#good">Good anchor</a>
|
||||
<a href="urlencoding_anchor.html#bad">Bad anchor</a>
|
||||
|
||||
<!-- different encodings of the same complex anchor -->
|
||||
<a href="urlencoding_anchor.html#with_pipes_|_and_parentheses_(and—em-dashes)">Non-encoded anchor</a>
|
||||
<a href="urlencoding_anchor.html#with_pipes_|_and_parentheses_%28and%E2%80%94em-dashes%29">Partially-encoded version of the same anchor</a>
|
||||
<a href="urlencoding_anchor.html#with_pipes_%7C_and_parentheses_%28and%E2%80%94em-dashes%29">Fully-encoded version of the same anchor</a>
|
||||
|
||||
<!-- just another complex anchor -->
|
||||
<a href="urlencoding_anchor.html#another_with_pipes_%7C_and_parentheses_%28and%E2%80%94em-dashes%29">Distinct encoded anchor</a>
|
||||
|
||||
<!-- bad anchor, encoded two ways -->
|
||||
<a href="urlencoding_anchor.html#bad_|_%28and%E2%80%94em-dashes%29">Bad encoded anchor, partially encoded</a>
|
||||
<a href="urlencoding_anchor.html#bad_%7C_%28and%E2%80%94em-dashes%29">Bad encoded anchor, fully encoded</a>
|
||||
|
||||
<!-- stand-alone test for partially-encoded anchor -->
|
||||
<a href="urlencoding_anchor.html#partially_%7C_(encoded_em—dash)">Partially-encoded anchor, for testing</a>
|
||||
42
tests/checker/data/urlencoding_anchor.html.file.result
Normal file
42
tests/checker/data/urlencoding_anchor.html.file.result
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_%%28and%%E2%%80%%94em-dashes%%29
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
name Distinct encoded anchor
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#bad
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad
|
||||
name Bad anchor
|
||||
warning Anchor `bad' (decoded: `bad') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'.
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#bad_|_%%28and%%E2%%80%%94em-dashes%%29
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes)
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes)
|
||||
name Bad encoded anchor, partially encoded
|
||||
warning Anchor `bad_%%7C_(and%%E2%%80%%94em-dashes)' (decoded: `bad_|_(and—em-dashes)') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'.
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#good
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#good
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#good
|
||||
name Good anchor
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#partially_%%7C_(encoded_em—dash)
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash)
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash)
|
||||
name Partially-encoded anchor, for testing
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#with_pipes_|_and_parentheses_(and—em-dashes)
|
||||
cache key file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
real url file://%(curdir)s/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
name Non-encoded anchor
|
||||
valid
|
||||
42
tests/checker/data/urlencoding_anchor.html.result
Normal file
42
tests/checker/data/urlencoding_anchor.html.result
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_%%28and%%E2%%80%%94em-dashes%%29
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#another_with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
name Distinct encoded anchor
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#bad
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad
|
||||
name Bad anchor
|
||||
warning Anchor `bad' (decoded: `bad') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'.
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#bad_|_%%28and%%E2%%80%%94em-dashes%%29
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes)
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#bad_%%7C_(and%%E2%%80%%94em-dashes)
|
||||
name Bad encoded anchor, partially encoded
|
||||
warning Anchor `bad_%%7C_(and%%E2%%80%%94em-dashes)' (decoded: `bad_|_(and—em-dashes)') not found. Available anchors: `another_with_pipes_|_and_parentheses_(and—em-dashes)', `good', `partially_|_(encoded_em—dash)', `with_pipes_|_and_parentheses_(and—em-dashes)'.
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#good
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#good
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#good
|
||||
name Good anchor
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#partially_%%7C_(encoded_em—dash)
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash)
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#partially_%%7C_(encoded_em%%E2%%80%%94dash)
|
||||
name Partially-encoded anchor, for testing
|
||||
valid
|
||||
|
||||
url urlencoding_anchor.html#with_pipes_|_and_parentheses_(and—em-dashes)
|
||||
cache key http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
real url http://localhost:%(port)d/%(datadir)s/urlencoding_anchor.html#with_pipes_%%7C_and_parentheses_(and%%E2%%80%%94em-dashes)
|
||||
name Non-encoded anchor
|
||||
valid
|
||||
|
|
@ -20,22 +20,23 @@ from . import LinkCheckTest
|
|||
from .httpserver import HttpServerTest
|
||||
|
||||
|
||||
class TestAnchor(LinkCheckTest):
|
||||
class TestFileAnchor(LinkCheckTest):
|
||||
"""
|
||||
Test anchor checking of HTML pages.
|
||||
Test anchor checking of HTML files.
|
||||
"""
|
||||
|
||||
def test_anchor(self):
|
||||
def test_anchor_file(self):
|
||||
confargs = {"enabledplugins": ["AnchorCheck"]}
|
||||
anchor = "broken"
|
||||
url = "file://%(curdir)s/%(datadir)s/anchor.html#%(anchor)s" % self.get_attrs(
|
||||
anchor=anchor)
|
||||
nurl = self.norm(url)
|
||||
resultlines = [
|
||||
"url %s" % url,
|
||||
"cache key %s" % nurl,
|
||||
"real url %s" % nurl,
|
||||
"warning Anchor `%s' not found. Available anchors: `myid:'." % anchor,
|
||||
f"url {url}",
|
||||
f"cache key {nurl}",
|
||||
f"real url {nurl}",
|
||||
f"warning Anchor `{anchor}' (decoded: `{anchor}') not found."
|
||||
" Available anchors: `myid:'.",
|
||||
"valid",
|
||||
]
|
||||
self.direct(url, resultlines, confargs=confargs)
|
||||
|
|
@ -46,11 +47,35 @@ class TestHttpAnchor(HttpServerTest):
|
|||
Test checking of HTML pages containing links to anchors served over http.
|
||||
"""
|
||||
|
||||
def test_anchor_html(self):
|
||||
def test_anchor_http(self):
|
||||
confargs = dict(enabledplugins=["AnchorCheck"], recursionlevel=1)
|
||||
self.file_test("http_anchor.html", confargs=confargs)
|
||||
|
||||
|
||||
class TestEncodedAnchors(HttpServerTest):
|
||||
"""Test HTML pages containing urlencoded links to anchors"""
|
||||
|
||||
def test_anchor_encoded_http(self):
|
||||
"""
|
||||
http://
|
||||
"""
|
||||
confargs = dict(enabledplugins=["AnchorCheck"], recursionlevel=1)
|
||||
self.file_test("urlencoding_anchor.html", confargs=confargs)
|
||||
|
||||
def test_anchor_encoded_file(self):
|
||||
"""
|
||||
file://
|
||||
This should have identical behavior as http://
|
||||
"""
|
||||
filename = "urlencoding_anchor.html"
|
||||
confargs = {"enabledplugins": ["AnchorCheck"]}
|
||||
url = "file://%(curdir)s/%(datadir)s/%(filename)s" % self.get_attrs(
|
||||
filename=filename)
|
||||
# get results from the special result file that has `.file.` in its name
|
||||
resultlines = self.get_resultlines(f"{filename}.file")
|
||||
self.direct(url, resultlines, recursionlevel=1, confargs=confargs)
|
||||
|
||||
|
||||
class TestAnchorsAcrossMultipleFiles(LinkCheckTest):
|
||||
"""Test anchors when there are multiple files"""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue