/
FactoryTest.php
134 lines (109 loc) · 4.17 KB
/
FactoryTest.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* JBZoo Toolbox - Assets.
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @see https://github.com/JBZoo/Assets
*/
declare(strict_types=1);
namespace JBZoo\PHPUnit;
use JBZoo\Assets\Asset\AbstractAsset;
use JBZoo\Assets\Manager;
use JBZoo\Path\Path;
use JBZoo\Utils\FS;
class FactoryTest extends PHPUnitAssets
{
public function testDefaultParams(): void
{
$params = $this->manager->getParams();
isClass('JBZoo\Data\Data', $params);
isFalse((bool)$params->get('debug'));
isSame([], $params->get('less'));
isSame([
'debug' => false,
'strict_mode' => false,
'less' => [],
], $params->getArrayCopy());
}
public function testReloadParams(): void
{
$manager = new Manager(new Path(), [
'debug' => true,
'some_option' => 123456,
]);
$params = $manager->getParams();
isTrue((bool)$params->get('debug'));
isSame(123456, $params->get('some_option'));
}
public function testCreateUndefinedAssetType(): void
{
$this->expectException(\JBZoo\Assets\Exception::class);
$this->factory->create('test', 'path/to/my-file.undefined');
}
public function testCreateDifferentTypes(): void
{
// CSS File
$asset = $this->factory->create('test', 'file.css');
isClass('JBZoo\Assets\Asset\AbstractAsset', $asset);
isClass('JBZoo\Assets\Asset\AbstractFile', $asset);
isClass('JBZoo\Assets\Asset\CssFile', $asset);
// JS File
$asset = $this->factory->create('test', 'http://site.com/script.js?version=1');
isClass('JBZoo\Assets\Asset\AbstractAsset', $asset);
isClass('JBZoo\Assets\Asset\AbstractFile', $asset);
isClass('JBZoo\Assets\Asset\JsFile', $asset);
// Less File
$asset = $this->factory->create('test', 'file.less');
isClass('JBZoo\Assets\Asset\AbstractAsset', $asset);
isClass('JBZoo\Assets\Asset\AbstractFile', $asset);
isClass('JBZoo\Assets\Asset\LessFile', $asset);
// JS Custom Code
$asset = $this->factory->create('test', 'alert(1);', [], ['type' => AbstractAsset::TYPE_JS_CODE]);
isClass('JBZoo\Assets\Asset\AbstractAsset', $asset);
isClass('JBZoo\Assets\Asset\JsCode', $asset);
// CSS Custom Code
$asset = $this->factory->create('test', 'div{display:block;}', [], ['type' => AbstractAsset::TYPE_CSS_CODE]);
isClass('JBZoo\Assets\Asset\AbstractAsset', $asset);
isClass('JBZoo\Assets\Asset\CssCode', $asset);
}
public function testCreateSimpleAssets(): void
{
$asset = $this->factory->create('test', 'path/to/my-file.css');
isSame('test', $asset->getAlias());
isSame('path/to/my-file.css', $asset->getSource());
isSame([], $asset->getDependencies());
isSame([], $asset->getOptions()->getArrayCopy());
}
public function testCreateByDependenciesIsString(): void
{
$asset = $this->factory->create('test', '\path\to/my-file.JS', 'uikit');
isSame('test', $asset->getAlias());
isSame('\path\to/my-file.JS', $asset->getSource());
isSame(['uikit'], $asset->getDependencies());
isSame([], $asset->getOptions()->getArrayCopy());
}
public function testCreateByDependenciesIsArray(): void
{
$asset = $this->factory->create('test', '\path\to/my-file.css', ['uikit', 'jquery-ui']);
isSame('test', $asset->getAlias());
isSame('\path\to/my-file.css', $asset->getSource());
isSame(['uikit', 'jquery-ui'], $asset->getDependencies());
isSame([], $asset->getOptions()->getArrayCopy());
}
public function testGetRoot(): void
{
$dir = __DIR__;
$path = new Path();
$path->setRoot($dir);
$manager = new Manager($path);
isSame(
FS::clean($dir),
FS::clean($manager->getPath()->getRoot()),
);
}
}