Skip to content

Commit

Permalink
Add JQueryProviderAsset::class. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Feb 28, 2024
1 parent 836c92c commit e107da3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Asset/DateTimePickerAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class DateTimePickerAsset extends AssetBundle
*/
public $depends = [
PopperAsset::class,
JQueryProviderAsset::class,
];

public function __construct()
Expand Down
20 changes: 15 additions & 5 deletions src/Asset/DateTimePickerCdnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,25 @@ public function init(): void
{
parent::init();

$this->css = ['https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.19/dist/css/tempus-dominus.min.css'];
$this->css = ['https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/css/tempus-dominus.min.css'];
$this->cssOptions = [
'crossorigin' => 'anonymous',
'integrity' => 'sha256-CnrhpfYrXdEi7tt7MaXkXnjHOtTw2WUF/ZtHsRYTd9o=',
'rel' => 'stylesheet',
];
$this->js = ['https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.19/dist/js/tempus-dominus.min.js'];
$this->jsOptions = [
'crossorigin' => 'anonymous',
'rel' => 'stylesheet',
$this->js = [
[
'https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/js/jQuery-provider.min.js',
'crossorigin' => 'anonymous',
'integrity' => 'sha256-NMrbeybKZu57CqLc5IecBME3FpiCIhcicPBoZCQ2gXc=',
'rel' => 'stylesheet',
],
[
'https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/js/tempus-dominus.min.js',
'crossorigin' => 'anonymous',
'integrity' => 'sha256-HhK4pzV6V5uvaAYnvGv7rdtJPnECOyPE5ht/eE6dvYw=',
'rel' => 'stylesheet',
],
];
}
}
26 changes: 26 additions & 0 deletions src/Asset/JQueryProviderAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Yii2\Extensions\DateTimePicker\Asset;

use yii\web\AssetBundle;

/**
* Eonasdan DateTimePicker JQuery provider asset bundle.
*/
final class JQueryProviderAsset extends AssetBundle
{
public $sourcePath = '@npm/eonasdan--tempus-dominus/dist/js';

public function __construct()
{
parent::__construct();

$environment = defined('YII_ENV') ? YII_ENV : 'prod';
$jsFiles = $environment === 'prod' ? 'JQuery-provider.min.js' : 'JQuery-provider.js';

$this->js = [$jsFiles];
$this->publishOptions['only'] = [$jsFiles];
}
}
16 changes: 12 additions & 4 deletions tests/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testDateTimePickerAssetSimpleDependency(): void

DateTimePickerAsset::register($this->view);

$this->assertCount(2, $this->view->assetBundles);
$this->assertCount(3, $this->view->assetBundles);

$this->assertInstanceOf(AssetBundle::class, $this->view->assetBundles[DateTimePickerAsset::class]);
$this->assertInstanceOf(AssetBundle::class, $this->view->assetBundles[PopperAsset::class]);
Expand All @@ -39,7 +39,7 @@ public function testDateTimePickerAssetRegister(): void

DateTimePickerAsset::register($this->view);

$this->assertCount(2, $this->view->assetBundles);
$this->assertCount(3, $this->view->assetBundles);

$result = $this->view->renderFile(
__DIR__ . '/Support/main.php',
Expand All @@ -55,6 +55,8 @@ public function testDateTimePickerAssetRegister(): void

$this->assertStringContainsString('css/tempus-dominus.css', $result);
$this->assertStringContainsString('js/tempus-dominus.js', $result);
$this->assertStringContainsString('popper.js', $result);
$this->assertStringContainsString('JQuery-provider.js', $result);
$this->assertStringContainsString('jquery.js', $result);
}

Expand Down Expand Up @@ -93,7 +95,7 @@ public function testDateTimePickerCdnAssetRegister(): void

$this->assertStringContainsString(
<<<HTML
<link href="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.19/dist/css/tempus-dominus.min.css" rel="stylesheet" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/css/tempus-dominus.min.css" rel="stylesheet" crossorigin="anonymous" integrity="sha256-CnrhpfYrXdEi7tt7MaXkXnjHOtTw2WUF/ZtHsRYTd9o=">
HTML,
$result,
);
Expand All @@ -105,7 +107,13 @@ public function testDateTimePickerCdnAssetRegister(): void
);
$this->assertStringContainsString(
<<<HTML
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.19/dist/js/tempus-dominus.min.js" rel="stylesheet" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/js/jQuery-provider.min.js" rel="stylesheet" crossorigin="anonymous" integrity="sha256-NMrbeybKZu57CqLc5IecBME3FpiCIhcicPBoZCQ2gXc="></script>
HTML,
$result,
);
$this->assertStringContainsString(
<<<HTML
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.9.5/dist/js/tempus-dominus.min.js" rel="stylesheet" crossorigin="anonymous" integrity="sha256-HhK4pzV6V5uvaAYnvGv7rdtJPnECOyPE5ht/eE6dvYw="></script>
HTML,
$result,
);
Expand Down

0 comments on commit e107da3

Please sign in to comment.