Skip to content

Commit

Permalink
[+]: update default config + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Sep 22, 2017
1 parent 56b778b commit aa07b11
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -28,9 +28,9 @@ use voku\helper\HtmlMin;

require_once 'composer/autoload.php';

$html = '<html>\r\n\t<body>\xc3\xa0</body>\r\n\t</html>';
$html = "<html>\r\n\t<body>\xc3\xa0</body>\r\n\t</html>";
$htmlMin = new HtmlMin();
echo $htmlMin->minify($html); // '<html><body>à</body></html>'
echo $htmlMin->minify($html); // '<html> <body>à</body> </html>'
```

## Options
Expand All @@ -49,7 +49,7 @@ $htmlMin->doSumUpWhitespace(); // sum-up extra whitespace
$htmlMin->doRemoveWhitespaceAroundTags(); // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doOptimizeAttributes(); // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveHttpPrefixFromAttributes(); // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDefaultAttributes(); // remove defaults (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDefaultAttributes(); // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveDeprecatedAnchorName(); // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromScriptTag(); // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
Expand All @@ -58,6 +58,7 @@ $htmlMin->doRemoveEmptyAttributes(); // remove some empty attri
$htmlMin->doRemoveValueFromEmptyInput(); // remove 'value=""' from empty <input> (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortCssClassNames(); // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortHtmlAttributes(); // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveSpacesBetweenTags(); // remove more (aggressive) spaces in the dom (disabled by default)
```

## Unit Test
Expand Down
4 changes: 2 additions & 2 deletions src/voku/helper/HtmlMin.php
Expand Up @@ -179,7 +179,7 @@ class HtmlMin
/**
* @var bool
*/
private $doRemoveDefaultAttributes = true;
private $doRemoveDefaultAttributes = false;

/**
* @var bool
Expand Down Expand Up @@ -214,7 +214,7 @@ class HtmlMin
/**
* @var bool
*/
private $doRemoveSpacesBetweenTags = true;
private $doRemoveSpacesBetweenTags = false;

