|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use InvalidArgumentException; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper; |
|
17
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
|
18
|
|
|
use WBW\Bundle\CoreBundle\Tests\Fixtures\Helper\TestAssetsHelper; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Assets helper test. |
|
22
|
|
|
* |
|
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
24
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Helper |
|
25
|
|
|
*/ |
|
26
|
|
|
class AssetsHelperTest extends AbstractTestCase { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Directory "assets". |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $directoryAssets; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Directory "illegal". |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
private $directoryIllegal; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Directory "public". |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
private $directoryPublic; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function setUp(): void { |
|
53
|
|
|
parent::setUp(); |
|
54
|
|
|
|
|
55
|
|
|
// Set the directories. |
|
56
|
|
|
$this->directoryAssets = getcwd() . "/Resources/assets"; |
|
57
|
|
|
$this->directoryIllegal = getcwd() . "/composer.json"; |
|
58
|
|
|
$this->directoryPublic = getcwd() . "/Resources/public"; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Tests the listAssets() method. |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testListAssets(): void { |
|
68
|
|
|
|
|
69
|
|
|
// Load the YAML configuration. |
|
70
|
|
|
$config = ConfigurationHelper::loadYamlConfig(getcwd() . "/DependencyInjection", "assets"); |
|
71
|
|
|
$plugins = $config["assets"]["wbw.core.asset.core"]["plugins"]; |
|
72
|
|
|
|
|
73
|
|
|
$res = TestAssetsHelper::listAssets($this->directoryAssets); |
|
74
|
|
|
$this->assertCount(14, $res); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertRegExp("/animate\.css\-" . preg_quote($plugins["animate_css"]["version"]) . "\.zip$/", $res[0]); |
|
77
|
|
|
$this->assertRegExp("/clippy\.js\.zip$/", $res[1]); |
|
78
|
|
|
$this->assertRegExp("/fontawesome\-" . preg_quote($plugins["font_awesome"]["version"]) . "\.zip$/", $res[2]); |
|
79
|
|
|
$this->assertRegExp("/jquery\-" . preg_quote($plugins["jquery"]["version"]) . "\.zip$/", $res[3]); |
|
80
|
|
|
$this->assertRegExp("/jquery\-easyautocomplete\-" . preg_quote($plugins["jquery_easy_autocomplete"]["version"]) . "\.zip$/", $res[4]); |
|
81
|
|
|
$this->assertRegExp("/jquery\-inputmask\-" . preg_quote($plugins["jquery_input_mask"]["version"]) . "\.zip$/", $res[5]); |
|
82
|
|
|
$this->assertRegExp("/jquery\-select2\-" . preg_quote($plugins["jquery_select2"]["version"]) . "\.zip$/", $res[6]); |
|
83
|
|
|
$this->assertRegExp("/material\-design\-color\-palette\-" . preg_quote($plugins["material_design_color_palette"]["version"]) . "\.zip$/", $res[7]); |
|
84
|
|
|
$this->assertRegExp("/material\-design\-hierarchical\-display\-" . preg_quote($plugins["material_design_hierarchical_display"]["version"]) . "\.zip$/", $res[8]); |
|
85
|
|
|
$this->assertRegExp("/material\-design\-iconic\-font\-" . preg_quote($plugins["material_design_iconic_font"]["version"]) . "\.zip$/", $res[9]); |
|
86
|
|
|
$this->assertRegExp("/meteocons\.zip$/", $res[10]); |
|
87
|
|
|
$this->assertRegExp("/sweetalert\-" . preg_quote($plugins["sweet_alert"]["version"]) . "\.zip$/", $res[11]); |
|
88
|
|
|
$this->assertRegExp("/syntaxhighlighter\-" . preg_quote($plugins["syntax_highlighter"]["version"]) . "\.zip$/", $res[12]); |
|
89
|
|
|
$this->assertRegExp("/waitme\-" . preg_quote($plugins["wait_me"]["version"]) . "\.zip$/", $res[13]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Tests the listAssets() method. |
|
94
|
|
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
|
public function testListAssetsWithInvalidArgumentException(): void { |
|
98
|
|
|
|
|
99
|
|
|
try { |
|
100
|
|
|
|
|
101
|
|
|
TestAssetsHelper::listAssets($this->directoryIllegal); |
|
102
|
|
|
} catch (Exception $ex) { |
|
103
|
|
|
|
|
104
|
|
|
$this->assertInstanceOf(InvalidArgumentException::class, $ex); |
|
105
|
|
|
$this->assertEquals('"' . $this->directoryIllegal . '" is not a directory', $ex->getMessage()); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Tests the unzipAssets() method. |
|
111
|
|
|
* |
|
112
|
|
|
* @return void |
|
113
|
|
|
* @throws Exception Throws an exception if an error occurs. |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testUnzipAssets(): void { |
|
116
|
|
|
|
|
117
|
|
|
$res = TestAssetsHelper::unzipAssets($this->directoryAssets, $this->directoryPublic); |
|
118
|
|
|
$this->assertCount(14, $res); |
|
119
|
|
|
|
|
120
|
|
|
foreach ($res as $k => $v) { |
|
121
|
|
|
$this->assertDirectoryExists(str_replace([$this->directoryAssets, ".zip"], [$this->directoryPublic, ""], $k)); |
|
122
|
|
|
$this->assertTrue($v); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Tests the unzipAssets() method. |
|
128
|
|
|
* |
|
129
|
|
|
* @return void |
|
130
|
|
|
*/ |
|
131
|
|
|
public function testUnzipAssetsWithInvalidArgumentException(): void { |
|
132
|
|
|
|
|
133
|
|
|
try { |
|
134
|
|
|
|
|
135
|
|
|
TestAssetsHelper::unzipAssets($this->directoryAssets, $this->directoryIllegal); |
|
136
|
|
|
} catch (Exception $ex) { |
|
137
|
|
|
|
|
138
|
|
|
$this->assertInstanceOf(InvalidArgumentException::class, $ex); |
|
139
|
|
|
$this->assertEquals('"' . $this->directoryIllegal . '" is not a directory', $ex->getMessage()); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|