File: 020-inline-css.t

package info (click to toggle)
libhtml-rewriteattributes-perl 0.05-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 216 kB
  • sloc: perl: 2,139; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (5)
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
#!/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" />
        <link type="text/css" href="print.css" media="print" />
    </head>
    <body>
        <img src="moose.jpg" />
        <img src="http://example.com/nethack.png">
        <a href="Example.html">Example</a>
        <p align="justified" style="color: red">
            hooray
        </p>
    </body>
</html>
END

my @seen;
my @seen_inline;

my $rewrote = HTML::RewriteAttributes::Resources->rewrite($html, sub {
    my $uri  = shift;
    my %args = @_;

    push @seen, [$uri, $args{tag}, $args{attr}];

    return uc $uri;
}, inline_css => sub {
    my $uri = shift;

    push @seen_inline, $uri;

    "INLINED CSS";
});

is_deeply(\@seen, [
    ["moose.jpg" => img => "src"],
    ["http://example.com/nethack.png" => img => "src"],
]);

is_deeply(\@seen_inline, [
    "foo.css",
    "print.css",
]);

is($rewrote, << "END", "rewrote the html correctly");
<html>
    <head>
        
<style type="text/css">
<!--

/* foo.css */
INLINED CSS
-->
</style>

        
<style type="text/css" media="print">
<!--

/* print.css */
INLINED CSS
-->
</style>

    </head>
    <body>
        <img src="MOOSE.JPG" />
        <img src="HTTP://EXAMPLE.COM/NETHACK.PNG">
        <a href="Example.html">Example</a>
        <p align="justified" style="color: red">
            hooray
        </p>
    </body>
</html>
END