local navigation_sample = [[ http://m.gutenberg.org/ebooks.opds/ 2014-05-17T12:04:49Z Project Gutenberg Free ebooks since 1971. Marcello Perathoner http://www.gutenberg.org webmaster@gutenberg.org http://m.gutenberg.org/pics/favicon.png 25 1 2014-05-17T12:04:49Z http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads Popular Our most popular books. 2014-05-17T12:04:49Z http://m.gutenberg.org/ebooks/search.opds/?sort_order=release_date Latest Our latest releases. 2014-05-17T12:04:49Z http://m.gutenberg.org/ebooks/search.opds/?sort_order=random Random Random books. ]] local acquisition_sample = [[ http://m.gutenberg.org:80/ebooks/42474.opds 2014-09-03T12:16:15Z 1000 Mythological Characters Briefly Described by Edward Sylvester Ellis Free ebooks since 1971. Marcello Perathoner http://www.gutenberg.org webmaster@gutenberg.org http://m.gutenberg.org:80/pics/favicon.png 25 1 2014-09-03T12:16:15Z 1000 Mythological Characters Briefly Described

This edition had all images removed.

Title: 1000 Mythological Characters Briefly Described
Adapted to Private Schools, High Schools and Academies

Author: Ellis, Edward Sylvester, 1840-1916

Ebook No.: 42474

Published: Apr 7, 2013

Downloads: 1209

Language: English

Category: Text

Rights: Public domain in the USA.

urn:gutenberg:42474:2 2013-04-07T00:00:00+00:00 Public domain in the USA. Ellis, Edward Sylvester en 1
2014-09-03T12:16:15Z 1000 Mythological Characters Briefly Described

This edition has images.

Title: 1000 Mythological Characters Briefly Described
Adapted to Private Schools, High Schools and Academies

Author: Ellis, Edward Sylvester, 1840-1916

Ebook No.: 42474

Published: Apr 7, 2013

Downloads: 1209

Language: English

Category: Text

Rights: Public domain in the USA.

urn:gutenberg:42474:3 2013-04-07T00:00:00+00:00 Public domain in the USA. Ellis, Edward Sylvester en 1
]] local popular_new_sample = [[ http://www.feedbooks.com/publicdomain/catalog.atom Public Domain Books 2014-11-30T17:54:01Z http://assets3.feedbooks.net/images/favicon.ico?t=1417192326 Feedbooks http://www.feedbooks.com support@feedbooks.zendesk.com Most Popular 2014-11-30T17:54:01Z http://www.feedbooks.com/books/top.atom Based on last week's downloads Recently Added 2014-11-30T17:54:01Z http://www.feedbooks.com/books/recent.atom Find the latest books available Fiction 2014-11-30T17:54:01Z http://www.feedbooks.com/books/categories.atom Browse book by category Non-Fiction 2014-11-30T17:54:01Z http://www.feedbooks.com/books/categories.atom Browse book by category ]] local facet_sample = [[ tag:root:authors:Санд Книги по авторам 2014-11-30T17:27:27+01:00 /favicon.ico 2014-11-30T17:27:27+01:00 tag:author:75357 Санд Жаклин 6 книг ]] describe("OPDS module #nocov", function() local OPDSParser, OPDSBrowser setup(function() require("commonrequire") OPDSParser = require("ui/opdsparser") OPDSBrowser = require("ui/widget/opdsbrowser") end) describe("OPDS parser module", function() it("should parse OPDS navigation catalog", function() local catalog = OPDSParser:parse(navigation_sample) local feed = catalog.feed assert.truthy(feed) assert.are.same(feed.title, "Project Gutenberg") local entries = feed.entry assert.truthy(entries) assert.are.same(#entries, 3) local entry = entries[3] assert.are.same(entry.title, "Random") assert.are.same(entry.id, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=random") assert.are.same( "/ebooks/search.opds/?sort_order=random&limit=5", entry.link[1].href) end) it("should parse OPDS acquisition catalog", function() local catalog = OPDSParser:parse(acquisition_sample) local feed = catalog.feed assert.truthy(feed) local entries = feed.entry assert.truthy(entries) assert.are.same(#entries, 2) local entry = entries[2] assert.are.same(entry.title, "1000 Mythological Characters Briefly Described") assert.are.same(entry.link[1].href, "//www.gutenberg.org/ebooks/42474.epub.images") end) end) describe("OPDS browser module", function() describe("URL generation", function() it("should generate URL on rel=subsection", function() local catalog = OPDSParser:parse(navigation_sample) local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://m.gutenberg.org/ebooks.opds/?format=opds") assert.truthy(item_table) assert.are.same(item_table[1].title, "Popular") assert.are.same(item_table[1].url, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads") end) it("should generate URL on rel=popular and rel=new", function() local catalog = OPDSParser:parse(popular_new_sample) local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://www.feedbooks.com/publicdomain/catalog.atom") assert.truthy(item_table) assert.are.same(item_table[1].title, "Most Popular") assert.are.same(item_table[1].url, "http://www.feedbooks.com/books/top.atom") assert.are.same(item_table[2].title, "Recently Added") assert.are.same(item_table[2].url, "http://www.feedbooks.com/books/recent.atom") end) it("should use the main URL for faceted links as long as faceted links aren't properly supported", function() local catalog = OPDSParser:parse(facet_sample) local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://flibusta.net/opds") assert.truthy(item_table) assert.are.same(item_table[1].url, "http://flibusta.net/opds/author/75357") end) end) it("should not fill item table incorrectly with thumbnail or image URL", function() local catalog = OPDSParser:parse(facet_sample) local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://flibusta.net/opds") assert.truthy(item_table) assert.are_not.same(item_table[1].image, "http://flibusta.net/opds/author/75357") end) end) end)