1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bummzack\SilverStripeEmogrify\Tests; |
4
|
|
|
|
5
|
|
|
use Bummzack\SilverStripeEmogrify\EmogrifierPlugin; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Core\Path; |
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
9
|
|
|
|
10
|
|
|
class EmogrifierPluginTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
protected $usesDatabase = false; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
Config::modify()->remove(EmogrifierPlugin::class, 'css_file'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testLoadCssFromConfig() |
22
|
|
|
{ |
23
|
|
|
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css'; |
24
|
|
|
Config::modify()->set(EmogrifierPlugin::class, 'css_file', $file); |
25
|
|
|
|
26
|
|
|
$plugin = new EmogrifierPlugin(); |
27
|
|
|
$this->assertEquals($plugin->getCss(), file_get_contents($file)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testLoadCssFromFile() |
31
|
|
|
{ |
32
|
|
|
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'EmogrifierPluginTest.css'; |
33
|
|
|
|
34
|
|
|
$plugin = new EmogrifierPlugin(); |
35
|
|
|
$plugin->loadCssFromFile($file); |
36
|
|
|
$this->assertEquals($plugin->getCss(), file_get_contents($file)); |
37
|
|
|
|
38
|
|
|
$this->expectException(\InvalidArgumentException::class); |
39
|
|
|
$this->expectExceptionMessage('File "' . __FILE__ . '" does not have .css extension.'); |
40
|
|
|
$plugin->loadCssFromFile(__FILE__); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testLoadNonExistantCssFile() |
44
|
|
|
{ |
45
|
|
|
$this->expectException(\InvalidArgumentException::class); |
46
|
|
|
$this->expectExceptionMessage('File at "'. Path::join(BASE_PATH, 'testDummy.css') .'" does not exist'); |
47
|
|
|
$plugin = new EmogrifierPlugin(); |
48
|
|
|
$plugin->loadCssFromFile('testDummy.css'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|