/**
* HtmlMin constructor.
Expand Down
22 changes: 11 additions & 11 deletions tests/HtmlMinTest.php
Expand Up @@ -52,11 +52,11 @@ public function providerMultipleSpaces()
return array(
array(
'<html> <body> <h1>h oi</h1> </body></html>',
'<html><body><h1>h oi</h1></body></html>',
'<html> <body> <h1>h oi</h1> </body></html>',
),
array(
'<html> </html>',
'<html></html>',
'<html> </html>',
),
array(
"<html><body> pre \r\n suf\r\n </body>",
Expand All @@ -73,11 +73,11 @@ public function providerNewLinesTabsReturns()
return array(
array(
"<html>\r\t<body>\n\t\t<h1>hoi</h1>\r\n\t</body>\r\n</html>",
'<html><body><h1>hoi</h1></body></html>',
'<html> <body> <h1>hoi</h1> </body></html>',
),
array(
"<html>\r\t<h1>hoi</h1>\r\n\t\r\n</html>",
'<html><h1>hoi</h1></html>',
'<html> <h1>hoi</h1> </html>',
),
array(
"<html><p>abc\r\ndef</p></html>",
Expand All @@ -94,7 +94,7 @@ public function providerSpaceAfterGt()
return array(
array(
'<html> <body> <h1>hoi</h1> </body> </html>',
'<html><body><h1>hoi</h1></body></html>',
'<html> <body> <h1>hoi</h1> </body> </html>',
),
array(
'<html> a',
Expand All @@ -111,7 +111,7 @@ public function providerSpaceBeforeLt()
return array(
array(
'<html> <body> <h1>hoi</h1></body> </html> ',
'<html><body><h1>hoi</h1></body></html>',
'<html> <body> <h1>hoi</h1></body> </html>',
),
array(
'a <html>',
Expand All @@ -128,7 +128,7 @@ public function providerSpecialCharacterEncoding()
return array(
array(
"<html>\r\n\t<body>\xc3\xa0</body>\r\n\t</html>",
'<html><body>à</body></html>',
'<html> <body>à</body> </html>',
),
);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public function testOptionsDomFalse()

$expected = '<p id="text" class="foo">
foo
</p> <br/> <ul><li><p class="foo">lall</p></li></ul>';
</p> <br/> <ul> <li> <p class="foo">lall</p> </li></ul>';

self::assertSame(
str_replace(array("\r\n", "\r", "\n"), "\n", $expected),
Expand Down Expand Up @@ -275,7 +275,7 @@ public function testOptionsFalse()
$expected = '<html> <head> </head> <body>
<p id="text" class="foo">
foo
</p> <br> <ul><li><p class="foo">lall</p></li></ul>
</p> <br> <ul> <li> <p class="foo">lall</p> </li></ul>
</body>
</html>';

Expand Down Expand Up @@ -315,7 +315,7 @@ public function testOptionsTrue()
</html>
';

$expected = '<html><head></head><body><p class="foo" id="text">foo</p><br><ul><li><p class="foo foo2">lall</p></li></ul></body></html>';
$expected = '<html> <head> </head> <body><p class="foo" id="text">foo</p><br> <ul> <li><p class="foo foo2">lall</p></li></ul> </body> </html>';

self::assertSame($expected, $htmlMin->minify($html));
}
Expand All @@ -334,7 +334,7 @@ public function testMinifySimple()
</html>
';

$expected = '<html><head></head><body><p class="foo" id="text">foo</p><br><ul><li><p class="foo">lall</p></li></ul></body></html>';
$expected = '<html> <head> </head> <body><p class="foo" id="text">foo</p><br> <ul> <li><p class="foo">lall</p></li></ul> </body> </html>';

self::assertSame($expected, $htmlMin->minify($html));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/base1_result.html
Expand Up @@ -44,7 +44,7 @@
display/**/:/**/none;
display:none;
}
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1><h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym>
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1> <h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym>
Design</span></h2></div><pre>
White space is important here!
</pre><div id="quickSummary"><p class="p1"><span>A demonstration of what can be accomplished visually through <acronym title="Cascading Style Sheets">CSS</acronym>-based design. Select any style sheet from the list to load it into this page.</span></p><p class="p2"><span>Download the sample <a href="/zengarden-sample.html" title="This page's source HTML code, not to be modified.">html file</a> and <a href="/zengarden-sample.css" title="This page's sample CSS, the file you may modify.">css file</a></span></p></div><textarea class="maxwidth" cols="80" id="comment" name="comment" rows="6">66666
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/base2_result.html
Expand Up @@ -42,7 +42,7 @@
display/**/:/**/none;
display:none;
}
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1><h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym> Design</span></h2></div><pre>
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1> <h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym> Design</span></h2></div><pre>
White space is important here!
</pre><div id="quickSummary"><p class="p1"><span>A demonstration of what can be accomplished visually through <acronym title="Cascading Style Sheets">CSS</acronym>-based design. Select any style sheet from the list to load it into this page.</span></p><p class="p2"><span>Download the sample <a href="/zengarden-sample.html" title="This page's source HTML code, not to be modified.">html file</a> and <a href="/zengarden-sample.css" title="This page's sample CSS, the file you may modify.">css file</a></span></p></div><textarea class="maxwidth" cols="80" id="comment" name="comment" rows="6">66666

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/base3_result.html
Expand Up @@ -44,7 +44,7 @@
display/**/:/**/none;
display:none;
}
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1><h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym> Design</span></h2></div><pre>
</style><link href="//www.csszengarden.com/favicon.ico" rel="Shortcut Icon" type="image/x-icon"><link href="//www.csszengarden.com/zengarden.xml" rel="alternate" title="RSS" type="application/rss+xml"></head><body id="css-zen-garden"><!--[if !IE]>--><p>Browser != IE</p><!--<![endif]--><div id="container"><div id="pageHeader"><h1><span>css Zen Garden</span></h1> <h2><span>The Beauty of <acronym title="Cascading Style Sheets">CSS</acronym> Design</span></h2></div><pre>
White space is important here!
</pre><div id="quickSummary"><p class="p1"><span>A demonstration of what can be accomplished visually through <acronym title="Cascading Style Sheets">CSS</acronym>-based design. Select any style sheet from the list to load it into this page.</span></p><p class="p2"><span>Download the sample <a href="/zengarden-sample.html" title="This page's source HTML code, not to be modified.">html file</a> and <a href="/zengarden-sample.css" title="This page's sample CSS, the file you may modify.">css file</a></span></p></div><textarea class="maxwidth" cols="80" id="comment" name="comment" rows="6">66666

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/code_result.html
Expand Up @@ -14,4 +14,4 @@

$socket-&gt;listen(1337);
$loop-&gt;run();
</code></pre><script async id="asciicast-18487" src="https://asciinema.org/a/18487.js"></script></body></html>
</code></pre> <script async id="asciicast-18487" src="https://asciinema.org/a/18487.js"></script></body></html>
8 changes: 4 additions & 4 deletions tests/fixtures/hlt_result.html

Large diffs are not rendered by default.

0 comments on commit aa07b11

Please sign in to comment.