|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Filament; |
| 4 | + |
| 5 | +use App\Filament\Resources\PluginResource; |
| 6 | +use App\Filament\Resources\PluginResource\Pages\EditPlugin; |
| 7 | +use App\Filament\Resources\UserResource; |
| 8 | +use App\Models\Plugin; |
| 9 | +use App\Models\User; |
| 10 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 11 | +use Livewire\Livewire; |
| 12 | +use Tests\TestCase; |
| 13 | + |
| 14 | +class PluginResourceTest extends TestCase |
| 15 | +{ |
| 16 | + use RefreshDatabase; |
| 17 | + |
| 18 | + private User $admin; |
| 19 | + |
| 20 | + protected function setUp(): void |
| 21 | + { |
| 22 | + parent::setUp(); |
| 23 | + |
| 24 | + $this->admin = User::factory()->create(['email' => 'admin@test.com']); |
| 25 | + config(['filament.users' => ['admin@test.com']]); |
| 26 | + } |
| 27 | + |
| 28 | + public function test_free_plugin_shows_packagist_link_for_composer_name(): void |
| 29 | + { |
| 30 | + $plugin = Plugin::factory()->free()->approved()->create([ |
| 31 | + 'name' => 'acme/camera-123', |
| 32 | + ]); |
| 33 | + |
| 34 | + $response = $this->actingAs($this->admin)->get( |
| 35 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 36 | + ); |
| 37 | + |
| 38 | + $response->assertOk(); |
| 39 | + $response->assertSee('https://packagist.org/packages/acme/camera-123'); |
| 40 | + } |
| 41 | + |
| 42 | + public function test_paid_plugin_does_not_show_packagist_link(): void |
| 43 | + { |
| 44 | + $plugin = Plugin::factory()->paid()->approved()->create([ |
| 45 | + 'name' => 'acme/paid-plugin-123', |
| 46 | + ]); |
| 47 | + |
| 48 | + $response = $this->actingAs($this->admin)->get( |
| 49 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 50 | + ); |
| 51 | + |
| 52 | + $response->assertOk(); |
| 53 | + $response->assertDontSee('https://packagist.org/packages/acme/paid-plugin-123'); |
| 54 | + } |
| 55 | + |
| 56 | + public function test_paid_third_party_plugin_hides_repository_url_placeholder(): void |
| 57 | + { |
| 58 | + $plugin = Plugin::factory()->paid()->approved()->create([ |
| 59 | + 'name' => 'acme/paid-plugin-456', |
| 60 | + 'repository_url' => 'https://github.com/acme/paid-plugin-456', |
| 61 | + 'is_official' => false, |
| 62 | + ]); |
| 63 | + |
| 64 | + Livewire::actingAs($this->admin) |
| 65 | + ->test(EditPlugin::class, ['record' => $plugin->getRouteKey()]) |
| 66 | + ->assertDontSee('Repository URL'); |
| 67 | + } |
| 68 | + |
| 69 | + public function test_paid_official_plugin_shows_repository_url(): void |
| 70 | + { |
| 71 | + $plugin = Plugin::factory()->paid()->approved()->create([ |
| 72 | + 'name' => 'nativephp/paid-official-789', |
| 73 | + 'repository_url' => 'https://github.com/nativephp/paid-official-789', |
| 74 | + 'is_official' => true, |
| 75 | + ]); |
| 76 | + |
| 77 | + $response = $this->actingAs($this->admin)->get( |
| 78 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 79 | + ); |
| 80 | + |
| 81 | + $response->assertOk(); |
| 82 | + $response->assertSee('https://github.com/nativephp/paid-official-789'); |
| 83 | + } |
| 84 | + |
| 85 | + public function test_free_plugin_shows_repository_url(): void |
| 86 | + { |
| 87 | + $plugin = Plugin::factory()->free()->approved()->create([ |
| 88 | + 'name' => 'acme/free-plugin-321', |
| 89 | + 'repository_url' => 'https://github.com/acme/free-plugin-321', |
| 90 | + 'is_official' => false, |
| 91 | + ]); |
| 92 | + |
| 93 | + $response = $this->actingAs($this->admin)->get( |
| 94 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 95 | + ); |
| 96 | + |
| 97 | + $response->assertOk(); |
| 98 | + $response->assertSee('https://github.com/acme/free-plugin-321'); |
| 99 | + } |
| 100 | + |
| 101 | + public function test_paid_plugin_license_links_to_license_page(): void |
| 102 | + { |
| 103 | + $plugin = Plugin::factory()->paid()->approved()->create([ |
| 104 | + 'name' => 'acme/paid-license-111', |
| 105 | + 'composer_data' => ['license' => 'Commercial'], |
| 106 | + ]); |
| 107 | + |
| 108 | + $response = $this->actingAs($this->admin)->get( |
| 109 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 110 | + ); |
| 111 | + |
| 112 | + $response->assertOk(); |
| 113 | + $response->assertSee(route('plugins.license', ['vendor' => 'acme', 'package' => 'paid-license-111'])); |
| 114 | + } |
| 115 | + |
| 116 | + public function test_free_plugin_license_links_to_github(): void |
| 117 | + { |
| 118 | + $plugin = Plugin::factory()->free()->approved()->create([ |
| 119 | + 'name' => 'acme/free-license-222', |
| 120 | + 'repository_url' => 'https://github.com/acme/free-license-222', |
| 121 | + 'composer_data' => ['license' => 'MIT'], |
| 122 | + ]); |
| 123 | + |
| 124 | + $response = $this->actingAs($this->admin)->get( |
| 125 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 126 | + ); |
| 127 | + |
| 128 | + $response->assertOk(); |
| 129 | + $response->assertSee('https://github.com/acme/free-license-222/blob/main/LICENSE'); |
| 130 | + } |
| 131 | + |
| 132 | + public function test_submission_info_shows_go_to_user_action(): void |
| 133 | + { |
| 134 | + $user = User::factory()->create(); |
| 135 | + $plugin = Plugin::factory()->for($user)->approved()->create(); |
| 136 | + |
| 137 | + $response = $this->actingAs($this->admin)->get( |
| 138 | + PluginResource::getUrl('edit', ['record' => $plugin]) |
| 139 | + ); |
| 140 | + |
| 141 | + $response->assertOk(); |
| 142 | + $expectedUrl = UserResource::getUrl('edit', ['record' => $user->id]); |
| 143 | + $response->assertSee($expectedUrl); |
| 144 | + } |
| 145 | +} |
0 commit comments