1
|
|
|
<?php namespace Modules\Core\Tests\Asset; |
2
|
|
|
|
3
|
|
|
use Modules\Core\Foundation\Asset\Manager\AsgardAssetManager; |
4
|
|
|
use Modules\Core\Tests\BaseTestCase; |
5
|
|
|
|
6
|
|
|
class AsgardAssetManagerTest extends BaseTestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var \Modules\Core\Foundation\Asset\Manager\AsgardAssetManager |
10
|
|
|
*/ |
11
|
|
|
private $assetManager; |
12
|
|
|
|
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
parent::__construct(); |
|
|
|
|
16
|
|
|
$this->assetManager = new AsgardAssetManager(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** @test */ |
20
|
|
View Code Duplication |
public function it_should_return_empty_collection_if_no_assets() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$cssResult = $this->assetManager->allCss(); |
23
|
|
|
$jsResult = $this->assetManager->allJs(); |
24
|
|
|
|
25
|
|
|
$this->assertInstanceOf('Illuminate\Support\Collection', $cssResult); |
26
|
|
|
$this->assertEquals(0, $cssResult->count()); |
|
|
|
|
27
|
|
|
$this->assertInstanceOf('Illuminate\Support\Collection', $jsResult); |
28
|
|
|
$this->assertEquals(0, $jsResult->count()); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @test */ |
32
|
|
|
public function it_should_add_one_javascript_asset() |
33
|
|
|
{ |
34
|
|
|
$this->assetManager->addAsset('jquery', '/path/to/jquery.js'); |
35
|
|
|
|
36
|
|
|
$jsResult = $this->assetManager->allJs(); |
37
|
|
|
|
38
|
|
|
$this->assertEquals(1, $jsResult->count()); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @test */ |
42
|
|
|
public function it_should_add_one_css_asset() |
43
|
|
|
{ |
44
|
|
|
$this->assetManager->addAsset('main', '/path/to/main.css'); |
45
|
|
|
|
46
|
|
|
$cssResult = $this->assetManager->allCss(); |
47
|
|
|
|
48
|
|
|
$this->assertEquals(1, $cssResult->count()); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @test */ |
52
|
|
View Code Duplication |
public function it_should_add_multiple_assets() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$this->assetManager->addAsset('main', '/path/to/main.css'); |
55
|
|
|
$this->assetManager->addAsset('footer', '/path/to/footer.css'); |
56
|
|
|
$this->assetManager->addAsset('jquery', '/path/to/jquery.js'); |
57
|
|
|
$this->assetManager->addAsset('jquery_plugin', '/path/to/jquery_plugin.js'); |
58
|
|
|
|
59
|
|
|
$cssResults = $this->assetManager->allCss(); |
60
|
|
|
$jsResults = $this->assetManager->allJs(); |
61
|
|
|
|
62
|
|
|
$this->assertEquals(2, $cssResults->count()); |
|
|
|
|
63
|
|
|
$this->assertEquals(2, $jsResults->count()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @test */ |
67
|
|
View Code Duplication |
public function it_should_return_the_dependency_asked_for() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$this->assetManager->addAsset('main', '/path/to/main.css'); |
70
|
|
|
$this->assetManager->addAsset('footer', '/path/to/footer.css'); |
71
|
|
|
$this->assetManager->addAsset('jquery', '/path/to/jquery.js'); |
72
|
|
|
$this->assetManager->addAsset('jquery_plugin', '/path/to/jquery_plugin.js'); |
73
|
|
|
|
74
|
|
|
$jquery = $this->assetManager->getJs('jquery'); |
75
|
|
|
$footer = $this->assetManager->getCss('footer'); |
76
|
|
|
|
77
|
|
|
$this->assertEquals('/path/to/jquery.js', $jquery); |
78
|
|
|
$this->assertEquals('/path/to/footer.css', $footer); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** @test */ |
82
|
|
|
public function it_should_throw_an_exception_if_js_asset_not_found() |
83
|
|
|
{ |
84
|
|
|
$this->setExpectedException('Modules\Core\Foundation\Asset\AssetNotFoundException'); |
85
|
|
|
|
86
|
|
|
$this->assetManager->addAsset('jquery', '/path/to/jquery.js'); |
87
|
|
|
|
88
|
|
|
$this->assetManager->getJs('app'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** @test */ |
92
|
|
|
public function it_should_throw_an_exception_if_css_asset_not_found() |
93
|
|
|
{ |
94
|
|
|
$this->setExpectedException('Modules\Core\Foundation\Asset\AssetNotFoundException'); |
95
|
|
|
|
96
|
|
|
$this->assetManager->addAsset('main', '/path/to/main.css'); |
97
|
|
|
|
98
|
|
|
$this->assetManager->getCss('iCheck'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** @test */ |
102
|
|
|
public function it_should_add_an_array_of_assets() |
103
|
|
|
{ |
104
|
|
|
$this->assetManager->addAssets([ |
105
|
|
|
'jquery' => '/path/to/jquery.js', |
106
|
|
|
'plugin' => '/path/to/plugin.js', |
107
|
|
|
'main' => '/path/to/main.css', |
108
|
|
|
'icheck' => '/path/to/icheck.css', |
109
|
|
|
]); |
110
|
|
|
|
111
|
|
|
$jsAssets = $this->assetManager->allJs(); |
112
|
|
|
$cssAssets = $this->assetManager->allCss(); |
113
|
|
|
|
114
|
|
|
$expectedJs = [ |
115
|
|
|
'jquery' => '/path/to/jquery.js', |
116
|
|
|
'plugin' => '/path/to/plugin.js', |
117
|
|
|
]; |
118
|
|
|
$expectedCss = [ |
119
|
|
|
'main' => '/path/to/main.css', |
120
|
|
|
'icheck' => '/path/to/icheck.css', |
121
|
|
|
]; |
122
|
|
|
|
123
|
|
|
$this->assertEquals($expectedJs, $jsAssets->toArray()); |
|
|
|
|
124
|
|
|
$this->assertEquals($expectedCss, $cssAssets->toArray()); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.