3 namespace Tests\Settings;
5 use Illuminate\Support\Facades\Storage;
7 use Tests\Uploads\UsesImages;
9 class SettingsTest extends TestCase
13 public function test_settings_endpoint_redirects_to_settings_view()
15 $resp = $this->asAdmin()->get('/settings');
17 $resp->assertStatus(302);
19 // Manually check path to ensure it's generated as the full path
20 $location = $resp->headers->get('location');
21 $this->assertEquals(url('/settings/features'), $location);
24 public function test_settings_category_links_work_as_expected()
28 'features' => 'Features & Security',
29 'customization' => 'Customization',
30 'registration' => 'Registration',
33 foreach ($categories as $category => $title) {
34 $resp = $this->get("/settings/{$category}");
35 $this->withHtml($resp)->assertElementContains('h1', $title);
36 $this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
40 public function test_not_found_setting_category_throws_404()
42 $resp = $this->asAdmin()->get('/settings/biscuits');
44 $resp->assertStatus(404);
45 $resp->assertSee('Page Not Found');
48 public function test_updating_and_removing_app_icon()
51 $galleryFile = $this->getTestImage('my-app-icon.png');
52 $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
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'));
60 $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
62 $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
63 $upload->assertRedirect('/settings/customization');
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'));
72 $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
73 $this->assertEquals(5, $newFileCount - $prevFileCount);
75 $resp = $this->get('/');
76 $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
78 $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
79 $reset->assertRedirect('/settings/customization');
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'));