|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use App\Features\ShowPlugins; |
| 6 | +use App\Models\Plugin; |
| 7 | +use App\Models\PluginVersion; |
| 8 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 9 | +use Laravel\Pennant\Feature; |
| 10 | +use Tests\TestCase; |
| 11 | + |
| 12 | +class PluginPermissionAndChangelogDisplayTest extends TestCase |
| 13 | +{ |
| 14 | + use RefreshDatabase; |
| 15 | + |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + |
| 20 | + Feature::define(ShowPlugins::class, true); |
| 21 | + } |
| 22 | + |
| 23 | + public function test_it_shows_declared_permissions_from_the_latest_visible_version(): void |
| 24 | + { |
| 25 | + $plugin = Plugin::factory()->approved()->create(); |
| 26 | + |
| 27 | + PluginVersion::create([ |
| 28 | + 'plugin_id' => $plugin->id, |
| 29 | + 'version' => '1.0.0', |
| 30 | + 'tag_name' => 'v1.0.0', |
| 31 | + 'github_release_id' => '1', |
| 32 | + 'published_at' => now(), |
| 33 | + 'manifest_permissions' => [ |
| 34 | + 'android_permissions' => ['android.permission.CAMERA'], |
| 35 | + 'ios_background_modes' => ['fetch'], |
| 36 | + ], |
| 37 | + ]); |
| 38 | + |
| 39 | + $response = $this->get(route('plugins.show', $plugin->routeParams())); |
| 40 | + |
| 41 | + $response->assertStatus(200); |
| 42 | + $response->assertSee('What This Plugin Can Access'); |
| 43 | + $response->assertSee('Camera'); |
| 44 | + $response->assertSee('Background Fetch'); |
| 45 | + } |
| 46 | + |
| 47 | + public function test_it_does_not_show_the_permission_panel_when_nothing_is_declared(): void |
| 48 | + { |
| 49 | + $plugin = Plugin::factory()->approved()->create(); |
| 50 | + |
| 51 | + PluginVersion::create([ |
| 52 | + 'plugin_id' => $plugin->id, |
| 53 | + 'version' => '1.0.0', |
| 54 | + 'tag_name' => 'v1.0.0', |
| 55 | + 'github_release_id' => '1', |
| 56 | + 'published_at' => now(), |
| 57 | + 'manifest_permissions' => ['android_permissions' => []], |
| 58 | + ]); |
| 59 | + |
| 60 | + $response = $this->get(route('plugins.show', $plugin->routeParams())); |
| 61 | + |
| 62 | + $response->assertStatus(200); |
| 63 | + $response->assertDontSee('What This Plugin Can Access'); |
| 64 | + } |
| 65 | + |
| 66 | + public function test_a_version_pending_review_is_not_used_for_the_permission_panel(): void |
| 67 | + { |
| 68 | + $plugin = Plugin::factory()->approved()->create(); |
| 69 | + |
| 70 | + PluginVersion::create([ |
| 71 | + 'plugin_id' => $plugin->id, |
| 72 | + 'version' => '1.0.0', |
| 73 | + 'tag_name' => 'v1.0.0', |
| 74 | + 'github_release_id' => '1', |
| 75 | + 'published_at' => now(), |
| 76 | + 'manifest_permissions' => ['android_permissions' => ['android.permission.CAMERA']], |
| 77 | + ]); |
| 78 | + |
| 79 | + PluginVersion::create([ |
| 80 | + 'plugin_id' => $plugin->id, |
| 81 | + 'version' => '2.0.0', |
| 82 | + 'tag_name' => 'v2.0.0', |
| 83 | + 'github_release_id' => '2', |
| 84 | + 'published_at' => now()->addDay(), |
| 85 | + 'manifest_permissions' => ['android_permissions' => ['android.permission.CAMERA', 'android.permission.ACCESS_FINE_LOCATION']], |
| 86 | + 'requires_review' => true, |
| 87 | + ]); |
| 88 | + |
| 89 | + $response = $this->get(route('plugins.show', $plugin->routeParams())); |
| 90 | + |
| 91 | + $response->assertStatus(200); |
| 92 | + $response->assertSee('Camera'); |
| 93 | + $response->assertDontSee('Precise Location'); |
| 94 | + } |
| 95 | + |
| 96 | + public function test_it_shows_version_history_with_rendered_release_notes(): void |
| 97 | + { |
| 98 | + $plugin = Plugin::factory()->approved()->create(); |
| 99 | + |
| 100 | + PluginVersion::create([ |
| 101 | + 'plugin_id' => $plugin->id, |
| 102 | + 'version' => '1.0.0', |
| 103 | + 'tag_name' => 'v1.0.0', |
| 104 | + 'github_release_id' => '1', |
| 105 | + 'published_at' => now(), |
| 106 | + 'release_notes' => '**Fixed** a crash on launch.', |
| 107 | + 'release_notes_html' => '<p><strong>Fixed</strong> a crash on launch.</p>', |
| 108 | + ]); |
| 109 | + |
| 110 | + $response = $this->get(route('plugins.show', $plugin->routeParams())); |
| 111 | + |
| 112 | + $response->assertStatus(200); |
| 113 | + $response->assertSee('Version History'); |
| 114 | + $response->assertSee('<strong>Fixed</strong> a crash on launch.', false); |
| 115 | + } |
| 116 | + |
| 117 | + public function test_version_history_excludes_versions_pending_review(): void |
| 118 | + { |
| 119 | + $plugin = Plugin::factory()->approved()->create(); |
| 120 | + |
| 121 | + PluginVersion::create([ |
| 122 | + 'plugin_id' => $plugin->id, |
| 123 | + 'version' => '2.0.0', |
| 124 | + 'tag_name' => 'v2.0.0', |
| 125 | + 'github_release_id' => '2', |
| 126 | + 'published_at' => now(), |
| 127 | + 'release_notes_html' => '<p>Secret unreleased notes.</p>', |
| 128 | + 'requires_review' => true, |
| 129 | + ]); |
| 130 | + |
| 131 | + $response = $this->get(route('plugins.show', $plugin->routeParams())); |
| 132 | + |
| 133 | + $response->assertStatus(200); |
| 134 | + $response->assertDontSee('Secret unreleased notes.'); |
| 135 | + } |
| 136 | +} |
0 commit comments