2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Uploads;
|
2020-04-05 12:27:16 -04:00
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
use BookStack\Entities\Models\Page;
|
2020-04-05 12:27:16 -04: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 11:23:15 -04:00
|
|
|
'content' => 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gEcDCo5iYNs+gAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFElEQVQI12O0jN/KgASYGFABqXwAZtoBV6Sl3hIAAAAASUVORK5CYII=',
|
2020-04-05 12:27:16 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawing_base64_upload()
|
|
|
|
{
|
|
|
|
$page = Page::first();
|
|
|
|
$editor = $this->getEditor();
|
|
|
|
$this->actingAs($editor);
|
|
|
|
|
|
|
|
$upload = $this->postJson('images/drawio', [
|
|
|
|
'uploaded_to' => $page->id,
|
2021-06-26 11:23:15 -04:00
|
|
|
'image' => 'image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gEcDCo5iYNs+gAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFElEQVQI12O0jN/KgASYGFABqXwAZtoBV6Sl3hIAAAAASUVORK5CYII=',
|
2020-04-05 12:27:16 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
$upload->assertStatus(200);
|
|
|
|
$upload->assertJson([
|
2021-06-26 11:23:15 -04:00
|
|
|
'type' => 'drawio',
|
2020-04-05 12:27:16 -04:00
|
|
|
'uploaded_to' => $page->id,
|
2021-06-26 11:23:15 -04:00
|
|
|
'created_by' => $editor->id,
|
|
|
|
'updated_by' => $editor->id,
|
2020-04-05 12:27:16 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
$image = Image::where('type', '=', 'drawio')->first();
|
2021-06-26 11:23:15 -04:00
|
|
|
$this->assertTrue(file_exists(public_path($image->path)), 'Uploaded image not found at path: ' . public_path($image->path));
|
2020-04-05 12:27:16 -04:00
|
|
|
|
|
|
|
$testImageData = file_get_contents($this->getTestImageFilePath());
|
|
|
|
$uploadedImageData = file_get_contents(public_path($image->path));
|
2021-06-26 11:23:15 -04:00
|
|
|
$this->assertTrue($testImageData === $uploadedImageData, 'Uploaded image file data does not match our test image as expected');
|
2020-04-05 12:27:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawio_url_can_be_configured()
|
|
|
|
{
|
|
|
|
config()->set('services.drawio', 'http://cats.com?dog=tree');
|
|
|
|
$page = Page::first();
|
|
|
|
$editor = $this->getEditor();
|
|
|
|
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
|
|
|
$resp->assertSee('drawio-url="http://cats.com?dog=tree"');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_drawio_url_can_be_disabled()
|
|
|
|
{
|
|
|
|
config()->set('services.drawio', true);
|
|
|
|
$page = Page::first();
|
|
|
|
$editor = $this->getEditor();
|
|
|
|
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
2020-09-28 15:45:38 -04:00
|
|
|
$resp->assertSee('drawio-url="https://embed.diagrams.net/?embed=1&proto=json&spin=1"');
|
2020-04-05 12:27:16 -04:00
|
|
|
|
|
|
|
config()->set('services.drawio', false);
|
|
|
|
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
|
|
|
|
$resp->assertDontSee('drawio-url');
|
|
|
|
}
|
2021-06-26 11:23:15 -04:00
|
|
|
}
|