App-FuguWeb

 view release on metacpan or  search on metacpan

t/fuguweb/check.t  view on Meta::CPAN

};

subtest 'a page that nothing links to' => sub {
	# en/index.html no longer links to other.html. 404.html is
	# unlinked on purpose, so it must not be reported.
	my $alone = swap( qr{<p><a href="\./other\.html">Other</a></p>\n<p><a href="\./other\.html#here">The anchor</a></p>\n}, '' );
	my @problems = built( 'en/index.html' => $alone )->run;
	my $joined   = join "\n", @problems;

	like( $joined, qr{en/other\.html: no page links to it},
		'the unreachable page' );
	unlike( $joined, qr{404\.html: no page links to it},
		'a page marked unlinked is not reported' );

	# WEB-LANGUAGE-13. The walk starts at the entry page of the
	# tree, and never at a page of the top level. A link of the
	# top-level 404.html reaches no page of the tree, and neither
	# does a link of en/404.html, which no page links to.
	@problems = built(
		'en/index.html' => $alone,
		lost(qq{<a href="other.html">Other</a>\n}),
	)->run;
	is_deeply( \@problems, ['en/other.html: no page links to it'],
		'a link of the top level does not count' );

	# The walk stays inside the tree. A link out of the tree to the
	# top level reaches no page of the tree through it.
	@problems = built(
		'en/index.html' => sub ($html) {
			return inside(qq{<a href="../404.html">Out</a>\n})
			    ->( $alone->($html) );
		},
		lost(qq{<a href="other.html">Other</a>\n}),
	)->run;
	is_deeply( \@problems, ['en/other.html: no page links to it'],
		'and neither does a page of the top level on the way' );

	@problems = built( 'en/index.html' => undef )->run;
	like( join( "\n", @problems ), qr{en/index\.html: the entry page is missing},
		'the entry page of the tree is missing' );
};

subtest 'what is not a problem stays not a problem' => sub {
	# The two skip rules. Without a case that exercises each of
	# them, a check that lost one would report a false positive and
	# only the real site would notice.
	my @problems = built( 'en/other.html' => inside(<<'HTML') )->run;
<a href="mailto:hi@example.org">Mail</a>
<a class="Xr" href="https://man.openbsd.org/rc.8">rc(8)</a>
HTML
	my $joined = join "\n", @problems;

	is( scalar @problems, 0, 'no problem' ) or diag $joined;
	unlike( $joined, qr/mailto/,
		'a mailto: link is not a dead local link' );
	unlike( $joined, qr/man\.openbsd\.org/,
		'a cross-reference that left for the host does not dangle' );
};

subtest 'a stray file in the output' => sub {
	my @problems = built( 'index.html~' => "an editor backup\n" )->run;
	like( join( "\n", @problems ),
		qr{index\.html~: in the output but not in the site},
		'the stray file is named' );

	# A page at the top level that the site does not name.
	@problems = built( 'other.html' => "<p>Other</p>\n" )->run;
	is_deeply( \@problems, ['other.html: in the output but not in the site'],
		'a page at the top level is named' );

	# WEB-OUTPUT-4. The tree of a language that the description
	# does not declare is no tree of the site.
	@problems = built( 'de/index.html' => "<p>Start</p>\n" )->run;
	is_deeply( \@problems, ['de/index.html: in the output but not in the site'],
		'a tree of no declared language is named' );
};

done_testing();



( run in 2.722 seconds using v1.01-cache-2.11-cpan-99fa8243a42 )