2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Uploads;
|
2020-04-05 18:27:16 +02:00
|
|
|
|
2020-11-22 01:17:45 +01:00
|
|
|
use BookStack\Entities\Models\Page;
|
2020-04-05 18:27:16 +02:00
|
|
|
use BookStack\Uploads\Image;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class DrawioTest extends TestCase
|
|
|
|
{
|
|
|
|
use UsesImages;
|
|
|
|
|
|
|
|
public function test_get_image_as_base64()
|
|
|
|
{
|
|
|
|
$page = Page::first();
|
|
|
|
$this->asAdmin();
|
|
|
|
$imageName = 'first-image.png';
|
|
|
|
|
|
|
|
$this->uploadImage($imageName, $page->id);
|
|
|
|
$image = Image::first();
|
|
|
|
$image->type = 'drawio';
|
|
|
|
$image->save();
|
|
|
|
|
|
|
|
$imageGet = $this->getJson("/images/drawio/base64/{$image->id}");
|
|
|
|
$imageGet->assertJson([
|
2021-06-26 17:23:15 +02:00
|
|
|
'content' => 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gEcDCo5iYNs+gAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFElEQVQI12O0jN/KgASYGFABqXwAZtoBV6Sl3hIAAAAASUVORK5CYII=',
|
2020-04-05 18:27:16 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawing_base64_upload()
|
|
|
|
{
|
|
|
|
$page = Page::first();
|
2023-01-21 12:08:34 +01:00
|
|
|
$editor = $this->users->editor();
|
2020-04-05 18:27:16 +02:00
|
|
|
$this->actingAs($editor);
|
|
|
|
|
|
|
|
$upload = $this->postJson('images/drawio', [
|
|
|
|
'uploaded_to' => $page->id,
|
2021-06-26 17:23:15 +02:00
|
|
|
'image' => 'image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gEcDCo5iYNs+gAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFElEQVQI12O0jN/KgASYGFABqXwAZtoBV6Sl3hIAAAAASUVORK5CYII=',
|
2020-04-05 18:27:16 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$upload->assertStatus(200);
|
|
|
|
$upload->assertJson([
|
2021-06-26 17:23:15 +02:00
|
|
|
'type' => 'drawio',
|
2020-04-05 18:27:16 +02:00
|
|
|
'uploaded_to' => $page->id,
|
2021-06-26 17:23:15 +02:00
|
|
|
'created_by' => $editor->id,
|
|
|
|
'updated_by' => $editor->id,
|
2020-04-05 18:27:16 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$image = Image::where('type', '=', 'drawio')->first();
|
2021-06-26 17:23:15 +02:00
|
|
|
$this->assertTrue(file_exists(public_path($image->path)), 'Uploaded image not found at path: ' . public_path($image->path));
|
2020-04-05 18:27:16 +02:00
|
|
|
|
|
|
|
$testImageData = file_get_contents($this->getTestImageFilePath());
|
|
|
|
$uploadedImageData = file_get_contents(public_path($image->path));
|
2021-06-26 17:23:15 +02:00
|
|
|
$this->assertTrue($testImageData === $uploadedImageData, 'Uploaded image file data does not match our test image as expected');
|
2020-04-05 18:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawio_url_can_be_configured()
|
|
|
|
{
|
|
|
|
config()->set('services.drawio', 'http://cats.com?dog=tree');
|
|
|
|
$page = Page::first();
|
2023-01-21 12:08:34 +01:00
|
|
|
$editor = $this->users->editor();
|
2020-04-05 18:27:16 +02:00
|
|
|
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
2021-10-26 23:04:18 +02:00
|
|
|
$resp->assertSee('drawio-url="http://cats.com?dog=tree"', false);
|
2020-04-05 18:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawio_url_can_be_disabled()
|
|
|
|
{
|
|
|
|
config()->set('services.drawio', true);
|
|
|
|
$page = Page::first();
|
2023-01-21 12:08:34 +01:00
|
|
|
$editor = $this->users->editor();
|
2020-04-05 18:27:16 +02:00
|
|
|
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
2022-04-21 00:42:47 +02:00
|
|
|
$resp->assertSee('drawio-url="https://embed.diagrams.net/?embed=1&proto=json&spin=1&configure=1"', false);
|
2020-04-05 18:27:16 +02:00
|
|
|
|
|
|
|
config()->set('services.drawio', false);
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
2021-10-26 23:04:18 +02:00
|
|
|
$resp->assertDontSee('drawio-url', false);
|
2020-04-05 18:27:16 +02:00
|
|
|
}
|
2021-06-26 17:23:15 +02:00
|
|
|
}
|