From 0c113faf62b384e255704af46878d5ba4f40dac5 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 11 Oct 2013 01:13:32 +0200 Subject: [PATCH] added unit test for asset bundles --- tests/unit/data/web/assets/.gitignore | 2 + tests/unit/framework/web/AssetBundleTest.php | 84 ++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/unit/data/web/assets/.gitignore create mode 100644 tests/unit/framework/web/AssetBundleTest.php diff --git a/tests/unit/data/web/assets/.gitignore b/tests/unit/data/web/assets/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tests/unit/data/web/assets/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/unit/framework/web/AssetBundleTest.php b/tests/unit/framework/web/AssetBundleTest.php new file mode 100644 index 0000000..60bb7eb --- /dev/null +++ b/tests/unit/framework/web/AssetBundleTest.php @@ -0,0 +1,84 @@ + + */ + +namespace yiiunit\framework\web; + +use Yii; +use yii\base\View; +use yii\web\AssetBundle; +use yii\web\AssetManager; + +/** + * @group web + */ +class AssetBundleTest extends \yiiunit\TestCase +{ + protected function setUp() + { + parent::setUp(); + $this->mockApplication(); + + Yii::setAlias('@testWeb', '/'); + Yii::setAlias('@testWebRoot', '@yiiunit/data/web'); + } + + protected function getView() + { + $view = new View(); + $view->setAssetManager(new AssetManager(array( + 'basePath' => '@testWebRoot/assets', + 'baseUrl' => '@testWeb/assets', + ))); + + return $view; + } + + public function testRegister() + { + $view = $this->getView(); + + $this->assertEmpty($view->assetBundles); + TestJqueryAsset::register($view); + $this->assertEquals(1, count($view->assetBundles)); + $this->assertArrayHasKey('yiiunit\\framework\\web\\TestJqueryAsset', $view->assetBundles); + } + + public function testSimpleDependency() + { + $view = $this->getView(); + + $this->assertEmpty($view->assetBundles); + 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); + } +} + +class TestAssetBundle extends AssetBundle +{ + public $basePath = '@testWebRoot/files'; + public $baseUrl = '@testWeb/files'; + public $css = array( + 'cssFile.css', + ); + public $js = array( + 'jsFile.js', + ); + public $depends = array( + 'yiiunit\\framework\\web\\TestJqueryAsset' + ); +} + +class TestJqueryAsset extends AssetBundle +{ + public $basePath = '@testWebRoot/js'; + public $baseUrl = '@testWeb/js'; + public $js = array( + 'jquery.js', + ); +} \ No newline at end of file