From c64fce52e785f6b0ed395b1442ae4b67ee7baeff Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 30 Jan 2022 15:39:12 +0400 Subject: [PATCH 1/6] Made 404 HTML template consistent with the rest --- static/templates/404.html | 2 +- test/server.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/static/templates/404.html b/static/templates/404.html index 55645dbd7..2f6cf2acf 100644 --- a/static/templates/404.html +++ b/static/templates/404.html @@ -1,5 +1,5 @@ - + Content not found diff --git a/test/server.cpp b/test/server.cpp index bff14f654..8b99a123c 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -392,7 +392,7 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const { const std::string frag[] = { R"FRAG( - + Content not found From 389d29c92e65e7bfb00525bda5ef9e47234fc39a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 30 Jan 2022 15:41:36 +0400 Subject: [PATCH 2/6] Searching in a non-existent book is a 404 case --- test/server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/server.cpp b/test/server.cpp index 8b99a123c..da8334c41 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -303,6 +303,7 @@ const char* urls404[] = { "/ROOT/random", "/ROOT/random?content=non-existent-book", "/ROOT/search", + "/ROOT/search?content=non-existing-book&pattern=asdfqwerty", "/ROOT/suggest", "/ROOT/suggest?content=non-existent-book&term=abcd", "/ROOT/catch/external", From e4a4b2f9618e126fbc6240b5693afe993a4943d0 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 30 Jan 2022 15:55:56 +0400 Subject: [PATCH 3/6] Extracted CSS out of no_search_results.html --- src/server/internalServer.cpp | 1 + static/resources_list.txt | 1 + static/skin/search_results.css | 86 ++++++++++++++++++++++++ static/templates/no_search_result.html | 90 +------------------------- 4 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 static/skin/search_results.css diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 1e0fe8a26..eb43286bd 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -517,6 +517,7 @@ std::unique_ptr InternalServer::handle_search(const RequestContext& re || (patternString.empty() && ! has_geo_query) ) { auto data = get_default_data(); data.set("pattern", encodeDiples(patternString)); + data.set("root", m_root); auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8"); response->set_taskbar(bookName, archive ? getArchiveTitle(*archive) : ""); response->set_code(MHD_HTTP_NOT_FOUND); diff --git a/static/resources_list.txt b/static/resources_list.txt index b0b7a336a..5587111c0 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -32,6 +32,7 @@ skin/index.css skin/fonts/Poppins.ttf skin/fonts/Roboto.ttf skin/block_external.js +skin/search_results.css templates/search_result.html templates/no_search_result.html templates/404.html diff --git a/static/skin/search_results.css b/static/skin/search_results.css new file mode 100644 index 000000000..df3a54c04 --- /dev/null +++ b/static/skin/search_results.css @@ -0,0 +1,86 @@ +body{ +color: #000000; +font: small/normal Arial,Helvetica,Sans-Serif; +margin-top: 0.5em; +font-size: 90%; +} + +a{ +color: #04c; +} + +a:visited { +color: #639 +} + +a:hover { +text-decoration: underline +} + +.header { +font-size: 120%; +} + +ul { +margin:0; +padding:0 +} + +.results { +font-size: 110%; +} + +.results li { +list-style-type:none; +margin-top: 0.5em; +} + +.results a { +font-size: 110%; +text-decoration: underline +} + +cite { +font-style:normal; +word-wrap:break-word; +display: block; +font-size: 100%; +} + +.informations { +color: #388222; +font-size: 100%; +} + +.footer { +padding: 0; +margin-top: 1em; +width: 100%; +float: left +} + +.footer a, .footer span { +display: block; +padding: .3em .7em; +margin: 0 .38em 0 0; +text-align:center; +text-decoration: none; +} + +.footer a:hover { +background: #ededed; +} + +.footer ul, .footer li { +list-style:none; +margin: 0; +padding: 0; +} + +.footer li { +float: left; +} + +.selected { +background: #ededed; +} diff --git a/static/templates/no_search_result.html b/static/templates/no_search_result.html index 104708850..5105e200c 100644 --- a/static/templates/no_search_result.html +++ b/static/templates/no_search_result.html @@ -2,96 +2,8 @@ - Fulltext search unavailable +
Not found
From a3460f6f4845c65d295aeac0bd604be8de1142a1 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 18 Mar 2022 15:50:25 +0400 Subject: [PATCH 4/6] Supporting varying page title in HTML response tests --- test/server.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/server.cpp b/test/server.cpp index da8334c41..f6685373f 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -328,11 +328,12 @@ namespace TestingOfHtmlResponses struct ExpectedResponseData { - const std::string bookName, bookTitle, expectedBody; + const std::string expectedPageTitle, bookName, bookTitle, expectedBody; }; enum ExpectedResponseDataType { + expected_page_title, book_name, book_title, expected_body @@ -345,9 +346,10 @@ ExpectedResponseData operator==(ExpectedResponseDataType t, std::string s) { switch (t) { - case book_name: return ExpectedResponseData{s, "", ""}; - case book_title: return ExpectedResponseData{"", s, ""}; - case expected_body: return ExpectedResponseData{"", "", s}; + case expected_page_title: return ExpectedResponseData{s, "", "", ""}; + case book_name: return ExpectedResponseData{"", s, "", ""}; + case book_title: return ExpectedResponseData{"", "", s, ""}; + case expected_body: return ExpectedResponseData{"", "", "", s}; default: assert(false); return ExpectedResponseData{}; } } @@ -364,6 +366,7 @@ ExpectedResponseData operator&&(const ExpectedResponseData& a, const ExpectedResponseData& b) { return ExpectedResponseData{ + selectNonEmpty(a.expectedPageTitle, b.expectedPageTitle), selectNonEmpty(a.bookName, b.bookName), selectNonEmpty(a.bookTitle, b.bookTitle), selectNonEmpty(a.expectedBody, b.expectedBody) @@ -384,6 +387,7 @@ public: std::string expectedResponse() const; private: + std::string pageTitle() const; std::string hiddenBookNameInput() const; std::string searchPatternInput() const; std::string taskbarLinks() const; @@ -396,7 +400,9 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const - Content not found + )FRAG", + + R"FRAG( @@ -436,14 +442,23 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const }; return frag[0] - + hiddenBookNameInput() + + pageTitle() + frag[1] - + searchPatternInput() + + hiddenBookNameInput() + frag[2] - + taskbarLinks() + + searchPatternInput() + frag[3] + + taskbarLinks() + + frag[4] + removeEOLWhitespaceMarkers(expectedBody) - + frag[4]; + + frag[5]; +} + +std::string TestContentIn404HtmlResponse::pageTitle() const +{ + return expectedPageTitle.empty() + ? "Content not found" + : expectedPageTitle; } std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const From aaf232bee46d1b22a9bec9c646ae9fd2be341dd4 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 11 Feb 2022 18:41:33 +0400 Subject: [PATCH 5/6] Support for CSS URL in HTML response tests --- test/server.cpp | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/test/server.cpp b/test/server.cpp index f6685373f..a011f1d33 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -328,12 +328,17 @@ namespace TestingOfHtmlResponses struct ExpectedResponseData { - const std::string expectedPageTitle, bookName, bookTitle, expectedBody; + const std::string expectedPageTitle; + const std::string expectedCssUrl; + const std::string bookName; + const std::string bookTitle; + const std::string expectedBody; }; enum ExpectedResponseDataType { expected_page_title, + expected_css_url, book_name, book_title, expected_body @@ -346,10 +351,11 @@ ExpectedResponseData operator==(ExpectedResponseDataType t, std::string s) { switch (t) { - case expected_page_title: return ExpectedResponseData{s, "", "", ""}; - case book_name: return ExpectedResponseData{"", s, "", ""}; - case book_title: return ExpectedResponseData{"", "", s, ""}; - case expected_body: return ExpectedResponseData{"", "", "", s}; + case expected_page_title: return ExpectedResponseData{s, "", "", "", ""}; + case expected_css_url: return ExpectedResponseData{"", s, "", "", ""}; + case book_name: return ExpectedResponseData{"", "", s, "", ""}; + case book_title: return ExpectedResponseData{"", "", "", s, ""}; + case expected_body: return ExpectedResponseData{"", "", "", "", s}; default: assert(false); return ExpectedResponseData{}; } } @@ -367,6 +373,7 @@ ExpectedResponseData operator&&(const ExpectedResponseData& a, { return ExpectedResponseData{ selectNonEmpty(a.expectedPageTitle, b.expectedPageTitle), + selectNonEmpty(a.expectedCssUrl, b.expectedCssUrl), selectNonEmpty(a.bookName, b.bookName), selectNonEmpty(a.bookTitle, b.bookTitle), selectNonEmpty(a.expectedBody, b.expectedBody) @@ -388,6 +395,7 @@ public: private: std::string pageTitle() const; + std::string pageCssLink() const; std::string hiddenBookNameInput() const; std::string searchPatternInput() const; std::string taskbarLinks() const; @@ -403,7 +411,9 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const )FRAG", R"FRAG( - +)FRAG", + + R"FRAG( @@ -444,14 +454,16 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const return frag[0] + pageTitle() + frag[1] - + hiddenBookNameInput() + + pageCssLink() + frag[2] - + searchPatternInput() + + hiddenBookNameInput() + frag[3] - + taskbarLinks() + + searchPatternInput() + frag[4] + + taskbarLinks() + + frag[5] + removeEOLWhitespaceMarkers(expectedBody) - + frag[5]; + + frag[6]; } std::string TestContentIn404HtmlResponse::pageTitle() const @@ -461,6 +473,17 @@ std::string TestContentIn404HtmlResponse::pageTitle() const : expectedPageTitle; } +std::string TestContentIn404HtmlResponse::pageCssLink() const +{ + if ( expectedCssUrl.empty() ) + return ""; + + return R"( +)"; +} + std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const { return bookName.empty() From 511261cc81b03b1dace7b61d3bef5ba2da83c42d Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 30 Jan 2022 15:59:17 +0400 Subject: [PATCH 6/6] Testing of "Fulltext search unavailable" page --- static/skin/search_results.css | 1 + static/templates/no_search_result.html | 4 ++-- test/server.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/static/skin/search_results.css b/static/skin/search_results.css index df3a54c04..8fb0a84b1 100644 --- a/static/skin/search_results.css +++ b/static/skin/search_results.css @@ -1,4 +1,5 @@ body{ +background-color: white; color: #000000; font: small/normal Arial,Helvetica,Sans-Serif; margin-top: 0.5em; diff --git a/static/templates/no_search_result.html b/static/templates/no_search_result.html index 5105e200c..baa7aa2c7 100644 --- a/static/templates/no_search_result.html +++ b/static/templates/no_search_result.html @@ -1,11 +1,11 @@ - + Fulltext search unavailable - +
Not found

There is no article with the title "{{pattern}}" diff --git a/test/server.cpp b/test/server.cpp index a011f1d33..4eb22e063 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -662,6 +662,30 @@ TEST_F(ServerTest, 404WithBodyTesting) Cannot find content entry invalid-article

)" }, + + { /* url */ "/ROOT/search?content=zimfile", + expected_page_title=="Fulltext search unavailable" && + expected_css_url=="/ROOT/skin/search_results.css" && + book_name=="zimfile" && + book_title=="Ray Charles" && + expected_body==R"( +
Not found
+

+ There is no article with the title "" + and the fulltext search engine is not available for this content. +

+)" }, + + { /* url */ "/ROOT/search?content=non-existent-book&pattern=asdfqwerty", + expected_page_title=="Fulltext search unavailable" && + expected_css_url=="/ROOT/skin/search_results.css" && + expected_body==R"( +
Not found
+

+ There is no article with the title "asdfqwerty" + and the fulltext search engine is not available for this content. +

+)" }, }; for ( const auto& t : testData ) {