-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathPluginResourceTest.php
More file actions
145 lines (116 loc) · 4.72 KB
/
PluginResourceTest.php
File metadata and controls
145 lines (116 loc) · 4.72 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\PluginResource;
use App\Filament\Resources\PluginResource\Pages\EditPlugin;
use App\Filament\Resources\UserResource;
use App\Models\Plugin;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class PluginResourceTest extends TestCase
{
use RefreshDatabase;
private User $admin;
protected function setUp(): void
{
parent::setUp();
$this->admin = User::factory()->create(['email' => 'admin@test.com']);
config(['filament.users' => ['admin@test.com']]);
}
public function test_free_plugin_shows_packagist_link_for_composer_name(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'name' => 'acme/camera-123',
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertSee('https://packagist.org/packages/acme/camera-123');
}
public function test_paid_plugin_does_not_show_packagist_link(): void
{
$plugin = Plugin::factory()->paid()->approved()->create([
'name' => 'acme/paid-plugin-123',
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertDontSee('https://packagist.org/packages/acme/paid-plugin-123');
}
public function test_paid_third_party_plugin_hides_repository_url_placeholder(): void
{
$plugin = Plugin::factory()->paid()->approved()->create([
'name' => 'acme/paid-plugin-456',
'repository_url' => 'https://github.com/acme/paid-plugin-456',
'is_official' => false,
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->assertDontSee('Repository URL');
}
public function test_paid_official_plugin_shows_repository_url(): void
{
$plugin = Plugin::factory()->paid()->approved()->create([
'name' => 'nativephp/paid-official-789',
'repository_url' => 'https://github.com/nativephp/paid-official-789',
'is_official' => true,
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertSee('https://github.com/nativephp/paid-official-789');
}
public function test_free_plugin_shows_repository_url(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'name' => 'acme/free-plugin-321',
'repository_url' => 'https://github.com/acme/free-plugin-321',
'is_official' => false,
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertSee('https://github.com/acme/free-plugin-321');
}
public function test_paid_plugin_license_links_to_license_page(): void
{
$plugin = Plugin::factory()->paid()->approved()->create([
'name' => 'acme/paid-license-111',
'composer_data' => ['license' => 'Commercial'],
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertSee(route('plugins.license', ['vendor' => 'acme', 'package' => 'paid-license-111']));
}
public function test_free_plugin_license_links_to_github(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'name' => 'acme/free-license-222',
'repository_url' => 'https://github.com/acme/free-license-222',
'composer_data' => ['license' => 'MIT'],
]);
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$response->assertSee('https://github.com/acme/free-license-222/blob/main/LICENSE');
}
public function test_submission_info_shows_go_to_user_action(): void
{
$user = User::factory()->create();
$plugin = Plugin::factory()->for($user)->approved()->create();
$response = $this->actingAs($this->admin)->get(
PluginResource::getUrl('edit', ['record' => $plugin])
);
$response->assertOk();
$expectedUrl = UserResource::getUrl('edit', ['record' => $user->id]);
$response->assertSee($expectedUrl);
}
}