11<?php namespace Tests \Entity ;
22
3-
43use BookStack \Entities \Chapter ;
54use BookStack \Entities \Page ;
6- use BookStack \ Uploads \ HttpFetcher ;
5+ use Illuminate \ Support \ Facades \ Storage ;
76use Illuminate \Support \Str ;
87use Tests \TestCase ;
98
@@ -154,14 +153,39 @@ public function test_page_html_export_use_absolute_dates()
154153 public function test_page_export_sets_right_data_type_for_svg_embeds ()
155154 {
156155 $ page = Page::first ();
157- $ page ->html = '<img src="http://example.com/image.svg"> ' ;
156+ Storage::disk ('local ' )->makeDirectory ('uploads/images/gallery ' );
157+ Storage::disk ('local ' )->put ('uploads/images/gallery/svg_test.svg ' , '<svg></svg> ' );
158+ $ page ->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"> ' ;
158159 $ page ->save ();
159160
160161 $ this ->asEditor ();
161- $ this ->mockHttpFetch ('<svg></svg> ' );
162162 $ resp = $ this ->get ($ page ->getUrl ('/export/html ' ));
163+ Storage::disk ('local ' )->delete ('uploads/images/gallery/svg_test.svg ' );
164+
163165 $ resp ->assertStatus (200 );
164166 $ resp ->assertSee ('<img src="data:image/svg+xml;base64 ' );
165167 }
166168
169+ public function test_page_export_contained_html_image_fetches_only_run_when_url_points_to_image_upload_folder ()
170+ {
171+ $ page = Page::first ();
172+ $ page ->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"/> '
173+ ."\n" .'<img src="http://localhost/uploads/svg_test.svg"/> '
174+ ."\n" .'<img src="/uploads/svg_test.svg"/> ' ;
175+ $ storageDisk = Storage::disk ('local ' );
176+ $ storageDisk ->makeDirectory ('uploads/images/gallery ' );
177+ $ storageDisk ->put ('uploads/images/gallery/svg_test.svg ' , '<svg>good</svg> ' );
178+ $ storageDisk ->put ('uploads/svg_test.svg ' , '<svg>bad</svg> ' );
179+ $ page ->save ();
180+
181+ $ resp = $ this ->asEditor ()->get ($ page ->getUrl ('/export/html ' ));
182+
183+ $ storageDisk ->delete ('uploads/images/gallery/svg_test.svg ' );
184+ $ storageDisk ->delete ('uploads/svg_test.svg ' );
185+
186+ $ resp ->assertDontSee ('http://localhost/uploads/images/gallery/svg_test.svg ' );
187+ $ resp ->assertSee ('http://localhost/uploads/svg_test.svg ' );
188+ $ resp ->assertSee ('src="/uploads/svg_test.svg" ' );
189+ }
190+
167191}
0 commit comments