5 use Test
::More tests
=> 14;
6 BEGIN { use_ok
('Plack::Middleware::BasicStyle') };
8 use HTTP
::Request
::Common
;
12 my $default_hdrs = ['Content-Type' => 'text/html; charset=utf-8'];
15 my ($args, $hdrs, $body, $expected, $title, $url) = @_;
19 enable
'BasicStyle', @
$args;
20 sub { [200, $hdrs, [$body]] }
24 my $result = $cb->(GET
$url);
25 if (ref $expected eq 'ARRAY') {
26 my ($hdr, $exp) = @
$expected;
27 is
$result->header($hdr), $exp, $title
29 is
$result->content, $expected, $title
34 run_test
[], $default_hdrs, <<'BODY', <<'EXPECTED', 'default';
38 <meta charset="utf-8">
48 <head><style>body{margin:40pxauto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:010px}h1,h2,h3{line-height:1.2}</style>
49 <meta charset="utf-8">
58 local $Plack::Middleware
::BasicStyle
::DEFAULT_STYLE
= '<here>';
60 run_test
[], $default_hdrs, <<'BODY', <<'EXPECTED', 'no head';
68 run_test
[], $default_hdrs, <<'BODY', <<'EXPECTED', 'no html';
76 run_test
[], $default_hdrs, 'content', '<here>content', 'no head, no html';
78 run_test
[], $default_hdrs, '<!DOCTYPE html>', '<!DOCTYPE html><here>', 'just doctype';
80 run_test
[], [], 'no change', 'no change', 'no content-type';
82 run_test
[any_content_type
=> 1], [], 'yes change', '<here>yes change', 'no content-type + any_content_type';
84 run_test
[], $default_hdrs, (<<'BODY') x 2, 'has <style>';
87 <style>h1 { color: red; }</style>
91 run_test
[], $default_hdrs, (<<'BODY') x 2, 'has external stylesheet';
94 <link href="/style.css" rel="stylesheet">
98 run_test
[even_if_styled
=> 1], $default_hdrs,
99 <<'BODY', <<'EXPECTED', 'has <style> + even_if_styled';
101 <style>h1 { color: red; }</style>
104 <!DOCTYPE html><here>
105 <style>h1 { color: red; }</style>
109 run_test
[style
=> '<there>'], $default_hdrs, 'content', '<there>content', 'style';
111 run_test
[use_link_header
=> '/basic-style.css'],
112 $default_hdrs, 'test', ['Link', '</basic-style.css>; rel=stylesheet'], 'use_link_header';
114 run_test
[use_link_header
=> '/basic-style.css'],
115 $default_hdrs, 'test', '<here>', 'use_link_header - /basic-style.css', '/basic-style.css';
This page took 0.030349 seconds and 4 git commands to generate.