]> BookStack Code Mirror - bookstack/commitdiff
Addressed a range of deprecation warnings
authorDan Brown <redacted>
Sat, 21 Jan 2023 20:50:04 +0000 (20:50 +0000)
committerDan Brown <redacted>
Sat, 21 Jan 2023 20:50:04 +0000 (20:50 +0000)
Closes #3969

17 files changed:
app/Entities/Tools/Markdown/MarkdownToHtml.php
app/Search/SearchIndex.php
app/Util/CspService.php
database/factories/Actions/TagFactory.php
database/factories/Actions/WebhookFactory.php
database/factories/Auth/UserFactory.php
database/factories/Entities/Models/BookFactory.php
database/factories/Entities/Models/ChapterFactory.php
database/factories/Entities/Models/PageFactory.php
database/factories/Uploads/ImageFactory.php
dev/docs/development.md
resources/views/common/notifications.blade.php
resources/views/exports/parts/meta.blade.php
resources/views/pages/parts/revisions-index-row.blade.php
tests/Entity/ExportTest.php
tests/Entity/PageContentTest.php
tests/TestCase.php

index f3cf7ab2fc41efbb95386bfd66b75fa2b53f35a7..06587ce1f6c75562e08bb4dca223f60634858f22 100644 (file)
@@ -5,10 +5,10 @@ namespace BookStack\Entities\Tools\Markdown;
 use BookStack\Facades\Theme;
 use BookStack\Theming\ThemeEvents;
 use League\CommonMark\Block\Element\ListItem;
-use League\CommonMark\CommonMarkConverter;
 use League\CommonMark\Environment;
 use League\CommonMark\Extension\Table\TableExtension;
 use League\CommonMark\Extension\TaskList\TaskListExtension;
