|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use App\Services\DocsVersionService; |
| 6 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 8 | +use PHPUnit\Framework\Attributes\Test; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +class DocsVersionServiceTest extends TestCase |
| 12 | +{ |
| 13 | + use RefreshDatabase; |
| 14 | + |
| 15 | + protected DocsVersionService $docsVersionService; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + $this->docsVersionService = app(DocsVersionService::class); |
| 22 | + } |
| 23 | + |
| 24 | + public static function platformDataProvider(): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + 'platform=mobile' => ['mobile'], |
| 28 | + 'platform=desktop' => ['desktop'], |
| 29 | + ]; |
| 30 | + } |
| 31 | + |
| 32 | + #[Test] |
| 33 | + #[DataProvider('platformDataProvider')] |
| 34 | + public function it_points_to_the_latest_version_when_page_exists_in_latest( |
| 35 | + string $platform, |
| 36 | + ): void { |
| 37 | + $latestVersion = $platform === 'mobile' ? config('docs.latest_versions.mobile') : config('docs.latest_versions.desktop'); |
| 38 | + |
| 39 | + $url = $this->docsVersionService->determineCanonicalUrl( |
| 40 | + platform: $platform, |
| 41 | + page: 'getting-started/introduction', |
| 42 | + ); |
| 43 | + |
| 44 | + $expected = route('docs.show', [ |
| 45 | + 'platform' => $platform, |
| 46 | + 'version' => $latestVersion, |
| 47 | + 'page' => 'getting-started/introduction', |
| 48 | + ]); |
| 49 | + |
| 50 | + $this->assertEquals($expected, $url); |
| 51 | + } |
| 52 | + |
| 53 | + #[Test] |
| 54 | + public function it_remaps_mobile_apis_pages_to_plugins_core_when_the_page_exists_there_in_latest(): void |
| 55 | + { |
| 56 | + $url = $this->docsVersionService->determineCanonicalUrl( |
| 57 | + platform: 'mobile', |
| 58 | + page: 'apis/camera', |
| 59 | + ); |
| 60 | + |
| 61 | + $expected = route('docs.show', [ |
| 62 | + 'platform' => 'mobile', |
| 63 | + 'version' => config('docs.latest_versions.mobile'), |
| 64 | + 'page' => 'plugins/core/camera', |
| 65 | + ]); |
| 66 | + |
| 67 | + $this->assertEquals($expected, $url); |
| 68 | + } |
| 69 | + |
| 70 | + #[Test] |
| 71 | + public function it_points_to_the_latest_version_of_getting_started_introduction_when_page_does_not_exist_in_latest(): void |
| 72 | + { |
| 73 | + // concepts/ci-cd only exists in version 1 of mobile documentation |
| 74 | + $url = $this->docsVersionService->determineCanonicalUrl( |
| 75 | + platform: 'mobile', |
| 76 | + page: 'concepts/ci-cd', |
| 77 | + ); |
| 78 | + |
| 79 | + $expected = route('docs.show', [ |
| 80 | + 'platform' => 'mobile', |
| 81 | + 'version' => '3', |
| 82 | + 'page' => 'getting-started/introduction', |
| 83 | + ]); |
| 84 | + |
| 85 | + $this->assertEquals($expected, $url); |
| 86 | + } |
| 87 | + |
| 88 | + #[Test] |
| 89 | + #[DataProvider('platformDataProvider')] |
| 90 | + public function it_points_to_the_latest_version_of_getting_started_introduction_when_page_does_not_exist( |
| 91 | + string $platform, |
| 92 | + ): void { |
| 93 | + $latestVersion = $platform === 'mobile' ? config('docs.latest_versions.mobile') : config('docs.latest_versions.desktop'); |
| 94 | + |
| 95 | + $url = $this->docsVersionService->determineCanonicalUrl( |
| 96 | + platform: $platform, |
| 97 | + page: 'non-existent-page', |
| 98 | + ); |
| 99 | + |
| 100 | + $expected = route('docs.show', [ |
| 101 | + 'platform' => $platform, |
| 102 | + 'version' => $latestVersion, |
| 103 | + 'page' => 'getting-started/introduction', |
| 104 | + ]); |
| 105 | + |
| 106 | + $this->assertEquals($expected, $url); |
| 107 | + } |
| 108 | +} |
0 commit comments