From 81cc1added095ebaef2345fa59d8701700b25bcc Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:02:50 +0100 Subject: [PATCH 01/29] Fix assertViewIs is not working (#67) Co-authored-by: Jackson Tong --- src/Features/AutoInjectRappasoftAssets.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 791bf876c..b3a5e9a11 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -57,7 +57,9 @@ public static function provide(): void $html = $handled->response->getContent(); if (str($html)->contains('')) { + $original = $handled->response->original; $handled->response->setContent(static::injectAssets($html)); + $handled->response->original = $original; } }); } From 288f2b5f4ade3243331d304fb7df66c124999ede Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:05:16 +0100 Subject: [PATCH 02/29] Check for "original" property --- src/Features/AutoInjectRappasoftAssets.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index b3a5e9a11..7aeeedd2d 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -40,6 +40,10 @@ public static function provide(): void if (! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent')) { return; } + + if (! property_exists($handled->response, 'original')) { + return; + } if ((! static::$hasRenderedAComponentThisRequest) && (! static::$forceAssetInjection)) { return; From 4239cf6e40c8964e2df5ed338cc10ad8ca41acdd Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sun, 24 Sep 2023 17:05:38 +0000 Subject: [PATCH 03/29] Fix styling --- src/Features/AutoInjectRappasoftAssets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 7aeeedd2d..c548b9fc5 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -40,7 +40,7 @@ public static function provide(): void if (! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent')) { return; } - + if (! property_exists($handled->response, 'original')) { return; } From 6a180d130abb6e4aaa13fd448df4ad77614f444f Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:23:35 +0100 Subject: [PATCH 04/29] Adjusting order of request validations --- src/Features/AutoInjectRappasoftAssets.php | 30 +++++++++------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index c548b9fc5..06b6d62c7 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Http\Events\RequestHandled; use Livewire\ComponentHook; use Rappasoft\LaravelLivewireTables\Mechanisms\RappasoftFrontendAssets; +use Illuminate\Support\Facades\Log; use function Livewire\on; @@ -25,26 +26,25 @@ public static function provide(): void return; } - app('events')->listen(RequestHandled::class, function ($handled) { - + app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { + if (! static::$forceAssetInjection && config('livewire-tables.inject_assets', true) === false) { return; } + if (! str($handled->response->headers->get('content-type'))->contains('text/html')) { return; } - if (! method_exists($handled->response, 'status') || $handled->response->status() !== 200) { - return; - } - if (! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent')) { + if (! method_exists($handled->response, 'status') || ! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent') || ! method_exists($handled->response, 'getOriginalContent') || ! property_exists($handled->response, 'original')) { return; } - if (! property_exists($handled->response, 'original')) { + if ($handled->response->status() !== 200) { return; } + if ((! static::$hasRenderedAComponentThisRequest) && (! static::$forceAssetInjection)) { return; } @@ -61,7 +61,7 @@ public static function provide(): void $html = $handled->response->getContent(); if (str($html)->contains('')) { - $original = $handled->response->original; + $original = $handled->response->getOriginalContent(); $handled->response->setContent(static::injectAssets($html)); $handled->response->original = $original; } @@ -75,25 +75,19 @@ public function dehydrate(): void public static function injectAssets(mixed $html): string { - $rappasoftTableStyles = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : ''; - $rappasoftTableScripts = config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : ''; - $rappasoftTableThirdPartyStyles = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''; - //$rappasoftTableThirdPartyStyles = ''; - $rappasoftTableThirdPartyScripts = config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : ''; - //$rappasoftTableThirdPartyScripts = ''; $html = str($html); if ($html->test('/<\s*head(?:\s|\s[^>])*>/i') && $html->test('/<\s*\/\s*body\s*>/i')) { return $html - ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.($rappasoftTableStyles.' '.$rappasoftTableThirdPartyStyles)) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ($rappasoftTableScripts.' '.$rappasoftTableThirdPartyScripts).'$1') + ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '')).'$1') ->toString(); } return $html - ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.($rappasoftTableStyles.' '.$rappasoftTableThirdPartyStyles)) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ($rappasoftTableScripts.' '.$rappasoftTableThirdPartyScripts).'$1') + ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '')).'$1') ->toString(); } } From ea14f2e65de2fbf7a3201f7bb16659a764f8d964 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sun, 24 Sep 2023 17:23:58 +0000 Subject: [PATCH 05/29] Fix styling --- src/Features/AutoInjectRappasoftAssets.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 06b6d62c7..e81d1a99e 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -5,7 +5,6 @@ use Illuminate\Foundation\Http\Events\RequestHandled; use Livewire\ComponentHook; use Rappasoft\LaravelLivewireTables\Mechanisms\RappasoftFrontendAssets; -use Illuminate\Support\Facades\Log; use function Livewire\on; @@ -27,11 +26,11 @@ public static function provide(): void } app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { - + if (! static::$forceAssetInjection && config('livewire-tables.inject_assets', true) === false) { return; } - + if (! str($handled->response->headers->get('content-type'))->contains('text/html')) { return; } @@ -44,7 +43,6 @@ public static function provide(): void return; } - if ((! static::$hasRenderedAComponentThisRequest) && (! static::$forceAssetInjection)) { return; } From 80bb100a15d4f190a6600f7eacc59ad234cfada3 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 19:19:22 +0100 Subject: [PATCH 06/29] Updates to Asset Injection Methods --- CHANGELOG.md | 6 ++++++ config/livewire-tables.php | 15 ++++++++++++--- src/Features/AutoInjectRappasoftAssets.php | 8 ++++---- src/LaravelLivewireTablesServiceProvider.php | 6 +++--- src/Mechanisms/RappasoftFrontendAssets.php | 12 ++++++++---- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf565fc8a..8fa2e521e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## [Unreleased] - 3.x - Updates to Injection Methods +- Add use_bundler option to configuration (disables all FrontendAsset methods) +- Amend AutoInjection/FrontendAsset to ensure it returns the original content correctly +- Remove errant disabling of Blade Directives when disabling auto-injection +- Amended in-line config documentation + ## [Unreleased] - 3.x - setSearchFieldAttributes - Add setSearchFieldAttributes() and getSearchFieldAttributes() diff --git a/config/livewire-tables.php b/config/livewire-tables.php index 3161f9280..9d8a51acb 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -6,7 +6,11 @@ */ 'theme' => 'tailwind', - 'cache_assets' => true, + /** + * Cache Rappasoft Frontend Assets (For 1 hour) + */ + 'cache_assets' => false, + /** * Enable or Disable automatic injection of assets */ @@ -15,7 +19,7 @@ /** * Enable or Disable automatic injection of assets */ - 'inject_third_party_assets' => false, + 'inject_third_party_assets' => true, /** * Enable or Disable inclusion of published third-party assets @@ -25,7 +29,12 @@ /** * Enable or Disable remote third-party assets */ - 'remote_third_party_assets' => true, + 'remote_third_party_assets' => false, + + /** + * Enable if using a bundler instead of injecting assets/scripts or using blade directives + */ + 'use_bundler' => false, /** * Configuration options for DateFilter diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index e81d1a99e..bd6871cdc 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -78,14 +78,14 @@ public static function injectAssets(mixed $html): string if ($html->test('/<\s*head(?:\s|\s[^>])*>/i') && $html->test('/<\s*\/\s*body\s*>/i')) { return $html - ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') ->toString(); } return $html - ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? RappasoftFrontendAssets::tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') ->toString(); } } diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index fe6387d96..55c6e23e4 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -46,8 +46,7 @@ public function boot(): void ]); } - if (config('livewire-tables.inject_assets', true) === true) { - + if (config('livewire-tables.use_bundler', false) === true) { (new RappasoftFrontendAssets)->boot(); } @@ -58,10 +57,11 @@ public function register(): void $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' ); - if (config('livewire-tables.inject_assets', true) === true) { + if (config('livewire-tables.use_bundler', false) === true) { (new RappasoftFrontendAssets)->register(); ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); } + } } diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index 3af34cb5c..6958964f9 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -31,7 +31,6 @@ public function boot(): void return Route::get($scriptPath, $handle); }); - Blade::directive('rappasoftTableScripts', [static::class, 'rappasoftTableScripts']); // Set the CSS route for the core tables CSS app($this::class)->setRappasoftTableStylesRoute(function ($handle) { @@ -40,7 +39,6 @@ public function boot(): void return Route::get($stylesPath, $handle); }); - Blade::directive('rappasoftTableStyles', [static::class, 'rappasoftTableStyles']); // Set the JS route for the third party JS app($this::class)->setRappasoftTableThirdPartyScriptRoute(function ($handle) { @@ -49,7 +47,6 @@ public function boot(): void return Route::get($scriptPath, $handle); }); - Blade::directive('rappasoftTableThirdPartyScripts', [static::class, 'rappasoftTableThirdPartyScripts']); // Set the CSS route for the third party CSS app($this::class)->setRappasoftTableThirdPartyStylesRoute(function ($handle) { @@ -58,8 +55,15 @@ public function boot(): void return Route::get($stylesPath, $handle); }); - Blade::directive('rappasoftTableThirdPartyStyles', [static::class, 'rappasoftTableThirdPartyStyles']); + static::registerBladeDirectives(); + } + protected function registerBladeDirectives() + { + Blade::directive('rappasoftTableScripts', [static::class, 'rappasoftTableScripts']); + Blade::directive('rappasoftTableStyles', [static::class, 'rappasoftTableStyles']); + Blade::directive('rappasoftTableThirdPartyScripts', [static::class, 'rappasoftTableThirdPartyScripts']); + Blade::directive('rappasoftTableThirdPartyStyles', [static::class, 'rappasoftTableThirdPartyStyles']); } protected function pretendResponseIsJs(string $file): \Symfony\Component\HttpFoundation\Response From 710857d9fe266b341f0bbb759bcb957f63c42953 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sun, 24 Sep 2023 18:19:48 +0000 Subject: [PATCH 07/29] Fix styling --- config/livewire-tables.php | 2 +- src/Mechanisms/RappasoftFrontendAssets.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/config/livewire-tables.php b/config/livewire-tables.php index 9d8a51acb..dee257684 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -6,7 +6,7 @@ */ 'theme' => 'tailwind', - /** + /** * Cache Rappasoft Frontend Assets (For 1 hour) */ 'cache_assets' => false, diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index 6958964f9..aa22ec034 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -31,7 +31,6 @@ public function boot(): void return Route::get($scriptPath, $handle); }); - // Set the CSS route for the core tables CSS app($this::class)->setRappasoftTableStylesRoute(function ($handle) { $stylesPath = '/rappasoft/laravel-livewire-tables/core.min.css'; @@ -39,7 +38,6 @@ public function boot(): void return Route::get($stylesPath, $handle); }); - // Set the JS route for the third party JS app($this::class)->setRappasoftTableThirdPartyScriptRoute(function ($handle) { $scriptPath = '/rappasoft/laravel-livewire-tables/thirdparty.min.js'; @@ -47,7 +45,6 @@ public function boot(): void return Route::get($scriptPath, $handle); }); - // Set the CSS route for the third party CSS app($this::class)->setRappasoftTableThirdPartyStylesRoute(function ($handle) { $stylesPath = '/rappasoft/laravel-livewire-tables/thirdparty.css'; From a80e26127536a3620834e84dd0c4a2b60f21d347 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 19:22:12 +0100 Subject: [PATCH 08/29] Fix ServiceProvider true/false mistake --- src/LaravelLivewireTablesServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index 55c6e23e4..62d80e5bf 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -46,7 +46,7 @@ public function boot(): void ]); } - if (config('livewire-tables.use_bundler', false) === true) { + if (config('livewire-tables.use_bundler', false) === false) { (new RappasoftFrontendAssets)->boot(); } @@ -57,7 +57,7 @@ public function register(): void $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' ); - if (config('livewire-tables.use_bundler', false) === true) { + if (config('livewire-tables.use_bundler', false) === false) { (new RappasoftFrontendAssets)->register(); ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); From b1b29baa38c1a92028e963fa37411796e6055af4 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Sun, 24 Sep 2023 19:36:52 +0100 Subject: [PATCH 09/29] Using the app singleton for RappasoftFrontendAssets, adding comments --- src/Features/AutoInjectRappasoftAssets.php | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index bd6871cdc..6dd433d84 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -21,13 +21,14 @@ public static function provide(): void static::$forceAssetInjection = false; }); - if (config('livewire-tables.inject_assets', true) === false) { + // If config use_bundler is true - abort injection of assets + if (config('livewire-tables.use_bundler', false) === true) { return; } app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { - if (! static::$forceAssetInjection && config('livewire-tables.inject_assets', true) === false) { + if (! static::$forceAssetInjection && (config('livewire-tables.use_bundler', false) === true || ! static::$hasRenderedAComponentThisRequest)) { return; } @@ -43,19 +44,11 @@ public static function provide(): void return; } - if ((! static::$hasRenderedAComponentThisRequest) && (! static::$forceAssetInjection)) { - return; - } - if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false) { - return; - } - if (config('livewire-tables.inject_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts && config('livewire-tables.inject_third_party_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { - return; - } elseif (config('livewire-tables.inject_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) { - return; - } elseif (config('livewire-tables.inject_third_party_assets', true) === true && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { + if (!static::shouldInjectAssets()) + { return; } + $html = $handled->response->getContent(); if (str($html)->contains('')) { @@ -66,6 +59,28 @@ public static function provide(): void }); } + public static function shouldInjectAssets(): bool + { + // If Neither Core nor Third Party Assets are injectable + if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false ) { + return false; + } + + // If Core Assets are Injectable, BUT have not been + if (config('livewire-tables.inject_assets', true) === true && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) + { + return true; + } + + // If Third Party Assets are Injectable, BUT have not been + if (config('livewire-tables.inject_third_party_assets', true) === true && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { + return true; + } + + // Fall Back to Not Injecting + return false; + } + public function dehydrate(): void { static::$hasRenderedAComponentThisRequest = true; From 7237ca8f4adfde48f335fcc97b5734b276e3f493 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Sun, 24 Sep 2023 18:37:20 +0000 Subject: [PATCH 10/29] Fix styling --- src/Features/AutoInjectRappasoftAssets.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 6dd433d84..951327361 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -44,11 +44,10 @@ public static function provide(): void return; } - if (!static::shouldInjectAssets()) - { + if (! static::shouldInjectAssets()) { return; } - + $html = $handled->response->getContent(); if (str($html)->contains('')) { @@ -62,21 +61,20 @@ public static function provide(): void public static function shouldInjectAssets(): bool { // If Neither Core nor Third Party Assets are injectable - if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false ) { + if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false) { return false; } - + // If Core Assets are Injectable, BUT have not been - if (config('livewire-tables.inject_assets', true) === true && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) - { + if (config('livewire-tables.inject_assets', true) === true && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) { return true; } // If Third Party Assets are Injectable, BUT have not been - if (config('livewire-tables.inject_third_party_assets', true) === true && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { + if (config('livewire-tables.inject_third_party_assets', true) === true && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { return true; } - + // Fall Back to Not Injecting return false; } From a38b711e82d5d739129c1c0f99e1f79bb7c505b4 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 00:09:04 +0100 Subject: [PATCH 11/29] Test fixes --- CHANGELOG.md | 1 - README copy.md | 94 ------------- config/livewire-tables.php | 132 +++++++++--------- .../laravel-livewire-tables-thirdparty.js | 2 + resources/imports/laravel-livewire-tables.js | 2 + src/Features/AutoInjectRappasoftAssets.php | 54 +++++-- src/LaravelLivewireTablesServiceProvider.php | 11 +- src/Mechanisms/RappasoftFrontendAssets.php | 1 + .../Mechanisms/WithRappasoftTableScripts.php | 4 +- .../Mechanisms/WithRappasoftTableStyles.php | 2 +- .../WithRappasoftTableThirdPartyScripts.php | 2 +- 11 files changed, 127 insertions(+), 178 deletions(-) delete mode 100644 README copy.md create mode 100644 resources/imports/laravel-livewire-tables-thirdparty.js create mode 100644 resources/imports/laravel-livewire-tables.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fa2e521e..785efac97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ All notable changes to `laravel-livewire-tables` will be documented in this file ## [Unreleased] - 3.x - Updates to Injection Methods -- Add use_bundler option to configuration (disables all FrontendAsset methods) - Amend AutoInjection/FrontendAsset to ensure it returns the original content correctly - Remove errant disabling of Blade Directives when disabling auto-injection - Amended in-line config documentation diff --git a/README copy.md b/README copy.md deleted file mode 100644 index bce1fceab..000000000 --- a/README copy.md +++ /dev/null @@ -1,94 +0,0 @@ -![Package Logo](https://banners.beyondco.de/Laravel%20Livewire%20Tables.png?theme=light&packageName=rappasoft%2Flaravel-livewire-tables&pattern=hideout&style=style_1&description=A+dynamic+table+component+for+Laravel+Livewire&md=1&fontSize=100px&images=table) - -[![Latest Version on Packagist](https://img.shields.io/packagist/v/rappasoft/laravel-livewire-tables.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-livewire-tables) -[![Styling](https://github.com/rappasoft/laravel-livewire-tables/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/rappasoft/laravel-livewire-tables/actions/workflows/php-cs-fixer.yml) -[![Tests](https://github.com/rappasoft/laravel-livewire-tables/actions/workflows/run-tests.yml/badge.svg)](https://github.com/rappasoft/laravel-livewire-tables/actions/workflows/run-tests.yml) -[![Total Downloads](https://img.shields.io/packagist/dt/rappasoft/laravel-livewire-tables.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-livewire-tables) - -### Enjoying this package? [Buy me a beer 🍺](https://www.buymeacoffee.com/rappasoft) - -A dynamic Laravel Livewire component for data tables. - -![Dark Mode](https://imgur.com/QoEdC7n.png) - -![Full Table](https://i.imgur.com/2kfibjR.png) - -### [Bootstrap 4 Demo](https://tables.laravel-boilerplate.com/bootstrap-4) | [Bootstrap 5 Demo](https://tables.laravel-boilerplate.com/bootstrap-5) | [Tailwind Demo](https://tables.laravel-boilerplate.com/tailwind) | [Demo Repository](https://github.com/rappasoft/laravel-livewire-tables-demo) - -## Installation - -You can install the package via composer: - -``` bash -composer require rappasoft/laravel-livewire-tables -``` - -You must also have [Alpine.js](https://alpinejs.dev) version 3 or greater installed and available to the component. - -## Documentation and Usage Instructions - -See the [documentation](https://rappasoft.com/docs/laravel-livewire-tables) for detailed installation and usage instructions. - -## Basic Example - -```php -setPrimaryKey('id'); - } - - public function columns(): array - { - return [ - Column::make('ID', 'id') - ->sortable(), - Column::make('Name') - ->sortable(), - ]; - } -} - -``` - -### [See advanced example](https://rappasoft.com/docs/laravel-livewire-tables/v2/examples/advanced-example) - -## Testing - -```bash -composer test -``` - -## Changelog - -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. - -## Contributing - -Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. - -## Security Vulnerabilities - -Please e-mail anthony@rappasoft.com to report any security vulnerabilities instead of the issue tracker. - -## Credits - -- [Anthony Rappa](https://github.com/rappasoft) -- [Joe McElwee](https://github.com/lrljoe) -- [All Contributors](./CONTRIBUTORS.md) - -## License - -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/config/livewire-tables.php b/config/livewire-tables.php index dee257684..a62dc44d6 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -7,83 +7,85 @@ 'theme' => 'tailwind', /** - * Cache Rappasoft Frontend Assets (For 1 hour) + * + * Filter Frontend Asset Options + * */ - 'cache_assets' => false, + + /** + * Cache Rappasoft Frontend Assets + */ + 'cache_assets' => false, - /** - * Enable or Disable automatic injection of assets - */ - 'inject_assets' => true, - - /** - * Enable or Disable automatic injection of assets - */ - 'inject_third_party_assets' => true, + /** + * Enable or Disable automatic injection of core assets + */ + 'inject_core_assets_enabled' => true, - /** - * Enable or Disable inclusion of published third-party assets - */ - 'published_third_party_assets' => false, + /** + * Enable or Disable automatic injection of third-party assets + */ + 'inject_third_party_assets_enabled' => true, - /** - * Enable or Disable remote third-party assets - */ - 'remote_third_party_assets' => false, + /** + * Enable Blade Directives (Not required if automatically injecting or using bundler approaches) + */ + 'enable_blade_directives ' => false, - /** - * Enable if using a bundler instead of injecting assets/scripts or using blade directives - */ - 'use_bundler' => false, + /** + * + * Filter Default Configuration Options + * + * */ - /** - * Configuration options for DateFilter - */ - 'dateFilter' => [ - 'defaultConfig' => [ - 'format' => 'Y-m-d', - 'pillFormat' => 'd M Y', // Used to display in the Filter Pills + /** + * Configuration options for DateFilter + */ + 'dateFilter' => [ + 'defaultConfig' => [ + 'format' => 'Y-m-d', + 'pillFormat' => 'd M Y', // Used to display in the Filter Pills + ], ], - ], - /** - * Configuration options for DateTimeFilter - */ - 'dateTimeFilter' => [ - 'defaultConfig' => [ - 'format' => 'Y-m-d\TH:i', - 'pillFormat' => 'd M Y - H:i', // Used to display in the Filter Pills + /** + * Configuration options for DateTimeFilter + */ + 'dateTimeFilter' => [ + 'defaultConfig' => [ + 'format' => 'Y-m-d\TH:i', + 'pillFormat' => 'd M Y - H:i', // Used to display in the Filter Pills + ], ], - ], - /** - * Configuration options for DateRangeFilter - */ - 'dateRange' => [ - 'defaultOptions' => [], - 'defaultConfig' => [ - 'allowInput' => true, // Allow manual input of dates - 'altFormat' => 'F j, Y', // Date format that will be displayed once selected - 'ariaDateFormat' => 'F j, Y', // An aria-friendly date format - 'dateFormat' => 'Y-m-d', // Date format that will be received by the filter - 'earliestDate' => null, // The earliest acceptable date - 'latestDate' => null, // The latest acceptable date + /** + * Configuration options for DateRangeFilter + */ + 'dateRange' => [ + 'defaultOptions' => [], + 'defaultConfig' => [ + 'allowInput' => true, // Allow manual input of dates + 'altFormat' => 'F j, Y', // Date format that will be displayed once selected + 'ariaDateFormat' => 'F j, Y', // An aria-friendly date format + 'dateFormat' => 'Y-m-d', // Date format that will be received by the filter + 'earliestDate' => null, // The earliest acceptable date + 'latestDate' => null, // The latest acceptable date + ], ], - ], - /** - * Configuration options for NumberRangeFilter - */ - 'numberRange' => [ - 'defaultOptions' => [ - 'min' => 0, // The default start value - 'max' => 100, // The default end value - ], - 'defaultConfig' => [ - 'minRange' => 0, // The minimum possible value - 'maxRange' => 100, // The maximum possible value - 'suffix' => '', // A suffix to append to the values when displayed + /** + * Configuration options for NumberRangeFilter + */ + 'numberRange' => [ + 'defaultOptions' => [ + 'min' => 0, // The default start value + 'max' => 100, // The default end value + ], + 'defaultConfig' => [ + 'minRange' => 0, // The minimum possible value + 'maxRange' => 100, // The maximum possible value + 'suffix' => '', // A suffix to append to the values when displayed + ], ], - ], ]; diff --git a/resources/imports/laravel-livewire-tables-thirdparty.js b/resources/imports/laravel-livewire-tables-thirdparty.js new file mode 100644 index 000000000..8dca724bb --- /dev/null +++ b/resources/imports/laravel-livewire-tables-thirdparty.js @@ -0,0 +1,2 @@ +import './css/laravel-livewire-tables-thirdparty.css' +import './js/laravel-livewire-tables-thirdparty.min.js' diff --git a/resources/imports/laravel-livewire-tables.js b/resources/imports/laravel-livewire-tables.js new file mode 100644 index 000000000..0048c0c16 --- /dev/null +++ b/resources/imports/laravel-livewire-tables.js @@ -0,0 +1,2 @@ +import './css/laravel-livewire-tables.css' +import './js/laravel-livewire-tables.js' diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 951327361..62db2c794 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -14,6 +14,10 @@ class AutoInjectRappasoftAssets extends ComponentHook public static bool $forceAssetInjection = false; + public ?bool $shouldInjectRappasoftThirdPartyAssets = null; + + public ?bool $shouldInjectRappasoftAssets = null; + public static function provide(): void { on('flush-state', function () { @@ -22,13 +26,16 @@ public static function provide(): void }); // If config use_bundler is true - abort injection of assets - if (config('livewire-tables.use_bundler', false) === true) { + if (config('livewire-tables.inject_core_assets_enabled', true) === false + && config('livewire-tables.inject_third_party_assets_enabled', true) === false + && config('livewire-tables.enable_blade_directives', false) === false + ) { return; } app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { - if (! static::$forceAssetInjection && (config('livewire-tables.use_bundler', false) === true || ! static::$hasRenderedAComponentThisRequest)) { + if (! static::$forceAssetInjection && (config('livewire-tables.inject_core_assets_enabled', false) === false || ! static::$hasRenderedAComponentThisRequest)) { return; } @@ -58,23 +65,48 @@ public static function provide(): void }); } + public static function setShouldInjectRappasoftAssets(bool $shouldInject = false): void + { + static::$shouldInjectRappasoftAssets = $shouldInject; + } + + public static function setShouldInjectRappsoftTableThirdPartyAssets(bool $shouldInject = false): void + { + static::$shouldInjectRappasoftThirdPartyAssets = $shouldInject; + } + + public static function shouldInjectAssets(): bool { + if (!isset(static::$shouldInjectRappasoftAssets)) + { + static::setShouldInjectRappasoftAssets(config('livewire-tables.inject_core_assets_enabled', true)); + } + if (!isset(static::$shouldInjectRappasoftThirdPartyAssets)) + { + static::setShouldInjectRappsoftTableThirdPartyAssets(config('livewire-tables.inject_third_party_assets_enabled', true)); + } + + // If Neither Core nor Third Party Assets are injectable - if (config('livewire-tables.inject_assets', true) === false && config('livewire-tables.inject_third_party_assets', true) === false) { + if (!static::$shouldInjectRappasoftAssets && !static::$shouldInjectRappasoftThirdPartyAssets) + { return false; } - // If Core Assets are Injectable, BUT have not been - if (config('livewire-tables.inject_assets', true) === true && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) { + if (static::$shouldInjectRappasoftAssets && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) + { return true; } - // If Third Party Assets are Injectable, BUT have not been - if (config('livewire-tables.inject_third_party_assets', true) === true && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { + + if (static::$shouldInjectRappasoftThirdPartyAssets && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) + { return true; } + + // Fall Back to Not Injecting return false; } @@ -91,14 +123,14 @@ public static function injectAssets(mixed $html): string if ($html->test('/<\s*head(?:\s|\s[^>])*>/i') && $html->test('/<\s*\/\s*body\s*>/i')) { return $html - ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') ->toString(); } return $html - ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((config('livewire-tables.inject_assets', true) ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(config('livewire-tables.inject_third_party_assets', true) ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '') . ' '. (static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') ->toString(); } } diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index 62d80e5bf..b48688975 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -46,7 +46,10 @@ public function boot(): void ]); } - if (config('livewire-tables.use_bundler', false) === false) { + if (config('livewire-tables.inject_core_assets_enabled', true) === true + || config('livewire-tables.inject_third_party_assets_enabled', true) === true + || config('livewire-tables.enable_blade_directives', false) === true + ) { (new RappasoftFrontendAssets)->boot(); } @@ -57,8 +60,10 @@ public function register(): void $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' ); - if (config('livewire-tables.use_bundler', false) === false) { - + if (config('livewire-tables.inject_core_assets_enabled', true) === true + || config('livewire-tables.inject_third_party_assets_enabled', true) === true + || config('livewire-tables.enable_blade_directives', false) === true + ) { (new RappasoftFrontendAssets)->register(); ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); } diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index aa22ec034..ca98a83d7 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -53,6 +53,7 @@ public function boot(): void }); static::registerBladeDirectives(); + } protected function registerBladeDirectives() diff --git a/src/Traits/Mechanisms/WithRappasoftTableScripts.php b/src/Traits/Mechanisms/WithRappasoftTableScripts.php index 0061e6ea3..b2f13a344 100644 --- a/src/Traits/Mechanisms/WithRappasoftTableScripts.php +++ b/src/Traits/Mechanisms/WithRappasoftTableScripts.php @@ -50,7 +50,7 @@ public static function tableScripts(array $options = []): ?string $scripts = static::tableJs($options); // HTML Label. - $html = $debug ? [''] : []; + $html = $debug ? [''] : []; $html[] = $scripts; @@ -75,7 +75,7 @@ public static function tableJs(array $options = []): string ); return << + HTML; } } diff --git a/src/Traits/Mechanisms/WithRappasoftTableStyles.php b/src/Traits/Mechanisms/WithRappasoftTableStyles.php index 261c1eded..6f663a4d1 100644 --- a/src/Traits/Mechanisms/WithRappasoftTableStyles.php +++ b/src/Traits/Mechanisms/WithRappasoftTableStyles.php @@ -43,7 +43,7 @@ public static function tableStyles(array $options = []): array|string|null $styles = static::tableCss($options); // HTML Label. - $html = $debug ? [''] : []; + $html = $debug ? [''] : []; $html[] = $styles; diff --git a/src/Traits/Mechanisms/WithRappasoftTableThirdPartyScripts.php b/src/Traits/Mechanisms/WithRappasoftTableThirdPartyScripts.php index e6bc28408..453a8c14f 100644 --- a/src/Traits/Mechanisms/WithRappasoftTableThirdPartyScripts.php +++ b/src/Traits/Mechanisms/WithRappasoftTableThirdPartyScripts.php @@ -73,7 +73,7 @@ public static function tableThirdpartyJs(array $options = []): string ); return << + HTML; } } From 9ff60d6f55916008775f76c069e46c82f661ef6c Mon Sep 17 00:00:00 2001 From: lrljoe Date: Mon, 25 Sep 2023 23:09:37 +0000 Subject: [PATCH 12/29] Fix styling --- config/livewire-tables.php | 127 +++++++++---------- src/Features/AutoInjectRappasoftAssets.php | 28 ++-- src/LaravelLivewireTablesServiceProvider.php | 8 +- src/Mechanisms/RappasoftFrontendAssets.php | 2 +- 4 files changed, 76 insertions(+), 89 deletions(-) diff --git a/config/livewire-tables.php b/config/livewire-tables.php index a62dc44d6..3dbdf1757 100644 --- a/config/livewire-tables.php +++ b/config/livewire-tables.php @@ -7,85 +7,82 @@ 'theme' => 'tailwind', /** - * * Filter Frontend Asset Options - * */ - - /** - * Cache Rappasoft Frontend Assets - */ - 'cache_assets' => false, - /** - * Enable or Disable automatic injection of core assets - */ - 'inject_core_assets_enabled' => true, + /** + * Cache Rappasoft Frontend Assets + */ + 'cache_assets' => false, + + /** + * Enable or Disable automatic injection of core assets + */ + 'inject_core_assets_enabled' => true, - /** - * Enable or Disable automatic injection of third-party assets - */ - 'inject_third_party_assets_enabled' => true, + /** + * Enable or Disable automatic injection of third-party assets + */ + 'inject_third_party_assets_enabled' => true, - /** - * Enable Blade Directives (Not required if automatically injecting or using bundler approaches) - */ - 'enable_blade_directives ' => false, + /** + * Enable Blade Directives (Not required if automatically injecting or using bundler approaches) + */ + 'enable_blade_directives ' => false, - /** - * - * Filter Default Configuration Options - * + /** + * Filter Default Configuration Options + * * */ - /** - * Configuration options for DateFilter - */ - 'dateFilter' => [ - 'defaultConfig' => [ - 'format' => 'Y-m-d', - 'pillFormat' => 'd M Y', // Used to display in the Filter Pills - ], + /** + * Configuration options for DateFilter + */ + 'dateFilter' => [ + 'defaultConfig' => [ + 'format' => 'Y-m-d', + 'pillFormat' => 'd M Y', // Used to display in the Filter Pills ], + ], - /** - * Configuration options for DateTimeFilter - */ - 'dateTimeFilter' => [ - 'defaultConfig' => [ - 'format' => 'Y-m-d\TH:i', - 'pillFormat' => 'd M Y - H:i', // Used to display in the Filter Pills - ], + /** + * Configuration options for DateTimeFilter + */ + 'dateTimeFilter' => [ + 'defaultConfig' => [ + 'format' => 'Y-m-d\TH:i', + 'pillFormat' => 'd M Y - H:i', // Used to display in the Filter Pills ], + ], - /** - * Configuration options for DateRangeFilter - */ - 'dateRange' => [ - 'defaultOptions' => [], - 'defaultConfig' => [ - 'allowInput' => true, // Allow manual input of dates - 'altFormat' => 'F j, Y', // Date format that will be displayed once selected - 'ariaDateFormat' => 'F j, Y', // An aria-friendly date format - 'dateFormat' => 'Y-m-d', // Date format that will be received by the filter - 'earliestDate' => null, // The earliest acceptable date - 'latestDate' => null, // The latest acceptable date - ], + /** + * Configuration options for DateRangeFilter + */ + 'dateRange' => [ + 'defaultOptions' => [], + 'defaultConfig' => [ + 'allowInput' => true, // Allow manual input of dates + 'altFormat' => 'F j, Y', // Date format that will be displayed once selected + 'ariaDateFormat' => 'F j, Y', // An aria-friendly date format + 'dateFormat' => 'Y-m-d', // Date format that will be received by the filter + 'earliestDate' => null, // The earliest acceptable date + 'latestDate' => null, // The latest acceptable date ], + ], - /** - * Configuration options for NumberRangeFilter - */ - 'numberRange' => [ - 'defaultOptions' => [ - 'min' => 0, // The default start value - 'max' => 100, // The default end value - ], - 'defaultConfig' => [ - 'minRange' => 0, // The minimum possible value - 'maxRange' => 100, // The maximum possible value - 'suffix' => '', // A suffix to append to the values when displayed - ], + /** + * Configuration options for NumberRangeFilter + */ + 'numberRange' => [ + 'defaultOptions' => [ + 'min' => 0, // The default start value + 'max' => 100, // The default end value + ], + 'defaultConfig' => [ + 'minRange' => 0, // The minimum possible value + 'maxRange' => 100, // The maximum possible value + 'suffix' => '', // A suffix to append to the values when displayed ], + ], ]; diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 62db2c794..4bffe0aa6 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -26,8 +26,8 @@ public static function provide(): void }); // If config use_bundler is true - abort injection of assets - if (config('livewire-tables.inject_core_assets_enabled', true) === false - && config('livewire-tables.inject_third_party_assets_enabled', true) === false + if (config('livewire-tables.inject_core_assets_enabled', true) === false + && config('livewire-tables.inject_third_party_assets_enabled', true) === false && config('livewire-tables.enable_blade_directives', false) === false ) { return; @@ -75,38 +75,28 @@ public static function setShouldInjectRappsoftTableThirdPartyAssets(bool $should static::$shouldInjectRappasoftThirdPartyAssets = $shouldInject; } - public static function shouldInjectAssets(): bool { - if (!isset(static::$shouldInjectRappasoftAssets)) - { + if (! isset(static::$shouldInjectRappasoftAssets)) { static::setShouldInjectRappasoftAssets(config('livewire-tables.inject_core_assets_enabled', true)); } - if (!isset(static::$shouldInjectRappasoftThirdPartyAssets)) - { + if (! isset(static::$shouldInjectRappasoftThirdPartyAssets)) { static::setShouldInjectRappsoftTableThirdPartyAssets(config('livewire-tables.inject_third_party_assets_enabled', true)); } - // If Neither Core nor Third Party Assets are injectable - if (!static::$shouldInjectRappasoftAssets && !static::$shouldInjectRappasoftThirdPartyAssets) - { + if (! static::$shouldInjectRappasoftAssets && ! static::$shouldInjectRappasoftThirdPartyAssets) { return false; } - if (static::$shouldInjectRappasoftAssets && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) - { + if (static::$shouldInjectRappasoftAssets && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) { return true; } - - if (static::$shouldInjectRappasoftThirdPartyAssets && !app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) - { + if (static::$shouldInjectRappasoftThirdPartyAssets && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { return true; } - - // Fall Back to Not Injecting return false; } @@ -129,8 +119,8 @@ public static function injectAssets(mixed $html): string } return $html - ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '') . ' '. (static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') ->toString(); } } diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index b48688975..cfbf0a27f 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -46,8 +46,8 @@ public function boot(): void ]); } - if (config('livewire-tables.inject_core_assets_enabled', true) === true - || config('livewire-tables.inject_third_party_assets_enabled', true) === true + if (config('livewire-tables.inject_core_assets_enabled', true) === true + || config('livewire-tables.inject_third_party_assets_enabled', true) === true || config('livewire-tables.enable_blade_directives', false) === true ) { (new RappasoftFrontendAssets)->boot(); @@ -60,8 +60,8 @@ public function register(): void $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' ); - if (config('livewire-tables.inject_core_assets_enabled', true) === true - || config('livewire-tables.inject_third_party_assets_enabled', true) === true + if (config('livewire-tables.inject_core_assets_enabled', true) === true + || config('livewire-tables.inject_third_party_assets_enabled', true) === true || config('livewire-tables.enable_blade_directives', false) === true ) { (new RappasoftFrontendAssets)->register(); diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index ca98a83d7..7c11e1a06 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -53,7 +53,7 @@ public function boot(): void }); static::registerBladeDirectives(); - + } protected function registerBladeDirectives() From 2ba2c7a7f5531aa2b5ac1c4efb8019682d2ef5bf Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:41:26 +0100 Subject: [PATCH 13/29] Tweaks for Auto Injection Options --- src/Features/AutoInjectRappasoftAssets.php | 139 ++++++++----------- src/LaravelLivewireTablesServiceProvider.php | 27 ++-- 2 files changed, 73 insertions(+), 93 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 4bffe0aa6..2b902bff9 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -14,92 +14,68 @@ class AutoInjectRappasoftAssets extends ComponentHook public static bool $forceAssetInjection = false; - public ?bool $shouldInjectRappasoftThirdPartyAssets = null; + public static bool $shouldInjectRappasoftThirdPartyAssets = false; - public ?bool $shouldInjectRappasoftAssets = null; + public static bool $shouldInjectRappasoftAssets = false; public static function provide(): void { + static::$shouldInjectRappasoftAssets = config('livewire-tables.inject_core_assets_enabled', true); + static::$shouldInjectRappasoftThirdPartyAssets = config('livewire-tables.inject_third_party_assets_enabled', true); + on('flush-state', function () { static::$hasRenderedAComponentThisRequest = false; static::$forceAssetInjection = false; }); - // If config use_bundler is true - abort injection of assets - if (config('livewire-tables.inject_core_assets_enabled', true) === false - && config('livewire-tables.inject_third_party_assets_enabled', true) === false - && config('livewire-tables.enable_blade_directives', false) === false - ) { - return; + if (static::$shouldInjectRappasoftAssets || static::$shouldInjectRappasoftThirdPartyAssets) + { + + app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { + + if (!static::$shouldInjectRappasoftAssets && !static::$shouldInjectRappasoftThirdPartyAssets) + { + return; + } + + // If All Scripts Have Been Rendered - Return + if ( + ( + !static::$shouldInjectRappasoftAssets || + (static::$shouldInjectRappasoftAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) + ) && + ( + !static::$shouldInjectRappasoftThirdPartyAssets || + (static::$shouldInjectRappasoftThirdPartyAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) + ) + ) + { + return; + } + + if (! str($handled->response->headers->get('content-type'))->contains('text/html')) { + return; + } + + if (! method_exists($handled->response, 'status') || ! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent') || ! method_exists($handled->response, 'getOriginalContent') || ! property_exists($handled->response, 'original')) { + return; + } + + if ($handled->response->status() !== 200) { + return; + } + + $html = $handled->response->getContent(); + + if (str($html)->contains('')) { + $original = $handled->response->getOriginalContent(); + $handled->response->setContent(static::injectAssets($html)); + $handled->response->original = $original; + } + }); } - - app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { - - if (! static::$forceAssetInjection && (config('livewire-tables.inject_core_assets_enabled', false) === false || ! static::$hasRenderedAComponentThisRequest)) { - return; - } - - if (! str($handled->response->headers->get('content-type'))->contains('text/html')) { - return; - } - - if (! method_exists($handled->response, 'status') || ! method_exists($handled->response, 'getContent') || ! method_exists($handled->response, 'setContent') || ! method_exists($handled->response, 'getOriginalContent') || ! property_exists($handled->response, 'original')) { - return; - } - - if ($handled->response->status() !== 200) { - return; - } - - if (! static::shouldInjectAssets()) { - return; - } - - $html = $handled->response->getContent(); - - if (str($html)->contains('')) { - $original = $handled->response->getOriginalContent(); - $handled->response->setContent(static::injectAssets($html)); - $handled->response->original = $original; - } - }); - } - - public static function setShouldInjectRappasoftAssets(bool $shouldInject = false): void - { - static::$shouldInjectRappasoftAssets = $shouldInject; - } - - public static function setShouldInjectRappsoftTableThirdPartyAssets(bool $shouldInject = false): void - { - static::$shouldInjectRappasoftThirdPartyAssets = $shouldInject; } - public static function shouldInjectAssets(): bool - { - if (! isset(static::$shouldInjectRappasoftAssets)) { - static::setShouldInjectRappasoftAssets(config('livewire-tables.inject_core_assets_enabled', true)); - } - if (! isset(static::$shouldInjectRappasoftThirdPartyAssets)) { - static::setShouldInjectRappsoftTableThirdPartyAssets(config('livewire-tables.inject_third_party_assets_enabled', true)); - } - - // If Neither Core nor Third Party Assets are injectable - if (! static::$shouldInjectRappasoftAssets && ! static::$shouldInjectRappasoftThirdPartyAssets) { - return false; - } - - if (static::$shouldInjectRappasoftAssets && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) { - return true; - } - - if (static::$shouldInjectRappasoftThirdPartyAssets && ! app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) { - return true; - } - - // Fall Back to Not Injecting - return false; - } public function dehydrate(): void { @@ -110,17 +86,24 @@ public static function injectAssets(mixed $html): string { $html = str($html); + $rappaStyles = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableStyles() : '') . ' ' . ((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''); + $rappaScripts = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableScripts() : '') . ' ' . ((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : ''); + if ($html->test('/<\s*head(?:\s|\s[^>])*>/i') && $html->test('/<\s*\/\s*body\s*>/i')) { + static::$shouldInjectRappasoftAssets = static::$shouldInjectRappasoftThirdPartyAssets = false; + return $html - ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*head(?:\s|\s[^>])*>)/i', '$1'.$rappaStyles) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', $rappaScripts.'$1') ->toString(); } + static::$shouldInjectRappasoftAssets = static::$shouldInjectRappasoftThirdPartyAssets = false; return $html - ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableStyles() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyStyles() : ''))) - ->replaceMatches('/(<\s*\/\s*head\s*>)/i', ((static::$shouldInjectRappasoftAssets ? app(RappasoftFrontendAssets::class)->tableScripts() : '').' '.(static::$shouldInjectRappasoftThirdPartyAssets ? app(RappasoftFrontendAssets::class)->tableThirdPartyScripts() : '')).'$1') + ->replaceMatches('/(<\s*html(?:\s[^>])*>)/i', '$1'.$rappaStyles) + ->replaceMatches('/(<\s*\/\s*head\s*>)/i', $rappaScripts.'$1') ->toString(); } + } diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index cfbf0a27f..c0941a44b 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -24,6 +24,14 @@ public function boot(): void $this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-tables'); + $this->consoleCommands(); + + (new RappasoftFrontendAssets)->boot(); + + } + + public function consoleCommands() + { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__.'/../resources/lang' => $this->app->langPath('livewire-tables'), @@ -45,14 +53,6 @@ public function boot(): void MakeCommand::class, ]); } - - if (config('livewire-tables.inject_core_assets_enabled', true) === true - || config('livewire-tables.inject_third_party_assets_enabled', true) === true - || config('livewire-tables.enable_blade_directives', false) === true - ) { - (new RappasoftFrontendAssets)->boot(); - } - } public function register(): void @@ -60,13 +60,10 @@ public function register(): void $this->mergeConfigFrom( __DIR__.'/../config/livewire-tables.php', 'livewire-tables' ); - if (config('livewire-tables.inject_core_assets_enabled', true) === true - || config('livewire-tables.inject_third_party_assets_enabled', true) === true - || config('livewire-tables.enable_blade_directives', false) === true - ) { - (new RappasoftFrontendAssets)->register(); - ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); - } + + (new RappasoftFrontendAssets)->register(); + + ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); } } From 373e81a65f4941d5bb9421725855e07ff538fc2d Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 00:41:54 +0000 Subject: [PATCH 14/29] Fix styling --- src/Features/AutoInjectRappasoftAssets.php | 24 ++++++++------------ src/LaravelLivewireTablesServiceProvider.php | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 2b902bff9..51a85d5fc 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -28,28 +28,25 @@ public static function provide(): void static::$forceAssetInjection = false; }); - if (static::$shouldInjectRappasoftAssets || static::$shouldInjectRappasoftThirdPartyAssets) - { + if (static::$shouldInjectRappasoftAssets || static::$shouldInjectRappasoftThirdPartyAssets) { app('events')->listen(RequestHandled::class, function (RequestHandled $handled) { - if (!static::$shouldInjectRappasoftAssets && !static::$shouldInjectRappasoftThirdPartyAssets) - { + if (! static::$shouldInjectRappasoftAssets && ! static::$shouldInjectRappasoftThirdPartyAssets) { return; } - + // If All Scripts Have Been Rendered - Return if ( ( - !static::$shouldInjectRappasoftAssets || + ! static::$shouldInjectRappasoftAssets || (static::$shouldInjectRappasoftAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) ) && ( - !static::$shouldInjectRappasoftThirdPartyAssets || + ! static::$shouldInjectRappasoftThirdPartyAssets || (static::$shouldInjectRappasoftThirdPartyAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) ) - ) - { + ) { return; } @@ -63,7 +60,7 @@ public static function provide(): void if ($handled->response->status() !== 200) { return; - } + } $html = $handled->response->getContent(); @@ -76,7 +73,6 @@ public static function provide(): void } } - public function dehydrate(): void { static::$hasRenderedAComponentThisRequest = true; @@ -86,9 +82,8 @@ public static function injectAssets(mixed $html): string { $html = str($html); - $rappaStyles = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableStyles() : '') . ' ' . ((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''); - $rappaScripts = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableScripts() : '') . ' ' . ((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : ''); - + $rappaStyles = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableStyles() : '').' '.((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyStyles() : ''); + $rappaScripts = ((static::$shouldInjectRappasoftAssets === true) ? RappasoftFrontendAssets::tableScripts() : '').' '.((static::$shouldInjectRappasoftThirdPartyAssets === true) ? RappasoftFrontendAssets::tableThirdPartyScripts() : ''); if ($html->test('/<\s*head(?:\s|\s[^>])*>/i') && $html->test('/<\s*\/\s*body\s*>/i')) { static::$shouldInjectRappasoftAssets = static::$shouldInjectRappasoftThirdPartyAssets = false; @@ -105,5 +100,4 @@ public static function injectAssets(mixed $html): string ->replaceMatches('/(<\s*\/\s*head\s*>)/i', $rappaScripts.'$1') ->toString(); } - } diff --git a/src/LaravelLivewireTablesServiceProvider.php b/src/LaravelLivewireTablesServiceProvider.php index c0941a44b..92be82358 100644 --- a/src/LaravelLivewireTablesServiceProvider.php +++ b/src/LaravelLivewireTablesServiceProvider.php @@ -62,7 +62,7 @@ public function register(): void ); (new RappasoftFrontendAssets)->register(); - + ComponentHookRegistry::register(AutoInjectRappasoftAssets::class); } From cdcc286e662dd3ac5d6246e8f6b5d43e6050776f Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:44:25 +0100 Subject: [PATCH 15/29] Fix all scripts have been rendered checks --- src/Features/AutoInjectRappasoftAssets.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 51a85d5fc..3a94598da 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -39,12 +39,10 @@ public static function provide(): void // If All Scripts Have Been Rendered - Return if ( ( - ! static::$shouldInjectRappasoftAssets || - (static::$shouldInjectRappasoftAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) + ! static::$shouldInjectRappasoftAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) ) && ( - ! static::$shouldInjectRappasoftThirdPartyAssets || - (static::$shouldInjectRappasoftThirdPartyAssets && app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) + ! static::$shouldInjectRappasoftThirdPartyAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) ) ) { return; From 1d299ebf91e44ccd456bedb57131b60e33cf8723 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:46:11 +0100 Subject: [PATCH 16/29] Fix errant brackets --- src/Features/AutoInjectRappasoftAssets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/AutoInjectRappasoftAssets.php b/src/Features/AutoInjectRappasoftAssets.php index 3a94598da..73e2c5e12 100644 --- a/src/Features/AutoInjectRappasoftAssets.php +++ b/src/Features/AutoInjectRappasoftAssets.php @@ -39,10 +39,10 @@ public static function provide(): void // If All Scripts Have Been Rendered - Return if ( ( - ! static::$shouldInjectRappasoftAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts) + ! static::$shouldInjectRappasoftAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableScripts ) && ( - ! static::$shouldInjectRappasoftThirdPartyAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts) + ! static::$shouldInjectRappasoftThirdPartyAssets || app(RappasoftFrontendAssets::class)->hasRenderedRappsoftTableThirdPartyScripts ) ) { return; From 5b248759d2400a2603dc89ab1c2829f819762a48 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:50:36 +0100 Subject: [PATCH 17/29] Test Fixes - Config Variable Changes --- .../AutoInjectRappasoftAssetsTest.php | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/Features/AutoInjectRappasoftAssetsTest.php b/tests/Features/AutoInjectRappasoftAssetsTest.php index 61b306bfe..64e453a69 100644 --- a/tests/Features/AutoInjectRappasoftAssetsTest.php +++ b/tests/Features/AutoInjectRappasoftAssetsTest.php @@ -10,30 +10,26 @@ class AutoInjectRappasoftAssetsTest extends TestCase /** @test */ public function shouldInjectRappasoftAndThirdParty() { - config()->set('livewire-tables.inject_assets', true); - config()->set('livewire-tables.inject_third_party_assets', true); - config()->set('livewire-tables.published_third_party_assets', false); - config()->set('livewire-tables.remote_third_party_assets', false); + config()->set('livewire-tables.inject_core_assets_enabled', true); + config()->set('livewire-tables.inject_third_party_assets_enabled', true); + $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); } /** @test */ public function shouldNotInjectRappasoftOrThirdParty() { - config()->set('livewire-tables.inject_assets', false); - config()->set('livewire-tables.inject_third_party_assets', false); - config()->set('livewire-tables.published_third_party_assets', false); - config()->set('livewire-tables.remote_third_party_assets', false); + config()->set('livewire-tables.inject_core_assets_enabled', false); + config()->set('livewire-tables.inject_third_party_assets_enabled', false); + $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); } /** @test */ public function shouldOnlyInjectThirdParty() { - config()->set('livewire-tables.inject_assets', false); - config()->set('livewire-tables.inject_third_party_assets', true); - config()->set('livewire-tables.published_third_party_assets', false); - config()->set('livewire-tables.remote_third_party_assets', false); + config()->set('livewire-tables.inject_core_assets_enabled', false); + config()->set('livewire-tables.inject_third_party_assets_enabled', true); $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); } @@ -41,10 +37,8 @@ public function shouldOnlyInjectThirdParty() /** @test */ public function shouldOnlyInjectRappasoft() { - config()->set('livewire-tables.inject_assets', true); - config()->set('livewire-tables.inject_third_party_assets', false); - config()->set('livewire-tables.published_third_party_assets', false); - config()->set('livewire-tables.remote_third_party_assets', false); + config()->set('livewire-tables.inject_core_assets_enabled', true); + config()->set('livewire-tables.inject_third_party_assets_enabled', false); $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); } From 34ab66061a77b84cbaf083cdb316c2b9cc403869 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:59:47 +0100 Subject: [PATCH 18/29] Test Fixes - AutoInjection --- .../AutoInjectRappasoftAssetsTest.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/Features/AutoInjectRappasoftAssetsTest.php b/tests/Features/AutoInjectRappasoftAssetsTest.php index 64e453a69..e0a0ffdf8 100644 --- a/tests/Features/AutoInjectRappasoftAssetsTest.php +++ b/tests/Features/AutoInjectRappasoftAssetsTest.php @@ -13,7 +13,12 @@ public function shouldInjectRappasoftAndThirdParty() config()->set('livewire-tables.inject_core_assets_enabled', true); config()->set('livewire-tables.inject_third_party_assets_enabled', true); - $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); + $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); + + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); } /** @test */ @@ -22,6 +27,8 @@ public function shouldNotInjectRappasoftOrThirdParty() config()->set('livewire-tables.inject_core_assets_enabled', false); config()->set('livewire-tables.inject_third_party_assets_enabled', false); + $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); + $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); } @@ -31,7 +38,11 @@ public function shouldOnlyInjectThirdParty() config()->set('livewire-tables.inject_core_assets_enabled', false); config()->set('livewire-tables.inject_third_party_assets_enabled', true); - $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); + $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); + + + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); } /** @test */ @@ -40,6 +51,10 @@ public function shouldOnlyInjectRappasoft() config()->set('livewire-tables.inject_core_assets_enabled', true); config()->set('livewire-tables.inject_third_party_assets_enabled', false); - $this->assertEquals(' ', AutoInjectRappasoftAssets::injectAssets('')); + $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); + + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); + } } From 8e445bbaccf387bd535ecc76bed1d4464a365ed5 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 01:00:11 +0000 Subject: [PATCH 19/29] Fix styling --- tests/Features/AutoInjectRappasoftAssetsTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Features/AutoInjectRappasoftAssetsTest.php b/tests/Features/AutoInjectRappasoftAssetsTest.php index e0a0ffdf8..4d196eac0 100644 --- a/tests/Features/AutoInjectRappasoftAssetsTest.php +++ b/tests/Features/AutoInjectRappasoftAssetsTest.php @@ -14,7 +14,7 @@ public function shouldInjectRappasoftAndThirdParty() config()->set('livewire-tables.inject_third_party_assets_enabled', true); $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); - + $this->assertStringContainsStringIgnoringCase('', $injectionReturn); $this->assertStringContainsStringIgnoringCase('', $injectionReturn); $this->assertStringContainsStringIgnoringCase('', $injectionReturn); @@ -39,7 +39,6 @@ public function shouldOnlyInjectThirdParty() config()->set('livewire-tables.inject_third_party_assets_enabled', true); $injectionReturn = AutoInjectRappasoftAssets::injectAssets(''); - $this->assertStringContainsStringIgnoringCase('', $injectionReturn); $this->assertStringContainsStringIgnoringCase('', $injectionReturn); From cbb3f60371242449a098158038128e62440a50d5 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 04:26:50 +0100 Subject: [PATCH 20/29] Test Updates - Frontend Assets --- src/Mechanisms/RappasoftFrontendAssets.php | 32 +++- .../RappasoftFrontendAssetsTest.php | 159 ++++++++++++++++++ 2 files changed, 184 insertions(+), 7 deletions(-) diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index 7c11e1a06..9e23ea40d 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -67,9 +67,18 @@ protected function registerBladeDirectives() protected function pretendResponseIsJs(string $file): \Symfony\Component\HttpFoundation\Response { - $expires = strtotime((config('livewire-tables.cache_assets', false) ? '+1 second' : '+1 hour')); - $lastModified = (config('livewire-tables.cache_assets', false) ? strtotime(now()) : filemtime($file)); - $cacheControl = (config('livewire-tables.cache_assets', false) ? 'public, max-age=1' : 'public, max-age=3600'); + if (config('livewire-tables.cache_assets', false) === true) + { + $expires = strtotime('+1 hour'); + $lastModified = filemtime($file); + $cacheControl = 'public, max-age=3600'; + } + else + { + $expires = strtotime('+1 second'); + $lastModified = \Carbon\Carbon::now()->timestamp; + $cacheControl = 'public, max-age=1'; + } $headers = [ 'Content-Type' => 'application/javascript; charset=utf-8', @@ -83,10 +92,19 @@ protected function pretendResponseIsJs(string $file): \Symfony\Component\HttpFou protected function pretendResponseIsCSS(string $file): \Symfony\Component\HttpFoundation\Response { - $expires = strtotime((config('livewire-tables.cache_assets', false) ? '+1 second' : '+1 hour')); - $lastModified = (config('livewire-tables.cache_assets', false) ? strtotime(now()) : filemtime($file)); - $cacheControl = (config('livewire-tables.cache_assets', false) ? 'public, max-age=1' : 'public, max-age=3600'); - + if (config('livewire-tables.cache_assets', false) === true) + { + $expires = strtotime('+1 hour'); + $lastModified = filemtime($file); + $cacheControl = 'public, max-age=3600'; + } + else + { + $expires = strtotime('+1 second'); + $lastModified = \Carbon\Carbon::now()->timestamp; + $cacheControl = 'public, max-age=1'; + } + $headers = [ 'Content-Type' => 'text/css; charset=utf-8', 'Expires' => Utils::httpDate($expires), diff --git a/tests/Mechanisms/RappasoftFrontendAssetsTest.php b/tests/Mechanisms/RappasoftFrontendAssetsTest.php index 34832e102..592f705a5 100644 --- a/tests/Mechanisms/RappasoftFrontendAssetsTest.php +++ b/tests/Mechanisms/RappasoftFrontendAssetsTest.php @@ -7,6 +7,76 @@ class RappasoftFrontendAssetsTest extends TestCase { + +/** + * @test + */ + public function jsResponseSetupCacheDisabled(): array + { + config()->set('livewire-tables.cache_assets', false); + $date = date_create(); + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableJavaScriptAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + /** + * @test + */ + public function cssResponseSetupCacheEnabled(): array + { + config()->set('livewire-tables.cache_assets', true); + $date = date_create(); + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableStylesAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + + + /** + * @test + */ + public function cssResponseSetupCacheDisabled(): array + { + config()->set('livewire-tables.cache_assets', false); + + $date = date_create(); + + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableStylesAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + + /** + * @test + */ + public function jsResponseSetupCacheEnabled(): array + { + config()->set('livewire-tables.cache_assets', true); + $lastModified = \Carbon\Carbon::now()->timestamp; + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableJavaScriptAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + + return ['lastModified' => $lastModified, 'responseHeaders' => $response->headers->all()]; + } + + /** @test */ public function styles() { @@ -54,4 +124,93 @@ public function thirdPartyscripts() $this->assertTrue($assets->hasRenderedRappsoftTableThirdPartyScripts); } + + /** + * @test + * + * @depends jsResponseSetupCacheEnabled + */ + public function check_pretend_response_is_js_returns_correct_cache_control_cache_enabled(array $jsResponseSetupCacheEnabled) + { + $this->assertSame('max-age=3600, public', $jsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends jsResponseSetupCacheEnabled + */ + public function check_pretend_response_is_js_returns_correct_content_type_cache_enabled(array $jsResponseSetupCacheEnabled) + { + $this->assertSame('application/javascript; charset=utf-8', $jsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); + } + + + + /** + * @test + * + * @depends jsResponseSetupCacheDisabled + */ + public function check_pretend_response_is_js_returns_correct_cache_control_cache_disabled(array $jsResponseSetupCacheDisabled) + { + $this->assertSame('max-age=1, public', $jsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends jsResponseSetupCacheDisabled + */ + public function check_pretend_response_is_js_returns_correct_content_type_cache_disabled(array $jsResponseSetupCacheDisabled) + { + $this->assertSame('application/javascript; charset=utf-8', $jsResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); + } + + /** + * @test + * + * @depends cssResponseSetupCacheEnabled + */ + public function check_pretend_response_is_css_returns_correct_cache_control_caching_enabled(array $cssResponseSetupCacheEnabled) + { + $this->assertSame('max-age=3600, public', $cssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends cssResponseSetupCacheEnabled + */ + public function check_pretend_response_is_css_returns_correct_content_type_caching_enabled(array $cssResponseSetupCacheEnabled) + { + $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); + } + + + + /** + * @test + * + * @depends cssResponseSetupCacheDisabled + */ + public function check_pretend_response_is_css_returns_correct_cache_control_caching_disabled(array $cssResponseSetupCacheDisabled) + { + $this->assertSame('max-age=1, public', $cssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends cssResponseSetupCacheDisabled + */ + public function check_pretend_response_is_css_returns_correct_content_type_caching_disabled(array $cssResponseSetupCacheDisabled) + { + $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); + } + } From d333442be0a315a5b1feb11358e5748abf4e0a55 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 03:27:17 +0000 Subject: [PATCH 21/29] Fix styling --- src/Mechanisms/RappasoftFrontendAssets.php | 16 +++++----------- .../RappasoftFrontendAssetsTest.php | 19 +++++-------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/Mechanisms/RappasoftFrontendAssets.php b/src/Mechanisms/RappasoftFrontendAssets.php index 9e23ea40d..8788d0f61 100644 --- a/src/Mechanisms/RappasoftFrontendAssets.php +++ b/src/Mechanisms/RappasoftFrontendAssets.php @@ -67,14 +67,11 @@ protected function registerBladeDirectives() protected function pretendResponseIsJs(string $file): \Symfony\Component\HttpFoundation\Response { - if (config('livewire-tables.cache_assets', false) === true) - { + if (config('livewire-tables.cache_assets', false) === true) { $expires = strtotime('+1 hour'); $lastModified = filemtime($file); $cacheControl = 'public, max-age=3600'; - } - else - { + } else { $expires = strtotime('+1 second'); $lastModified = \Carbon\Carbon::now()->timestamp; $cacheControl = 'public, max-age=1'; @@ -92,19 +89,16 @@ protected function pretendResponseIsJs(string $file): \Symfony\Component\HttpFou protected function pretendResponseIsCSS(string $file): \Symfony\Component\HttpFoundation\Response { - if (config('livewire-tables.cache_assets', false) === true) - { + if (config('livewire-tables.cache_assets', false) === true) { $expires = strtotime('+1 hour'); $lastModified = filemtime($file); $cacheControl = 'public, max-age=3600'; - } - else - { + } else { $expires = strtotime('+1 second'); $lastModified = \Carbon\Carbon::now()->timestamp; $cacheControl = 'public, max-age=1'; } - + $headers = [ 'Content-Type' => 'text/css; charset=utf-8', 'Expires' => Utils::httpDate($expires), diff --git a/tests/Mechanisms/RappasoftFrontendAssetsTest.php b/tests/Mechanisms/RappasoftFrontendAssetsTest.php index 592f705a5..a22a3a3d9 100644 --- a/tests/Mechanisms/RappasoftFrontendAssetsTest.php +++ b/tests/Mechanisms/RappasoftFrontendAssetsTest.php @@ -7,8 +7,7 @@ class RappasoftFrontendAssetsTest extends TestCase { - -/** + /** * @test */ public function jsResponseSetupCacheDisabled(): array @@ -24,6 +23,7 @@ public function jsResponseSetupCacheDisabled(): array return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } + /** * @test */ @@ -37,10 +37,10 @@ public function cssResponseSetupCacheEnabled(): array $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } - /** * @test */ @@ -49,13 +49,14 @@ public function cssResponseSetupCacheDisabled(): array config()->set('livewire-tables.cache_assets', false); $date = date_create(); - + $assets = app(RappasoftFrontendAssets::class); $response = $assets->returnRappasoftTableStylesAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } @@ -76,7 +77,6 @@ public function jsResponseSetupCacheEnabled(): array return ['lastModified' => $lastModified, 'responseHeaders' => $response->headers->all()]; } - /** @test */ public function styles() { @@ -134,7 +134,6 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=3600, public', $jsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -146,8 +145,6 @@ public function check_pretend_response_is_js_returns_correct_content_type_cache_ $this->assertSame('application/javascript; charset=utf-8', $jsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -157,7 +154,6 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=1, public', $jsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -178,7 +174,6 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=3600, public', $cssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -190,8 +185,6 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -201,7 +194,6 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=1, public', $cssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -212,5 +204,4 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi { $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); } - } From 3b28da1188fc917142c2d62041dcf4bd44a85e25 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 04:38:23 +0100 Subject: [PATCH 22/29] Add ThirdParty Basic Header Tests --- .../RappasoftFrontendAssetsTest.php | 180 +++++++++++++++++- 1 file changed, 176 insertions(+), 4 deletions(-) diff --git a/tests/Mechanisms/RappasoftFrontendAssetsTest.php b/tests/Mechanisms/RappasoftFrontendAssetsTest.php index a22a3a3d9..12c836671 100644 --- a/tests/Mechanisms/RappasoftFrontendAssetsTest.php +++ b/tests/Mechanisms/RappasoftFrontendAssetsTest.php @@ -7,6 +7,24 @@ class RappasoftFrontendAssetsTest extends TestCase { + + /** + * @test + */ + public function jsResponseSetupCacheEnabled(): array + { + config()->set('livewire-tables.cache_assets', true); + $lastModified = \Carbon\Carbon::now()->timestamp; + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableJavaScriptAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + + return ['lastModified' => $lastModified, 'responseHeaders' => $response->headers->all()]; + } + /** * @test */ @@ -24,6 +42,7 @@ public function jsResponseSetupCacheDisabled(): array return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } + /** * @test */ @@ -37,10 +56,10 @@ public function cssResponseSetupCacheEnabled(): array $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); - return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } + /** * @test */ @@ -49,26 +68,62 @@ public function cssResponseSetupCacheDisabled(): array config()->set('livewire-tables.cache_assets', false); $date = date_create(); - + $assets = app(RappasoftFrontendAssets::class); $response = $assets->returnRappasoftTableStylesAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + /** + * @test + */ + public function thirdPartyCssResponseSetupCacheEnabled(): array + { + config()->set('livewire-tables.cache_assets', true); + + $date = date_create(); + + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableThirdPartyStylesAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } + /** * @test */ - public function jsResponseSetupCacheEnabled(): array + public function thirdPartyCssResponseSetupCacheDisabled(): array + { + config()->set('livewire-tables.cache_assets', false); + + $date = date_create(); + + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableThirdPartyStylesAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + + /** + * @test + */ + public function thirdPartyJsResponseSetupCacheEnabled(): array { config()->set('livewire-tables.cache_assets', true); $lastModified = \Carbon\Carbon::now()->timestamp; $assets = app(RappasoftFrontendAssets::class); - $response = $assets->returnRappasoftTableJavaScriptAsFile(); + $response = $assets->returnRappasoftTableThirdPartyJavaScriptAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); @@ -77,6 +132,23 @@ public function jsResponseSetupCacheEnabled(): array return ['lastModified' => $lastModified, 'responseHeaders' => $response->headers->all()]; } + /** + * @test + */ + public function thirdPartyJsResponseSetupCacheDisabled(): array + { + config()->set('livewire-tables.cache_assets', false); + $date = date_create(); + $assets = app(RappasoftFrontendAssets::class); + $response = $assets->returnRappasoftTableThirdPartyJavaScriptAsFile(); + $this->assertIsObject($response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); + $this->assertIsIterable($response->headers->all()); + + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; + } + /** @test */ public function styles() { @@ -134,6 +206,7 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=3600, public', $jsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } + /** * @test @@ -145,6 +218,8 @@ public function check_pretend_response_is_js_returns_correct_content_type_cache_ $this->assertSame('application/javascript; charset=utf-8', $jsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } + + /** * @test * @@ -154,6 +229,7 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=1, public', $jsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } + /** * @test @@ -174,6 +250,7 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=3600, public', $cssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } + /** * @test @@ -185,6 +262,8 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } + + /** * @test * @@ -194,6 +273,7 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=1, public', $cssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } + /** * @test @@ -204,4 +284,96 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi { $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); } + + + + /** + * @test + * + * @depends thirdPartyCssResponseSetupCacheEnabled + */ + public function tp_check_pretend_response_is_css_returns_correct_cache_control_caching_enabled(array $thirdPartyCssResponseSetupCacheEnabled) + { + $this->assertSame('max-age=3600, public', $thirdPartyCssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends thirdPartyCssResponseSetupCacheEnabled + */ + public function tp_check_pretend_response_is_css_returns_correct_content_type_caching_enabled(array $thirdPartyCssResponseSetupCacheEnabled) + { + $this->assertSame('text/css; charset=utf-8', $thirdPartyCssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); + } + + + + /** + * @test + * + * @depends thirdPartyCssResponseSetupCacheDisabled + */ + public function tp_check_pretend_response_is_css_returns_correct_cache_control_caching_disabled(array $thirdPartyCssResponseSetupCacheDisabled) + { + $this->assertSame('max-age=1, public', $thirdPartyCssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends thirdPartyCssResponseSetupCacheDisabled + */ + public function tp_check_pretend_response_is_css_returns_correct_content_type_caching_disabled(array $thirdPartyCssResponseSetupCacheDisabled) + { + $this->assertSame('text/css; charset=utf-8', $thirdPartyCssResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); + } + + /** + * @test + * + * @depends thirdPartyJsResponseSetupCacheEnabled + */ + public function tp_check_pretend_response_is_js_returns_correct_cache_control_cache_enabled(array $thirdPartyJsResponseSetupCacheEnabled) + { + $this->assertSame('max-age=3600, public', $thirdPartyJsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends thirdPartyJsResponseSetupCacheEnabled + */ + public function tp_check_pretend_response_is_js_returns_correct_content_type_cache_enabled(array $thirdPartyJsResponseSetupCacheEnabled) + { + $this->assertSame('application/javascript; charset=utf-8', $thirdPartyJsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); + } + + + + /** + * @test + * + * @depends thirdPartyJsResponseSetupCacheDisabled + */ + public function tp_check_pretend_response_is_js_returns_correct_cache_control_cache_disabled(array $thirdPartyJsResponseSetupCacheDisabled) + { + $this->assertSame('max-age=1, public', $thirdPartyJsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); + } + + + /** + * @test + * + * @depends thirdPartyJsResponseSetupCacheDisabled + */ + public function tp_check_pretend_response_is_js_returns_correct_content_type_cache_disabled(array $thirdPartyJsResponseSetupCacheDisabled) + { + $this->assertSame('application/javascript; charset=utf-8', $thirdPartyJsResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); + } + + } From 3f0d2da381aa0a024b20af1106fe8f0180bcd635 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 03:38:56 +0000 Subject: [PATCH 23/29] Fix styling --- .../RappasoftFrontendAssetsTest.php | 36 +++++-------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/tests/Mechanisms/RappasoftFrontendAssetsTest.php b/tests/Mechanisms/RappasoftFrontendAssetsTest.php index 12c836671..32867efff 100644 --- a/tests/Mechanisms/RappasoftFrontendAssetsTest.php +++ b/tests/Mechanisms/RappasoftFrontendAssetsTest.php @@ -7,7 +7,6 @@ class RappasoftFrontendAssetsTest extends TestCase { - /** * @test */ @@ -42,7 +41,6 @@ public function jsResponseSetupCacheDisabled(): array return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } - /** * @test */ @@ -56,10 +54,10 @@ public function cssResponseSetupCacheEnabled(): array $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } - /** * @test */ @@ -68,13 +66,14 @@ public function cssResponseSetupCacheDisabled(): array config()->set('livewire-tables.cache_assets', false); $date = date_create(); - + $assets = app(RappasoftFrontendAssets::class); $response = $assets->returnRappasoftTableStylesAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } @@ -86,17 +85,17 @@ public function thirdPartyCssResponseSetupCacheEnabled(): array config()->set('livewire-tables.cache_assets', true); $date = date_create(); - + $assets = app(RappasoftFrontendAssets::class); $response = $assets->returnRappasoftTableThirdPartyStylesAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } - /** * @test */ @@ -105,13 +104,14 @@ public function thirdPartyCssResponseSetupCacheDisabled(): array config()->set('livewire-tables.cache_assets', false); $date = date_create(); - + $assets = app(RappasoftFrontendAssets::class); $response = $assets->returnRappasoftTableThirdPartyStylesAsFile(); $this->assertIsObject($response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class, $response); $this->assertInstanceOf(\Symfony\Component\HttpFoundation\ResponseHeaderBag::class, $response->headers); $this->assertIsIterable($response->headers->all()); + return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } @@ -148,7 +148,7 @@ public function thirdPartyJsResponseSetupCacheDisabled(): array return ['lastModified' => date_timestamp_get($date), 'responseHeaders' => $response->headers->all()]; } - + /** @test */ public function styles() { @@ -206,7 +206,6 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=3600, public', $jsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -218,8 +217,6 @@ public function check_pretend_response_is_js_returns_correct_content_type_cache_ $this->assertSame('application/javascript; charset=utf-8', $jsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -229,7 +226,6 @@ public function check_pretend_response_is_js_returns_correct_cache_control_cache { $this->assertSame('max-age=1, public', $jsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -250,7 +246,6 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=3600, public', $cssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -262,8 +257,6 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -273,7 +266,6 @@ public function check_pretend_response_is_css_returns_correct_cache_control_cach { $this->assertSame('max-age=1, public', $cssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -285,8 +277,6 @@ public function check_pretend_response_is_css_returns_correct_content_type_cachi $this->assertSame('text/css; charset=utf-8', $cssResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -296,7 +286,6 @@ public function tp_check_pretend_response_is_css_returns_correct_cache_control_c { $this->assertSame('max-age=3600, public', $thirdPartyCssResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -308,8 +297,6 @@ public function tp_check_pretend_response_is_css_returns_correct_content_type_ca $this->assertSame('text/css; charset=utf-8', $thirdPartyCssResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -319,7 +306,6 @@ public function tp_check_pretend_response_is_css_returns_correct_cache_control_c { $this->assertSame('max-age=1, public', $thirdPartyCssResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -340,7 +326,6 @@ public function tp_check_pretend_response_is_js_returns_correct_cache_control_ca { $this->assertSame('max-age=3600, public', $thirdPartyJsResponseSetupCacheEnabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -352,8 +337,6 @@ public function tp_check_pretend_response_is_js_returns_correct_content_type_cac $this->assertSame('application/javascript; charset=utf-8', $thirdPartyJsResponseSetupCacheEnabled['responseHeaders']['content-type'][0]); } - - /** * @test * @@ -363,7 +346,6 @@ public function tp_check_pretend_response_is_js_returns_correct_cache_control_ca { $this->assertSame('max-age=1, public', $thirdPartyJsResponseSetupCacheDisabled['responseHeaders']['cache-control'][0]); } - /** * @test @@ -374,6 +356,4 @@ public function tp_check_pretend_response_is_js_returns_correct_content_type_cac { $this->assertSame('application/javascript; charset=utf-8', $thirdPartyJsResponseSetupCacheDisabled['responseHeaders']['content-type'][0]); } - - } From 5a01d69eca22ed5c3edeeafa84f41977df4f158e Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:54:10 +0100 Subject: [PATCH 24/29] Add Initial Debuggable DTO Test --- .../DebuggableDataTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/DataTransferObjects/DebuggableDataTest.php diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php new file mode 100644 index 000000000..6194daa16 --- /dev/null +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -0,0 +1,51 @@ +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } + +} From 0019aab3407adde645706c1483373b454aadc66b Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 04:54:34 +0000 Subject: [PATCH 25/29] Fix styling --- .../DebuggableDataTest.php | 100 +++++++++--------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php index 6194daa16..a9118f31e 100644 --- a/tests/DataTransferObjects/DebuggableDataTest.php +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -1,51 +1,49 @@ -assertTrue(true); - } - - /** @test */ - public function test_example2() - { - $this->assertSame($this->basicTable->sortBy('id'), 'asc'); - } - - /** @test */ - public function check_all_default_dto_elements() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - - $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; - $this->assertSame($debuggableArray['query'], $defaultQuery); - $this->assertSame($debuggableArray['filters'], []); - $this->assertSame($debuggableArray['sorts'], []); - $this->assertSame($debuggableArray['search'], ''); - $this->assertFalse($debuggableArray['select-all']); - $this->assertSame($debuggableArray['selected'], []); - } - - /** @test */ - public function check_dto_returns_filters_correctly() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], []); - - $this->basicTable->setFilter('breed', ['1']); - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); - - } - -} +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } +} From 82dc27f1944c05a5d97f8e7e2611db1568cd9c08 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:57:32 +0100 Subject: [PATCH 26/29] Fix namespace issue --- .../DebuggableDataTest.php | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php index a9118f31e..94bf3354a 100644 --- a/tests/DataTransferObjects/DebuggableDataTest.php +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -1,49 +1,49 @@ -assertTrue(true); - } - - /** @test */ - public function test_example2() - { - $this->assertSame($this->basicTable->sortBy('id'), 'asc'); - } - - /** @test */ - public function check_all_default_dto_elements() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - - $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; - $this->assertSame($debuggableArray['query'], $defaultQuery); - $this->assertSame($debuggableArray['filters'], []); - $this->assertSame($debuggableArray['sorts'], []); - $this->assertSame($debuggableArray['search'], ''); - $this->assertFalse($debuggableArray['select-all']); - $this->assertSame($debuggableArray['selected'], []); - } - - /** @test */ - public function check_dto_returns_filters_correctly() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], []); - - $this->basicTable->setFilter('breed', ['1']); - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); - - } -} +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function test_check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function test_check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } +} From fc7b6945c4f5b30dfe437a328ac43cd731fad256 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 04:57:58 +0000 Subject: [PATCH 27/29] Fix styling --- .../DebuggableDataTest.php | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php index 94bf3354a..808aa3351 100644 --- a/tests/DataTransferObjects/DebuggableDataTest.php +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -1,49 +1,49 @@ -assertTrue(true); - } - - /** @test */ - public function test_example2() - { - $this->assertSame($this->basicTable->sortBy('id'), 'asc'); - } - - /** @test */ - public function test_check_all_default_dto_elements() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - - $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; - $this->assertSame($debuggableArray['query'], $defaultQuery); - $this->assertSame($debuggableArray['filters'], []); - $this->assertSame($debuggableArray['sorts'], []); - $this->assertSame($debuggableArray['search'], ''); - $this->assertFalse($debuggableArray['select-all']); - $this->assertSame($debuggableArray['selected'], []); - } - - /** @test */ - public function test_check_dto_returns_filters_correctly() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], []); - - $this->basicTable->setFilter('breed', ['1']); - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); - - } -} +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function test_check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function test_check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } +} From 896506c9943173fc9720e25db6270e17bdabf837 Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Tue, 26 Sep 2023 05:59:23 +0100 Subject: [PATCH 28/29] Fix missing class --- .../DebuggableDataTest.php | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php index 808aa3351..8f3092e64 100644 --- a/tests/DataTransferObjects/DebuggableDataTest.php +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -1,49 +1,50 @@ -assertTrue(true); - } - - /** @test */ - public function test_example2() - { - $this->assertSame($this->basicTable->sortBy('id'), 'asc'); - } - - /** @test */ - public function test_check_all_default_dto_elements() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - - $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; - $this->assertSame($debuggableArray['query'], $defaultQuery); - $this->assertSame($debuggableArray['filters'], []); - $this->assertSame($debuggableArray['sorts'], []); - $this->assertSame($debuggableArray['search'], ''); - $this->assertFalse($debuggableArray['select-all']); - $this->assertSame($debuggableArray['selected'], []); - } - - /** @test */ - public function test_check_dto_returns_filters_correctly() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], []); - - $this->basicTable->setFilter('breed', ['1']); - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); - - } -} +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function test_check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function test_check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } +} From b200fde539859b8c364028fa88f7c7b45d8ea03d Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 26 Sep 2023 04:59:57 +0000 Subject: [PATCH 29/29] Fix styling --- .../DebuggableDataTest.php | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/tests/DataTransferObjects/DebuggableDataTest.php b/tests/DataTransferObjects/DebuggableDataTest.php index 8f3092e64..efb0b24e2 100644 --- a/tests/DataTransferObjects/DebuggableDataTest.php +++ b/tests/DataTransferObjects/DebuggableDataTest.php @@ -1,50 +1,50 @@ -assertTrue(true); - } - - /** @test */ - public function test_example2() - { - $this->assertSame($this->basicTable->sortBy('id'), 'asc'); - } - - /** @test */ - public function test_check_all_default_dto_elements() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - - $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; - $this->assertSame($debuggableArray['query'], $defaultQuery); - $this->assertSame($debuggableArray['filters'], []); - $this->assertSame($debuggableArray['sorts'], []); - $this->assertSame($debuggableArray['search'], ''); - $this->assertFalse($debuggableArray['select-all']); - $this->assertSame($debuggableArray['selected'], []); - } - - /** @test */ - public function test_check_dto_returns_filters_correctly() - { - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], []); - - $this->basicTable->setFilter('breed', ['1']); - $debuggableDTO = new DebuggableData($this->basicTable); - $debuggableArray = $debuggableDTO->toArray(); - $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); - - } -} +assertTrue(true); + } + + /** @test */ + public function test_example2() + { + $this->assertSame($this->basicTable->sortBy('id'), 'asc'); + } + + /** @test */ + public function test_check_all_default_dto_elements() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + + $defaultQuery = 'select "pets"."id" as "id", "pets"."sort" as "sort", "pets"."name" as "name", "pets"."age" as "age", "breed"."name" as "breed.name", "pets"."last_visit" as "last_visit" from "pets" left join "breeds" as "breed" on "pets"."breed_id" = "breed"."id" limit 10 offset 0'; + $this->assertSame($debuggableArray['query'], $defaultQuery); + $this->assertSame($debuggableArray['filters'], []); + $this->assertSame($debuggableArray['sorts'], []); + $this->assertSame($debuggableArray['search'], ''); + $this->assertFalse($debuggableArray['select-all']); + $this->assertSame($debuggableArray['selected'], []); + } + + /** @test */ + public function test_check_dto_returns_filters_correctly() + { + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], []); + + $this->basicTable->setFilter('breed', ['1']); + $debuggableDTO = new DebuggableData($this->basicTable); + $debuggableArray = $debuggableDTO->toArray(); + $this->assertSame($debuggableArray['filters'], ['breed' => ['1']]); + + } +}