mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-04 17:04:32 +08:00
Updated to laravel 6
This commit is contained in:
@ -153,7 +153,7 @@ class SocialAuthTest extends TestCase
|
||||
config()->set('services.google.select_account', 'true');
|
||||
|
||||
$resp = $this->get('/login/service/google');
|
||||
$this->assertContains('prompt=select_account', $resp->headers->get('Location'));
|
||||
$this->assertStringContainsString('prompt=select_account', $resp->headers->get('Location'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class PageContentTest extends TestCase
|
||||
$resp->assertStatus(302);
|
||||
|
||||
$page = Page::find($page->id);
|
||||
$this->assertContains($includeTag, $page->html);
|
||||
$this->assertStringContainsString($includeTag, $page->html);
|
||||
$this->assertEquals('', $page->text);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Bookshelf;
|
||||
use BookStack\Entities\Chapter;
|
||||
use BookStack\Entities\Entity;
|
||||
use BookStack\Entities\Page;
|
||||
use BookStack\Entities\Repos\EntityRepo;
|
||||
@ -12,6 +10,7 @@ use BookStack\Auth\Permissions\PermissionService;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Settings\SettingService;
|
||||
use BookStack\Uploads\HttpFetcher;
|
||||
use Illuminate\Support\Env;
|
||||
|
||||
trait SharedTestHelpers
|
||||
{
|
||||
@ -77,6 +76,7 @@ trait SharedTestHelpers
|
||||
/**
|
||||
* Regenerate the permission for an entity.
|
||||
* @param Entity $entity
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function regenEntityPermissions(Entity $entity)
|
||||
{
|
||||
@ -116,6 +116,7 @@ trait SharedTestHelpers
|
||||
* Create and return a new test page
|
||||
* @param array $input
|
||||
* @return Page
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
|
||||
$book = Book::first();
|
||||
@ -204,4 +205,58 @@ trait SharedTestHelpers
|
||||
->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}");
|
||||
}
|
||||
|
||||
}
|
@ -12,22 +12,19 @@ class ConfigTest extends TestCase
|
||||
|
||||
public function test_filesystem_images_falls_back_to_storage_type_var()
|
||||
{
|
||||
putenv('STORAGE_TYPE=local_secure');
|
||||
|
||||
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
|
||||
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
|
||||
|
||||
putenv('STORAGE_TYPE=local');
|
||||
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
|
||||
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
|
||||
$this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_filesystem_attachments_falls_back_to_storage_type_var()
|
||||
{
|
||||
putenv('STORAGE_TYPE=local_secure');
|
||||
|
||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
|
||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
|
||||
|
||||
putenv('STORAGE_TYPE=local');
|
||||
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
|
||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
|
||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$originalVal = getenv($envName);
|
||||
|
||||
$envString = $envName . (is_null($envVal) ? '' : '=') . ($envVal ?? '');
|
||||
putenv($envString);
|
||||
$this->refreshApplication();
|
||||
$this->assertEquals($expectedResult, config($configKey));
|
||||
|
||||
$envString = $envName . (empty($originalVal) ? '' : '=') . ($originalVal ?? '');
|
||||
putenv($envString);
|
||||
$this->runWithEnv($envName, $envVal, function() use ($configKey, $expectedResult) {
|
||||
$this->assertEquals($expectedResult, config($configKey));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -22,19 +22,19 @@ class PageRepoTest extends TestCase
|
||||
$navMap = $this->pageRepo->getPageNav($content);
|
||||
|
||||
$this->assertCount(3, $navMap);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h1',
|
||||
'link' => '#testa',
|
||||
'text' => 'Hello',
|
||||
'level' => 1,
|
||||
], $navMap[0]);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h2',
|
||||
'link' => '#testb',
|
||||
'text' => 'There',
|
||||
'level' => 2,
|
||||
], $navMap[1]);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h3',
|
||||
'link' => '#testc',
|
||||
'text' => 'Donkey',
|
||||
@ -48,7 +48,7 @@ class PageRepoTest extends TestCase
|
||||
$navMap = $this->pageRepo->getPageNav($content);
|
||||
|
||||
$this->assertCount(1, $navMap);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h1',
|
||||
'link' => '#testa',
|
||||
'text' => 'Hello'
|
||||
@ -61,15 +61,15 @@ class PageRepoTest extends TestCase
|
||||
$navMap = $this->pageRepo->getPageNav($content);
|
||||
|
||||
$this->assertCount(3, $navMap);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h4',
|
||||
'level' => 1,
|
||||
], $navMap[0]);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h5',
|
||||
'level' => 2,
|
||||
], $navMap[1]);
|
||||
$this->assertArraySubset([
|
||||
$this->assertArrayMapIncludes([
|
||||
'nodeName' => 'h6',
|
||||
'level' => 3,
|
||||
], $navMap[2]);
|
||||
|
@ -16,18 +16,16 @@ class UrlTest extends TestCase
|
||||
|
||||
public function test_url_helper_takes_custom_url_into_account()
|
||||
{
|
||||
putenv('APP_URL=http://example.com/bookstack');
|
||||
$this->refreshApplication();
|
||||
$this->assertEquals('http://example.com/bookstack/books', url('/books'));
|
||||
putenv('APP_URL=');
|
||||
$this->runWithEnv('APP_URL', 'http://example.com/bookstack', function() {
|
||||
$this->assertEquals('http://example.com/bookstack/books', url('/books'));
|
||||
});
|
||||
}
|
||||
|
||||
public function test_url_helper_sets_correct_scheme_even_when_request_scheme_is_different()
|
||||
{
|
||||
putenv('APP_URL=https://example.com/');
|
||||
$this->refreshApplication();
|
||||
$this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css');
|
||||
putenv('APP_URL=');
|
||||
$this->runWithEnv('APP_URL', 'https://example.com/', function() {
|
||||
$this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -78,7 +78,7 @@ class AttachmentTest extends TestCase
|
||||
$upload->assertStatus(200);
|
||||
|
||||
$attachment = Attachment::query()->orderBy('id', 'desc')->first();
|
||||
$this->assertNotContains($fileName, $attachment->path);
|
||||
$this->assertStringNotContainsString($fileName, $attachment->path);
|
||||
$this->assertStringEndsWith('.txt', $attachment->path);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user