From 7a6562395a140dea199d3d4db2317930ccf6f9c1 Mon Sep 17 00:00:00 2001
From: Veloman Yunkan
Date: Fri, 11 Feb 2022 18:21:03 +0400
Subject: [PATCH] Testing of /ROOT/zimfile/invalid-article
---
test/server.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 72 insertions(+), 7 deletions(-)
diff --git a/test/server.cpp b/test/server.cpp
index 16b4e6aa1..8b0179934 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -322,17 +322,33 @@ TEST_F(ServerTest, 404)
EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url;
}
-struct TestContentIn404HtmlResponse
+class TestContentIn404HtmlResponse
{
+public:
TestContentIn404HtmlResponse(const std::string& url,
const std::string& expectedBody)
: url(url)
, expectedBody(expectedBody)
{}
- std::string url, expectedBody;
+ TestContentIn404HtmlResponse(const std::string& url,
+ const std::string& bookName,
+ const std::string& bookTitle,
+ const std::string& expectedBody)
+ : url(url)
+ , bookName(bookName)
+ , bookTitle(bookTitle)
+ , expectedBody(expectedBody)
+ {}
+
+ const std::string url, bookName, bookTitle, expectedBody;
std::string expectedResponse() const;
+
+private:
+ std::string hiddenBookNameInput() const;
+ std::string searchPatternInput() const;
+ std::string taskbarLinks() const;
};
std::string TestContentIn404HtmlResponse::expectedResponse() const
@@ -361,9 +377,6 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
)FRAG",
- R"FRAG(
-)FRAG",
-
R"FRAG(
@@ -385,12 +398,51 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
};
return frag[0]
+ + hiddenBookNameInput()
+ frag[1]
+ + searchPatternInput()
+ frag[2]
+ + taskbarLinks()
+ frag[3]
- + frag[4]
+ removeEOLWhitespaceMarkers(expectedBody)
- + frag[5];
+ + frag[4];
+}
+
+std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const
+{
+ return bookName.empty()
+ ? ""
+ : R"()";
+}
+
+std::string TestContentIn404HtmlResponse::searchPatternInput() const
+{
+ return R"(
+)";
+}
+
+std::string TestContentIn404HtmlResponse::taskbarLinks() const
+{
+ if ( bookName.empty() )
+ return "";
+
+ return R"(
+ )";
}
TEST_F(ServerTest, 404WithBodyTesting)
@@ -447,6 +499,19 @@ TEST_F(ServerTest, 404WithBodyTesting)
)" },
+ { /* url */ "/ROOT/zimfile/invalid-article",
+ /* book name */ "zimfile",
+ /* book title */ "Ray Charles",
+ /* expected body */ R"(
+ Not Found
+
+ The requested URL "/ROOT/zimfile/invalid-article" was not found on this server.
+
+
+ Make a full text search for invalid-article
+
+)" },
+
{ /* url */ "/ROOT/raw/no-such-book/meta/Title",
/* expected body */ R"(
Not Found