Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Make the $css parameter of the inlineCss method optional #700

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
[#698](https://github.com/MyIntervals/emogrifier/pull/698))

### Changed
- Make the `$css` parameter of the `inlineCss` method optional
([#700](https://github.com/MyIntervals/emogrifier/pull/700))
- Update the development dependencies
([#691](https://github.com/MyIntervals/emogrifier/pull/691))

Expand Down
2 changes: 1 addition & 1 deletion src/Emogrifier/CssInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function getHeadElement()
*
* @throws SyntaxErrorException
*/
public function inlineCss($css)
public function inlineCss($css = '')
{
$this->clearAllCaches();
$this->purgeVisitedNodes();
Expand Down
48 changes: 24 additions & 24 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function inlineCssProvidesFluentInterface()
{
$subject = CssInliner::fromHtml('<html><p>Hello world!</p></html>');

$result = $subject->inlineCss('');
$result = $subject->inlineCss();

self::assertSame($subject, $result);
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public function inlineCssKeepsWbrTag($html)
{
$subject = $this->buildDebugSubject($html);

$subject->inlineCss('');
$subject->inlineCss();

$result = $subject->render();
$expectedWbrTagCount = \substr_count($html, '<wbr');
Expand Down Expand Up @@ -916,7 +916,7 @@ public function inlineCssKeepsExistingStyleAttributes()
$styleAttribute = 'style="color: #ccc;"';
$subject = $this->buildDebugSubject('<html ' . $styleAttribute . '></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains($styleAttribute, $subject->render());
}
Expand Down Expand Up @@ -955,7 +955,7 @@ public function inlineCssLowercasesAttributeNamesFromStyleAttributes()
{
$subject = $this->buildDebugSubject('<html style="COLOR:#ccc;"></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('style="color: #ccc;"', $subject->render());
}
Expand Down Expand Up @@ -995,7 +995,7 @@ public function inlineCssPreservesCaseForAttributeValuesFromParsedStyleBlock()
'<html><head><style>p {' . $cssDeclaration . '}</style></head><body><p>target</p></body></html>'
);

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p style="' . $cssDeclaration . '">target</p>', $subject->render());
}
Expand All @@ -1007,7 +1007,7 @@ public function inlineCssRemovesStyleNodes()
{
$subject = $this->buildDebugSubject('<html><style type="text/css"></style></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotContains('<style', $subject->render());
}
Expand All @@ -1024,7 +1024,7 @@ public function inlineCssInDebugModeForInvalidCssSelectorThrowsException()
);
$subject->setDebug(true);

$subject->inlineCss('');
$subject->inlineCss();
}

/**
Expand All @@ -1038,7 +1038,7 @@ public function inlineCssNotInDebugModeIgnoresInvalidCssSelectors()
$subject = CssInliner::fromHtml($html);
$subject->setDebug(false);

$subject->inlineCss('');
$subject->inlineCss();

$result = $subject->render();
self::assertContains('color: red', $result);
Expand All @@ -1055,7 +1055,7 @@ public function inlineCssByDefaultIgnoresInvalidCssSelectors()
'<body><p></p></body></html>';
$subject = CssInliner::fromHtml($html);

$subject->inlineCss('');
$subject->inlineCss();

$result = $subject->render();
self::assertContains('color: red', $result);
Expand Down Expand Up @@ -1349,7 +1349,7 @@ public function inlineCssKeepsExistingStyleElementWithMediaInHead()
$html = '<html><head>' . $style . '</head><body></body></html>';
$subject = $this->buildDebugSubject($html);

$subject->inlineCss('');
$subject->inlineCss();

self::assertRegExp('/<head>.*<style.*<\\/head>/s', $subject->render());
}
Expand All @@ -1363,7 +1363,7 @@ public function inlineCssKeepsExistingStyleElementWithMediaOutOfBody()
$html = '<html><head>' . $style . '</head><body></body></html>';
$subject = $this->buildDebugSubject($html);

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotRegExp('/<body>.*<style/s', $subject->render());
}
Expand Down Expand Up @@ -1454,7 +1454,7 @@ public function inlineCssForHtmlWithValidMediaQueryContainsInnerCss($css)
{
$subject = $this->buildDebugSubject('<html><style type="text/css">' . $css . '</style><h1></h1><p></p></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertContainsCss('<style type="text/css">' . $css . '</style>', $subject->render());
}
Expand Down Expand Up @@ -1536,7 +1536,7 @@ public function inlineCssFromHtmlWithInvalidMediaQueryNotContainsInnerCss($css)
{
$subject = $this->buildDebugSubject('<html><style type="text/css">' . $css . '</style><h1></h1></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotContainsCss($css, $subject->render());
}
Expand All @@ -1552,7 +1552,7 @@ public function inlineCssFromHtmlWithInvalidMediaQueryNotContainsInlineCss($css)
{
$subject = $this->buildDebugSubject('<html><style type="text/css">' . $css . '</style><h1></h1></html>');

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotContains('style=', $subject->render());
}
Expand Down Expand Up @@ -1897,7 +1897,7 @@ public function inlineCssAppliesCssFromStyleNodes()
'<html><style type="text/css">html {' . $styleAttributeValue . '}</style></html>'
);

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<html style="' . $styleAttributeValue . '">', $subject->render());
}
Expand All @@ -1913,7 +1913,7 @@ public function inlineCssWhenDisabledNotAppliesCssFromStyleBlocks()
);
$subject->disableStyleBlocksParsing();

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotContains('style=', $subject->render());
}
Expand All @@ -1930,7 +1930,7 @@ public function inlineCssWhenStyleBlocksParsingDisabledKeepInlineStyles()
);
$subject->disableStyleBlocksParsing();

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p style="' . $styleAttributeValue . '">', $subject->render());
}
Expand All @@ -1943,7 +1943,7 @@ public function inlineCssWhenDisabledNotAppliesCssFromInlineStyles()
$subject = $this->buildDebugSubject('<html style="color: #ccc;"></html>');
$subject->disableInlineStyleAttributesParsing();

$subject->inlineCss('');
$subject->inlineCss();

self::assertNotContains('<html style', $subject->render());
}
Expand All @@ -1960,7 +1960,7 @@ public function inlineCssWhenInlineStyleAttributesParsingDisabledKeepStyleBlockS
);
$subject->disableInlineStyleAttributesParsing();

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p style="' . $styleAttributeValue . '">', $subject->render());
}
Expand All @@ -1977,7 +1977,7 @@ public function inlineCssAppliesCssWithMixedCaseAttributesInStyleBlock()
'<body><div id="topWrap"><p style="text-align: center;">some content</p></div></body></html>'
);

$subject->inlineCss('');
$subject->inlineCss();

$result = $subject->render();
self::assertContains('<p style="padding-bottom: 1px; padding-top: 0; text-align: center;">', $result);
Expand Down Expand Up @@ -2270,7 +2270,7 @@ public function inlineCssInDebugModeForInvalidExcludedSelectorThrowsException()
$subject->setDebug(true);

$subject->addExcludedSelector('..p');
$subject->inlineCss('');
$subject->inlineCss();
}

/**
Expand All @@ -2282,7 +2282,7 @@ public function inlineCssNotInDebugModeIgnoresInvalidExcludedSelector()
$subject->setDebug(false);

$subject->addExcludedSelector('..p');
$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p class="x"></p>', $subject->render());
}
Expand Down Expand Up @@ -2443,7 +2443,7 @@ public function inlineCssKeepsInlineStylePriorityVersusStyleBlockRules()
'<html><head><style>p {padding:10px};</style></head><body><p style="padding-left:20px;"></p></body></html>'
);

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p style="padding: 10px; padding-left: 20px;">', $subject->render());
}
Expand Down Expand Up @@ -2511,7 +2511,7 @@ public function inlineCssRemovesImportantRule($originalStyleAttributeContent, $e
'<html><head><body><p style="' . $originalStyleAttributeContent . '"></p></body></html>'
);

$subject->inlineCss('');
$subject->inlineCss();

self::assertContains('<p style="' . $expectedStyleAttributeContent . '">', $subject->render());
}
Expand Down