-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathExtensionTest.php
More file actions
115 lines (93 loc) · 3.53 KB
/
ExtensionTest.php
File metadata and controls
115 lines (93 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace WebLoader\Test\Nette;
use Nette\Utils\Finder;
class ExtensionTest extends \PHPUnit_Framework_TestCase
{
/** @var \Nette\DI\Container */
private $container;
private function prepareContainer($configFiles)
{
$tempDir = __DIR__ . '/../temp';
foreach (Finder::findFiles('*')->exclude('.gitignore')->from($tempDir . '/cache') as $file) {
unlink((string) $file);
}
$configurator = new \Nette\Configurator();
$configurator->setTempDirectory($tempDir);
foreach ($configFiles as $file) {
$configurator->addConfig($file, FALSE);
}
$configurator->addParameters(array(
'wwwDir' => __DIR__ . '/..',
'fixturesDir' => __DIR__ . '/../fixtures',
'tempDir' => $tempDir,
));
$extension = new \WebLoader\Nette\Extension();
$extension->install($configurator);
$this->container = @$configurator->createContainer(); // sends header X-Powered-By, ...
}
public function testJsCompilerService()
{
$this->prepareContainer(array(__DIR__ . '/../fixtures/extension.neon'));
$this->assertInstanceOf('WebLoader\Compiler', $this->container->getService('webloader.jsDefaultCompiler'));
}
public function testExcludeFiles()
{
$this->prepareContainer(array(__DIR__ . '/../fixtures/extension.neon'));
$files = $this->container->getService('webloader.jsExcludeCompiler')->getFileCollection()->getFiles();
$this->assertTrue(in_array(realpath(__DIR__ . '/../fixtures/a.txt'), $files));
$this->assertFalse(in_array(realpath(__DIR__ . '/../fixtures/dir/one.js'), $files));
}
public function testJoinFilesOn()
{
$this->prepareContainer(array(
__DIR__ . '/../fixtures/extension.neon',
__DIR__ . '/../fixtures/extensionJoinFilesTrue.neon',
));
$this->assertTrue($this->container->getService('webloader.jsDefaultCompiler')->getJoinFiles());
}
public function testJoinFilesOff()
{
$this->prepareContainer(array(
__DIR__ . '/../fixtures/extension.neon',
__DIR__ . '/../fixtures/extensionJoinFilesFalse.neon',
));
$this->assertFalse($this->container->getService('webloader.jsDefaultCompiler')->getJoinFiles());
}
public function testJoinFilesOffInOneService()
{
$this->prepareContainer(array(
__DIR__ . '/../fixtures/extension.neon',
));
$this->assertFalse($this->container->getService('webloader.cssJoinOffCompiler')->getJoinFiles());
}
public function testNonceSet()
{
$this->prepareContainer(array(
__DIR__ . '/../fixtures/extension.neon',
__DIR__ . '/../fixtures/extensionNonce.neon',
));
$this->assertEquals('rAnd0m123', $this->container->getService('webloader.jsDefaultCompiler')->getNonce());
}
public function testNonceNotSet()
{
$this->prepareContainer(array(
__DIR__ . '/../fixtures/extension.neon',
));
$this->assertNull($this->container->getService('webloader.jsDefaultCompiler')->getNonce());
}
public function testExtensionName()
{
$tempDir = __DIR__ . '/../temp';
$class = 'ExtensionNameServiceContainer';
$configurator = new \Nette\Configurator();
$configurator->setTempDirectory($tempDir);
$configurator->addParameters(array('container' => array('class' => $class)));
$configurator->onCompile[] = function ($configurator, \Nette\DI\Compiler $compiler) {
$compiler->addExtension('Foo', new \WebLoader\Nette\Extension());
};
$configurator->addConfig(__DIR__ . '/../fixtures/extensionName.neon', false);
$container = $configurator->createContainer();
$this->assertInstanceOf('WebLoader\Compiler', $container->getService('Foo.cssDefaultCompiler'));
$this->assertInstanceOf('WebLoader\Compiler', $container->getService('Foo.jsDefaultCompiler'));
}
}