]> BookStack Code Mirror - bookstack/blobdiff - tests/Sorting/BookSortTest.php
Mail: Removed custom symfony/mailer fork
[bookstack] / tests / Sorting / BookSortTest.php
index a726da148985d6094deb10b5d48a44a195f0c94d..4737ec231b62597bf05e605fdb1852f333c67635 100644 (file)
@@ -1,11 +1,11 @@
 <?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
@@ -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();
@@ -223,13 +249,13 @@ class BookSortTest extends TestCase
 
     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'));
@@ -238,7 +264,7 @@ class BookSortTest extends TestCase
 
     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'));
 
@@ -247,7 +273,7 @@ class BookSortTest extends TestCase
 
     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;
@@ -261,7 +287,7 @@ class BookSortTest extends TestCase
         $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'));