File tree Expand file tree Collapse file tree 4 files changed +91
-1
lines changed
Expand file tree Collapse file tree 4 files changed +91
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,13 @@ public function routeParams(): array
6464
6565 protected static function booted (): void
6666 {
67+ static ::saving (function (Plugin $ plugin ): void {
68+ if ($ plugin ->isDirty ('name ' ) && $ plugin ->name ) {
69+ $ vendor = explode ('/ ' , $ plugin ->name )[0 ] ?? null ;
70+ $ plugin ->is_official = $ vendor === 'nativephp ' ;
71+ }
72+ });
73+
6774 static ::created (function (Plugin $ plugin ): void {
6875 $ plugin ->recordActivity (
6976 PluginActivityType::Submitted,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate \Database \Migrations \Migration ;
4+ use Illuminate \Support \Facades \DB ;
5+
6+ return new class extends Migration
7+ {
8+ /**
9+ * Run the migrations.
10+ */
11+ public function up (): void
12+ {
13+ DB ::table ('plugins ' )
14+ ->where ('name ' , 'like ' , 'nativephp/% ' )
15+ ->update (['is_official ' => true ]);
16+
17+ DB ::table ('plugins ' )
18+ ->where ('name ' , 'not like ' , 'nativephp/% ' )
19+ ->update (['is_official ' => false ]);
20+ }
21+
22+ /**
23+ * Reverse the migrations.
24+ */
25+ public function down (): void
26+ {
27+ // No rollback — is_official will be maintained by the model going forward
28+ }
29+ };
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Feature ;
4+
5+ use App \Models \Plugin ;
6+ use Illuminate \Foundation \Testing \RefreshDatabase ;
7+ use PHPUnit \Framework \Attributes \Test ;
8+ use Tests \TestCase ;
9+
10+ class PluginIsOfficialTest extends TestCase
11+ {
12+ use RefreshDatabase;
13+
14+ #[Test]
15+ public function plugin_with_nativephp_namespace_is_automatically_marked_as_official (): void
16+ {
17+ $ plugin = Plugin::factory ()->create (['name ' => 'nativephp/mobile-camera ' ]);
18+
19+ $ this ->assertTrue ($ plugin ->fresh ()->is_official );
20+ }
21+
22+ #[Test]
23+ public function plugin_with_other_namespace_is_not_marked_as_official (): void
24+ {
25+ $ plugin = Plugin::factory ()->create (['name ' => 'acme/some-plugin ' ]);
26+
27+ $ this ->assertFalse ($ plugin ->fresh ()->is_official );
28+ }
29+
30+ #[Test]
31+ public function updating_plugin_name_to_nativephp_namespace_sets_official (): void
32+ {
33+ $ plugin = Plugin::factory ()->create (['name ' => 'acme/some-plugin ' ]);
34+
35+ $ this ->assertFalse ($ plugin ->fresh ()->is_official );
36+
37+ $ plugin ->update (['name ' => 'nativephp/some-plugin ' ]);
38+
39+ $ this ->assertTrue ($ plugin ->fresh ()->is_official );
40+ }
41+
42+ #[Test]
43+ public function updating_plugin_name_away_from_nativephp_namespace_unsets_official (): void
44+ {
45+ $ plugin = Plugin::factory ()->create (['name ' => 'nativephp/some-plugin ' ]);
46+
47+ $ this ->assertTrue ($ plugin ->fresh ()->is_official );
48+
49+ $ plugin ->update (['name ' => 'acme/some-plugin ' ]);
50+
51+ $ this ->assertFalse ($ plugin ->fresh ()->is_official );
52+ }
53+ }
Original file line number Diff line number Diff line change 1515use App \Notifications \SupportTicketSubmitted ;
1616use App \Notifications \SupportTicketUserReplied ;
1717use App \SupportTicket \Status ;
18+ use Illuminate \Database \Eloquent \ModelNotFoundException ;
1819use Illuminate \Foundation \Testing \RefreshDatabase ;
1920use Illuminate \Support \Facades \Notification ;
2021use Laravel \Cashier \Subscription ;
@@ -1130,7 +1131,7 @@ public function only_internal_notes_can_be_pinned(): void
11301131 'note ' => false ,
11311132 ]);
11321133
1133- $ this ->expectException (\ Illuminate \ Database \ Eloquent \ ModelNotFoundException::class);
1134+ $ this ->expectException (ModelNotFoundException::class);
11341135
11351136 Livewire::actingAs ($ admin )
11361137 ->test (TicketRepliesWidget::class, ['record ' => $ ticket ])
You can’t perform that action at this time.
0 commit comments