#include "../src/server/response.h" #include "gtest/gtest.h" #include "../src/server/request_context.h" namespace { using namespace kiwix; RequestContext makeHttpGetRequest(const std::string& url, const RequestContext::NameValuePairs& headers, const RequestContext::NameValuePairs& queryArgs) { return RequestContext("", url, "GET", "1.1", headers, queryArgs); } std::string getResponseContent(const ContentResponseBlueprint& crb) { return crb.generateResponseObject()->getContent(); } } // unnamed namespace TEST(HTTPErrorResponse, shouldBeInEnglishByDefault) { const RequestContext req = makeHttpGetRequest("/asdf", {}, {}); HTTPErrorResponse errResp(req, MHD_HTTP_NOT_FOUND, "404-page-title", "404-page-heading", "/css/error.css", /*includeKiwixResponseData=*/true); errResp += ParameterizedMessage("suggest-search", { { "PATTERN", "asdf" }, { "SEARCH_URL", "/search?q=asdf" } }); EXPECT_EQ(getResponseContent(errResp), R"( Content not found

Not Found

Make a full text search for asdf

)"); } TEST(HTTPErrorResponse, shouldBeTranslatable) { const RequestContext req = makeHttpGetRequest("/asdf", /* headers */ {}, /* query args */ {{"userlang", "test"}} ); HTTPErrorResponse errResp(req, MHD_HTTP_NOT_FOUND, "404-page-title", "404-page-heading", "/css/error.css", /*includeKiwixResponseData=*/true); errResp += ParameterizedMessage("suggest-search", { { "PATTERN", "asdf" }, { "SEARCH_URL", "/search?q=asdf" } }); EXPECT_EQ(getResponseContent(errResp), R"( [I18N TESTING] Not Found - Try Again

[I18N TESTING] Content not found, but at least the server is alive

[I18N TESTING] Make a full text search for asdf

)"); }