|
2 | 2 |
|
3 | 3 | namespace Tests\Settings; |
4 | 4 |
|
| 5 | +use Illuminate\Support\Facades\Storage; |
5 | 6 | use Tests\TestCase; |
| 7 | +use Tests\Uploads\UsesImages; |
6 | 8 |
|
7 | 9 | class SettingsTest extends TestCase |
8 | 10 | { |
| 11 | + use UsesImages; |
| 12 | + |
9 | 13 | public function test_settings_endpoint_redirects_to_settings_view() |
10 | 14 | { |
11 | 15 | $resp = $this->asAdmin()->get('/settings'); |
@@ -40,4 +44,46 @@ public function test_not_found_setting_category_throws_404() |
40 | 44 | $resp->assertStatus(404); |
41 | 45 | $resp->assertSee('Page Not Found'); |
42 | 46 | } |
| 47 | + |
| 48 | + public function test_updating_and_removing_app_icon() |
| 49 | + { |
| 50 | + $this->asAdmin(); |
| 51 | + $galleryFile = $this->getTestImage('my-app-icon.png'); |
| 52 | + $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png'); |
| 53 | + |
| 54 | + $this->assertFalse(setting()->get('app-icon')); |
| 55 | + $this->assertFalse(setting()->get('app-icon-180')); |
| 56 | + $this->assertFalse(setting()->get('app-icon-128')); |
| 57 | + $this->assertFalse(setting()->get('app-icon-64')); |
| 58 | + $this->assertFalse(setting()->get('app-icon-32')); |
| 59 | + |
| 60 | + $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); |
| 61 | + |
| 62 | + $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []); |
| 63 | + $upload->assertRedirect('/settings/customization'); |
| 64 | + |
| 65 | + $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath); |
| 66 | + $this->assertStringContainsString('my-app-icon', setting()->get('app-icon')); |
| 67 | + $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180')); |
| 68 | + $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128')); |
| 69 | + $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64')); |
| 70 | + $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32')); |
| 71 | + |
| 72 | + $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); |
| 73 | + $this->assertEquals(5, $newFileCount - $prevFileCount); |
| 74 | + |
| 75 | + $resp = $this->get('/'); |
| 76 | + $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6); |
| 77 | + |
| 78 | + $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']); |
| 79 | + $reset->assertRedirect('/settings/customization'); |
| 80 | + |
| 81 | + $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); |
| 82 | + $this->assertEquals($prevFileCount, $resetFileCount); |
| 83 | + $this->assertFalse(setting()->get('app-icon')); |
| 84 | + $this->assertFalse(setting()->get('app-icon-180')); |
| 85 | + $this->assertFalse(setting()->get('app-icon-128')); |
| 86 | + $this->assertFalse(setting()->get('app-icon-64')); |
| 87 | + $this->assertFalse(setting()->get('app-icon-32')); |
| 88 | + } |
43 | 89 | } |
0 commit comments