]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/BookTest.php
New translations editor.php (Italian)
[bookstack] / tests / Entity / BookTest.php
index 7f102a17eaede81e70792b8130f091444da0cdd9..6b3c6aa388534e1d84fce61efdb04568efc8f56d 100644 (file)
@@ -50,6 +50,33 @@ class BookTest extends TestCase
         $this->assertEquals('my-first-book', $books[1]->slug);
     }
 
+    public function test_create_sets_tags()
+    {
+        // Cheeky initial update to refresh slug
+        $this->asEditor()->post('books', [
+            'name'        => 'My book with tags',
+            'description' => 'A book with tags',
+            'tags'        => [
+                [
+                    'name'  => 'Category',
+                    'value' => 'Donkey Content',
+                ],
+                [
+                    'name'  => 'Level',
+                    'value' => '5',
+                ],
+            ],
+        ]);
+
+        /** @var Book $book */
+        $book = Book::query()->where('name', '=', 'My book with tags')->firstOrFail();
+        $tags = $book->tags()->get();
+
+        $this->assertEquals(2, $tags->count());
+        $this->assertEquals('Donkey Content', $tags[0]->value);
+        $this->assertEquals('Level', $tags[1]->name);
+    }
+
     public function test_update()
     {
         /** @var Book $book */
@@ -74,6 +101,36 @@ class BookTest extends TestCase
         $resp->assertSee($newDesc);
     }
 
+    public function test_update_sets_tags()
+    {
+        /** @var Book $book */
+        $book = Book::query()->first();
+
+        $this->assertEquals(0, $book->tags()->count());
+
+        // Cheeky initial update to refresh slug
+        $this->asEditor()->put($book->getUrl(), [
+            'name' => $book->name,
+            'tags' => [
+                [
+                    'name'  => 'Category',
+                    'value' => 'Dolphin Content',
+                ],
+                [
+                    'name'  => 'Level',
+                    'value' => '5',
+                ],
+            ],
+        ]);
+
+        $book->refresh();
+        $tags = $book->tags()->get();
+
+        $this->assertEquals(2, $tags->count());
+        $this->assertEquals('Dolphin Content', $tags[0]->value);
+        $this->assertEquals('Level', $tags[1]->name);
+    }
+
     public function test_delete()
     {
         $book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
@@ -290,6 +347,7 @@ class BookTest extends TestCase
 
         /** @var Book $copy */
         $copy = Book::query()->where('name', '=', 'My copy book')->first();
+
         $this->assertNotNull($copy->cover);
         $this->assertNotEquals($book->cover->id, $copy->cover->id);
     }