Skip to content

Commit

Permalink
[*]: fix test output (changed because of vendor update)
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Oct 19, 2018
1 parent c327382 commit ec9c378
Show file tree
Hide file tree
Showing 11 changed files with 983 additions and 714 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -29,7 +29,8 @@
"require": {
"php": ">=7.0.0",
"symfony/css-selector": "~3.0|~4.0",
"voku/simple_html_dom": "~4.0"
"voku/simple_html_dom": "~4.0",
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.0"
Expand Down
4 changes: 2 additions & 2 deletions src/CssToInlineStyles.php
Expand Up @@ -26,7 +26,7 @@ class CssToInlineStyles
*
* @var string
*/
private static $cssMediaQueriesRegEx = '#@media\\s+(?:only\\s)?(?:[\\s{\\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU';
private static $cssMediaQueriesRegEx = '#(?:____SIMPLE_HTML_DOM__VOKU__AT____|@)media\\s+(?:only\\s)?(?:[\\s{\\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU';

/**
* regular expression: css charset
Expand Down Expand Up @@ -899,7 +899,7 @@ public function setStripOriginalStyleTags(bool $on = true)
*
* Info: If this is enabled the media queries will be removed before inlining the rules.
*
* WARNING: If you use inline styles block "<style>" the this option will keep the media queries.
* WARNING: If you use inline styles block "<style>" this option will keep the media queries.
*
* @param bool $on
*
Expand Down
25 changes: 12 additions & 13 deletions tests/CssToInlineStylesTest.php
Expand Up @@ -263,7 +263,7 @@ public function testCssShorthandProperties()
->setCSS($css);
$actual = $cssToInlineStyles->convert();

self::assertSame($expected, $actual);
self::assertSame(trim($expected), trim($actual));
}

public function testDuplicateCssWithFoundation()
Expand All @@ -279,7 +279,7 @@ public function testDuplicateCssWithFoundation()
->setHTML($html);
$actual = $cssToInlineStyles->convert();

self::assertSame($expected, $actual);
self::assertSame(trim($expected), trim($actual));
}

public function testCssBigFile()
Expand All @@ -295,7 +295,7 @@ public function testCssBigFile()
->setCSS($css);
$actual = $cssToInlineStyles->convert();

self::assertSame($expected, ''. $actual); // UTF-8 Bom + string
self::assertSame(rtrim($expected), ''. rtrim($actual)); // UTF-8 Bom + string
}

public function testKeepMediaQuery()
Expand All @@ -315,7 +315,7 @@ public function testKeepMediaQuery()
->setCSS($css);
$actual = $cssToInlineStyles->convert();

self::assertSame($expected, $actual);
self::assertSame(trim($expected), trim($actual));
}

public function testKeepMediaQueryV2()
Expand All @@ -332,7 +332,7 @@ public function testKeepMediaQueryV2()
$cssToInlineStyles->setHTML($html);
$cssToInlineStyles->setCSS($css);
$actual = $cssToInlineStyles->convert();
self::assertSame($expected, $actual);
self::assertSame(trim($expected), trim($actual));
}

public function testLoadCssFile()
Expand Down Expand Up @@ -539,7 +539,7 @@ public function testSpecificity()
}
EOF;
$expected = <<<EOF
<a class="one" id="ONE" style="border: 1px solid red; width: 20px !important; border-bottom: 2px; height: 20px; margin: 10px; padding: 100px;"> <img class="two" id="TWO" style="padding-bottom: 20px; padding: 0; border: none; padding-top: 30px;"><img class="three" id="THREE" style="padding-bottom: 20px; border: none; padding: 100px; padding-left: 10px;"><img class="four" id="FOUR" style="padding-bottom: 20px; padding: 0; border: none; margin: 10px; margin-left: 100px;"><img class="five" id="FIVE" style="padding-bottom: 20px; border: none; padding-left: 10px; padding: 100px;"></a>
<a class="one" id="ONE" style="border: 1px solid red; width: 20px !important; border-bottom: 2px; height: 20px; margin: 10px; padding: 100px;"> <img class="two" id="TWO" style="padding-bottom: 20px; padding: 0; border: none; padding-top: 30px;"> <img class="three" id="THREE" style="padding-bottom: 20px; border: none; padding: 100px; padding-left: 10px;"> <img class="four" id="FOUR" style="padding-bottom: 20px; padding: 0; border: none; margin: 10px; margin-left: 100px;"> <img class="five" id="FIVE" style="padding-bottom: 20px; border: none; padding-left: 10px; padding: 100px;"></a>
EOF;
$this->runHTMLToCSS($html, $css, $expected);
}
Expand Down Expand Up @@ -582,7 +582,7 @@ public function testCleanupWithoutStyleTagCleanup()
{
$html = '<style>div { top: 1em; }</style><style>div { left: 1em; }</style><div id="id" class="className"> id="foo" class="bar" </div>';
$css = ' #id { display: inline; } .className { margin-right: 10px; }';
$expected = '<head><style>div { top: 1em; }</style><style>div { left: 1em; }</style></head><div style="top: 1em; left: 1em; margin-right: 10px; display: inline;"> id="foo" class="bar" </div>';
$expected = '<style>div { top: 1em; }</style><style>div { left: 1em; }</style><div style="top: 1em; left: 1em; margin-right: 10px; display: inline;"> id="foo" class="bar" </div>';
$this->cssToInlineStyles->setUseInlineStylesBlock(true);
$this->cssToInlineStyles->setStripOriginalStyleTags(false);
$this->cssToInlineStyles->setCleanup(true);
Expand All @@ -596,7 +596,7 @@ public function testCleanupWithStyleTagCleanup()
{
$html = '<style class="cleanup">div { top: 1em; }</style><style>.cleanup { top: 1em; } div { left: 1em; }</style><div id="id" class="className"> id="foo" class="bar" </div>';
$css = ' #id { display: inline; } .className { margin-right: 10px; }';
$expected = '<head><style>.cleanup { top: 1em; } div { left: 1em; }</style></head><div style="left: 1em; margin-right: 10px; display: inline;"> id="foo" class="bar" </div>';
$expected = '<style>.cleanup { top: 1em; } div { left: 1em; }</style><div style="left: 1em; margin-right: 10px; display: inline;"> id="foo" class="bar" </div>';
$this->cssToInlineStyles->setUseInlineStylesBlock(true);
$this->cssToInlineStyles->setStripOriginalStyleTags(false);
$this->cssToInlineStyles->setCleanup(true);
Expand Down Expand Up @@ -692,8 +692,7 @@ public function testXMLHeaderIsRemoved()
public function testXMLHeaderIsRemovedv2()
{
$html = '<html><body><p>Foo</p></body>';
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
$expected = '<html>
<body>
<p>Foo</p>
</body>
Expand Down Expand Up @@ -872,9 +871,9 @@ public function testCssRulesInlineResetDuringSecondLoad()
<p></p>
HTML;
$css = 'p { margin: 10px; }';
$this->runHTMLToCSS($html, $css, '<head><style> p { padding: 10px; }</style></head><p style="margin: 10px;"></p>');
$this->runHTMLToCSS($html, $css, '<style> p { padding: 10px; }</style><p style="margin: 10px;"></p>');
$this->cssToInlineStyles->setUseInlineStylesBlock(true);
$this->runHTMLToCSS($html, $css, '<head><style> p { padding: 10px; }</style></head><p style="margin: 10px; padding: 10px;"></p>');
$this->runHTMLToCSS($html, $css, '<style> p { padding: 10px; }</style><p style="margin: 10px; padding: 10px;"></p>');
}

public function testSimpleStyleTagsInHtml()
Expand Down Expand Up @@ -971,7 +970,7 @@ protected function file_get_contents($filename)
*/
protected function normalizeString($string)
{
return str_replace(array("\r\n", "\r"), "\n", $string);
return str_replace(array("\r\n", "\r"), "\n", trim($string));
}

public function testStyleTagsWithAttributeInHtml()
Expand Down
76 changes: 45 additions & 31 deletions tests/fixtures/test1Html_result.html
@@ -1,10 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email title or subject</title>
<style type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email title or subject</title>

<style type="text/css">

/* reset */
#outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
Expand All @@ -22,7 +23,7 @@
span {font-size: 13px; line-height: 17px; font-family: monospace; color: #000001;}

</style>
<!--[if gte mso 9]>
<!--[if gte mso 9]>
<style>
/* Target Outlook 2007 and 2010 */
</style>
Expand All @@ -31,39 +32,52 @@
<body style="width:100%; margin:0; padding:0; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;">

<!-- body wrapper -->
<table cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin: 0; padding: 0; width: 100%; line-height: 100% !important;"><tr>
<td valign="top" style="border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin: 0; padding: 0; width: 100%; line-height: 100% !important;">
<tr>
<td valign="top" style="border-collapse: collapse;">
<!-- edge wrapper -->
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #efefef;"><tr>
<td valign="top" style="border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #efefef;">
<tr>
<td valign="top" style="border-collapse: collapse;">
<!-- content wrapper -->
<table cellpadding="0" cellspacing="0" border="0" align="center" width="560" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #cfcfcf;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<table cellpadding="0" cellspacing="0" border="0" align="center" width="560" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #cfcfcf;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<!-- ///////////////////////////////////////////////////// -->

<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<span style="color: #000001; font-family: monospace; font-size: 13px; line-height: 17px;">text</span>
</td>
</tr></table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<img src="full path to image" alt="alt text" title="title text" width="50" height="50" style="-ms-interpolation-mode: bicubic; display: block; outline: none; text-decoration: none; width: 50px; height: 50px;">
</td>
</tr></table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr height="30">
<td valign="top" style="border-collapse: collapse; vertical-align: top; background: #efefef;" width="600">
</td>
</tr></table>
<!-- //////////// -->
</td>
</tr></table>
<!-- / content wrapper -->
</td>
</tr></table>
<!-- / edge wrapper -->
</td>
</tr></table>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr height="30">
<td valign="top" style="border-collapse: collapse; vertical-align: top; background: #efefef;" width="600">
</td>
</tr>
</table>

<!-- //////////// -->
</td>
</tr>
</table>
<!-- / content wrapper -->
</td>
</tr>
</table>
<!-- / edge wrapper -->
</td>
</tr>
</table>
<!-- / page wrapper -->
</body>
</html>
</html>
76 changes: 45 additions & 31 deletions tests/fixtures/test2Html_result.html
@@ -1,10 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email title or subject</title>
<style type="text/css">@media only screen and (max-width: 599px) {
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email title or subject</title>

<style type="text/css">@media only screen and (max-width: 599px) {
table.body {
position: relative;
display: block !important;
Expand Down Expand Up @@ -181,7 +182,7 @@
height: 1px !important;
}
}</style>
<!--[if gte mso 9]>
<!--[if gte mso 9]>
<style>
/* Target Outlook 2007 and 2010 */
</style>
Expand All @@ -190,39 +191,52 @@
<body style="width:100%; margin:0; padding:0; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;">

<!-- body wrapper -->
<table cellpadding="0" cellspacing="0" border="0" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin: 0; padding: 0; width: 100%; line-height: 100% !important;"><tr>
<td valign="top" style="border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" border="0" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin: 0; padding: 0; width: 100%; line-height: 100% !important;">
<tr>
<td valign="top" style="border-collapse: collapse;">
<!-- edge wrapper -->
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #efefef;"><tr>
<td valign="top" style="border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #efefef;">
<tr>
<td valign="top" style="border-collapse: collapse;">
<!-- content wrapper -->
<table cellpadding="0" cellspacing="0" border="0" align="center" width="560" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #cfcfcf;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<table cellpadding="0" cellspacing="0" border="0" align="center" width="560" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #cfcfcf;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<!-- ///////////////////////////////////////////////////// -->

<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<span style="color: #000001; font-family: monospace; font-size: 13px; line-height: 17px;">text</span>
</td>
</tr></table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr>
<td valign="top" style="border-collapse: collapse; vertical-align: top;">
<img src="full path to image" alt="alt text" title="title text" width="50" height="50" style="-ms-interpolation-mode: bicubic; display: block; outline: none; text-decoration: none; width: 50px; height: 50px;">
</td>
</tr></table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;"><tr height="30">
<td valign="top" style="border-collapse: collapse; vertical-align: top; background: #efefef;" width="600">
</td>
</tr></table>
<!-- //////////// -->
</td>
</tr></table>
<!-- / content wrapper -->
</td>
</tr></table>
<!-- / edge wrapper -->
</td>
</tr></table>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="border: 1px solid red; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr height="30">
<td valign="top" style="border-collapse: collapse; vertical-align: top; background: #efefef;" width="600">
</td>
</tr>
</table>

<!-- //////////// -->
</td>
</tr>
</table>
<!-- / content wrapper -->
</td>
</tr>
</table>
<!-- / edge wrapper -->
</td>
</tr>
</table>
<!-- / page wrapper -->
</body>
</html>
</html>

0 comments on commit ec9c378

Please sign in to comment.