-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZIP Imports: Added high level import run tests
- Loading branch information
1 parent
b7476a9
commit 7681e32
Showing
5 changed files
with
192 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Tests\Exports; | ||
|
||
use BookStack\Exports\ZipExports\ZipImportRunner; | ||
use Tests\TestCase; | ||
|
||
class ZipImportRunnerTest extends TestCase | ||
{ | ||
protected ZipImportRunner $runner; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->runner = app()->make(ZipImportRunner::class); | ||
} | ||
|
||
// TODO - Test full book import | ||
// TODO - Test full chapter import | ||
// TODO - Test full page import | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Tests\Exports; | ||
|
||
use BookStack\Exports\Import; | ||
use Illuminate\Http\UploadedFile; | ||
use ZipArchive; | ||
|
||
class ZipTestHelper | ||
{ | ||
public static function importFromData(array $importData, array $zipData): Import | ||
{ | ||
if (isset($zipData['book'])) { | ||
$importData['type'] = 'book'; | ||
} else if (isset($zipData['chapter'])) { | ||
$importData['type'] = 'chapter'; | ||
} else if (isset($zipData['page'])) { | ||
$importData['type'] = 'page'; | ||
} | ||
|
||
$import = Import::factory()->create($importData); | ||
$zip = static::zipUploadFromData($zipData); | ||
rename($zip->getRealPath(), storage_path($import->path)); | ||
|
||
return $import; | ||
} | ||
|
||
public static function deleteZipForImport(Import $import): void | ||
{ | ||
$path = storage_path($import->path); | ||
if (file_exists($path)) { | ||
unlink($path); | ||
} | ||
} | ||
|
||
public static function zipUploadFromData(array $data): UploadedFile | ||
{ | ||
$zipFile = tempnam(sys_get_temp_dir(), 'bstest-'); | ||
|
||
$zip = new ZipArchive(); | ||
$zip->open($zipFile, ZipArchive::CREATE); | ||
$zip->addFromString('data.json', json_encode($data)); | ||
$zip->close(); | ||
|
||
return new UploadedFile($zipFile, 'upload.zip', 'application/zip', null, true); | ||
} | ||
} |