diff --git a/test/components/zotero-unit.js b/test/components/zotero-unit.js index a1d3cc6854..2928cbdbd4 100644 --- a/test/components/zotero-unit.js +++ b/test/components/zotero-unit.js @@ -33,6 +33,9 @@ ZoteroUnit.prototype = { handle:function(cmdLine) { this.tests = cmdLine.handleFlagWithParam("test", false); this.noquit = cmdLine.handleFlag("noquit", false); + this.makeTestData = cmdLine.handleFlag("makeTestData", false); + this.noquit = !this.makeTestData && this.noquit; + this.runTests = !this.makeTestData; }, dump:function(x) { diff --git a/test/content/runtests.js b/test/content/runtests.js index 1b3d8dc9b7..7e3ddb1b37 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -1,17 +1,17 @@ -Components.utils.import("resource://gre/modules/FileUtils.jsm"); Components.utils.import("resource://gre/modules/osfile.jsm"); Components.utils.import("resource://zotero/q.js"); var EventUtils = Components.utils.import("resource://zotero-unit/EventUtils.jsm"); var ZoteroUnit = Components.classes["@mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit"]. - getService(Components.interfaces.nsISupports). - wrappedJSObject; + getService(Components.interfaces.nsISupports). + wrappedJSObject; + var dump = ZoteroUnit.dump; function quit(failed) { // Quit with exit status if(!failed) { - OS.File.writeAtomic(FileUtils.getFile("ProfD", ["success"]).path, Uint8Array(0)); + OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, "success"), new Uint8Array(0)); } if(!ZoteroUnit.noquit) { Components.classes['@mozilla.org/toolkit/app-startup;1']. @@ -20,6 +20,72 @@ function quit(failed) { } } +if (ZoteroUnit.makeTestData) { + let dataPath = getTestDataDirectory().path; + + Zotero.Prefs.set("export.citePaperJournalArticleURL", true); + + let dataFiles = [ + { + name: 'allTypesAndFields', + func: generateAllTypesAndFieldsData + }, + { + name: 'itemJSON', + func: generateItemJSONData, + args: [null] + }, + { + name: 'citeProcJSExport', + func: generateCiteProcJSExportData + }, + { + name: 'translatorExportLegacy', + func: generateTranslatorExportData, + args: [true] + }, + { + name: 'translatorExport', + func: generateTranslatorExportData, + args: [false] + } + ]; + let p = Q.resolve(); + for (let i=0; i m.toLowerCase()); // not all-caps words + } + + itemFields[name] = value; + } + + let creatorTypes = Zotero.CreatorTypes.getTypesForItemType(itemTypes[i].id), + creators = itemFields.creators = []; + for (let j = 0; j < creatorTypes.length; j++) { + let typeName = creatorTypes[j].name; + creators.push({ + creatorType: typeName, + firstName: typeName + 'First', + lastName: typeName + 'Last' + }); + } + } + + return data; +} + +/** + * Populates the database with sample items + * The field values should be in the form exactly as they would appear in Zotero + */ +function populateDBWithSampleData(data) { + Zotero.DB.beginTransaction(); + + for (let itemName in data) { + let item = data[itemName]; + let zItem = new Zotero.Item(item.itemType); + for (let itemField in item) { + if (itemField == 'itemType') continue; + + if (itemField == 'creators') { + let creators = item[itemField]; + for (let i=0; i&2 <