Skip to content

Commit a50b0ea

Browse files
committed
Covered app icon setting with testing
1 parent 3c658e3 commit a50b0ea

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/Settings/SettingsTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace Tests\Settings;
44

5+
use Illuminate\Support\Facades\Storage;
56
use Tests\TestCase;
7+
use Tests\Uploads\UsesImages;
68

79
class SettingsTest extends TestCase
810
{
11+
use UsesImages;
12+
913
public function test_settings_endpoint_redirects_to_settings_view()
1014
{
1115
$resp = $this->asAdmin()->get('/settings');
@@ -40,4 +44,46 @@ public function test_not_found_setting_category_throws_404()
4044
$resp->assertStatus(404);
4145
$resp->assertSee('Page Not Found');
4246
}
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+
}
4389
}

0 commit comments

Comments
 (0)