diff --git a/test/content/support.js b/test/content/support.js index cf47985e58..8d311f4e00 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -624,8 +624,19 @@ async function resetDB(options = {}) { var db = Zotero.DataDirectory.getDatabase(); await Zotero.reinit( async function () { - // Swap in the initial copy we made of the DB - await OS.File.copy(db + '-test-template', db); + // Extract a zipped DB file into place as the initial DB + if (options.dbFile && options.dbFile.endsWith('.zip')) { + let zipReader = Components.classes['@mozilla.org/libjar/zip-reader;1'] + .createInstance(Components.interfaces.nsIZipReader); + zipReader.open(Zotero.File.pathToFile(options.dbFile)); + zipReader.extract('zotero.sqlite', Zotero.File.pathToFile(db)); + zipReader.close(); + } + // Otherwise swap in the initial copy we made of the DB, or an alternative non-zip file + // if given + else { + await OS.File.copy(options.dbFile || db + '-test-template', db); + } _defaultGroup = null; }, false, diff --git a/test/tests/data/zotero-4.0.sqlite.zip b/test/tests/data/zotero-4.0.sqlite.zip new file mode 100644 index 0000000000..d35425d727 Binary files /dev/null and b/test/tests/data/zotero-4.0.sqlite.zip differ diff --git a/test/tests/schemaTest.js b/test/tests/schemaTest.js index 8e528ced7e..53b392d638 100644 --- a/test/tests/schemaTest.js +++ b/test/tests/schemaTest.js @@ -303,4 +303,24 @@ describe("Zotero.Schema", function() { await assert.isTrue(await Zotero.Schema.integrityCheck()); }); }) + + describe("Database Upgrades", function () { + after(async function () { + await resetDB({ + thisArg: this, + skipBundledFiles: true, + }); + }); + + it("should upgrade 4.0 database", async function () { + await resetDB({ + thisArg: this, + skipBundledFiles: true, + dbFile: OS.Path.join(getTestDataDirectory().path, 'zotero-4.0.sqlite.zip') + }); + // Make sure we can open the Zotero pane without errors + win = await loadZoteroPane(); + win.close(); + }); + }); })