-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from kilburn/options
Add configuration settings
- Loading branch information
Showing
9 changed files
with
183 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Strip styles | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Settings this to false prevents the inliner from removing the style | ||
| definitions that have been inlined. | ||
| | ||
| Notice that media query styles are not inlined, and hence never | ||
| stripped. | ||
| | ||
*/ | ||
|
||
'strip-styles' => true, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Remove classes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Settings this to false disables the removal of class attributes from | ||
| your html elements (do not enable this if you use media queries) | ||
| | ||
*/ | ||
|
||
'strip-classes' => true, | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,30 @@ | |
|
||
class CssInlinerPluginTest extends PHPUnit_Framework_TestCase | ||
{ | ||
|
||
protected $stubs; | ||
|
||
protected $options; | ||
|
||
protected static $stubDefinitions = array( | ||
'plain-text', 'original-html', 'converted-html', 'converted-html-with-classes', | ||
'converted-html-with-styles' | ||
); | ||
|
||
public function setUp() | ||
{ | ||
$this->stubs['plain-text'] = file_get_contents(__DIR__.'/stubs/plain-text.stub'); | ||
$this->stubs['original-html'] = file_get_contents(__DIR__.'/stubs/original-html.stub'); | ||
$this->stubs['converted-html'] = file_get_contents(__DIR__.'/stubs/converted-html.stub'); | ||
foreach (self::$stubDefinitions as $stub) { | ||
$this->stubs[$stub] = file_get_contents(__DIR__.'/stubs/'.$stub.'.stub'); | ||
} | ||
|
||
$this->options = require(__DIR__.'/../config/css-inliner.php'); | ||
} | ||
|
||
/** @test **/ | ||
public function itShouldConvertHtmlBody() | ||
{ | ||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin()); | ||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
|
@@ -33,12 +41,54 @@ public function itShouldConvertHtmlBody() | |
$this->assertEquals($this->stubs['converted-html'], $message->getBody()); | ||
} | ||
|
||
/** @test **/ | ||
public function itShouldConvertHtmlBodyKeepingClasses() | ||
{ | ||
$this->options['strip-classes'] = false; | ||
|
||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
$message->setFrom('[email protected]'); | ||
$message->setTo('[email protected]'); | ||
$message->setSubject('Test'); | ||
$message->setBody($this->stubs['original-html'], 'text/html'); | ||
|
||
$mailer->send($message); | ||
|
||
$this->assertEquals($this->stubs['converted-html-with-classes'], $message->getBody()); | ||
} | ||
|
||
/** @test **/ | ||
public function itShouldConvertHtmlBodyKeepingStyles() | ||
{ | ||
$this->options['strip-styles'] = false; | ||
|
||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
$message->setFrom('[email protected]'); | ||
$message->setTo('[email protected]'); | ||
$message->setSubject('Test'); | ||
$message->setBody($this->stubs['original-html'], 'text/html'); | ||
|
||
$mailer->send($message); | ||
|
||
$this->assertEquals($this->stubs['converted-html-with-styles'], $message->getBody()); | ||
} | ||
|
||
/** @test **/ | ||
public function itShouldConvertHtmlBodyAndTextParts() | ||
{ | ||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin()); | ||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
|
@@ -61,7 +111,7 @@ public function itShouldLeavePlainTextUnmodified() | |
{ | ||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin()); | ||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
|
@@ -82,7 +132,7 @@ public function itShouldConvertHtmlBodyAsAPart() | |
{ | ||
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); | ||
|
||
$mailer->registerPlugin(new CssInlinerPlugin()); | ||
$mailer->registerPlugin(new CssInlinerPlugin($this->options)); | ||
|
||
$message = Swift_Message::newInstance(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><head><style></style></head><body> | ||
<div class="block" style="height: 20px; width: 100px;"> | ||
text | ||
|
||
<ul><li> | ||
Big list | ||
</li> | ||
<li class="small" style="margin: 10px;"> | ||
Small list | ||
</li> | ||
</ul></div> | ||
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><head><style> | ||
.block { | ||
width: 100px; | ||
height: 20px; | ||
} | ||
div.block ul li.small { | ||
margin: 10px; | ||
} | ||
</style></head><body> | ||
<div style="height: 20px; width: 100px;"> | ||
text | ||
|
||
<ul><li> | ||
Big list | ||
</li> | ||
<li style="margin: 10px;"> | ||
Small list | ||
</li> | ||
</ul></div> | ||
</body></html> |