Skip Menu |

This queue is for tickets about the CSS-Inliner CPAN distribution.

Report information
The Basics
Id: 58923
Status: resolved
Priority: 0/
Queue: CSS-Inliner

People
Owner: Nobody in particular
Requestors: wonko [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2544
Fixed in: (no value)



Subject: Add tests
I'm about to make some fixes to CSS::Inliner to handle actual cascading rules for CSS, but before that I wanted some base regression tests that will help to make sure that I don't cause other problems. I'm attaching 3 test files that provide some basic tests. I'll probably be attaching more.
Subject: basic.t
use Test::More; use Test::LongString; plan(tests => 5); use_ok('CSS::Inliner'); my $html = <<END; <html> <head> <title>Test Document</title> <style type="text/javascript"> h1 { color: red; font-size: 20px } h2 { color: blue; font-size: 17px; } </style> </head> <body> <h1>Howdy!</h1> <h2>Let's Play</h2> <p>Got any games?</p> </body> </html> END my $inliner = CSS::Inliner->new(); $inliner->read({html => $html}); my $inlined = $inliner->inlinify(); contains_string($inlined, q(<h1 style="color:red;font-size:20px;">Howdy!</h1>), 'h1 rule inlined'); contains_string($inlined, q(<h2 style="color:blue;font-size:17px;">Let's Play</h2>), 'h2 rule inlined'); contains_string($inlined, q(<p>Got any games?</p>), 'p not styled'); lacks_string($inlined, q(<style), 'no style blocks left');
Subject: advanced.t
use Test::More; use Test::LongString; use CSS::Inliner; plan('no_plan'); my $html = <<END; <html> <head> <title>Test Document</title> <style type="text/javascript"> h1 { font-size: 20px } h1.alert { color: red } h1.cool { color: blue } .intro { color: #555555; font-size: 10px; } div p { color: #123123; font-size: 8px } </style> </head> <body> <h1 class="alert">Lorem ipsum dolor sit amet</h1> <h1 class="cool">Consectetur adipiscing elit</h1> <p class="intro">Aliquam ornare luctus egestas.</p> <p>Nulla vulputate tellus vitae justo luctus scelerisque accumsan nunc porta.</p> <div> <p>Phasellus pharetra viverra sollicitudin. <strong>Vivamus ac enim ante.</strong></p> <p>Nunc augue massa, <em>dictum id eleifend non</em> posuere nec purus.</p> </div> </body> </html> END my $inliner = CSS::Inliner->new(); $inliner->read({html => $html}); my $inlined = $inliner->inlinify(); contains_string($inlined, q(<h1 class="alert" style="font-size:20px;color:red;">Lorem ipsum), 'h1.alert rule inlined'); contains_string($inlined, q(<h1 class="cool" style="font-size:20px;color:blue;">Consectetur), 'h1.cool rule inlined'); contains_string($inlined, q(<p class="intro" style="color:#555555;font-size:10px;">Aliquam), '.intro rule inlined'); contains_string($inlined, q(<p style="color:#123123;font-size:8px;">Phasellus), 'div p rule inlined'); contains_string($inlined, q(<p style="color:#123123;font-size:8px;">Nunc augue), 'div p rule inlined again'); contains_string($inlined, q(<p>Nulla), 'no rule for just "p"'); lacks_string($inlined, q(<style), 'no style blocks left');
Subject: custom_html_tree.t
use Test::More; use Test::LongString; use HTML::TreeBuilder; use CSS::Inliner; plan(tests => 6); my $html = <<END; <html> <head> <title>Test Document</title> <style type="text/javascript"> 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(); contains_string($inlined, q(<h1 style="color:red;font-size:20px;">Howdy!</h1>), 'h1 rule inlined'); lacks_string($inlined, q(<style), 'no style blocks left'); lacks_string($inlined, '<foo>', 'ignoring unknown elements'); $html_tree->ignore_unknown(0); $inliner = CSS::Inliner->new({ html_tree => $html_tree }); $inliner->read({html => $html}); $inlined = $inliner->inlinify(); contains_string($inlined, q(<h1 style="color:red;font-size:20px;">Howdy!</h1>), 'h1 rule inlined'); lacks_string($inlined, q(<style), 'no style blocks left'); contains_string($inlined, '<foo>', 'ignoring unknown elements');
Here's a better advanced.t Btw, do you have this module on git or svn somewhere? It's easier to contribute that way than all these patches and files.
Subject: advanced.t
use Test::More; use Test::LongString; use CSS::Inliner; plan(tests => 8); my $html = <<'END'; <html> <head> <title>Test Document</title> <style type="text/javascript"> h1 { font-size: 20px } h1.alert { color: red } h1.cool { color: blue } .intro { color: #555555; font-size: 10px; } div p { color: #123123; font-size: 8px } p:hover { color: yellow } </style> </head> <body> <h1 class="alert">Lorem ipsum dolor sit amet</h1> <h1 class="cool">Consectetur adipiscing elit</h1> <p class="intro">Aliquam ornare luctus egestas.</p> <p>Nulla vulputate tellus vitae justo luctus scelerisque accumsan nunc porta.</p> <div> <p>Phasellus pharetra viverra sollicitudin. <strong>Vivamus ac enim ante.</strong></p> <p>Nunc augue massa, <em>dictum id eleifend non</em> posuere nec purus.</p> </div> </body> </html> END my $inliner = CSS::Inliner->new(); $inliner->read({html => $html}); my $inlined = $inliner->inlinify(); contains_string($inlined, q(<h1 class="alert" style="font-size:20px;color:red;">Lorem ipsum), 'h1.alert rule inlined'); contains_string($inlined, q(<h1 class="cool" style="font-size:20px;color:blue;">Consectetur), 'h1.cool rule inlined'); contains_string($inlined, q(<p class="intro" style="color:#555555;font-size:10px;">Aliquam), '.intro rule inlined'); contains_string($inlined, q(<p style="color:#123123;font-size:8px;">Phasellus), 'div p rule inlined'); contains_string($inlined, q(<p style="color:#123123;font-size:8px;">Nunc augue), 'div p rule inlined again'); contains_string($inlined, q(<p>Nulla), 'no rule for just "p"'); lacks_string($inlined, q(<style), 'no style blocks left'); lacks_string($inlined, q(yellow), ':hover pseudo-attribute was ignored');
Hi Michael, I created the tests directory and added these tests to it. Another contributor asked me about a github today, and I started reading about it. The development of this library is currently housed within svn at MailerMailer - but there is no reason that it can't move. If it's easier for everyone else then I'm all for it, I'll poke around and see what's involved. thanks again, Kevin On Tue Jun 29 10:12:10 2010, WONKO wrote: Show quoted text
> Here's a better advanced.t > > Btw, do you have this module on git or svn somewhere? It's easier to > contribute that way than all these patches and files.