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