File: custom_html_tree.t

package info (click to toggle)
libcss-inliner-perl 4024-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 412 kB
  • sloc: perl: 882; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
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
use strict;
use warnings;
use lib qw( ./lib ../lib );

use Test::More;
use Cwd;
use CSS::Inliner;
use HTML::TreeBuilder;

plan(tests => 6);

my $html = <<END;
<html>
  <head>
    <title>Test Document</title>
    <style type="text/css">
    h1 { color: red; font-size: 20px }
    h2 { color: blue; font-size: 17px; }
    </style>
  </head>
  <body>
    <!-- Some comment -->
    <h1>Howdy!</h1>
    <h2>Let's Play</h2>
    <p>Got any games?</p>
    <foo>Bar</foo>
  </body>
</html>
END

my $html_tree = HTML::TreeBuilder->new();
$html_tree->ignore_unknown(1);
my $inliner = CSS::Inliner->new({ html_tree => $html_tree });
$inliner->read({ html => $html });
my $inlined = $inliner->inlinify();

ok($inlined =~ m/<h1 style="color: red; font-size: 20px;">Howdy!<\/h1>/, 'h1 rule inlined');
ok($inlined !~ m/<style/, 'no style blocks left');
ok($inlined !~ m/<foo>/, 'ignoring unknown elements');

$html_tree->ignore_unknown(0);
$inliner = CSS::Inliner->new({ html_tree => $html_tree });
$inliner->read({ html => $html });
$inlined = $inliner->inlinify();

ok($inlined =~ m/<h1 style="color: red; font-size: 20px;">Howdy!<\/h1>/, 'custom html_tree: h1 rule inlined');
ok($inlined !~ m/<style/, 'no style blocks left');
ok($inlined =~ m/<foo>/, 'ignoring unknown elements');