diff --git a/packages/framework/tests/Unit/HydeFrontServiceTest.php b/packages/framework/tests/Unit/HydeFrontServiceTest.php new file mode 100644 index 00000000000..f10e5636af3 --- /dev/null +++ b/packages/framework/tests/Unit/HydeFrontServiceTest.php @@ -0,0 +1,86 @@ +assertSame('v3.4', HydeFrontService::HYDEFRONT_VERSION); + } + + public function testServiceHasVersionString() + { + $this->assertIsString((new HydeFrontService())->version()); + } + + public function testVersionStringDefaultsToConstant() + { + $this->assertSame(HydeFrontService::HYDEFRONT_VERSION, (new HydeFrontService())->version()); + } + + public function testVersionCanBeSetInConfig() + { + self::mockConfig(['hyde.hydefront_version' => '1.0.0']); + $this->assertSame('1.0.0', (new HydeFrontService())->version()); + } + + public function testCdnPatternConstant() + { + $this->assertSame('https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}', HydeFrontService::HYDEFRONT_CDN_URL); + } + + public function testCanSetCustomCdnUrlInConfig() + { + self::mockConfig(['hyde.hydefront_url' => 'https://example.com']); + $this->assertSame('https://example.com', (new HydeFrontService())->cdnLink('')); + } + + public function testCanUseCustomCdnUrlWithVersion() + { + self::mockConfig(['hyde.hydefront_url' => '{{ $version }}']); + $this->assertSame('v3.4', (new HydeFrontService())->cdnLink('')); + } + + public function testCanUseCustomCdnUrlWithFile() + { + self::mockConfig(['hyde.hydefront_url' => '{{ $file }}']); + $this->assertSame('styles.css', (new HydeFrontService())->cdnLink('styles.css')); + } + + public function testCanUseCustomCdnUrlWithVersionAndFile() + { + self::mockConfig(['hyde.hydefront_url' => '{{ $version }}/{{ $file }}']); + $this->assertSame('v3.4/styles.css', (new HydeFrontService())->cdnLink('styles.css')); + } + + public function testCanUseCustomCdnUrlWithCustomVersion() + { + self::mockConfig([ + 'hyde.hydefront_url' => '{{ $version }}', + 'hyde.hydefront_version' => '1.0.0', + ]); + $this->assertSame('1.0.0', (new HydeFrontService())->cdnLink('')); + } + + public function testCdnLinkHelper() + { + $this->assertSame( + 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css', + (new HydeFrontService())->cdnLink('styles.css') + ); + } +}