diff --git a/test/library_server.cpp b/test/library_server.cpp index d5270a200..a472f2356 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -945,6 +945,259 @@ TEST_F(LibraryServerTest, no_name_mapper_catalog_v2_individual_entry_access) EXPECT_EQ(r1->status, 404); } - +#define HTML_PREAMBLE \ + "\n" \ + "\n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " Welcome to Kiwix Server\n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + "
\n" + +#define CHARLES_RAY_BOOK_HTML \ + "
\n" \ + " \n" \ + "
fra
\n" \ + "
\n" \ + " unittest\n" \ + " wikipedia\n" \ + "
\n" \ + "
\n" \ + "
\n" + +#define RAY_CHARLES_BOOK_HTML \ + "
\n" \ + " \n" \ + "
eng
\n" \ + "
\n" \ + " public_tag_without_a_value\n" \ + " wikipedia\n" \ + "
\n" \ + "
\n" \ + "
\n" + +#define RAY_CHARLES_UNCTZ_BOOK_HTML \ + "
\n" \ + " \n" \ + "
rus,eng
\n" \ + "
\n" \ + " public_tag_with_a_value:value_of_a_public_tag\n" \ + " wikipedia\n" \ + "
\n" \ + "
\n" \ + "
\n" + +#define FINAL_HTML_TEXT \ + "
\n" \ + " \n" \ + "
Powered by Kiwix
\n" \ + " \n" \ + "" + +#define FILTERS_HTML(SELECTED_ENG) \ + "
\n" \ + "
\n" \ + " \n" \ + "
\n" \ + "
\n" \ + " \n" \ + "
\n" \ + "
\n" \ + "
\n" \ + " \n" \ + " \n" \ + "
\n" \ + " \n" + +#define HOME_BODY_TEXT(X) \ + "
\n" \ + " \n" \ + "
\n" \ + "

" X " book(s)

\n" + +#define HOME_BODY_0_RESULTS \ + "
\n" \ + " \n" \ + "
\n" \ + " No result. Would you like to reset filter?\n" \ + "
\n" \ + " \n" \ + "
\n" \ + "

0 book(s)

\n" \ + " \n" + +#define RAY_CHARLES_UNCTZ_DOWNLOAD \ + "\n" \ + "\n" \ + "\n" \ + " \n" \ + " \n" \ + " \n" \ + " Download book\n" \ + "\n" \ + "\n" \ + "\n" \ + "
\n" \ + " Download links for Ray (uncategorized) Charles\n" \ + "
\n" \ + " \n" \ + "
Direct
\n" \ + "
\n" \ + " \n" \ + "
Sha256 hash
\n" \ + "
\n" \ + " \n" \ + "
Magnet link
\n" \ + "
\n" \ + " \n" \ + "
Torrent file
\n" \ + "
\n" \ + "\n" \ + "" + +TEST_F(LibraryServerTest, noJS) { + // no_js_default + auto r = zfs1_->GET("/ROOT%23%3F/nojs"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(r->body, + HTML_PREAMBLE + FILTERS_HTML("") + HOME_BODY_TEXT("3") + CHARLES_RAY_BOOK_HTML + RAY_CHARLES_BOOK_HTML + RAY_CHARLES_UNCTZ_BOOK_HTML + FINAL_HTML_TEXT); + + // no_js_eng_lang + r = zfs1_->GET("/ROOT%23%3F/nojs?lang=eng"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(r->body, + HTML_PREAMBLE + FILTERS_HTML(" selected ") + HOME_BODY_TEXT("2") + RAY_CHARLES_UNCTZ_BOOK_HTML + RAY_CHARLES_BOOK_HTML + FINAL_HTML_TEXT); + + // no_js_no_books + r = zfs1_->GET("/ROOT%23%3F/nojs?lang=fas"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(r->body, + HTML_PREAMBLE + FILTERS_HTML("") + HOME_BODY_0_RESULTS + FINAL_HTML_TEXT); + + // no_js_download + r = zfs1_->GET("/ROOT%23%3F/nojs/download/zimfile"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(r->body, RAY_CHARLES_UNCTZ_DOWNLOAD); +} #undef EXPECT_SEARCH_RESULTS diff --git a/test/server.cpp b/test/server.cpp index 7f29e2644..c9cbe4f2a 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -97,6 +97,8 @@ const ResourceCollection resources200Compressible{ { ZIM_CONTENT, "/ROOT%23%3F/raw/zimfile/content/A/index" }, { ZIM_CONTENT, "/ROOT%23%3F/raw/zimfile/content/A/Ray_Charles" }, + + { DYNAMIC_CONTENT, "/ROOT%23%3F/nojs"}, }; const ResourceCollection resources200Uncompressible{ @@ -179,6 +181,8 @@ const ResourceCollection resources200Uncompressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/suggest?content=zimfile" }, { ZIM_CONTENT, "/ROOT%23%3F/raw/zimfile/meta/Creator" }, { ZIM_CONTENT, "/ROOT%23%3F/raw/zimfile/meta/Title" }, + + { DYNAMIC_CONTENT, "/ROOT%23%3F/nojs/download/zimfile"}, }; ResourceCollection all200Resources() @@ -395,6 +399,8 @@ const char* urls404[] = { // zimfile has no Favicon nor Illustration_48x48@1 meta item "/ROOT%23%3F/raw/zimfile/meta/Favicon", "/ROOT%23%3F/raw/zimfile/meta/Illustration_48x48@1", + + "/ROOT%23%3F/nojs/download/thiszimdoesntexist" }; TEST_F(ServerTest, 404)