Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JQueryProviderAsset::class. #14

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
*/
public $depends = [
PopperAsset::class,
JQueryProviderAsset::class,
];

public function __construct()
Expand All @@ -31,6 +32,6 @@

$this->css = [$cssFiles];
$this->js = [$jsFiles];
$this->publishOptions['only'] = [$cssFiles, "$cssFiles.map", $jsFiles, "$jsFiles.map"];

Check warning on line 35 in src/Asset/DateTimePickerAsset.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $jsFiles = $environment === 'prod' ? 'js/tempus-dominus.min.js' : 'js/tempus-dominus.js'; $this->css = [$cssFiles]; $this->js = [$jsFiles]; - $this->publishOptions['only'] = [$cssFiles, "{$cssFiles}.map", $jsFiles, "{$jsFiles}.map"]; + $this->publishOptions['only'] = ["{$cssFiles}.map", $jsFiles, "{$jsFiles}.map"]; } }
}
}
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
Loading