3 namespace Tests\Uploads;
5 use BookStack\Exceptions\DrawioPngReaderException;
6 use BookStack\Uploads\DrawioPngReader;
9 class DrawioPngReaderTest extends TestCase
11 public function test_exact_drawing()
13 $file = $this->files->testFilePath('test.drawio.png');
14 $stream = fopen($file, 'r');
16 $reader = new DrawioPngReader($stream);
17 $drawing = $reader->extractDrawing();
19 $this->assertStringStartsWith('<mxfile ', $drawing);
20 $this->assertStringEndsWith("</mxfile>\n", $drawing);
23 public function test_extract_drawing_with_non_drawing_image_throws_exception()
25 $file = $this->files->testFilePath('test-image.png');
26 $stream = fopen($file, 'r');
27 $reader = new DrawioPngReader($stream);
31 $drawing = $reader->extractDrawing();
32 } catch (\Exception $e) {
36 $this->assertInstanceOf(DrawioPngReaderException::class, $exception);
37 $this->assertEquals($exception->getMessage(), 'Unable to find drawing data within PNG file');
40 public function test_extract_drawing_with_non_png_image_throws_exception()
42 $file = $this->files->testFilePath('test-image.jpg');
43 $stream = fopen($file, 'r');
44 $reader = new DrawioPngReader($stream);
48 $drawing = $reader->extractDrawing();
49 } catch (\Exception $e) {
53 $this->assertInstanceOf(DrawioPngReaderException::class, $exception);
54 $this->assertEquals($exception->getMessage(), 'File does not appear to be a valid PNG file');