Skip to content

Commit 9866ee8

Browse files
simonhampclaude
andcommitted
Auto-set is_official on plugins with nativephp/ namespace, fix Pint style
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8d4eb87 commit 9866ee8

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

app/Models/Plugin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

tests/Feature/SupportTicketTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use App\Notifications\SupportTicketSubmitted;
1616
use App\Notifications\SupportTicketUserReplied;
1717
use App\SupportTicket\Status;
18+
use Illuminate\Database\Eloquent\ModelNotFoundException;
1819
use Illuminate\Foundation\Testing\RefreshDatabase;
1920
use Illuminate\Support\Facades\Notification;
2021
use 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])

0 commit comments

Comments
 (0)