forked from wjdp/htmltest
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-link_test.go
648 lines (553 loc) · 20.8 KB
/
check-link_test.go
1
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
package htmltest
import (
"github.com/wjdp/htmltest/issues"
"testing"
)
// Spec tests
func TestAnchorMissingHref(t *testing.T) {
// fails for link with no href
hT := tTestFile("fixtures/links/missingLinkHref.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "href blank", 1)
}
func TestAnchorIgnorable(t *testing.T) {
// ignores links marked as ignore data-proofer-ignore
hT := tTestFile("fixtures/links/ignorableLinks.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorIgnorableChildren(t *testing.T) {
// ignores links marked as ignore data-proofer-ignore in child elements
hT := tTestFile("fixtures/links/ignorableLinksChildren.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorMatchIgnore(t *testing.T) {
// ignores links in IgnoreURLs
hT := tTestFileOpts("fixtures/links/brokenLinkExternalSingle.html",
map[string]interface{}{
"IgnoreURLs": []interface{}{"www.asdo3IRJ395295jsingrkrg4.com"},
})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalBroken(t *testing.T) {
// fails for broken external links
hT := tTestFileOpts("fixtures/links/brokenLinkExternal.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 1)
}
func TestAnchorExternalBrokenNoVCR(t *testing.T) {
// fails for broken external links without VCR. This is needed as the code that handles 'dial tcp' errors doesn't
// get called with VCR. It returns a rather empty response with status code of 0.
tSkipShortExternal(t)
hT := tTestFile("fixtures/links/brokenLinkExternal.html")
tExpectIssueCount(t, hT, 1)
}
func TestAnchorExternalIgnore(t *testing.T) {
// ignores external links when asked
hT := tTestFileOpts("fixtures/links/brokenLinkExternal.html",
map[string]interface{}{"CheckExternal": false, "VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHashBrokenDefault(t *testing.T) {
// passes for broken external hashes by default
hT := tTestFileOpts("fixtures/links/brokenHashOnTheWeb.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHashBrokenOption(t *testing.T) {
// fails for broken external hashes when asked
t.Skip("Not yet implemented")
hT := tTestFileOpts("fixtures/links/brokenHashOnTheWeb.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "no such hash", 1)
}
func TestAnchorExternalCache(t *testing.T) {
// does not check links with parameters multiple times
// TODO check cache is being checked
t.Skip("Not yet implemented")
hT := tTestFile("fixtures/links/check_just_once.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHrefMalformed(t *testing.T) {
// does not explode on bad external links in files
hT := tTestFileOpts("fixtures/links/bad_external_links.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 2)
}
func TestAnchorExternalInsecureDefault(t *testing.T) {
// passes for non-HTTPS links when not asked
hT := tTestFileOpts("fixtures/links/non_https.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalInsecureOption(t *testing.T) {
// fails for non-HTTPS links when asked
hT := tTestFileOpts("fixtures/links/non_https.html",
map[string]interface{}{"EnforceHTTPS": true, "VCREnable": true})
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "is not an HTTPS target", 1)
}
func TestAnchorExternalInsecureOptionIgnored(t *testing.T) {
// passes when checking for non-HTTPS links but they're in the IgnoreURLs list
hT := tTestFileOpts("fixtures/links/issues/94.html",
map[string]interface{}{
"EnforceHTTPS": true,
"IgnoreURLs": []interface{}{"plantuml.com", "plantuml.net", "forum.plantuml.net"},
})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHrefIP(t *testing.T) {
// fails for broken IP address links
hT := tTestFileOpts("fixtures/links/ip_href.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 2)
}
func TestAnchorExternalHrefIPTimeout(t *testing.T) {
// fails for broken IP address links
hT := tTestFileOpts("fixtures/links/ip_timeout.html",
map[string]interface{}{"ExternalTimeout": 1})
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "request exceeded our ExternalTimeout", 1)
}
func TestAnchorExternalFollowRedirects(t *testing.T) {
// should follow redirects
hT := tTestFileOpts("fixtures/links/linkWithRedirect.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalFollowRedirectsDisabled(t *testing.T) {
// fails on redirects if not following
t.Skip("Not yet implemented, need new link, times out")
hT := tTestFileOpts("fixtures/links/linkWithRedirect.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 99)
tExpectIssue(t, hT, "PLACEHOLDER", 99)
}
func TestAnchorExternalHTTPS(t *testing.T) {
// should understand https
hT := tTestFileOpts("fixtures/links/https-valid.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHTTPSInvalid(t *testing.T) {
// should understand https
hT := tTestFileOpts("fixtures/links/https-invalid.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 6)
}
func TestAnchorExternalHTTPSBadH2(t *testing.T) {
// should connect to servers with bad http/2 support
// See issue #49
hT := tTestFileOpts("fixtures/links/https-valid-h2.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalRequiresAccepts(t *testing.T) {
// should connect to servers with bad http/2 support
// See issue #49
hT := tTestFileOpts("fixtures/links/http_requires_accept.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalMissingProtocolValid(t *testing.T) {
// works for valid links missing the protocol
hT := tTestFileOpts("fixtures/links/link_missing_protocol_valid.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalMissingProtocolInvalid(t *testing.T) {
// fails for invalid links missing the protocol
hT := tTestFileOpts("fixtures/links/link_missing_protocol_invalid.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 1)
// tExpectIssue(t, hT, "no such host", 1)
}
func TestLinkExternalHrefPipes(t *testing.T) {
// works for pipes in the URL
hT := tTestFileOpts("fixtures/links/escape_pipes.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHrefNonstandardChars(t *testing.T) {
// passes non-standard characters
hT := tTestFileOpts("fixtures/links/non_standard_characters.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorExternalHrefUTF8(t *testing.T) {
// passes for external UTF-8 links
hT := tTestFileOpts("fixtures/links/utf8Link.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalBroken(t *testing.T) {
// fails for broken internal links
hT := tTestFile("fixtures/links/brokenLinkInternal.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "target does not exist", 1)
}
func TestAnchorInternalBrokenIgnore(t *testing.T) {
// fails for broken internal links
hT := tTestFileOpts("fixtures/links/brokenLinkInternal.html",
map[string]interface{}{"CheckInternal": false})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalRelativeLinksBase(t *testing.T) {
// passes for relative links with a base
hT := tTestFile("fixtures/links/relativeLinksWithBase.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorHashInternalValid(t *testing.T) {
// passes for valid internal hash
hT := tTestFile("fixtures/links/hashInternalOk.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorHashInternalBroken(t *testing.T) {
// fails for broken internal hash
hT := tTestFile("fixtures/links/hashInternalBroken.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "hash does not exist", 1)
}
func TestAnchorHashSelfValid(t *testing.T) {
// passes for valid self hash
hT := tTestFile("fixtures/links/hashSelfOk.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorHashSelfBroken(t *testing.T) {
// fails for broken self hash
hT := tTestFile("fixtures/links/hashSelfBroken.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "hash does not exist", 1)
}
func TestAnchorHashBrokenIgnore(t *testing.T) {
// fails for broken internal hash
hT1 := tTestFileOpts("fixtures/links/hashInternalBroken.html",
map[string]interface{}{"CheckInternalHash": false})
hT2 := tTestFileOpts("fixtures/links/hashSelfBroken.html",
map[string]interface{}{"CheckInternalHash": false})
tExpectIssueCount(t, hT1, 0)
tExpectIssueCount(t, hT2, 0)
}
func TestAnchorDirectoryRootResolve(t *testing.T) {
// properly resolves implicit /index.html in link paths
hT := tTestFile("fixtures/links/linkToFolder.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryRootResolveWithIgnoredDir(t *testing.T) {
// ignoring the target of the link does not break
hT := tTestFileOpts("fixtures/links/linkToFolder.html",
map[string]interface{}{"IgnoreDirs": []interface{}{"folder"}})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryCustomRoot(t *testing.T) {
// works for custom directory index file
t.Skip("Not yet implemented")
hT := tTestFile("fixtures/links/link_pointing_to_directory.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryCustomRootBroken(t *testing.T) {
// fails if custom directory index file doesn't exist
hT := tTestFile("fixtures/links/link_pointing_to_directory.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "target is a directory, no index", 1)
}
func TestAnchorDirectoryNoTrailingSlash(t *testing.T) {
// fails for internal linking to a directory without trailing slash
hT := tTestFile("fixtures/links/link_directory_without_slash.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "target is a directory, href lacks trailing slash", 1)
}
func TestAnchorDirectoryNoTrailingSlashOption(t *testing.T) {
// passes for internal linking to a directory without trailing slash when asked
hT := tTestFileOpts("fixtures/links/link_directory_without_slash.html",
map[string]interface{}{"IgnoreDirectoryMissingTrailingSlash": true})
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryQueryHash(t *testing.T) {
// passes for internal linking to a directory with trailing slash
hT := tTestFile("fixtures/links/link_directory_with_slash_query_hash.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryRootExplicit(t *testing.T) {
// passes when linking explicitly to the directory root
hT := tTestFile("fixtures/links/root-link-explicit.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryHtmlExtension(t *testing.T) {
// works for custom directory index file
hT := tTestDirectory("fixtures/links/_site/")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorDirectoryWithEncodedCharacters(t *testing.T) {
// passes for folder with encoded characters
hT := tTestFile("fixtures/links/linkToFolderWithSpace.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalRootLink(t *testing.T) {
// properly checks links to root
hT := tTestFile("fixtures/links/rootLink/rootLink.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalRelativeLinks(t *testing.T) {
// properly checks relative links
hT := tTestFile("fixtures/links/relativeLinks.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalHrefUrlEncoded(t *testing.T) {
// passes for urlencoded href
hT := tTestFile("fixtures/links/urlencoded-href.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorErrorDuplication(t *testing.T) {
// does not dupe errors
hT := tTestFile("fixtures/links/nodupe.html")
tExpectIssueCount(t, hT, 1)
}
func TestAnchorInternalDashedAttrs(t *testing.T) {
// does not complain for files with attributes containing dashes
hT := tTestFile("fixtures/links/attributeWithDash.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalCaseMismatch(t *testing.T) {
// does not complain for internal hash links with mismatched cases
t.Skip("Unsure on whether we should ignore case, pretty sure we shouldn't")
hT := tTestFile("fixtures/links/ignores_cases.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorInternalHashBlankDefault(t *testing.T) {
// fails for href="#" when not asked
hT := tTestFile("fixtures/links/hash_href.html")
tExpectIssue(t, hT, "empty hash", 1)
tExpectIssueCount(t, hT, 1)
}
func TestAnchorInternalHashBlankOption(t *testing.T) {
// passes for href="#" when asked, see
// https://github.com/wjdp/htmltest/issues/30
hT1 := tTestFileOpts("fixtures/links/hash_href.html",
map[string]interface{}{"CheckInternalHash": false})
tExpectIssueCount(t, hT1, 0)
hT2 := tTestFileOpts("fixtures/links/hash_href.html",
map[string]interface{}{"IgnoreInternalEmptyHash": true})
tExpectIssueCount(t, hT2, 0)
}
func TestAnchorInternalHashWeird(t *testing.T) {
// works for internal links to weird encoding IDs
hT := tTestFile("fixtures/links/encodingLink.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorMultipleProblems(t *testing.T) {
// finds a mix of broken and unbroken links
t.Skip("Only single problem, and an hash which is not yet supported.")
// TODO make our own multiple problem file
hT := tTestFile("fixtures/links/multipleProblems.html")
tExpectIssueCount(t, hT, 99)
tExpectIssue(t, hT, "PLACEHOLDER", 99)
}
func TestAnchorJavascriptLinkIgnore(t *testing.T) {
// ignores javascript links
hT := tTestFile("fixtures/links/javascript_link.html")
tExpectIssueCount(t, hT, 0)
}
func TestMailtoValid(t *testing.T) {
// ignores valid mailto links
hT := tTestFile("fixtures/links/mailto_link.html")
tExpectIssueCount(t, hT, 0)
}
func TestMailtoBlank(t *testing.T) {
// fails for blank mailto links
hT := tTestFile("fixtures/links/blank_mailto_link.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "mailto is empty", 1)
}
func TestMailtoInvalid(t *testing.T) {
// fails for invalid mailto links
hT := tTestFile("fixtures/links/invalid_mailto_link.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "contains an invalid email address", 1)
}
func TestMailtoIgnore(t *testing.T) {
// ignores mailto links when told to
hT := tTestFileOpts("fixtures/links/blank_mailto_link.html",
map[string]interface{}{"CheckMailto": false})
tExpectIssueCount(t, hT, 0)
}
func TestTelValid(t *testing.T) {
// ignores valid tel links
hT := tTestFile("fixtures/links/tel_link.html")
tExpectIssueCount(t, hT, 0)
}
func TestTelBlank(t *testing.T) {
// fails for blank tel links
hT := tTestFile("fixtures/links/blank_tel_link.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "tel is empty", 1)
}
func TestTelBlankIgnore(t *testing.T) {
// fails for broken internal links
hT := tTestFileOpts("fixtures/links/blank_tel_link.html",
map[string]interface{}{"CheckTel": false})
tExpectIssueCount(t, hT, 0)
}
func TestLinkHrefValid(t *testing.T) {
// works for valid href within link elements
hT := tTestFile("fixtures/links/head_link_href.html")
tExpectIssueCount(t, hT, 0)
}
func TestLinkHrefBlank(t *testing.T) {
// fails for empty href within link elements
hT := tTestFile("fixtures/links/head_link_href_empty.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "href blank", 1)
}
func TestLinkHrefBlankIgnore(t *testing.T) {
// works for empty href within link elements when ignoring
hT := tTestFileOpts("fixtures/links/head_link_href_empty.html",
map[string]interface{}{"IgnoreEmptyHref": true})
tExpectIssueCount(t, hT, 0)
}
func TestLinkHrefAbsent(t *testing.T) {
// fails for absent href within link elements
hT := tTestFile("fixtures/links/head_link_href_absent.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "link tag missing href", 1)
}
func TestLinkHrefBrokenCanonicalDefault(t *testing.T) {
// works for valid href within link elements
hT := tTestFileOpts("fixtures/links/brokenCanonicalLink.html",
map[string]interface{}{"VCREnable": true})
tExpectIssueCount(t, hT, 0)
}
func TestLinkHrefBrokenCanonicalOption(t *testing.T) {
// works for valid href within link elements
hT := tTestFileOpts("fixtures/links/brokenCanonicalLink.html",
map[string]interface{}{"IgnoreCanonicalBrokenLinks": false, "VCREnable": true})
tExpectIssueCount(t, hT, 1)
}
func TestLinkRelDnsPrefetch(t *testing.T) {
// ignores links with rel="dns-prefetch"
hT := tTestFile("fixtures/links/link-rel-dns-prefetch.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorPre(t *testing.T) {
// works for broken anchors within pre & code
hT := tTestFile("fixtures/links/anchors_in_pre.html")
tExpectIssueCount(t, hT, 0)
}
func TestLinkPre(t *testing.T) {
// works for broken link within pre & code
hT := tTestFile("fixtures/links/links_in_pre.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorHashQueryBroken(t *testing.T) {
// fails for broken hash with query
t.Skip("Not yet dealt with")
hT := tTestFile("fixtures/links/broken_hash_with_query.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "PLACEHOLDER", 99)
}
func TestAnchorHashSelf(t *testing.T) {
// works for hash referring to itself
hT := tTestFile("fixtures/links/hashReferringToSelf.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorNameIgnore(t *testing.T) {
// ignores placeholder with name
hT := tTestFile("fixtures/links/placeholder_with_name.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorIdIgnore(t *testing.T) {
// ignores placeholder with id
hT := tTestFile("fixtures/links/placeholder_with_id.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorIdEmpty(t *testing.T) {
// fails for placeholder with empty id
// TODO: Should we only fail here if missing href?
t.Skip("Not yet implemented")
hT := tTestFile("fixtures/links/placeholder_with_empty_id.html")
tExpectIssueCount(t, hT, 1)
tExpectIssue(t, hT, "anchor with empty id", 99)
}
func TestAnchorOtherProtocols(t *testing.T) {
// ignores non-hypertext protocols
hT := tTestFile("fixtures/links/other_protocols.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorBlankHTML5(t *testing.T) {
// does not expect href for anchors in HTML5
hT := tTestFile("fixtures/links/blank_href_html5.html")
tExpectIssueCount(t, hT, 0)
}
func TestAnchorBlankHTML4(t *testing.T) {
// does expect href for anchors in non-HTML5
t.Skip("Not yet implemented")
hT1 := tTestFile("fixtures/links/blank_href_html4.html")
tExpectIssueCount(t, hT1, 1)
hT2 := tTestFile("fixtures/links/blank_href_htmlunknown.html")
tExpectIssueCount(t, hT2, 1)
}
func TestSelfSignedLink(t *testing.T) {
hT := tTestFileOpts("fixtures/links/selfSignedLink.html",
map[string]interface{}{"IgnoreSSLVerify": false})
tExpectIssueCount(t, hT, 1)
}
func TestSelfSignedLinkIgnoreSSLVerify(t *testing.T) {
hT := tTestFileOpts("fixtures/links/selfSignedLink.html",
map[string]interface{}{"IgnoreSSLVerify": true})
tExpectIssueCount(t, hT, 0)
}
// Favicon
func TestFaviconDefaultMissing(t *testing.T) {
// passes, by default, for missing favicon
hT := tTestFile("fixtures/favicon/favicon_absent.html")
tExpectIssue(t, hT, "favicon missing", 0)
}
func TestFaviconOptionMissing(t *testing.T) {
// fails, when asked, for missing favicon
hT := tTestFileOpts("fixtures/favicon/favicon_absent.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 1)
}
func TestFaviconOptionMissingApple(t *testing.T) {
// fails, when asked, for present apple icon but missing favicon
hT := tTestFileOpts("fixtures/favicon/favicon_absent_apple.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 1)
}
func TestFaviconOptionBroken(t *testing.T) {
// fails for broken favicon
hT := tTestFileOpts("fixtures/favicon/favicon_broken.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "target does not exist", 1)
}
func TestFaviconOptionBrokenIgnored(t *testing.T) {
// fails with missing favicon for ignored icon link tag
hT := tTestFileOpts("fixtures/favicon/favicon_broken_but_ignored.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 1)
}
func TestFaviconOptionPresent(t *testing.T) {
// passes, when asked, for present favicon
hT := tTestFileOpts("fixtures/favicon/favicon_present.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 0)
}
func TestFaviconOptionPresentShortcut(t *testing.T) {
// passes, when asked, with present favicon with legacy rel="shortcut icon"
hT := tTestFileOpts("fixtures/favicon/favicon_present_shortcut.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 0)
}
func TestFaviconOptionPresentButInBody(t *testing.T) {
// fails when favicon isn't a first level child of <head>
hT := tTestFileOpts("fixtures/favicon/favicon_present_but_in_body.html",
map[string]interface{}{"CheckFavicon": true})
tExpectIssue(t, hT, "favicon missing", 1)
}
// Benchmarks
func BenchmarkManyExternalLinks(b *testing.B) {
for i := 0; i < b.N; i++ {
tTestFileOpts("fixtures/benchmarks/manyExternalLinks.html",
map[string]interface{}{"LogLevel": issues.LevelNone})
}
}