www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 3c5912f68d4f91bf09549e3f95863e422abc03db
parent 333675d8ea0569dcbb6355ce53e46c94568e50f0
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 21 Feb 2017 16:40:33 -0500

Merge pull request #1180 from adomasven/fix/savePage-no-translator

Diffstat:
Mchrome/content/zotero/xpcom/server_connector.js | 8++++++--
Atest/tests/data/coins.html | 12++++++++++++
Mtest/tests/server_connectorTest.js | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js @@ -201,6 +201,7 @@ Zotero.Server.Connector.Detect.prototype = { * uri - The URI of the page to be saved * html - document.innerHTML or equivalent * cookie - document.cookie or equivalent + * translatorID [optional] - a translator ID as returned by /connector/detect * * Returns: * If a single item, sends response code 201 with item in body. @@ -297,8 +298,11 @@ Zotero.Server.Connector.SavePage.prototype = { } }); - // set translator and translate - translate.setTranslator(this._parsedPostData.translatorID); + if (this._parsedPostData.translatorID) { + translate.setTranslator(this._parsedPostData.translatorID); + } else { + translate.setTranslator(translators[0]); + } translate.translate(libraryID); } } diff --git a/test/tests/data/coins.html b/test/tests/data/coins.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"/> + <title>Test Page</title> +</head> +<body> + <span class='Z3988' title='url_ver=Z39.88-2004&amp;ctx_ver=Z39.88-2004&amp;rfr_id=info%3Asid%2Fzotero.org%3A2&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rft.type=blogPost&amp;rft.title=Test%20Page&amp;rft.identifier=https%3A%2F%2Fexample.com%2Ftest&amp;rft.aulast=Zotero&amp;rft.au=Zotero&amp;rft.date=2017-02-21'></span> + <p>This is a test page</p> +</footer> +</body> +</html> diff --git a/test/tests/server_connectorTest.js b/test/tests/server_connectorTest.js @@ -390,6 +390,58 @@ describe("Connector Server", function () { }); }); + describe("/connector/savePage", function() { + // TEMP: Wait for indexing to complete, which happens after a 1-second delay, after a 201 has + // been returned to the connector. Would be better to make sure indexing has completed. + afterEach(function* () { + yield Zotero.Promise.delay(1050); + }); + + it("should return 500 if no translator available for page", function* () { + var xmlhttp = yield Zotero.HTTP.request( + 'POST', + connectorServerPath + "/connector/savePage", + { + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + uri: "http://example.com", + html: "<html><head><title>Title</title><body>Body</body></html>" + }), + successCodes: false + } + ); + assert.equal(xmlhttp.status, 500); + }); + + it("should translate a page if translators are available", function* () { + var html = Zotero.File.getContentsFromURL(getTestDataUrl('coins.html')); + var promise = waitForItemEvent('add'); + var xmlhttp = yield Zotero.HTTP.request( + 'POST', + connectorServerPath + "/connector/savePage", + { + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + uri: "https://example.com/test", + html + }), + successCodes: false + } + ); + + let ids = yield promise; + var item = Zotero.Items.get(ids[0]); + var title = "Test Page"; + assert.equal(JSON.parse(xmlhttp.responseText).items[0].title, title); + assert.equal(item.getField('title'), title); + assert.equal(xmlhttp.status, 201); + }); + }); + describe('/connector/installStyle', function() { var endpoint;