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
|
#!/usr/bin/env perl
use strict;
use warnings;
use HTML::RewriteAttributes::Resources;
use Test::More tests => 3;
my $html = << 'END';
<html>
<head>
<link type="text/css" href="foo.css" />
<style type="text/css">
@import "bar.css";
</style>
<link type="text/css" href="baz.css" />
</head>
<body>
</body>
</html>
END
my %css = (
"foo.css" => 'foo; @import "quux.css";',
"bar.css" => 'bar; @import "quux.css";',
"baz.css" => 'baz; @import "foo.css";',
"quux.css" => 'quux; @import "bar.css"; @import "quux.css";',
);
my @seen;
my @seen_css;
my $rewrote = HTML::RewriteAttributes::Resources->rewrite($html, sub {
my $uri = shift;
push @seen, $uri;
return $uri;
}, inline_css => sub {
my $uri = shift;
push @seen_css, $uri;
return $css{$uri};
});
is(@seen, 0, "no ordinary resources seen");
is_deeply(\@seen_css, [
"foo.css",
"baz.css",
]);
$rewrote =~ s/ +$//mg;
$rewrote =~ s/^ +//mg;
is($rewrote, << 'END', "rewrote the html correctly");
<html>
<head>
<style type="text/css">
<!--
/* foo.css */
foo; @import "quux.css";
-->
</style>
<style type="text/css">
@import "bar.css";
</style>
<style type="text/css">
<!--
/* baz.css */
baz; @import "foo.css";
-->
</style>
</head>
<body>
</body>
</html>
END
|