<?php
-namespace Sorting;
+namespace Tests\Sorting;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
-use BookStack\Sorting\SortSet;
+use BookStack\Sorting\SortRule;
use Tests\TestCase;
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();
public function test_book_sort_item_shows_auto_sort_status()
{
- $sort = SortSet::factory()->create(['name' => 'My sort']);
+ $sort = SortRule::factory()->create(['name' => 'My sort']);
$book = $this->entities->book();
$resp = $this->asAdmin()->get($book->getUrl('/sort-item'));
$this->withHtml($resp)->assertElementNotExists("span[title='Auto Sort Active: My sort']");
- $book->sort_set_id = $sort->id;
+ $book->sort_rule_id = $sort->id;
$book->save();
$resp = $this->asAdmin()->get($book->getUrl('/sort-item'));
public function test_auto_sort_options_shown_on_sort_page()
{
- $sort = SortSet::factory()->create();
+ $sort = SortRule::factory()->create();
$book = $this->entities->book();
$resp = $this->asAdmin()->get($book->getUrl('/sort'));
public function test_auto_sort_option_submit_saves_to_book()
{
- $sort = SortSet::factory()->create();
+ $sort = SortRule::factory()->create();
$book = $this->entities->book();
$bookPage = $book->pages()->first();
$bookPage->priority = 10000;
$book->refresh();
$bookPage->refresh();
- $this->assertEquals($sort->id, $book->sort_set_id);
+ $this->assertEquals($sort->id, $book->sort_rule_id);
$this->assertNotEquals(10000, $bookPage->priority);
$resp = $this->get($book->getUrl('/sort'));