mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Aligned user preference endpoints in style and behaviour
Changes their endpoints and remove the user id from the URLs. Simplifies list changes to share a single endpoint, which aligns it to the behaviour of the existing sort preference endpoint. Also added test to ensure user preferences are deleted on user delete.
This commit is contained in:
@@ -225,18 +225,18 @@ class BookTest extends TestCase
|
||||
setting()->putUser($editor, 'books_view_type', 'list');
|
||||
|
||||
$resp = $this->actingAs($editor)->get('/books');
|
||||
$this->withHtml($resp)->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'Grid View');
|
||||
$this->withHtml($resp)->assertElementExists('input[name="view_type"][value="grid"]');
|
||||
$this->withHtml($resp)->assertElementContains('form[action$="/preferences/change-view/books"]', 'Grid View');
|
||||
$this->withHtml($resp)->assertElementExists('button[name="view"][value="grid"]');
|
||||
|
||||
$resp = $this->patch("/settings/users/{$editor->id}/switch-books-view", ['view_type' => 'grid']);
|
||||
$resp = $this->patch("/preferences/change-view/books", ['view' => 'grid']);
|
||||
$resp->assertRedirect();
|
||||
$this->assertEquals('grid', setting()->getUser($editor, 'books_view_type'));
|
||||
|
||||
$resp = $this->actingAs($editor)->get('/books');
|
||||
$this->withHtml($resp)->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'List View');
|
||||
$this->withHtml($resp)->assertElementExists('input[name="view_type"][value="list"]');
|
||||
$this->withHtml($resp)->assertElementContains('form[action$="/preferences/change-view/books"]', 'List View');
|
||||
$this->withHtml($resp)->assertElementExists('button[name="view"][value="list"]');
|
||||
|
||||
$resp = $this->patch("/settings/users/{$editor->id}/switch-books-view", ['view_type' => 'list']);
|
||||
$resp = $this->patch("/preferences/change-view/books", ['view_type' => 'list']);
|
||||
$resp->assertRedirect();
|
||||
$this->assertEquals('list', setting()->getUser($editor, 'books_view_type'));
|
||||
}
|
||||
|
@@ -160,6 +160,23 @@ class UserManagementTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_removes_user_preferences()
|
||||
{
|
||||
$editor = $this->getEditor();
|
||||
setting()->putUser($editor, 'dark-mode-enabled', 'true');
|
||||
|
||||
$this->assertDatabaseHas('settings', [
|
||||
'setting_key' => 'user:' . $editor->id . ':dark-mode-enabled',
|
||||
'value' => 'true',
|
||||
]);
|
||||
|
||||
$this->asAdmin()->delete("settings/users/{$editor->id}");
|
||||
|
||||
$this->assertDatabaseMissing('settings', [
|
||||
'setting_key' => 'user:' . $editor->id . ':dark-mode-enabled',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_guest_profile_shows_limited_form()
|
||||
{
|
||||
$guest = User::getDefault();
|
||||
|
@@ -50,7 +50,7 @@ class UserPreferencesTest extends TestCase
|
||||
$editor = $this->getEditor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/books', [
|
||||
$updateRequest = $this->patch('/preferences/change-sort/books', [
|
||||
'sort' => 'created_at',
|
||||
'order' => 'desc',
|
||||
]);
|
||||
@@ -73,7 +73,7 @@ class UserPreferencesTest extends TestCase
|
||||
$editor = $this->getEditor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/dogs', [
|
||||
$updateRequest = $this->patch('/preferences/change-sort/dogs', [
|
||||
'sort' => 'name',
|
||||
'order' => 'asc',
|
||||
]);
|
||||
@@ -88,7 +88,7 @@ class UserPreferencesTest extends TestCase
|
||||
$editor = $this->getEditor();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$updateRequest = $this->patch('/settings/users/' . $editor->id . '/update-expansion-preference/home-details', ['expand' => 'true']);
|
||||
$updateRequest = $this->patch('/preferences/change-expansion/home-details', ['expand' => 'true']);
|
||||
$updateRequest->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('settings', [
|
||||
@@ -97,7 +97,7 @@ class UserPreferencesTest extends TestCase
|
||||
]);
|
||||
$this->assertEquals(true, setting()->getForCurrentUser('section_expansion#home-details'));
|
||||
|
||||
$invalidKeyRequest = $this->patch('/settings/users/' . $editor->id . '/update-expansion-preference/my-home-details', ['expand' => 'true']);
|
||||
$invalidKeyRequest = $this->patch('/preferences/change-expansion/my-home-details', ['expand' => 'true']);
|
||||
$invalidKeyRequest->assertStatus(500);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class UserPreferencesTest extends TestCase
|
||||
$this->withHtml($home)->assertElementNotExists('.dark-mode');
|
||||
|
||||
$this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled', false));
|
||||
$prefChange = $this->patch('/settings/users/toggle-dark-mode');
|
||||
$prefChange = $this->patch('/preferences/toggle-dark-mode');
|
||||
$prefChange->assertRedirect();
|
||||
$this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
|
||||
|
||||
@@ -162,7 +162,7 @@ class UserPreferencesTest extends TestCase
|
||||
->assertElementNotExists('.featured-image-container')
|
||||
->assertElementExists('.content-wrap .entity-list-item');
|
||||
|
||||
$req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
|
||||
$req = $this->patch("/preferences/change-view/bookshelf", ['view' => 'grid']);
|
||||
$req->assertRedirect($shelf->getUrl());
|
||||
|
||||
$resp = $this->actingAs($editor)->get($shelf->getUrl())
|
||||
@@ -179,14 +179,14 @@ class UserPreferencesTest extends TestCase
|
||||
$page = $this->entities->page();
|
||||
$this->actingAs($editor);
|
||||
|
||||
$this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => true]);
|
||||
$this->patch('/settings/users/update-code-language-favourite', ['language' => 'javascript', 'active' => true]);
|
||||
$this->patch('/preferences/update-code-language-favourite', ['language' => 'php', 'active' => true]);
|
||||
$this->patch('/preferences/update-code-language-favourite', ['language' => 'javascript', 'active' => true]);
|
||||
|
||||
$resp = $this->get($page->getUrl('/edit'));
|
||||
$resp->assertSee('option:code-editor:favourites="php,javascript"', false);
|
||||
|
||||
$this->patch('/settings/users/update-code-language-favourite', ['language' => 'ruby', 'active' => true]);
|
||||
$this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => false]);
|
||||
$this->patch('/preferences/update-code-language-favourite', ['language' => 'ruby', 'active' => true]);
|
||||
$this->patch('/preferences/update-code-language-favourite', ['language' => 'php', 'active' => false]);
|
||||
|
||||
$resp = $this->get($page->getUrl('/edit'));
|
||||
$resp->assertSee('option:code-editor:favourites="javascript,ruby"', false);
|
||||
|
Reference in New Issue
Block a user