Skip to content

Commit

Permalink
Update for SilverStripe 4.9 / Swiftmailer 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bummzack committed Oct 11, 2021
1 parent 53370d9 commit 7f632e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 49 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
sudo: false
dist: trusty

env:
global:
Expand All @@ -9,21 +8,21 @@ env:

matrix:
include:
- php: 5.6
- php: 7.2
env:
- PHP5=1
- PHPCS_TEST=1
- PHPUNIT_TEST=1
- php: 7.0
env:
- PHPUNIT_TEST=1
- php: 7.4
env:
- PHPUNIT_COVERAGE_TEST=1
- php: 8.0
env:
- PHPUNIT_TEST=1


before_script:
# Init PHP
- composer self-update || true
- composer self-update --2 || true
- phpenv rehash
- phpenv config-rm xdebug.ini || true

Expand All @@ -32,7 +31,6 @@ before_script:
- composer update

script:
- if [[ $PHP5 ]]; then composer require silverstripe/assets 1.4.8; fi
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then composer run-script lint; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Easily integrate Emogrifier into SilverStripe and send Emails with inlined CSS a
## Installation and Requirements

- Requires the [EmogrifierPlugin](https://github.com/bummzack/swiftmailer-emogrifyplugin) and its dependencies.
- SilverStripe 4.1+
- SilverStripe 4.9+

Install via composer:

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
"emogrifier"
],
"require": {
"silverstripe/framework": "^4.1",
"silverstripe/assets": "^1.1",
"bummzack/swiftmailer-emogrifyplugin" : "^0.2"
"php": "^7.2 || ^8.0",
"silverstripe/framework": "^4.9",
"bummzack/swiftmailer-emogrifyplugin" : "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3"
},
"extra": {
"branch-alias": {
"dev-master": "0.x-dev"
"dev-master": "1.x-dev"
}
},
"autoload": {
Expand Down
10 changes: 3 additions & 7 deletions src/EmogrifierPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Bummzack\SilverStripeEmogrify;

use Pelago\Emogrifier;
use SilverStripe\Assets\File;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Path;
Expand All @@ -22,18 +21,15 @@ class EmogrifierPlugin extends \Bummzack\SwiftMailer\EmogrifyPlugin\EmogrifierPl
* Can be set via config YAML.
*
* @config
* @var string
* @var string|null
*/
private static $css_file = null;

/**
* EmogrifierPlugin constructor.
* @param Emogrifier|null $emogrifier
*/
public function __construct(Emogrifier $emogrifier = null)
public function __construct()
{
parent::__construct($emogrifier);

if ($file = $this->config()->css_file) {
$this->loadCssFromFile($file);
}
Expand Down Expand Up @@ -61,7 +57,7 @@ public function loadCssFromFile($file)
throw new \InvalidArgumentException('File "' . $path . '" does not have .css extension.');
}

$this->getEmogrifier()->setCss(file_get_contents($path));
$this->setCss(file_get_contents($path));

return $this;
}
Expand Down
35 changes: 6 additions & 29 deletions tests/EmogrifierPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Bummzack\SilverStripeEmogrify\Tests;

use Bummzack\SilverStripeEmogrify\EmogrifierPlugin;
use Pelago\Emogrifier;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Path;
use SilverStripe\Dev\SapphireTest;

class EmogrifierPluginTest extends SapphireTest
{
protected $usesDatabase = false;

public function setUp()
{
parent::setUp();
Expand All @@ -22,15 +23,17 @@ public function testLoadCssFromConfig()
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css';
Config::modify()->set(EmogrifierPlugin::class, 'css_file', $file);

new EmogrifierPlugin($this->createMockEmogrifier());
$plugin = new EmogrifierPlugin();
$this->assertEquals($plugin->getCss(), file_get_contents($file));
}

public function testLoadCssFromFile()
{
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css';

$plugin = new EmogrifierPlugin($this->createMockEmogrifier());
$plugin = new EmogrifierPlugin();
$plugin->loadCssFromFile($file);
$this->assertEquals($plugin->getCss(), file_get_contents($file));

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('File "' . __FILE__ . '" does not have .css extension.');
Expand All @@ -44,30 +47,4 @@ public function testLoadNonExistantCssFile()
$plugin = new EmogrifierPlugin();
$plugin->loadCssFromFile('testDummy.css');
}

/**
* Create a mock emogrifier instance to ensure the CSS that is being set will match the code from the test file.
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createMockEmogrifier()
{
$css = <<<EOT
.test {
color: green;
}
EOT;

$emogrifier = $this->getMockBuilder(Emogrifier::class)
->disableOriginalConstructor()
->getMock();

$emogrifier->expects($this->once())
->method('setCss')
->with(
$this->equalTo($css)
);

return $emogrifier;
}
}

0 comments on commit 7f632e8

Please sign in to comment.