]> BookStack Code Mirror - bookstack/commitdiff
Fixed failing tests after conversion changes
authorDan Brown <redacted>
Sun, 19 Jun 2022 17:44:34 +0000 (18:44 +0100)
committerDan Brown <redacted>
Sun, 19 Jun 2022 17:44:34 +0000 (18:44 +0100)
app/Entities/Tools/Cloner.php
app/Http/Controllers/BookshelfController.php
tests/Entity/BookTest.php

index 000f28a056f69d319a72c8d740a0dd56ed233c10..ad9ec01ec2a3a0be484af14d96e816d1ce4bd0df 100644 (file)
@@ -99,8 +99,7 @@ class Cloner
 
         // Add a cover to the data if existing on the original entity
         if ($entity->cover instanceof Image) {
-            $tmpImgFile = tmpfile();
-            $uploadedFile = $this->imageToUploadedFile($entity->cover, $tmpImgFile);
+            $uploadedFile = $this->imageToUploadedFile($entity->cover);
             $inputData['image'] = $uploadedFile;
         }
 
@@ -123,10 +122,10 @@ class Cloner
      * Convert an image instance to an UploadedFile instance to mimic
      * a file being uploaded.
      */
-    protected function imageToUploadedFile(Image $image, &$tmpFile): ?UploadedFile
+    protected function imageToUploadedFile(Image $image,): ?UploadedFile
     {
         $imgData = $this->imageService->getImageData($image);
-        $tmpImgFilePath = stream_get_meta_data($tmpFile)['uri'];
+        $tmpImgFilePath = tempnam(sys_get_temp_dir(), 'bs_cover_clone_');
         file_put_contents($tmpImgFilePath, $imgData);
 
         return new UploadedFile($tmpImgFilePath, basename($image->path));
index 121110e8335d83cff6cc67e04a1efaf636dab5f2..a294bf7318c2a35a44d42ff3772b15f900a5123d 100644 (file)
@@ -87,6 +87,7 @@ class BookshelfController extends Controller
             'name'        => ['required', 'string', 'max:255'],
             'description' => ['string', 'max:1000'],
             'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
+            'tags'        => ['array'],
         ]);
 
         $bookIds = explode(',', $request->get('books', ''));
@@ -163,6 +164,7 @@ class BookshelfController extends Controller
             'name'        => ['required', 'string', 'max:255'],
             'description' => ['string', 'max:1000'],
             'image'       => array_merge(['nullable'], $this->getImageValidationRules()),
+            'tags'        => ['array'],
         ]);
 
         if ($request->has('image_reset')) {
index 7f102a17eaede81e70792b8130f091444da0cdd9..8b2702b46e7c1bacfdcf72456cdd4a163a9f054f 100644 (file)
@@ -290,6 +290,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);
     }