diff --git a/test/server.cpp b/test/server.cpp index fe584ad83..d5e05a652 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -322,6 +322,253 @@ TEST_F(ServerTest, 404) EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url; } +class TestContentIn404HtmlResponse +{ +public: + TestContentIn404HtmlResponse(const std::string& url, + const std::string& expectedBody) + : url(url) + , expectedBody(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 +{ + const std::string frag[] = { + R"FRAG( + +
+ ++ No such book: non-existent-book +
+)" }, + + { /* url */ "/ROOT/suggest?content=no-such-book&term=whatever", + /* expected body */ R"( ++ No such book: no-such-book +
+)" }, + + { /* url */ "/ROOT/catalog/", + /* expected body */ R"( ++ The requested URL "/ROOT/catalog/" was not found on this server. +
++ //EOLWHITESPACEMARKER +
+)" }, + + { /* url */ "/ROOT/catalog/invalid_endpoint", + /* expected body */ R"( ++ The requested URL "/ROOT/catalog/invalid_endpoint" was not found on this server. +
++ //EOLWHITESPACEMARKER +
+)" }, + + { /* url */ "/ROOT/invalid-book/whatever", + /* expected body */ R"( ++ The requested URL "/ROOT/invalid-book/whatever" was not found on this server. +
++ Make a full text search for whatever +
+)" }, + + { /* url */ "/ROOT/zimfile/invalid-article", + /* book name */ "zimfile", + /* book title */ "Ray Charles", + /* expected body */ R"( ++ 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"( ++ The requested URL "/ROOT/raw/no-such-book/meta/Title" was not found on this server. +
++ No such book: no-such-book +
+)" }, + + { /* url */ "/ROOT/raw/zimfile/XYZ", + /* expected body */ R"( ++ The requested URL "/ROOT/raw/zimfile/XYZ" was not found on this server. +
++ XYZ is not a valid request for raw content. +
+)" }, + + { /* url */ "/ROOT/raw/zimfile/meta/invalid-metadata", + /* book name */ "zimfile", + /* book title */ "Ray Charles", + /* expected body */ R"( ++ The requested URL "/ROOT/raw/zimfile/meta/invalid-metadata" was not found on this server. +
++ Cannot find meta entry invalid-metadata +
+)" }, + + { /* url */ "/ROOT/raw/zimfile/content/invalid-article", + /* book name */ "zimfile", + /* book title */ "Ray Charles", + /* expected body */ R"( ++ The requested URL "/ROOT/raw/zimfile/content/invalid-article" was not found on this server. +
++ Cannot find content entry invalid-article +
+)" }, + }; + + for ( const auto& t : testData ) { + const TestContext ctx{ {"url", t.url} }; + const auto r = zfs1_->GET(t.url.c_str()); + EXPECT_EQ(r->status, 404) << ctx; + EXPECT_EQ(r->body, t.expectedResponse()) << ctx; + } +} + TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle) { auto g = zfs1_->GET("/ROOT/random?content=zimfile");