|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Notifications; |
| 4 | + |
| 5 | +use App\Models\Plugin; |
| 6 | +use App\Models\User; |
| 7 | +use App\Notifications\PluginRejected; |
| 8 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +class PluginRejectedTest extends TestCase |
| 12 | +{ |
| 13 | + use RefreshDatabase; |
| 14 | + |
| 15 | + public function test_mail_action_links_to_dashboard_plugin_page(): void |
| 16 | + { |
| 17 | + $user = User::factory()->create(); |
| 18 | + $plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']); |
| 19 | + |
| 20 | + $notification = new PluginRejected($plugin); |
| 21 | + $mail = $notification->toMail($user); |
| 22 | + |
| 23 | + $this->assertEquals(route('customer.plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $mail->actionUrl); |
| 24 | + } |
| 25 | + |
| 26 | + public function test_database_notification_contains_action_url(): void |
| 27 | + { |
| 28 | + $user = User::factory()->create(); |
| 29 | + $plugin = Plugin::factory()->for($user)->create(['name' => 'acme/awesome-plugin']); |
| 30 | + |
| 31 | + $notification = new PluginRejected($plugin); |
| 32 | + $data = $notification->toArray($user); |
| 33 | + |
| 34 | + $this->assertEquals(route('customer.plugins.show', ['vendor' => 'acme', 'package' => 'awesome-plugin']), $data['action_url']); |
| 35 | + $this->assertEquals('View Plugin', $data['action_label']); |
| 36 | + } |
| 37 | + |
| 38 | + public function test_mail_contains_rejection_reason(): void |
| 39 | + { |
| 40 | + $user = User::factory()->create(); |
| 41 | + $plugin = Plugin::factory()->for($user)->create([ |
| 42 | + 'name' => 'acme/awesome-plugin', |
| 43 | + 'rejection_reason' => 'Missing license file', |
| 44 | + ]); |
| 45 | + |
| 46 | + $notification = new PluginRejected($plugin); |
| 47 | + $rendered = $notification->toMail($user)->render()->toHtml(); |
| 48 | + |
| 49 | + $this->assertStringContainsString('Missing license file', $rendered); |
| 50 | + } |
| 51 | + |
| 52 | + public function test_database_notification_contains_rejection_reason(): void |
| 53 | + { |
| 54 | + $user = User::factory()->create(); |
| 55 | + $plugin = Plugin::factory()->for($user)->create([ |
| 56 | + 'name' => 'acme/awesome-plugin', |
| 57 | + 'rejection_reason' => 'Missing license file', |
| 58 | + ]); |
| 59 | + |
| 60 | + $notification = new PluginRejected($plugin); |
| 61 | + $data = $notification->toArray($user); |
| 62 | + |
| 63 | + $this->assertEquals('Missing license file', $data['rejection_reason']); |
| 64 | + } |
| 65 | + |
| 66 | + public function test_via_returns_mail_and_database(): void |
| 67 | + { |
| 68 | + $user = User::factory()->create(); |
| 69 | + $plugin = Plugin::factory()->for($user)->create(); |
| 70 | + |
| 71 | + $notification = new PluginRejected($plugin); |
| 72 | + |
| 73 | + $this->assertEquals(['mail', 'database'], $notification->via($user)); |
| 74 | + } |
| 75 | +} |
0 commit comments