+use League\CommonMark\MarkdownConverter;
 
 class MarkdownToHtml
 {
@@ -26,7 +26,7 @@ class MarkdownToHtml
         $environment->addExtension(new TaskListExtension());
         $environment->addExtension(new CustomStrikeThroughExtension());
         $environment = Theme::dispatch(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, $environment) ?? $environment;
-        $converter = new CommonMarkConverter([], $environment);
+        $converter = new MarkdownConverter($environment);
 
         $environment->addBlockRenderer(ListItem::class, new CustomListItemRenderer(), 10);
 
index 8c793a109ffb905c2d75904d17a24b34f802e770..54ed95ebbe515f8aa322c2cbf405a7c7fbe99213 100644 (file)
@@ -112,12 +112,12 @@ class SearchIndex
      *
      * @returns array<string, int>
      */
-    protected function generateTermScoreMapFromText(string $text, int $scoreAdjustment = 1): array
+    protected function generateTermScoreMapFromText(string $text, float $scoreAdjustment = 1): array
     {
         $termMap = $this->textToTermCountMap($text);
 
         foreach ($termMap as $term => $count) {
-            $termMap[$term] = $count * $scoreAdjustment;
+            $termMap[$term] = floor($count * $scoreAdjustment);
         }
 
         return $termMap;
index f9ab666acb79c6b9726bd6de7bf84b744f40092e..227ec8e0b3db683d0b17d98c3139feac406bc371 100644 (file)
@@ -126,7 +126,7 @@ class CspService
 
     protected function getAllowedIframeHosts(): array
     {
-        $hosts = config('app.iframe_hosts', '');
+        $hosts = config('app.iframe_hosts') ?? '';
 
         return array_filter(explode(' ', $hosts));
     }
index 8d5c77e09bfdbc04e34786503cfa01d50e1b027e..8b9c529f2ee7d69a385b069991a9314894ab8108 100644 (file)
@@ -21,7 +21,7 @@ class TagFactory extends Factory
     public function definition()
     {
         return [
-            'name'  => $this->faker->city,
+            'name'  => $this->faker->city(),
             'value' => $this->faker->sentence(3),
         ];
     }
index 662f64f8bc90a5856f1b9c3ec2ffd4ba700ad70a..c7393b32c53d01344c7fbbe314223c105f4ff23d 100644 (file)
@@ -18,7 +18,7 @@ class WebhookFactory extends Factory
     {
         return [
             'name'     => 'My webhook for ' . $this->faker->country(),
-            'endpoint' => $this->faker->url,
+            'endpoint' => $this->faker->url(),
             'active'   => true,
             'timeout'  => 3,
         ];
index 805782fd809891b7ba1fdbf06ceb771a59c5be41..6ff62a97569e5932e09b8da8d827c57e42f04b90 100644 (file)
@@ -22,11 +22,11 @@ class UserFactory extends Factory
      */
     public function definition()
     {
-        $name = $this->faker->name;
+        $name = $this->faker->name();
 
         return [
             'name'            => $name,
-            'email'           => $this->faker->email,
+            'email'           => $this->faker->email(),
             'slug'            => Str::slug($name . '-' . Str::random(5)),
             'password'        => Str::random(10),
             'remember_token'  => Str::random(10),
index 0613800a14350499844d9e0e3b62e176c0b70170..3bf15778670387554fd7f655147610a200103a32 100644 (file)
@@ -22,9 +22,9 @@ class BookFactory extends Factory
     public function definition()
     {
         return [
-            'name'        => $this->faker->sentence,
+            'name'        => $this->faker->sentence(),
             'slug'        => Str::random(10),
-            'description' => $this->faker->paragraph,
+            'description' => $this->faker->paragraph(),
         ];
     }
 }
index 4fcd69c392d337b98fdeead8dde2226b0adb14ab..36379866ed85bfafe7822413ed99510ba751ab4b 100644 (file)
@@ -22,9 +22,9 @@ class ChapterFactory extends Factory
     public function definition()
     {
         return [
-            'name'        => $this->faker->sentence,
+            'name'        => $this->faker->sentence(),
             'slug'        => Str::random(10),
-            'description' => $this->faker->paragraph,
+            'description' => $this->faker->paragraph(),
         ];
     }
 }
index c83e0f828c4ffd3b43b815fdaeb437ae6b287ee7..319d97880ca08ce389fa9386aac9a436f34da93b 100644 (file)
@@ -24,7 +24,7 @@ class PageFactory extends Factory
         $html = '<p>' . implode('</p>', $this->faker->paragraphs(5)) . '</p>';
 
         return [
-            'name'           => $this->faker->sentence,
+            'name'           => $this->faker->sentence(),
             'slug'           => Str::random(10),
             'html'           => $html,
             'text'           => strip_tags($html),
index c6d0e08012848c12c855dcff5effe4a1339bd940..b66c0a52c043399d75d6c963d70c9b4b9409a7ab 100644 (file)
@@ -21,9 +21,9 @@ class ImageFactory extends Factory
     public function definition()
     {
         return [
-            'name'        => $this->faker->slug . '.jpg',
-            'url'         => $this->faker->url,
-            'path'        => $this->faker->url,
+            'name'        => $this->faker->slug() . '.jpg',
+            'url'         => $this->faker->url(),
+            'path'        => $this->faker->url(),
             'type'        => 'gallery',
             'uploaded_to' => 0,
         ];
index 1611de578fc5fd49795bcaa22e7d546faed994b1..b68f2664aa38762df7743f8628e4dc474bcf3c6e 100644 (file)
@@ -29,6 +29,8 @@ The testing database will also need migrating and seeding beforehand. This can b
 
 Once done you can run `composer test` in the application root directory to run all tests. Tests can be ran in parallel by running them via `composer t`. This will use Laravel's built-in parallel testing functionality, and attempt to create and seed a database instance for each testing thread. If required these parallel testing instances can be reset, before testing again, by running `composer t-reset`.
 
+If the codebase needs to be tested with deprecations, this can be done via uncommenting the relevant line within the TestCase@setUp function. 
+
 ## Code Standards
 
 PHP code standards are managed by [using PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
index e06bd5fd13861b0e85a03ebdbea69817fc8644f6..8b76a8dd53e9ade61cfd48ac03361af3d9007fd8 100644 (file)
@@ -5,7 +5,7 @@
      style="display: none;"
      class="notification pos"
      role="alert">
-    @icon('check-circle') <span>{!! nl2br(htmlentities(session()->get('success'))) !!}</span><div class="dismiss">@icon('close')</div>
+    @icon('check-circle') <span>@if(session()->has('success')){!! nl2br(htmlentities(session()->get('success'))) !!}@endif</span><div class="dismiss">@icon('close')</div>
 </div>
 
 <div component="notification"
@@ -15,7 +15,7 @@
      style="display: none;"
      class="notification warning"
      role="alert">
-    @icon('info') <span>{!! nl2br(htmlentities(session()->get('warning'))) !!}</span><div class="dismiss">@icon('close')</div>
+    @icon('info') <span>@if(session()->has('warning')){!! nl2br(htmlentities(session()->get('warning'))) !!}@endif</span><div class="dismiss">@icon('close')</div>
 </div>
 
 <div component="notification"
@@ -25,5 +25,5 @@
      style="display: none;"
      class="notification neg"
      role="alert">
-    @icon('danger') <span>{!! nl2br(htmlentities(session()->get('error'))) !!}</span><div class="dismiss">@icon('close')</div>
+    @icon('danger') <span>@if(session()->has('error')){!! nl2br(htmlentities(session()->get('error'))) !!}@endif</span><div class="dismiss">@icon('close')</div>
 </div>
\ No newline at end of file
index 02a39e78c9218873251da588345113516ab98b0c..d4128898bc8dc8094d37fcd4c73945c1afd828b2 100644 (file)
@@ -4,13 +4,13 @@
     @endif
 
     @icon('star'){!! trans('entities.meta_created' . ($entity->createdBy ? '_name' : ''), [
-        'timeLength' => $entity->created_at->formatLocalized('%e %B %Y %H:%M:%S'),
+        'timeLength' => $entity->created_at->isoFormat('D MMMM Y HH:mm:ss'),
         'user' => e($entity->createdBy->name ?? ''),
         ]) !!}
     <br>
 
     @icon('edit'){!! trans('entities.meta_updated' . ($entity->updatedBy ? '_name' : ''), [
-            'timeLength' => $entity->updated_at->formatLocalized('%e %B %Y %H:%M:%S'),
+            'timeLength' => $entity->updated_at->isoFormat('D MMMM Y HH:mm:ss'),
             'user' => e($entity->updatedBy->name ?? '')
         ]) !!}
 </div>
\ No newline at end of file
index 597b53234198cef25addab495078237721302a61..fdc6a772d1734bd6e67c5bac7430305ea5dc88f6 100644 (file)
@@ -17,7 +17,7 @@
                 @if($revision->createdBy) {{ $revision->createdBy->name }} @else {{ trans('common.deleted_user') }} @endif
                 <br>
                 <div class="text-muted">
-                    <small>{{ $revision->created_at->formatLocalized('%e %B %Y %H:%M:%S') }}</small>
+                    <small>{{ $revision->created_at->isoFormat('D MMMM Y HH:mm:ss') }}</small>
                     <small>({{ $revision->created_at->diffForHumans() }})</small>
                 </div>
             </div>
index 0f80bdd49283134cd40045a5d5c328503f27a105..68c70e6c0062f5132b2ee39b2682d5c3e4e73391 100644 (file)
@@ -160,9 +160,9 @@ class ExportTest extends TestCase
         $page = $this->entities->page();
 
         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
-        $resp->assertSee($page->created_at->formatLocalized('%e %B %Y %H:%M:%S'));
+        $resp->assertSee($page->created_at->isoFormat('D MMMM Y HH:mm:ss'));
         $resp->assertDontSee($page->created_at->diffForHumans());
-        $resp->assertSee($page->updated_at->formatLocalized('%e %B %Y %H:%M:%S'));
+        $resp->assertSee($page->updated_at->isoFormat('D MMMM Y HH:mm:ss'));
         $resp->assertDontSee($page->updated_at->diffForHumans());
     }
 
index 0c9854206d12be7c9124c5057c24a2a203b8e822..53107d14d19177cc6adb6ea408cb28714e952936 100644 (file)
@@ -310,7 +310,7 @@ class PageContentTest extends TestCase
     {
         $this->asEditor();
         $page = $this->entities->page();
-        config()->push('app.allow_content_scripts', 'true');
+        config()->set('app.allow_content_scripts', 'true');
 
         $script = 'abc123<script>console.log("hello-test")</script>abc123';
         $page->html = "no escape {$script}";
@@ -355,7 +355,7 @@ class PageContentTest extends TestCase
     {
         $this->asEditor();
         $page = $this->entities->page();
-        config()->push('app.allow_content_scripts', 'true');
+        config()->set('app.allow_content_scripts', 'true');
 
         $script = '<p onmouseenter="console.log(\'test\')">Hello</p>';
         $page->html = "escape {$script}";
index d0dd7d772084f9a6042e2902022854dfd0a7b21b..d9a614fc6d7c8bc09f6f88cb9b7ba07ef31724ce 100644 (file)
@@ -43,6 +43,10 @@ abstract class TestCase extends BaseTestCase
     {
         $this->entities = new EntityProvider();
         parent::setUp();
+
+        // We can uncomment the below to run tests with failings upon deprecations.
+        // Can't leave on since some deprecations can only be fixed upstream.
+         // $this->withoutDeprecationHandling();
     }
 
     /**
Morty Proxy This is a proxified and sanitized view of the page, visit original site.