ZIP Import & Exports: Addressed issues during testing

- Handled links to within-zip page images found in chapter/book
  descriptions; Added test to cover.
- Fixed session showing unrelated success on failed import.

Tested import file-create undo on failure as part of this testing.
This commit is contained in:
Dan Brown 2024-11-25 15:54:15 +00:00
parent f79c6aef8d
commit 9ecc91929a
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
4 changed files with 33 additions and 3 deletions

View File

@ -89,6 +89,8 @@ class ImportController extends Controller
try {
$entity = $this->imports->runImport($import, $parent);
} catch (ZipImportException $exception) {
session()->flush();
$this->showErrorNotification(trans('errors.import_zip_failed_notification'));
return redirect($import->getUrl())->with('import_errors', $exception->errors);
}

View File

@ -127,11 +127,12 @@ class ZipExportReferences
return null;
}
// We don't expect images to be part of book/chapter content
if (!($exportModel instanceof ZipExportPage)) {
return null;
// Handle simple links outside of page content
if (!($exportModel instanceof ZipExportPage) && isset($this->images[$model->id])) {
return "[[bsexport:image:{$model->id}]]";
}
// Find and include images if in visibility
$page = $model->getPage();
if ($page && userCan('view', $page)) {
if (!isset($this->images[$model->id])) {

View File

@ -110,6 +110,7 @@ return [
'import_zip_cant_decode_data' => 'Could not find and decode ZIP data.json content.',
'import_zip_no_data' => 'ZIP file data has no expected book, chapter or page content.',
'import_validation_failed' => 'Import ZIP failed to validate with errors:',
'import_zip_failed_notification' => 'Failed to import ZIP file.',
'import_perms_books' => 'You are lacking the required permissions to create books.',
'import_perms_chapters' => 'You are lacking the required permissions to create chapters.',
'import_perms_pages' => 'You are lacking the required permissions to create pages.',

View File

@ -274,6 +274,32 @@ class ZipExportTest extends TestCase
$this->assertStringContainsString('href="[[bsexport:book:' . $book->id . ']]?view=true"', $pageData['html']);
}
public function test_book_and_chapter_description_links_to_images_in_pages_are_converted()
{
$book = $this->entities->bookHasChaptersAndPages();
$chapter = $book->chapters()->first();
$page = $chapter->pages()->first();
$this->asEditor();
$this->files->uploadGalleryImageToPage($this, $page);
/** @var Image $image */
$image = Image::query()->where('type', '=', 'gallery')
->where('uploaded_to', '=', $page->id)->first();
$book->description_html = '<p><a href="' . $image->url . '">Link to image</a></p>';
$book->save();
$chapter->description_html = '<p><a href="' . $image->url . '">Link to image</a></p>';
$chapter->save();
$zipResp = $this->get($book->getUrl("/export/zip"));
$zip = $this->extractZipResponse($zipResp);
$bookData = $zip->data['book'];
$chapterData = $bookData['chapters'][0];
$this->assertStringContainsString('href="[[bsexport:image:' . $image->id . ']]"', $bookData['description_html']);
$this->assertStringContainsString('href="[[bsexport:image:' . $image->id . ']]"', $chapterData['description_html']);
}
public function test_cross_reference_links_external_to_export_are_not_converted()
{
$page = $this->entities->page();