Updated to laravel 6

This commit is contained in:
Dan Brown 2019-09-14 14:12:39 +01:00
parent 140298bd96
commit cbf9d701af
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
17 changed files with 573 additions and 328 deletions

View File

@ -1,8 +1,8 @@
dist: bionic dist: bionic
language: php language: php
php: php:
- '7.1.3'
- '7.2' - '7.2'
- '7.3'
services: services:
- mysql - mysql

View File

@ -1,5 +1,6 @@
<?php <?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
/** /**
@ -71,6 +72,11 @@ return [
'driver' => 'errorlog', 'driver' => 'errorlog',
'level' => 'debug', 'level' => 'debug',
], ],
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
], ],
]; ];

View File

@ -29,6 +29,7 @@ class Kernel extends HttpKernel
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class, \Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\BookStack\Http\Middleware\VerifyCsrfToken::class, \BookStack\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
\BookStack\Http\Middleware\Localization::class \BookStack\Http\Middleware\Localization::class

View File

@ -5,39 +5,38 @@
"license": "MIT", "license": "MIT",
"type": "project", "type": "project",
"require": { "require": {
"php": "^7.1.3", "php": "^7.2",
"ext-json": "*",
"ext-tidy": "*",
"ext-dom": "*",
"ext-xml": "*",
"ext-mbstring": "*",
"ext-gd": "*",
"ext-curl": "*", "ext-curl": "*",
"laravel/framework": "5.8.*", "ext-dom": "*",
"fideloper/proxy": "^4.0", "ext-gd": "*",
"intervention/image": "^2.5", "ext-json": "*",
"laravel/socialite": "^4.2", "ext-mbstring": "*",
"league/flysystem-aws-s3-v3": "^1.0", "ext-tidy": "*",
"ext-xml": "*",
"barryvdh/laravel-dompdf": "^0.8.5", "barryvdh/laravel-dompdf": "^0.8.5",
"barryvdh/laravel-snappy": "^0.4.5", "barryvdh/laravel-snappy": "^0.4.5",
"predis/predis": "^1.1", "doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.0",
"gathercontent/htmldiff": "^0.2.1", "gathercontent/htmldiff": "^0.2.1",
"socialiteproviders/slack": "^3.0", "intervention/image": "^2.5",
"laravel/framework": "^6.0",
"laravel/socialite": "^4.2",
"league/flysystem-aws-s3-v3": "^1.0",
"predis/predis": "^1.1",
"socialiteproviders/discord": "^2.0",
"socialiteproviders/gitlab": "^3.0",
"socialiteproviders/microsoft-azure": "^3.0", "socialiteproviders/microsoft-azure": "^3.0",
"socialiteproviders/okta": "^1.0", "socialiteproviders/okta": "^1.0",
"socialiteproviders/gitlab": "^3.0", "socialiteproviders/slack": "^3.0",
"socialiteproviders/twitch": "^3.0", "socialiteproviders/twitch": "^3.0"
"socialiteproviders/discord": "^2.0",
"doctrine/dbal": "^2.9"
}, },
"require-dev": { "require-dev": {
"beyondcode/laravel-dump-server": "^1.0", "facade/ignition": "^1.4",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4", "fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0", "mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.5", "phpunit/phpunit": "^8.0",
"nunomaduro/collision": "^3.0", "nunomaduro/collision": "^3.0",
"laravel/browser-kit-testing": "^4.2.1", "laravel/browser-kit-testing": "^5.1",
"barryvdh/laravel-ide-helper": "^2.6.4", "barryvdh/laravel-ide-helper": "^2.6.4",
"barryvdh/laravel-debugbar": "^3.2.8", "barryvdh/laravel-debugbar": "^3.2.8",
"squizlabs/php_codesniffer": "^3.4" "squizlabs/php_codesniffer": "^3.4"
@ -89,7 +88,7 @@
"preferred-install": "dist", "preferred-install": "dist",
"sort-packages": true, "sort-packages": true,
"platform": { "platform": {
"php": "7.1.3" "php": "7.2.0"
} }
}, },
"extra": { "extra": {

698
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,8 @@ $factory->define(\BookStack\Auth\User::class, function ($faker) {
return [ return [
'name' => $faker->name, 'name' => $faker->name,
'email' => $faker->email, 'email' => $faker->email,
'password' => str_random(10), 'password' => Str::random(10),
'remember_token' => str_random(10), 'remember_token' => Str::random(10),
'email_confirmed' => 1 'email_confirmed' => 1
]; ];
}); });
@ -24,7 +24,7 @@ $factory->define(\BookStack\Auth\User::class, function ($faker) {
$factory->define(\BookStack\Entities\Bookshelf::class, function ($faker) { $factory->define(\BookStack\Entities\Bookshelf::class, function ($faker) {
return [ return [
'name' => $faker->sentence, 'name' => $faker->sentence,
'slug' => str_random(10), 'slug' => Str::random(10),
'description' => $faker->paragraph 'description' => $faker->paragraph
]; ];
}); });
@ -32,7 +32,7 @@ $factory->define(\BookStack\Entities\Bookshelf::class, function ($faker) {
$factory->define(\BookStack\Entities\Book::class, function ($faker) { $factory->define(\BookStack\Entities\Book::class, function ($faker) {
return [ return [
'name' => $faker->sentence, 'name' => $faker->sentence,
'slug' => str_random(10), 'slug' => Str::random(10),
'description' => $faker->paragraph 'description' => $faker->paragraph
]; ];
}); });
@ -40,7 +40,7 @@ $factory->define(\BookStack\Entities\Book::class, function ($faker) {
$factory->define(\BookStack\Entities\Chapter::class, function ($faker) { $factory->define(\BookStack\Entities\Chapter::class, function ($faker) {
return [ return [
'name' => $faker->sentence, 'name' => $faker->sentence,
'slug' => str_random(10), 'slug' => Str::random(10),
'description' => $faker->paragraph 'description' => $faker->paragraph
]; ];
}); });
@ -49,7 +49,7 @@ $factory->define(\BookStack\Entities\Page::class, function ($faker) {
$html = '<p>' . implode('</p>', $faker->paragraphs(5)) . '</p>'; $html = '<p>' . implode('</p>', $faker->paragraphs(5)) . '</p>';
return [ return [
'name' => $faker->sentence, 'name' => $faker->sentence,
'slug' => str_random(10), 'slug' => Str::random(10),
'html' => $html, 'html' => $html,
'text' => strip_tags($html), 'text' => strip_tags($html),
'revision_count' => 1 'revision_count' => 1

View File

@ -28,7 +28,8 @@
<server name="QUEUE_CONNECTION" value="sync"/> <server name="QUEUE_CONNECTION" value="sync"/>
<server name="DB_CONNECTION" value="mysql_testing"/> <server name="DB_CONNECTION" value="mysql_testing"/>
<server name="BCRYPT_ROUNDS" value="4"/> <server name="BCRYPT_ROUNDS" value="4"/>
<server name="MAIL_DRIVER" value="log"/> <server name="MAIL_DRIVER" value="array"/>
<server name="LOG_CHANNEL" value="null"/>
<server name="AUTH_METHOD" value="standard"/> <server name="AUTH_METHOD" value="standard"/>
<server name="DISABLE_EXTERNAL_SERVICES" value="true"/> <server name="DISABLE_EXTERNAL_SERVICES" value="true"/>
<server name="AVATAR_URL" value=""/> <server name="AVATAR_URL" value=""/>

View File

@ -7,7 +7,7 @@
<div class="my-l">&nbsp;</div> <div class="my-l">&nbsp;</div>
<div class="card content-wrap auto-height"> <div class="card content-wrap auto-height">
<h1 class="list-heading">{{ title_case(trans('auth.log_in')) }}</h1> <h1 class="list-heading">{{ Str::title(trans('auth.log_in')) }}</h1>
<form action="{{ url('/login') }}" method="POST" id="login-form" class="mt-l"> <form action="{{ url('/login') }}" method="POST" id="login-form" class="mt-l">
{!! csrf_field() !!} {!! csrf_field() !!}
@ -28,7 +28,7 @@
</div> </div>
<div class="text-right"> <div class="text-right">
<button class="button" tabindex="1">{{ title_case(trans('auth.log_in')) }}</button> <button class="button" tabindex="1">{{ Str::title(trans('auth.log_in')) }}</button>
</div> </div>
</div> </div>

View File

@ -6,7 +6,7 @@
<div class="my-l">&nbsp;</div> <div class="my-l">&nbsp;</div>
<div class="card content-wrap auto-height"> <div class="card content-wrap auto-height">
<h1 class="list-heading">{{ title_case(trans('auth.sign_up')) }}</h1> <h1 class="list-heading">{{ Str::title(trans('auth.sign_up')) }}</h1>
<form action="{{ url("/register") }}" method="POST" class="mt-l stretch-inputs"> <form action="{{ url("/register") }}" method="POST" class="mt-l stretch-inputs">
{!! csrf_field() !!} {!! csrf_field() !!}

View File

@ -2,7 +2,7 @@
<?php $breadcrumbCount = 0; ?> <?php $breadcrumbCount = 0; ?>
{{-- Show top level books item --}} {{-- Show top level books item --}}
@if (count($crumbs) > 0 && array_first($crumbs) instanceof \BookStack\Entities\Book) @if (count($crumbs) > 0 && ($crumbs[0] ?? null) instanceof \BookStack\Entities\Book)
<a href="{{ url('/books') }}" class="text-book icon-list-item outline-hover"> <a href="{{ url('/books') }}" class="text-book icon-list-item outline-hover">
<span>@icon('books')</span> <span>@icon('books')</span>
<span>{{ trans('entities.books') }}</span> <span>{{ trans('entities.books') }}</span>
@ -11,7 +11,7 @@
@endif @endif
{{-- Show top level shelves item --}} {{-- Show top level shelves item --}}
@if (count($crumbs) > 0 && array_first($crumbs) instanceof \BookStack\Entities\Bookshelf) @if (count($crumbs) > 0 && ($crumbs[0] ?? null) instanceof \BookStack\Entities\Bookshelf)
<a href="{{ url('/shelves') }}" class="text-bookshelf icon-list-item outline-hover"> <a href="{{ url('/shelves') }}" class="text-bookshelf icon-list-item outline-hover">
<span>@icon('bookshelf')</span> <span>@icon('bookshelf')</span>
<span>{{ trans('entities.shelves') }}</span> <span>{{ trans('entities.shelves') }}</span>

View File

@ -153,7 +153,7 @@ class SocialAuthTest extends TestCase
config()->set('services.google.select_account', 'true'); config()->set('services.google.select_account', 'true');
$resp = $this->get('/login/service/google'); $resp = $this->get('/login/service/google');
$this->assertContains('prompt=select_account', $resp->headers->get('Location')); $this->assertStringContainsString('prompt=select_account', $resp->headers->get('Location'));
} }
} }

View File

@ -50,7 +50,7 @@ class PageContentTest extends TestCase
$resp->assertStatus(302); $resp->assertStatus(302);
$page = Page::find($page->id); $page = Page::find($page->id);
$this->assertContains($includeTag, $page->html); $this->assertStringContainsString($includeTag, $page->html);
$this->assertEquals('', $page->text); $this->assertEquals('', $page->text);
} }

View File

@ -1,8 +1,6 @@
<?php namespace Tests; <?php namespace Tests;
use BookStack\Entities\Book; use BookStack\Entities\Book;
use BookStack\Entities\Bookshelf;
use BookStack\Entities\Chapter;
use BookStack\Entities\Entity; use BookStack\Entities\Entity;
use BookStack\Entities\Page; use BookStack\Entities\Page;
use BookStack\Entities\Repos\EntityRepo; use BookStack\Entities\Repos\EntityRepo;
@ -12,6 +10,7 @@ use BookStack\Auth\Permissions\PermissionService;
use BookStack\Entities\Repos\PageRepo; use BookStack\Entities\Repos\PageRepo;
use BookStack\Settings\SettingService; use BookStack\Settings\SettingService;
use BookStack\Uploads\HttpFetcher; use BookStack\Uploads\HttpFetcher;
use Illuminate\Support\Env;
trait SharedTestHelpers trait SharedTestHelpers
{ {
@ -77,6 +76,7 @@ trait SharedTestHelpers
/** /**
* Regenerate the permission for an entity. * Regenerate the permission for an entity.
* @param Entity $entity * @param Entity $entity
* @throws \Throwable
*/ */
protected function regenEntityPermissions(Entity $entity) protected function regenEntityPermissions(Entity $entity)
{ {
@ -116,6 +116,7 @@ trait SharedTestHelpers
* Create and return a new test page * Create and return a new test page
* @param array $input * @param array $input
* @return Page * @return Page
* @throws \Throwable
*/ */
public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) { public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
$book = Book::first(); $book = Book::first();
@ -204,4 +205,58 @@ trait SharedTestHelpers
->andReturn($returnData); ->andReturn($returnData);
} }
/**
* Run a set test with the given env variable.
* Remembers the original and resets the value after test.
* @param string $name
* @param $value
* @param callable $callback
*/
protected function runWithEnv(string $name, $value, callable $callback)
{
Env::disablePutenv();
$originalVal = $_ENV[$name] ?? null;
if (is_null($value)) {
unset($_ENV[$name]);
unset($_SERVER[$name]);
} else {
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
$this->refreshApplication();
$callback();
if (is_null($originalVal)) {
unset($_SERVER[$name]);
unset($_ENV[$name]);
} else {
$_SERVER[$name] = $originalVal;
$_ENV[$name] = $originalVal;
}
}
/**
* Check the keys and properties in the given map to include
* exist, albeit not exclusively, within the map to check.
* @param array $mapToInclude
* @param array $mapToCheck
* @param string $message
*/
protected function assertArrayMapIncludes(array $mapToInclude, array $mapToCheck, string $message = '') : void
{
$passed = true;
foreach ($mapToInclude as $key => $value) {
if (!isset($mapToCheck[$key]) || $mapToCheck[$key] !== $mapToInclude[$key]) {
$passed = false;
}
}
$toIncludeStr = print_r($mapToInclude, true);
$toCheckStr = print_r($mapToCheck, true);
self::assertThat($passed, self::isTrue(), "Failed asserting that given map:\n\n{$toCheckStr}\n\nincludes:\n\n{$toIncludeStr}");
}
} }

