mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Sorting: Updated sort set command, Changed sort timestamp handling
- Renamed AssignSortSetCommand to AssignSortRuleCommand, updated contents and testing. - Updated sorting operations to not update timestamps if only priority is changed.
This commit is contained in:
@@ -207,6 +207,32 @@ class BookSortTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_book_sort_does_not_change_timestamps_on_just_order_changes()
|
||||
{
|
||||
$book = $this->entities->bookHasChaptersAndPages();
|
||||
$chapter = $book->chapters()->first();
|
||||
\DB::table('chapters')->where('id', '=', $chapter->id)->update([
|
||||
'priority' => 10001,
|
||||
'updated_at' => \Carbon\Carbon::now()->subYear(5),
|
||||
]);
|
||||
|
||||
$chapter->refresh();
|
||||
$oldUpdatedAt = $chapter->updated_at->unix();
|
||||
|
||||
$sortData = [
|
||||
'id' => $chapter->id,
|
||||
'sort' => 0,
|
||||
'parentChapter' => false,
|
||||
'type' => 'chapter',
|
||||
'book' => $book->id,
|
||||
];
|
||||
$this->asEditor()->put($book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
|
||||
|
||||
$chapter->refresh();
|
||||
$this->assertNotEquals(10001, $chapter->priority);
|
||||
$this->assertEquals($oldUpdatedAt, $chapter->updated_at->unix());
|
||||
}
|
||||
|
||||
public function test_book_sort_item_returns_book_content()
|
||||
{
|
||||
$bookToSort = $this->entities->book();
|
||||
|
@@ -165,6 +165,27 @@ class SortRuleTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_auto_book_sort_does_not_touch_timestamps()
|
||||
{
|
||||
$book = $this->entities->bookHasChaptersAndPages();
|
||||
$rule = SortRule::factory()->create(['sequence' => 'name_asc,chapters_first']);
|
||||
$book->sort_rule_id = $rule->id;
|
||||
$book->save();
|
||||
$page = $book->pages()->first();
|
||||
$chapter = $book->chapters()->first();
|
||||
|
||||
$resp = $this->actingAsApiEditor()->put("/api/pages/{$page->id}", [
|
||||
'name' => '1111 page',
|
||||
]);
|
||||
$resp->assertOk();
|
||||
|
||||
$oldTime = $chapter->updated_at->unix();
|
||||
$oldPriority = $chapter->priority;
|
||||
$chapter->refresh();
|
||||
$this->assertEquals($oldTime, $chapter->updated_at->unix());
|
||||
$this->assertNotEquals($oldPriority, $chapter->priority);
|
||||
}
|
||||
|
||||
public function test_name_numeric_ordering()
|
||||
{
|
||||
$book = Book::factory()->create();
|
||||
|
Reference in New Issue
Block a user