mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #727 from kiwix/testing_of_ft_search_unavailable_page
This commit is contained in:
commit
ddc4c3ec2c
|
@ -517,6 +517,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
||||||
|| (patternString.empty() && ! has_geo_query) ) {
|
|| (patternString.empty() && ! has_geo_query) ) {
|
||||||
auto data = get_default_data();
|
auto data = get_default_data();
|
||||||
data.set("pattern", encodeDiples(patternString));
|
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");
|
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_taskbar(bookName, archive ? getArchiveTitle(*archive) : "");
|
||||||
response->set_code(MHD_HTTP_NOT_FOUND);
|
response->set_code(MHD_HTTP_NOT_FOUND);
|
||||||
|
|
|
@ -32,6 +32,7 @@ skin/index.css
|
||||||
skin/fonts/Poppins.ttf
|
skin/fonts/Poppins.ttf
|
||||||
skin/fonts/Roboto.ttf
|
skin/fonts/Roboto.ttf
|
||||||
skin/block_external.js
|
skin/block_external.js
|
||||||
|
skin/search_results.css
|
||||||
templates/search_result.html
|
templates/search_result.html
|
||||||
templates/no_search_result.html
|
templates/no_search_result.html
|
||||||
templates/404.html
|
templates/404.html
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
body{
|
||||||
|
background-color: white;
|
||||||
|
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;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
||||||
<title>Content not found</title>
|
<title>Content not found</title>
|
||||||
|
|
|
@ -1,99 +1,11 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
||||||
<style type="text/css">
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
<title>Fulltext search unavailable</title>
|
<title>Fulltext search unavailable</title>
|
||||||
|
<link type="text/css" href="{{root}}/skin/search_results.css" rel="Stylesheet" />
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body>
|
||||||
<div class="header">Not found</div>
|
<div class="header">Not found</div>
|
||||||
<p>
|
<p>
|
||||||
There is no article with the title <b> "{{pattern}}"</b>
|
There is no article with the title <b> "{{pattern}}"</b>
|
||||||
|
|
|
@ -303,6 +303,7 @@ const char* urls404[] = {
|
||||||
"/ROOT/random",
|
"/ROOT/random",
|
||||||
"/ROOT/random?content=non-existent-book",
|
"/ROOT/random?content=non-existent-book",
|
||||||
"/ROOT/search",
|
"/ROOT/search",
|
||||||
|
"/ROOT/search?content=non-existing-book&pattern=asdfqwerty",
|
||||||
"/ROOT/suggest",
|
"/ROOT/suggest",
|
||||||
"/ROOT/suggest?content=non-existent-book&term=abcd",
|
"/ROOT/suggest?content=non-existent-book&term=abcd",
|
||||||
"/ROOT/catch/external",
|
"/ROOT/catch/external",
|
||||||
|
@ -327,11 +328,17 @@ namespace TestingOfHtmlResponses
|
||||||
|
|
||||||
struct ExpectedResponseData
|
struct ExpectedResponseData
|
||||||
{
|
{
|
||||||
const std::string 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
|
enum ExpectedResponseDataType
|
||||||
{
|
{
|
||||||
|
expected_page_title,
|
||||||
|
expected_css_url,
|
||||||
book_name,
|
book_name,
|
||||||
book_title,
|
book_title,
|
||||||
expected_body
|
expected_body
|
||||||
|
@ -344,9 +351,11 @@ ExpectedResponseData operator==(ExpectedResponseDataType t, std::string s)
|
||||||
{
|
{
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case book_name: return ExpectedResponseData{s, "", ""};
|
case expected_page_title: return ExpectedResponseData{s, "", "", "", ""};
|
||||||
case book_title: return ExpectedResponseData{"", s, ""};
|
case expected_css_url: return ExpectedResponseData{"", s, "", "", ""};
|
||||||
case expected_body: 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{};
|
default: assert(false); return ExpectedResponseData{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,6 +372,8 @@ ExpectedResponseData operator&&(const ExpectedResponseData& a,
|
||||||
const ExpectedResponseData& b)
|
const ExpectedResponseData& b)
|
||||||
{
|
{
|
||||||
return ExpectedResponseData{
|
return ExpectedResponseData{
|
||||||
|
selectNonEmpty(a.expectedPageTitle, b.expectedPageTitle),
|
||||||
|
selectNonEmpty(a.expectedCssUrl, b.expectedCssUrl),
|
||||||
selectNonEmpty(a.bookName, b.bookName),
|
selectNonEmpty(a.bookName, b.bookName),
|
||||||
selectNonEmpty(a.bookTitle, b.bookTitle),
|
selectNonEmpty(a.bookTitle, b.bookTitle),
|
||||||
selectNonEmpty(a.expectedBody, b.expectedBody)
|
selectNonEmpty(a.expectedBody, b.expectedBody)
|
||||||
|
@ -383,6 +394,8 @@ public:
|
||||||
std::string expectedResponse() const;
|
std::string expectedResponse() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string pageTitle() const;
|
||||||
|
std::string pageCssLink() const;
|
||||||
std::string hiddenBookNameInput() const;
|
std::string hiddenBookNameInput() const;
|
||||||
std::string searchPatternInput() const;
|
std::string searchPatternInput() const;
|
||||||
std::string taskbarLinks() const;
|
std::string taskbarLinks() const;
|
||||||
|
@ -392,11 +405,15 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
|
||||||
{
|
{
|
||||||
const std::string frag[] = {
|
const std::string frag[] = {
|
||||||
R"FRAG(<!DOCTYPE html>
|
R"FRAG(<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
||||||
<title>Content not found</title>
|
<title>)FRAG",
|
||||||
<link type="root" href="/ROOT"><link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
|
||||||
|
R"FRAG(</title>
|
||||||
|
)FRAG",
|
||||||
|
|
||||||
|
R"FRAG( <link type="root" href="/ROOT"><link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
||||||
<link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
<link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
||||||
<link type="text/css" href="/ROOT/skin/taskbar.css" rel="Stylesheet" />
|
<link type="text/css" href="/ROOT/skin/taskbar.css" rel="Stylesheet" />
|
||||||
<script type="text/javascript" src="/ROOT/skin/jquery-ui/external/jquery/jquery.js" defer></script>
|
<script type="text/javascript" src="/ROOT/skin/jquery-ui/external/jquery/jquery.js" defer></script>
|
||||||
|
@ -435,14 +452,36 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
|
||||||
};
|
};
|
||||||
|
|
||||||
return frag[0]
|
return frag[0]
|
||||||
+ hiddenBookNameInput()
|
+ pageTitle()
|
||||||
+ frag[1]
|
+ frag[1]
|
||||||
+ searchPatternInput()
|
+ pageCssLink()
|
||||||
+ frag[2]
|
+ frag[2]
|
||||||
+ taskbarLinks()
|
+ hiddenBookNameInput()
|
||||||
+ frag[3]
|
+ frag[3]
|
||||||
|
+ searchPatternInput()
|
||||||
|
+ frag[4]
|
||||||
|
+ taskbarLinks()
|
||||||
|
+ frag[5]
|
||||||
+ removeEOLWhitespaceMarkers(expectedBody)
|
+ removeEOLWhitespaceMarkers(expectedBody)
|
||||||
+ frag[4];
|
+ frag[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestContentIn404HtmlResponse::pageTitle() const
|
||||||
|
{
|
||||||
|
return expectedPageTitle.empty()
|
||||||
|
? "Content not found"
|
||||||
|
: expectedPageTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestContentIn404HtmlResponse::pageCssLink() const
|
||||||
|
{
|
||||||
|
if ( expectedCssUrl.empty() )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return R"( <link type="text/css" href=")"
|
||||||
|
+ expectedCssUrl
|
||||||
|
+ R"(" rel="Stylesheet" />
|
||||||
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const
|
std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const
|
||||||
|
@ -623,6 +662,30 @@ TEST_F(ServerTest, 404WithBodyTesting)
|
||||||
Cannot find content entry invalid-article
|
Cannot find content entry invalid-article
|
||||||
</p>
|
</p>
|
||||||
)" },
|
)" },
|
||||||
|
|
||||||
|
{ /* 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"(
|
||||||
|
<div class="header">Not found</div>
|
||||||
|
<p>
|
||||||
|
There is no article with the title <b> ""</b>
|
||||||
|
and the fulltext search engine is not available for this content.
|
||||||
|
</p>
|
||||||
|
)" },
|
||||||
|
|
||||||
|
{ /* 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"(
|
||||||
|
<div class="header">Not found</div>
|
||||||
|
<p>
|
||||||
|
There is no article with the title <b> "asdfqwerty"</b>
|
||||||
|
and the fulltext search engine is not available for this content.
|
||||||
|
</p>
|
||||||
|
)" },
|
||||||
};
|
};
|
||||||
|
|
||||||
for ( const auto& t : testData ) {
|
for ( const auto& t : testData ) {
|
||||||
|
|
Loading…
Reference in New Issue