View File

@ -12,22 +12,19 @@ class ConfigTest extends TestCase
public function test_filesystem_images_falls_back_to_storage_type_var() public function test_filesystem_images_falls_back_to_storage_type_var()
{ {
putenv('STORAGE_TYPE=local_secure'); $this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3'); $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure'); });
putenv('STORAGE_TYPE=local');
} }
public function test_filesystem_attachments_falls_back_to_storage_type_var() public function test_filesystem_attachments_falls_back_to_storage_type_var()
{ {
putenv('STORAGE_TYPE=local_secure'); putenv('STORAGE_TYPE=local_secure');
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3'); $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure'); $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
});
putenv('STORAGE_TYPE=local');
} }
public function test_app_url_blank_if_old_default_value() public function test_app_url_blank_if_old_default_value()
@ -49,15 +46,9 @@ class ConfigTest extends TestCase
*/ */
protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult) protected function checkEnvConfigResult(string $envName, $envVal, string $configKey, string $expectedResult)
{ {
$originalVal = getenv($envName); $this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
$this->assertEquals($expectedResult, config($configKey));
$envString = $envName . (is_null($envVal) ? '' : '=') . ($envVal ?? ''); });
putenv($envString);
$this->refreshApplication();
$this->assertEquals($expectedResult, config($configKey));
$envString = $envName . (empty($originalVal) ? '' : '=') . ($originalVal ?? '');
putenv($envString);
} }
} }

