Extracted test file handling to its own class

Closes #3995
This commit is contained in:
Dan Brown
2023-02-08 14:39:13 +00:00
parent 5d18e7df79
commit da1a66abd3
17 changed files with 293 additions and 309 deletions

View File

@ -8,12 +8,9 @@ use BookStack\Entities\Models\Bookshelf;
use BookStack\Uploads\Image;
use Illuminate\Support\Str;
use Tests\TestCase;
use Tests\Uploads\UsesImages;
class BookShelfTest extends TestCase
{
use UsesImages;
public function test_shelves_shows_in_header_if_have_view_permissions()
{
$viewer = $this->users->viewer();
@ -114,7 +111,7 @@ class BookShelfTest extends TestCase
'description' => 'Test book description ' . Str::random(10),
];
$imageFile = $this->getTestImage('shelf-test.png');
$imageFile = $this->files->uploadedImage('shelf-test.png');
$resp = $this->asEditor()->call('POST', '/shelves', $shelfInfo, [], ['image' => $imageFile]);
$resp->assertRedirect();

View File

@ -7,12 +7,9 @@ use BookStack\Entities\Models\BookChild;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Repos\BookRepo;
use Tests\TestCase;
use Tests\Uploads\UsesImages;
class BookTest extends TestCase
{
use UsesImages;
public function test_create()
{
$book = Book::factory()->make([
@ -333,7 +330,7 @@ class BookTest extends TestCase
{
$book = $this->entities->book();
$bookRepo = $this->app->make(BookRepo::class);
$coverImageFile = $this->getTestImage('cover.png');
$coverImageFile = $this->files->uploadedImage('cover.png');
$bookRepo->updateCoverImage($book, $coverImageFile);
$this->asEditor()->post($book->getUrl('/copy'), ['name' => 'My copy book']);

View File

@ -5,12 +5,9 @@ namespace Tests\Entity;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\PageContent;
use Tests\TestCase;
use Tests\Uploads\UsesImages;
class PageContentTest extends TestCase
{
use UsesImages;
protected $base64Jpeg = '/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=';
public function test_page_includes()
@ -591,7 +588,7 @@ class PageContentTest extends TestCase
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile));
$this->deleteImage($imagePath);
$this->files->deleteAtRelativePath($imagePath);
}
public function test_base64_images_get_extracted_when_containing_whitespace()
@ -615,7 +612,7 @@ class PageContentTest extends TestCase
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($base64PngWithoutWhitespace), file_get_contents($imageFile));
$this->deleteImage($imagePath);
$this->files->deleteAtRelativePath($imagePath);
}
public function test_base64_images_within_html_blanked_if_not_supported_extension_for_extract()
@ -659,7 +656,7 @@ class PageContentTest extends TestCase
$imageFile = public_path($imagePath);
$this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile));
$this->deleteImage($imagePath);
$this->files->deleteAtRelativePath($imagePath);
}
public function test_markdown_base64_extract_not_limited_by_pcre_limits()
@ -690,7 +687,7 @@ class PageContentTest extends TestCase
$imageFile = public_path($imagePath);
$this->assertEquals($content, file_get_contents($imageFile));
$this->deleteImage($imagePath);
$this->files->deleteAtRelativePath($imagePath);
ini_set('pcre.backtrack_limit', $pcreBacktrackLimit);
ini_set('pcre.recursion_limit', $pcreRecursionLimit);
}