]> BookStack Code Mirror - bookstack/commitdiff
Fixed tests, applied StyleCI changes
authorDan Brown <redacted>
Sat, 26 Mar 2022 20:38:03 +0000 (20:38 +0000)
committerDan Brown <redacted>
Sat, 26 Mar 2022 20:38:03 +0000 (20:38 +0000)
app/Actions/WebhookFormatter.php
app/Entities/Models/PageRevision.php
app/Uploads/ImageService.php
tests/Actions/WebhookFormatTesting.php
tests/ThemeTest.php

index 48b1a392944d23e9616ded1cbc4b7480f4dc75ce..5b64a747ac21a827ea281bf16ca033048783af33 100644 (file)
@@ -60,13 +60,13 @@ class WebhookFormatter
 
     /**
      * @param callable(string, Model):bool $condition
 
     /**
      * @param callable(string, Model):bool $condition
-     * @param callable(Model):void $format
+     * @param callable(Model):void         $format
      */
     public function addModelFormatter(callable $condition, callable $format): void
     {
         $this->modelFormatters[] = [
             'condition' => $condition,
      */
     public function addModelFormatter(callable $condition, callable $format): void
     {
         $this->modelFormatters[] = [
             'condition' => $condition,
-            'format' => $format,
+            'format'    => $format,
         ];
     }
 
         ];
     }
 
@@ -74,14 +74,14 @@ class WebhookFormatter
     {
         // Load entity owner, creator, updater details
         $this->addModelFormatter(
     {
         // Load entity owner, creator, updater details
         $this->addModelFormatter(
-            fn($event, $model) => ($model instanceof Entity),
-            fn($model) => $model->load(['ownedBy', 'createdBy', 'updatedBy'])
+            fn ($event, $model) => ($model instanceof Entity),
+            fn ($model) => $model->load(['ownedBy', 'createdBy', 'updatedBy'])
         );
 
         // Load revision detail for page update and create events
         $this->addModelFormatter(
         );
 
         // Load revision detail for page update and create events
         $this->addModelFormatter(
-            fn($event, $model) => ($model instanceof Page && ($event === ActivityType::PAGE_CREATE || $event === ActivityType::PAGE_UPDATE)),
-            fn($model) => $model->load('currentRevision')
+            fn ($event, $model) => ($model instanceof Page && ($event === ActivityType::PAGE_CREATE || $event === ActivityType::PAGE_UPDATE)),
+            fn ($model) => $model->load('currentRevision')
         );
     }
 
         );
     }
 
@@ -118,6 +118,7 @@ class WebhookFormatter
     {
         $instance = new static($event, $webhook, $detail, $initiator, $initiatedTime);
         $instance->addDefaultModelFormatters();
     {
         $instance = new static($event, $webhook, $detail, $initiator, $initiatedTime);
         $instance->addDefaultModelFormatters();
+
         return $instance;
     }
         return $instance;
     }
-}
\ No newline at end of file
+}
index aacc94586be9dc2ab88c6fbed1086bb10f0ced49..800e5e7f2d8d0332bfcc868bbdcdcb8c872d5698 100644 (file)
@@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 /**
  * Class PageRevision.
  *
 /**
  * Class PageRevision.
  *
- * @property mixed $id
+ * @property mixed  $id
  * @property int    $page_id
  * @property string $slug
  * @property string $book_slug
  * @property int    $page_id
  * @property string $slug
  * @property string $book_slug
index ee414aacb29aff0ca1ec0be21673a3e6cfc6dffb..ca0db997b47a77b727ceb7eb33c126b49a62a0a5 100644 (file)
@@ -338,7 +338,7 @@ class ImageService
      * can be used (At least when created using binary string data) so we need to do some
      * implementation on our side to use the original image data.
      * Bulk of logic taken from: https://github.com/Intervention/image/blob/b734a4988b2148e7d10364b0609978a88d277536/src/Intervention/Image/Commands/OrientateCommand.php
      * can be used (At least when created using binary string data) so we need to do some
      * implementation on our side to use the original image data.
      * Bulk of logic taken from: https://github.com/Intervention/image/blob/b734a4988b2148e7d10364b0609978a88d277536/src/Intervention/Image/Commands/OrientateCommand.php
-     * Copyright (c) Oliver Vogel, MIT License
+     * Copyright (c) Oliver Vogel, MIT License.
      */
     protected function orientImageToOriginalExif(InterventionImage $image, string $originalData): void
     {
      */
     protected function orientImageToOriginalExif(InterventionImage $image, string $originalData): void
     {
@@ -347,7 +347,8 @@ class ImageService
         }
 
         $stream = Utils::streamFor($originalData)->detach();
         }
 
         $stream = Utils::streamFor($originalData)->detach();
-        $orientation = exif_read_data($stream)['Orientation'] ?? null;
+        $exif = @exif_read_data($stream);
+        $orientation = $exif ? ($exif['Orientation'] ?? null) : null;
 
         switch ($orientation) {
             case 2:
 
         switch ($orientation) {
             case 2:
index 56a569ca9bb1ea7faa319ba2000055d9e6020804..4e9ba5e477c69a75ce59f84ef65da66f29143339 100644 (file)
@@ -16,9 +16,9 @@ class WebhookFormatTesting extends TestCase
     public function test_entity_events_show_related_user_info()
     {
         $events = [
     public function test_entity_events_show_related_user_info()
     {
         $events = [
-            ActivityType::BOOK_UPDATE => Book::query()->first(),
+            ActivityType::BOOK_UPDATE    => Book::query()->first(),
             ActivityType::CHAPTER_CREATE => Chapter::query()->first(),
             ActivityType::CHAPTER_CREATE => Chapter::query()->first(),
-            ActivityType::PAGE_MOVE => Page::query()->first(),
+            ActivityType::PAGE_MOVE      => Page::query()->first(),
         ];
 
         foreach ($events as $event => $entity) {
         ];
 
         foreach ($events as $event => $entity) {
@@ -47,6 +47,7 @@ class WebhookFormatTesting extends TestCase
         $webhook = Webhook::factory()->make();
         $user = $this->getEditor();
         $formatter = WebhookFormatter::getDefault($event, $webhook, $detail, $user, time());
         $webhook = Webhook::factory()->make();
         $user = $this->getEditor();
         $formatter = WebhookFormatter::getDefault($event, $webhook, $detail, $user, time());
+
         return $formatter->format();
     }
         return $formatter->format();
     }
-}
\ No newline at end of file
+}
index 775be92fc371379186f3bfad71f7fa41d80a178e..cad2369f8bec50825e626052d52947d3b8b33b05 100644 (file)
@@ -186,7 +186,7 @@ class ThemeTest extends TestCase
 
         dispatch((new DispatchWebhookJob($webhook, $event, $detail)));
 
 
         dispatch((new DispatchWebhookJob($webhook, $event, $detail)));
 
-        $this->assertCount(3, $args);
+        $this->assertCount(5, $args);
         $this->assertEquals($event, $args[0]);
         $this->assertEquals($webhook->id, $args[1]->id);
         $this->assertEquals($detail->id, $args[2]->id);
         $this->assertEquals($event, $args[0]);
         $this->assertEquals($webhook->id, $args[1]->id);
         $this->assertEquals($detail->id, $args[2]->id);