2022-03-28 06:09:55 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Settings;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class SettingsTest extends TestCase
|
|
|
|
{
|
2023-07-04 16:40:05 -04:00
|
|
|
public function test_admin_can_see_settings()
|
|
|
|
{
|
|
|
|
$this->asAdmin()->get('/settings/features')->assertSee('Settings');
|
|
|
|
}
|
|
|
|
|
2022-03-28 06:09:55 -04:00
|
|
|
public function test_settings_endpoint_redirects_to_settings_view()
|
|
|
|
{
|
|
|
|
$resp = $this->asAdmin()->get('/settings');
|
|
|
|
|
2022-03-30 14:15:24 -04:00
|
|
|
$resp->assertStatus(302);
|
|
|
|
|
|
|
|
// Manually check path to ensure it's generated as the full path
|
|
|
|
$location = $resp->headers->get('location');
|
|
|
|
$this->assertEquals(url('/settings/features'), $location);
|
2022-03-28 06:09:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_settings_category_links_work_as_expected()
|
|
|
|
{
|
|
|
|
$this->asAdmin();
|
|
|
|
$categories = [
|
2022-03-28 06:31:06 -04:00
|
|
|
'features' => 'Features & Security',
|
2022-03-28 06:09:55 -04:00
|
|
|
'customization' => 'Customization',
|
2022-03-28 06:31:06 -04:00
|
|
|
'registration' => 'Registration',
|
2022-03-28 06:09:55 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($categories as $category => $title) {
|
|
|
|
$resp = $this->get("/settings/{$category}");
|
2022-07-23 10:10:18 -04:00
|
|
|
$this->withHtml($resp)->assertElementContains('h1', $title);
|
|
|
|
$this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]");
|
2022-03-28 06:09:55 -04:00
|
|
|
}
|
|
|
|
}
|
2022-03-28 06:16:20 -04:00
|
|
|
|
|
|
|
public function test_not_found_setting_category_throws_404()
|
|
|
|
{
|
|
|
|
$resp = $this->asAdmin()->get('/settings/biscuits');
|
|
|
|
|
|
|
|
$resp->assertStatus(404);
|
|
|
|
$resp->assertSee('Page Not Found');
|
|
|
|
}
|
2023-01-25 11:41:41 -05:00
|
|
|
|
|
|
|
public function test_updating_and_removing_app_icon()
|
|
|
|
{
|
|
|
|
$this->asAdmin();
|
2023-02-08 09:39:13 -05:00
|
|
|
$galleryFile = $this->files->uploadedImage('my-app-icon.png');
|
2023-01-25 11:41:41 -05:00
|
|
|
$expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png');
|
|
|
|
|
|
|
|
$this->assertFalse(setting()->get('app-icon'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-180'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-128'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-64'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-32'));
|
2023-02-09 08:24:43 -05:00
|
|
|
$this->assertEquals(
|
|
|
|
file_get_contents(public_path('icon.ico')),
|
|
|
|
file_get_contents(public_path('favicon.ico')),
|
|
|
|
);
|
2023-01-25 11:41:41 -05:00
|
|
|
|
|
|
|
$prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
|
|
|
|
|
|
|
|
$upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []);
|
|
|
|
$upload->assertRedirect('/settings/customization');
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
|
|
|
|
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon'));
|
|
|
|
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180'));
|
|
|
|
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128'));
|
|
|
|
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64'));
|
|
|
|
$this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32'));
|
|
|
|
|
|
|
|
$newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
|
|
|
|
$this->assertEquals(5, $newFileCount - $prevFileCount);
|
|
|
|
|
|
|
|
$resp = $this->get('/');
|
|
|
|
$this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
|
|
|
|
|
2023-02-09 08:24:43 -05:00
|
|
|
$this->assertNotEquals(
|
|
|
|
file_get_contents(public_path('icon.ico')),
|
|
|
|
file_get_contents(public_path('favicon.ico')),
|
|
|
|
);
|
|
|
|
|
2023-01-25 11:41:41 -05:00
|
|
|
$reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
|
|
|
|
$reset->assertRedirect('/settings/customization');
|
|
|
|
|
|
|
|
$resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
|
|
|
|
$this->assertEquals($prevFileCount, $resetFileCount);
|
|
|
|
$this->assertFalse(setting()->get('app-icon'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-180'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-128'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-64'));
|
|
|
|
$this->assertFalse(setting()->get('app-icon-32'));
|
2023-02-09 08:24:43 -05:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
file_get_contents(public_path('icon.ico')),
|
|
|
|
file_get_contents(public_path('favicon.ico')),
|
|
|
|
);
|
2023-01-25 11:41:41 -05:00
|
|
|
}
|
2022-03-28 06:31:06 -04:00
|
|
|
}
|