Skip to content

Commit

Permalink
Merge pull request #16 from OpenBuildings/css-inliner-upgrade
Browse files Browse the repository at this point in the history
Upgrade tijsverkoyen/css-to-inline-styles to 2.0
  • Loading branch information
hkdobrev authored Aug 28, 2016
2 parents 6b3121c + bbca57f commit 3b5b80d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ env:

matrix:
fast_finish: true
allow_failures:
- php: hhvm
exclude:
- php: hhvm
env: DEPS=lowest
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require" : {
"php": ">=5.4",
"swiftmailer/swiftmailer": "^5.1",
"tijsverkoyen/css-to-inline-styles": "^1.5"
"tijsverkoyen/css-to-inline-styles": "^2.0"
},
"require-dev" : {
"phpunit/phpunit": "^4.0|^5.0",
Expand Down
23 changes: 11 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions src/CssInlinerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function __construct(CssToInlineStyles $converter = null)
$this->converter = $converter;
} else {
$this->converter = new CssToInlineStyles();
$this->converter->setUseInlineStylesBlock(true);
}
}

Expand All @@ -40,18 +39,12 @@ public function beforeSendPerformed(Swift_Events_SendEvent $event)
$message = $event->getMessage();

if ($message->getContentType() === 'text/html') {
$this->converter->setCSS('');
$this->converter->setHTML($message->getBody());

$message->setBody($this->converter->convert());
$message->setBody($this->converter->convert($message->getBody()));
}

foreach ($message->getChildren() as $part) {
if (strpos($part->getContentType(), 'text/html') === 0) {
$this->converter->setCSS('');
$this->converter->setHTML($part->getBody());

$part->setBody($this->converter->convert());
$part->setBody($this->converter->convert($part->getBody()));
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions tests/fixtures/emailConverted.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><style>
<html>
<head>
<style><![CDATA[
.block {
width: 100px;
height: 20px;
}
div.block ul li.small {
margin: 10px;
}
</style></head><body>
<div class="block" style="height: 20px; width: 100px;">
]]></style>
</head>
<body>
<div class="block" style="width: 100px; height: 20px;">
text

<ul><li>
Expand All @@ -18,4 +22,5 @@
Small list
</li>
</ul></div>
</body></html>
</body>
</html>
18 changes: 0 additions & 18 deletions tests/src/CssInlinerPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,6 @@ public function testHtmlPart()
$this->assertEquals($this->emailConverted, $children[0]->getBody());
}

/**
* @covers ::__construct
*/
public function testDefaultConverterUsesInlineStylesBlock()
{
$plugin = new CssInlinerPlugin();

$converter = PHPUnit_Framework_Assert::readAttribute($plugin, 'converter');

$this->assertTrue(
PHPUnit_Framework_Assert::readAttribute(
$converter,
'useInlineStylesBlock'
),
'setUseInlineStylesBlock() should be called on default $converter'
);
}

/**
* @covers ::__construct
* @covers ::beforeSendPerformed
Expand Down

0 comments on commit 3b5b80d

Please sign in to comment.