|
|
|
@ -45,6 +45,13 @@ class AssetBundleTest extends \yiiunit\TestCase
|
|
|
|
|
TestJqueryAsset::register($view); |
|
|
|
|
$this->assertEquals(1, count($view->assetBundles)); |
|
|
|
|
$this->assertArrayHasKey('yiiunit\\framework\\web\\TestJqueryAsset', $view->assetBundles); |
|
|
|
|
$this->assertTrue($view->assetBundles['yiiunit\\framework\\web\\TestJqueryAsset'] instanceof AssetBundle); |
|
|
|
|
|
|
|
|
|
$expected = <<<EOF |
|
|
|
|
123<script src="/js/jquery.js"></script> |
|
|
|
|
4 |
|
|
|
|
EOF; |
|
|
|
|
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testSimpleDependency() |
|
|
|
@ -56,6 +63,125 @@ class AssetBundleTest extends \yiiunit\TestCase
|
|
|
|
|
$this->assertEquals(2, count($view->assetBundles)); |
|
|
|
|
$this->assertArrayHasKey('yiiunit\\framework\\web\\TestAssetBundle', $view->assetBundles); |
|
|
|
|
$this->assertArrayHasKey('yiiunit\\framework\\web\\TestJqueryAsset', $view->assetBundles); |
|
|
|
|
$this->assertTrue($view->assetBundles['yiiunit\\framework\\web\\TestAssetBundle'] instanceof AssetBundle); |
|
|
|
|
$this->assertTrue($view->assetBundles['yiiunit\\framework\\web\\TestJqueryAsset'] instanceof AssetBundle); |
|
|
|
|
|
|
|
|
|
$expected = <<<EOF |
|
|
|
|
1<link href="/files/cssFile.css" rel="stylesheet"> |
|
|
|
|
23<script src="/js/jquery.js"></script> |
|
|
|
|
<script src="/files/jsFile.js"></script> |
|
|
|
|
4 |
|
|
|
|
EOF; |
|
|
|
|
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function positionProvider() |
|
|
|
|
{ |
|
|
|
|
return array( |
|
|
|
|
array(View::POS_HEAD, true), |
|
|
|
|
array(View::POS_HEAD, false), |
|
|
|
|
array(View::POS_BEGIN, true), |
|
|
|
|
array(View::POS_BEGIN, false), |
|
|
|
|
array(View::POS_END, true), |
|
|
|
|
array(View::POS_END, false), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider positionProvider |
|
|
|
|
*/ |
|
|
|
|
public function testPositionDependency($pos, $jqAlreadyRegistered) |
|
|
|
|
{ |
|
|
|
|
$view = $this->getView(); |
|
|
|
|
|
|
|
|
|
$view->getAssetManager()->bundles['yiiunit\\framework\\web\\TestAssetBundle'] = array( |
|
|
|
|
'jsOptions' => array( |
|
|
|
|
'position' => $pos, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->assertEmpty($view->assetBundles); |
|
|
|
|
if ($jqAlreadyRegistered) { |
|
|
|
|
TestJqueryAsset::register($view); |
|
|
|
|
} |
|
|
|
|
TestAssetBundle::register($view); |
|
|
|
|
$this->assertEquals(2, count($view->assetBundles)); |
|
|
|
|
$this->assertArrayHasKey('yiiunit\\framework\\web\\TestAssetBundle', $view->assetBundles); |
|
|
|
|
$this->assertArrayHasKey('yiiunit\\framework\\web\\TestJqueryAsset', $view->assetBundles); |
|
|
|
|
|
|
|
|
|
$this->assertTrue($view->assetBundles['yiiunit\\framework\\web\\TestAssetBundle'] instanceof AssetBundle); |
|
|
|
|
$this->assertTrue($view->assetBundles['yiiunit\\framework\\web\\TestJqueryAsset'] instanceof AssetBundle); |
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('position', $view->assetBundles['yiiunit\\framework\\web\\TestAssetBundle']->jsOptions); |
|
|
|
|
$this->assertEquals($pos, $view->assetBundles['yiiunit\\framework\\web\\TestAssetBundle']->jsOptions['position']); |
|
|
|
|
$this->assertArrayHasKey('position', $view->assetBundles['yiiunit\\framework\\web\\TestJqueryAsset']->jsOptions); |
|
|
|
|
$this->assertEquals($pos, $view->assetBundles['yiiunit\\framework\\web\\TestJqueryAsset']->jsOptions['position']); |
|
|
|
|
|
|
|
|
|
switch($pos) |
|
|
|
|
{ |
|
|
|
|
case View::POS_HEAD: |
|
|
|
|
$expected = <<<EOF |
|
|
|
|
1<link href="/files/cssFile.css" rel="stylesheet"> |
|
|
|
|
<script src="/js/jquery.js"></script> |
|
|
|
|
<script src="/files/jsFile.js"></script> |
|
|
|
|
234 |
|
|
|
|
EOF; |
|
|
|
|
break; |
|
|
|
|
case View::POS_BEGIN: |
|
|
|
|
$expected = <<<EOF |
|
|
|
|
1<link href="/files/cssFile.css" rel="stylesheet"> |
|
|
|
|
2<script src="/js/jquery.js"></script> |
|
|
|
|
<script src="/files/jsFile.js"></script> |
|
|
|
|
34 |
|
|
|
|
EOF; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
case View::POS_END: |
|
|
|
|
$expected = <<<EOF |
|
|
|
|
1<link href="/files/cssFile.css" rel="stylesheet"> |
|
|
|
|
23<script src="/js/jquery.js"></script> |
|
|
|
|
<script src="/files/jsFile.js"></script> |
|
|
|
|
4 |
|
|
|
|
EOF; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function positionProvider2() |
|
|
|
|
{ |
|
|
|
|
return array( |
|
|
|
|
array(View::POS_BEGIN, true), |
|
|
|
|
array(View::POS_BEGIN, false), |
|
|
|
|
array(View::POS_END, true), |
|
|
|
|
array(View::POS_END, false), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider positionProvider |
|
|
|
|
*/ |
|
|
|
|
public function testPositionDependencyConflict($pos, $jqAlreadyRegistered) |
|
|
|
|
{ |
|
|
|
|
$view = $this->getView(); |
|
|
|
|
|
|
|
|
|
$view->getAssetManager()->bundles['yiiunit\\framework\\web\\TestAssetBundle'] = array( |
|
|
|
|
'jsOptions' => array( |
|
|
|
|
'position' => $pos - 1, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
$view->getAssetManager()->bundles['yiiunit\\framework\\web\\TestJqueryAsset'] = array( |
|
|
|
|
'jsOptions' => array( |
|
|
|
|
'position' => $pos, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->assertEmpty($view->assetBundles); |
|
|
|
|
if ($jqAlreadyRegistered) { |
|
|
|
|
TestJqueryAsset::register($view); |
|
|
|
|
} |
|
|
|
|
$this->setExpectedException('yii\\base\\InvalidConfigException'); |
|
|
|
|
TestAssetBundle::register($view); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|