View File

@ -22,19 +22,19 @@ class PageRepoTest extends TestCase
$navMap = $this->pageRepo->getPageNav($content); $navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap); $this->assertCount(3, $navMap);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h1', 'nodeName' => 'h1',
'link' => '#testa', 'link' => '#testa',
'text' => 'Hello', 'text' => 'Hello',
'level' => 1, 'level' => 1,
], $navMap[0]); ], $navMap[0]);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h2', 'nodeName' => 'h2',
'link' => '#testb', 'link' => '#testb',
'text' => 'There', 'text' => 'There',
'level' => 2, 'level' => 2,
], $navMap[1]); ], $navMap[1]);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h3', 'nodeName' => 'h3',
'link' => '#testc', 'link' => '#testc',
'text' => 'Donkey', 'text' => 'Donkey',
@ -48,7 +48,7 @@ class PageRepoTest extends TestCase
$navMap = $this->pageRepo->getPageNav($content); $navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(1, $navMap); $this->assertCount(1, $navMap);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h1', 'nodeName' => 'h1',
'link' => '#testa', 'link' => '#testa',
'text' => 'Hello' 'text' => 'Hello'
@ -61,15 +61,15 @@ class PageRepoTest extends TestCase
$navMap = $this->pageRepo->getPageNav($content); $navMap = $this->pageRepo->getPageNav($content);
$this->assertCount(3, $navMap); $this->assertCount(3, $navMap);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h4', 'nodeName' => 'h4',
'level' => 1, 'level' => 1,
], $navMap[0]); ], $navMap[0]);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h5', 'nodeName' => 'h5',
'level' => 2, 'level' => 2,
], $navMap[1]); ], $navMap[1]);
$this->assertArraySubset([ $this->assertArrayMapIncludes([
'nodeName' => 'h6', 'nodeName' => 'h6',
'level' => 3, 'level' => 3,
], $navMap[2]); ], $navMap[2]);

