1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* For the full copyright and license information, please view the LICENSE |
4
|
|
|
* file that was distributed with this source code. |
5
|
|
|
* 11/05/12 17:20 |
6
|
|
|
*/ |
7
|
|
|
namespace CssEmbed\Tests; |
8
|
|
|
|
9
|
|
|
use CssEmbed\CssEmbed; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Pierre Tachoire <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class CssEmbedTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function testEmbedCss() |
17
|
|
|
{ |
18
|
|
|
$origin = __DIR__.'/rsc/test.css'; |
19
|
|
|
$expected = file_get_contents(__DIR__.'/rsc/expected.css'); |
20
|
|
|
|
21
|
|
|
$cssEmbed = new CssEmbed(); |
22
|
|
|
$tested = $cssEmbed->embedCss($origin); |
23
|
|
|
|
24
|
|
|
$this->assertEquals($expected, $tested); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testEmbedString() |
28
|
|
|
{ |
29
|
|
|
$origin = file_get_contents(__DIR__.'/rsc/test.css'); |
30
|
|
|
$expected = file_get_contents(__DIR__.'/rsc/expected.css'); |
31
|
|
|
|
32
|
|
|
$cssEmbed = new CssEmbed(); |
33
|
|
|
$cssEmbed->setRootDir(__DIR__.'/rsc'); |
34
|
|
|
$tested = $cssEmbed->embedString($origin); |
35
|
|
|
|
36
|
|
|
$this->assertEquals($expected, $tested); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function mimeTypeProvider() |
40
|
|
|
{ |
41
|
|
|
return array( |
42
|
|
|
array('application/octet-stream', 'binary.file'), |
43
|
|
|
array('image/gif', 'php.gif') |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @dataProvider mimeTypeProvider |
49
|
|
|
*/ |
50
|
|
|
public function testMimeType($expected, $file) |
51
|
|
|
{ |
52
|
|
|
$cssEmbed = new CssEmbedTestable(); |
53
|
|
|
$file = __DIR__.'/rsc/'.$file; |
54
|
|
|
$this->assertEquals($expected, $cssEmbed->mimeType($file)); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
class CssEmbedTestable extends CssEmbed |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
public function mimeType($file) |
61
|
|
|
{ |
62
|
|
|
return parent::mimeType($file); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.