|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Asmaster\EquipTwig\Tests\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Asmaster\EquipTwig\Exception\LoaderException; |
|
6
|
|
|
use Asmaster\EquipTwig\Loader\FilesystemLoader; |
|
7
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class FilesystemLoaderTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testConstructor() |
|
12
|
|
|
{ |
|
13
|
|
|
$path = __DIR__; |
|
14
|
|
|
$fileExtensions = ['html.twig']; |
|
15
|
|
|
|
|
16
|
|
|
$loader = new FilesystemLoader( |
|
17
|
|
|
$path, |
|
18
|
|
|
$fileExtensions |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
$class = new \ReflectionClass($loader); |
|
22
|
|
|
|
|
23
|
|
|
$propPath = $class->getProperty('path'); |
|
24
|
|
|
$propPath->setAccessible(true); |
|
25
|
|
|
|
|
26
|
|
|
$propFileExtensions = $class->getProperty('fileExtensions'); |
|
27
|
|
|
$propFileExtensions->setAccessible(true); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals($path, $propPath->getValue($loader)); |
|
30
|
|
|
$this->assertEquals($fileExtensions, $propFileExtensions->getValue($loader)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGetSource() |
|
34
|
|
|
{ |
|
35
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
36
|
|
|
$template = 'sugar.html.twig'; |
|
37
|
|
|
|
|
38
|
|
|
$loader = new FilesystemLoader($path); |
|
39
|
|
|
$source = $loader->getSource($template); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals("sugar\n", $source); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGetCacheKey() |
|
45
|
|
|
{ |
|
46
|
|
|
$template = 'sugar.html.twig'; |
|
47
|
|
|
|
|
48
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
49
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $template); |
|
50
|
|
|
|
|
51
|
|
|
$loader = new FilesystemLoader($path); |
|
52
|
|
|
$loader->getSource($template); |
|
53
|
|
|
|
|
54
|
|
|
$cacheKey = $loader->getCacheKey($template); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals($realPath, $cacheKey); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testIsFresh() |
|
60
|
|
|
{ |
|
61
|
|
|
$template = 'sugar.html.twig'; |
|
62
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
63
|
|
|
|
|
64
|
|
|
$loader = new FilesystemLoader($path); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertTrue($loader->isFresh($template, time())); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testExists() |
|
70
|
|
|
{ |
|
71
|
|
|
$template = 'sugar.html.twig'; |
|
72
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
73
|
|
|
|
|
74
|
|
|
$loader = new FilesystemLoader($path); |
|
75
|
|
|
$exists = $loader->exists($template); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertTrue($exists); |
|
78
|
|
|
|
|
79
|
|
|
$loader = new FilesystemLoader($path); |
|
80
|
|
|
$loader->getSource($template); |
|
81
|
|
|
|
|
82
|
|
|
$exists = $loader->exists($template); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertTrue($exists); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testFindTemplateException() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->expectException(LoaderException::class); |
|
90
|
|
|
|
|
91
|
|
|
$loader = new FilesystemLoader('/templates'); |
|
92
|
|
|
$loader->getSource('nowhere.html.twig'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|