css = new \MailPoetVendor\CSS(); } // tests public function testItCanBeInstantiated() { expect_that($this->css instanceof \MailPoetVendor\CSS); } /** * Rules of same specificity should be ordered by their order in styles string * so that the rule which appears earlier is treated as rule with lower specificity. */ public function testItParsesCssAndOrdersThemCorrectly() { $css = " div a { color: brown; } .green { color: green; } .purple.bold { color: purple; } span a { color: blue; } a { color: red; } "; $parsed = $this->css->parseCSS($css); $this->assertEquals('purple', $parsed[0]['properties']['color']); $this->assertEquals('green', $parsed[1]['properties']['color']); $this->assertEquals('blue', $parsed[2]['properties']['color']); $this->assertEquals('brown', $parsed[3]['properties']['color']); $this->assertEquals('red', $parsed[4]['properties']['color']); } public function testItCanInlineARule() { $styles = 'p { color: red; }'; $content = '
Foo
'; $html = $this->buildHtml($styles, $content); $resultHtml = (string)$this->css->inlineCSS($html); $this->assertContains('', $resultHtml); } public function testItInlinesMoreSpecificRule() { $styles = 'p { color: red; } .blue { color: blue; }'; $content = '
Foo
'; $html = $this->buildHtml($styles, $content); $resultHtml = (string)$this->css->inlineCSS($html); $this->assertContains('', $resultHtml); } public function testItPreserveInlinedRule() { $styles = 'p { color: red; }'; $content = '
Foo
'; $html = $this->buildHtml($styles, $content); $resultHtml = (string)$this->css->inlineCSS($html); $this->assertContains('', $resultHtml); } public function testItAlwaysInlinesGlobalImportantRule() { $styles = 'p { color: red !important; }'; $content = '
Foo
'; $html = $this->buildHtml($styles, $content); $resultHtml = (string)$this->css->inlineCSS($html); $this->assertContains('', $resultHtml); } public function testItMergesInlineStylesCorrectly() { $styles = $this->css->mergeInlineStyles('color: red', 'margin: 10px'); $this->assertEquals('color:red;margin:10px', $styles); $styles = $this->css->mergeInlineStyles('color: red', 'margin: 10px; color: blue'); $this->assertEquals('color:blue;margin:10px', $styles); $styles = $this->css->mergeInlineStyles('', 'margin: 10px; color: blue'); $this->assertEquals('margin:10px;color:blue', $styles); $styles = $this->css->mergeInlineStyles('margin:10px;color:blue', ''); $this->assertEquals('margin:10px;color:blue', $styles); } private function buildHtml($styles, $content) { return "
{$content}"; } }