public void MoveCSSInline_PreservesXMLNamespace() { string input = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.StartsWith("<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">", premailedOutput.Html); }
public void MoveCssInline_InlineStyleElementTakesPrecedence() { string input = "<html><head><style type=\"text/css\">.test { width: 150px; }</style></head><body><div class=\"test\" style=\"width: 100px;\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.Contains("<div class=\"test\" style=\"width: 100px", premailedOutput.Html); }
public void MoveCSSInline_PreservesDocType() { string input = "<!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></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.StartsWith("<!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\">")); }
public void MoveCssInline_AddBgColorStyle() { string input = "<html><head><style type=\"text/css\">.test { background-color:#f1f1f1; }</style></head><body><table><tr><td class=\"test\" bgcolor=\"\"></td></tr></table></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.Contains("<td class=\"test\" bgcolor=\"#f1f1f1\" style=\"background-color: #f1f1f1\">", premailedOutput.Html); }
public void MoveCssInline_SupportedMediaAttribute_InlinesAsNormal() { string input = "<html><head><style type=\"text/css\" media=\"screen\">div { width: 100% }</style></head><body><div>Target</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<div style=\"width: 100%;\">Target</div>")); }
public void MoveCssInline_KeepMediaQueries_InsertsStyleTag() { string input = "<html><head><style type=\"text/css\">li:before { width: 42px; } @media only screen and (max-width:620px) { div { width: 100% } }</style></head><body><div class=\"target\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, removeStyleElements: true, keepMediaQueries: true); Assert.IsTrue(premailedOutput.Html.Contains("<style>@media only screen and (max-width:620px) { div { width: 100% } }</style>")); }
public void MoveCssInline_StripsClassAttributes() { string input = "<html><head></head><body><table id=\"testTable\"><tr><td class=\"test\"></td></tr></table></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false, css: ".test { background-color:#f1f1f1; }", stripIdAndClassAttributes: true); Assert.IsTrue(premailedOutput.Html.Contains("<td style=\"background-color: #f1f1f1\"")); }
public void MoveCssInline_CssWithHigherSpecificity_AppliesMoreSpecificCss() { string input = "<html><head><style type=\"text/css\">#high-imp.test { width: 42px; } .test { width: 150px; }</style></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("style=\"width: 42px;\"")); }
public void MoveCssInline_NoStyleElement_StylesGivenInCSSParam_InlinesThat() { string input = "<html><head></head><body><table><tr><td class=\"test\"></td></tr></table></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false, css: ".test { background-color:#f1f1f1; }"); Assert.IsTrue(premailedOutput.Html.Contains("<td class=\"test\" style=\"background-color: #f1f1f1\"")); }
public void MoveCssInline_UnsupportedMediaAttribute_IgnoresStyles() { string input = "<html><head><style type=\"text/css\" media=\"print\">div { width: 100% }</style></head><body><div>Target</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<div>Target</div>")); }
public void MoveCssInline_AddSpecial_RemoveEmptyStyle() { string input = "<html><head><style type=\"text/css\">.test { -premailer-cellspacing: 5; -premailer-width: 14%; }</style></head><body><table><tr><td class=\"test\"></td></tr></table></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("<td class=\"test\" cellspacing=\"5\" width=\"14%\">"), "Actual: " + premailedOutput.Html); }
public void MoveCssInline_AbsoluteBackgroundUrl_ShouldNotBeCleanedAsComment() { string input = "<style>div { background: url('http://my.web.site.com/Content/email/content.png') repeat-y }</style><div></div>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<div style=\"background: url('http://my.web.site.com/Content/email/content.png') repeat-y\"></div>")); }
public void MoveCssInline_RespectExistingStyleElement() { string input = "<html><head><style type=\"text/css\">.test { height: 100px; }</style></head><body><div class=\"test\" style=\"width: 100px;\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("<div class=\"test\" style=\"height: 100px;width: 100px")); }
public void MoveCssInline_MultipleSelectors_HonorsIndividualSpecificity() { string input = "<html><head><style type=\"text/css\">p,li,tr.pub-heading td,tr.pub-footer td,tr.footer-heading td { font-size: 12px; line-height: 16px; } td.disclaimer p {font-size: 11px;} </style></head><body><table><tr class=\"pub-heading\"><td class=\"disclaimer\"><p></p></td></tr></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<p style=\"font-size: 11px;line-height: 16px\"></p>")); }
public void MoveCssInline_ImportantFlag_HonorsImportantFlagInline() { string input = "<style>div { color: blue !important; }</style><div style=\"color: red !important\">Red</div>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<div style=\"color: red")); }
public void MoveCssInline_UnsupportedSelector_AppliesCss() { string input = "<html><head><style type=\"text/css\">p:first-letter { width: 42px; }</style></head><body><p>target</p></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<p>target</p>")); }
public void MoveCssInline_KeepStyleElementsIgnoreElementsMatchesStyleElement_DoesntRemoveScriptTag() { string input = "<html><head><style id=\"ignore\" type=\"text/css\">li:before { width: 42px; }</style></head><body><div class=\"target\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, removeStyleElements: false, ignoreElements: "#ignore"); Assert.IsTrue(premailedOutput.Html.Contains("<style id=\"ignore\" type=\"text/css\">")); }
public void MoveCssInline_SupportedjQuerySelector_AppliesCss() { string input = "<html><head><style type=\"text/css\">li:first-child { width: 42px; }</style></head><body><ul><li>target</li><li>blargh></li></ul></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsTrue(premailedOutput.Html.Contains("<li style=\"width: 42px\">target</li>")); }
public void MoveCssInline_IgnoreStyleElement_DoesntApplyCss() { string input = "<html><head><style type=\"text/css\">.target { width: 42px; }</style><style type=\"text/css\" id=\"ignore\">.target { width: 1337px; }</style></head><body><div class=\"outer\"><div class=\"inner\"><div class=\"target\">test</div></div></div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false, ignoreElements: "#ignore"); Assert.IsTrue(premailedOutput.Html.Contains("style=\"width: 42px;\"")); }
public void MoveCssInline_CssWithHigherSpecificityInSeparateStyleTag_AppliesMoreSpecificCss() { string input = "<html><head><style type=\"text/css\">.target { width: 42px; }</style><style type=\"text/css\">.outer .inner .target { width: 1337px; }</style></head><body><div class=\"outer\"><div class=\"inner\"><div class=\"target\">test</div></div></div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("style=\"width: 1337px;\"")); }
public void MoveCssInline_StripsIdAttributes() { string input = "<html><head><style type=\"text/css\">#high-imp.test { width: 42px; } .test { width: 150px; }</style></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false, stripIdAndClassAttributes: true); Assert.IsTrue(premailedOutput.Html.Contains("<div style=\"width: 42px\">")); }
public void MoveCssInline_AddBgColorStyle_IgnoreElementWithBackgroundColorAndNoBgColor() { string input = "<html><head><style type=\"text/css\">.test { background-color:#f1f1f1; }</style></head><body><table><tr><td class=\"test\"></td></tr></table></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("<td class=\"test\" style=\"background-color: #f1f1f1\"")); }
public void MoveCSSInline_PreservesDocType_HTML401_Frameset() { string docType = "<!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">"; string input = $"{docType}<html><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.StartsWith($"{docType}<html>")); }
public void MoveCSSInline_PreservesDocType_XHTML10_Transitional() { string docType = "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; string input = $"{docType}<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.True(premailedOutput.Html.StartsWith($"{docType}<html xmlns=\"http://www.w3.org/1999/xhtml\">")); }
public void MoveCSSInline_PreservesDocType_HTML5() { string docType = "<!DOCTYPE html>"; string input = $"{docType}<html><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.StartsWith($"{docType}<html>")); }
public void MoveCssInline_StripsComments() { string input = "<html><head></head><body><!--This should be removed--></body></html>"; string expected = "<html><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, removeComments: true); Assert.IsTrue(expected == premailedOutput.Html); }
public void MoveCSSInline_PreservesDocType_HTML401_Transitional() { string docType = "<!DOCTYPE html PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"; string input = $"{docType}<html><head></head><body></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.StartsWith($"{docType}<html>", premailedOutput.Html); }
public void MoveCssInline_NoStyle_DoesNotBreakImageWidthAttribute() { string input = "<html><head><style type=\"text/css\"></style></head>" + "<body><img style=\"width: 206px; height: 64px;\" src=\"http://localhost/left.gif\" height=\"64\" WIDTH=\"206\" border=\"0\"></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsFalse(premailedOutput.Html.Contains("width=\"206px\"")); Assert.IsTrue(premailedOutput.Html.Contains("width=\"206\"")); }
public void MoveCssInline_UnsupportedPseudoSelector_AddsWarning() { string input = "<html><head><style type=\"text/css\">li:before { width: 42px; }</style></head><body><div><div class=\"target\">test</div></div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); var warnings = premailedOutput.Warnings; Assert.IsTrue(warnings.Contains("PreMailer.Net is unable to process the pseudo class/element 'li:before' due to a limitation in CsQuery.")); }
public void MoveCssInline_LaterPositionStylesWithEqualSpecificityHasPrecedence_Nested_InSeparateBlocks() { string input1 = "<html><head><style type=\"text/css\">table.child td { color: #00F; } table.parent td { color: #00F; }</style><style type=\"text/css\">table.parent td { color: #0F0; }</style></head><body><table class=\"parent\"><tr><td><table class=\"child\"><tr><td>test</td></tr></table></td></tr></table></body></html>"; string input2 = "<html><head><style type=\"text/css\">table.parent td { color: #0F0; } table.child td { color: #0F0; }</style><style type=\"text/css\">table.child td { color: #00F; }</style></head><body><table class=\"parent\"><tr><td><table class=\"child\"><tr><td>test</td></tr></table></td></tr></table></body></html>"; var premailedOutput1 = PreMailer.MoveCssInline(input1, false); var premailedOutput2 = PreMailer.MoveCssInline(input2, false); Assert.IsTrue(premailedOutput1.Html.Contains("<td style=\"color: #0F0\">test</td>")); Assert.IsTrue(premailedOutput2.Html.Contains("<td style=\"color: #00F\">test</td>")); }
public void TestMethod1() { string testProjectDirectoryPath = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = new DirectoryInfo(testProjectDirectoryPath); while (!directory.Name.Equals("PreMailer.Net.Tests")) { directory = directory.Parent; } testProjectDirectoryPath = directory.FullName; string htmlSource = File.ReadAllText(String.Join("\\", testProjectDirectoryPath, "testmail.html")); PreMailer pm = new PreMailer(); string premailedOutput = pm.MoveCssInline(htmlSource, false); }
public void ContainsLinkCssElement_DownloadsCss_InlinesContent() { var mockDownloader = new Mock<IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny<Uri>())).Returns(".test { width: 150px; }"); WebDownloader.SharedDownloader = mockDownloader.Object; string input = "<html><head><link href=\"http://a.com/b.css\"></link></head><body><div class=\"test\">test</div></body></html>"; PreMailer sut = new PreMailer(input, new Uri("http://a.com")); var premailedOutput = sut.MoveCssInline(); Assert.IsTrue(premailedOutput.Html.Contains("<div class=\"test\" style=\"width: 150px\">")); }
public void ContainsLinkCssElement_NotCssFile_DoNotDownload() { var mockDownloader = new Mock<IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny<Uri>())).Returns(".a { display: block; }"); WebDownloader.SharedDownloader = mockDownloader.Object; Uri baseUri = new Uri("http://a.com"); Uri fullUrl = new Uri(baseUri, "b.bs"); string input = String.Format("<html><head><link href=\"{0}\"></link></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>", fullUrl); PreMailer sut = new PreMailer(input, baseUri); sut.MoveCssInline(); mockDownloader.Verify(d => d.DownloadString(It.IsAny<Uri>()), Times.Never()); }