3 namespace Tests\Settings;
7 class SettingsTest extends TestCase
9 public function test_admin_can_see_settings()
11 $this->asAdmin()->get('/settings/features')->assertSee('Settings');
14 public function test_settings_endpoint_redirects_to_settings_view()
16 $resp = $this->asAdmin()->get('/settings');
18 $resp->assertStatus(302);
20 // Manually check path to ensure it's generated as the full path
21 $location = $resp->headers->get('location');
22 $this->assertEquals(url('/settings/features'), $location);
25 public function test_settings_category_links_work_as_expected()
29 'features' => 'Features & Security',
30 'customization' => 'Customization',
31 'registration' => 'Registration',
34 foreach ($categories as $category => $title) {
35 $resp = $this->get("/settings/{$category}");
36 $this->withHtml($resp)->assertElementContains('h1', $title);
37 $this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
41 public function test_not_found_setting_category_throws_404()
43 $resp = $this->asAdmin()->get('/settings/biscuits');
45 $resp->assertStatus(404);
46 $resp->assertSee('Page Not Found');
49 public function test_updating_and_removing_app_icon()
52 $galleryFile = $this->files->uploadedImage('my-app-icon.png');
53 $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
55 $this->assertFalse(setting()->get('app-icon'));
56 $this->assertFalse(setting()->get('app-icon-180'));
57 $this->assertFalse(setting()->get('app-icon-128'));
58 $this->assertFalse(setting()->get('app-icon-64'));
59 $this->assertFalse(setting()->get('app-icon-32'));
61 file_get_contents(public_path('icon.ico')),
62 file_get_contents(public_path('favicon.ico')),
65 $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
67 $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
68 $upload->assertRedirect('/settings/customization');
70 $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
71 $this->assertStringContainsString('my-app-icon', setting()->get('app-icon'));
72 $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180'));
73 $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128'));
74 $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64'));
75 $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32'));
77 $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
78 $this->assertEquals(5, $newFileCount - $prevFileCount);
80 $resp = $this->get('/');
81 $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
83 $this->assertNotEquals(
84 file_get_contents(public_path('icon.ico')),
85 file_get_contents(public_path('favicon.ico')),
88 $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
89 $reset->assertRedirect('/settings/customization');
91 $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
92 $this->assertEquals($prevFileCount, $resetFileCount);
93 $this->assertFalse(setting()->get('app-icon'));
94 $this->assertFalse(setting()->get('app-icon-180'));
95 $this->assertFalse(setting()->get('app-icon-128'));
96 $this->assertFalse(setting()->get('app-icon-64'));
97 $this->assertFalse(setting()->get('app-icon-32'));
100 file_get_contents(public_path('icon.ico')),
101 file_get_contents(public_path('favicon.ico')),