diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 8c5c60c89..a1cd61a16 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -57,7 +57,7 @@ Zotero.Translate.ItemSaver = function(options) { this._proxy = options.proxy; // the URI to which other URIs are assumed to be relative - if(typeof baseURI === "object" && baseURI instanceof Components.interfaces.nsIURI) { + if(typeof options.baseURI === "object" && options.baseURI instanceof Components.interfaces.nsIURI) { this._baseURI = options.baseURI; } else { // try to convert to a URI diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index b648b1c44..26bfb84ae 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -597,6 +597,45 @@ describe("Zotero.Translate", function() { }); }); + + describe("Translators", function () { + it("should round-trip child attachment via BibTeX", function* () { + var item = yield createDataObject('item'); + yield importFileAttachment('test.png', { parentItemID: item.id }); + + var translation = new Zotero.Translate.Export(); + var tmpDir = yield getTempDirectory(); + var exportDir = OS.Path.join(tmpDir, 'export'); + translation.setLocation(Zotero.File.pathToFile(exportDir)); + translation.setItems([item]); + translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); + translation.setDisplayOptions({ + exportFileData: true + }); + yield translation.translate(); + + var exportFile = OS.Path.join(exportDir, 'export.bib'); + assert.isTrue(yield OS.File.exists(exportFile)); + + var translation = new Zotero.Translate.Import(); + translation.setLocation(Zotero.File.pathToFile(exportFile)); + var translators = yield translation.getTranslators(); + translation.setTranslator(translators[0]); + var importCollection = yield createDataObject('collection'); + var items = yield translation.translate({ + libraryID: Zotero.Libraries.userLibraryID, + collections: [importCollection.id] + }); + + assert.lengthOf(items, 1); + var attachments = items[0].getAttachments(); + assert.lengthOf(attachments, 1); + var attachment = Zotero.Items.get(attachments[0]); + assert.isTrue(yield attachment.fileExists()); + }); + }); + + describe("ItemSaver", function () { describe("#saveCollections()", function () { it("should add top-level collections to specified collection", function* () {