View File

@ -16,18 +16,16 @@ class UrlTest extends TestCase
public function test_url_helper_takes_custom_url_into_account() public function test_url_helper_takes_custom_url_into_account()
{ {
putenv('APP_URL=http://example.com/bookstack'); $this->runWithEnv('APP_URL', 'http://example.com/bookstack', function() {
$this->refreshApplication(); $this->assertEquals('http://example.com/bookstack/books', url('/books'));
$this->assertEquals('http://example.com/bookstack/books', url('/books')); });
putenv('APP_URL=');
} }
public function test_url_helper_sets_correct_scheme_even_when_request_scheme_is_different() public function test_url_helper_sets_correct_scheme_even_when_request_scheme_is_different()
{ {
putenv('APP_URL=https://example.com/'); $this->runWithEnv('APP_URL', 'https://example.com/', function() {
$this->refreshApplication(); $this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css');
$this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css'); });
putenv('APP_URL=');
} }
} }

View File

@ -78,7 +78,7 @@ class AttachmentTest extends TestCase
$upload->assertStatus(200); $upload->assertStatus(200);
$attachment = Attachment::query()->orderBy('id', 'desc')->first(); $attachment = Attachment::query()->orderBy('id', 'desc')->first();
$this->assertNotContains($fileName, $attachment->path); $this->assertStringNotContainsString($fileName, $attachment->path);
$this->assertStringEndsWith('.txt', $attachment->path); $this->assertStringEndsWith('.txt', $attachment->path);
} }