mirror of https://github.com/kiwix/libkiwix.git
Improved ServerTest.UserLanguageControl unittest
- Description of a test point was not updated in an earlier commit that added proper handling of the Accept-Language header. Also after enhancing the limited implementation it made sense to add another test point demonstrating that the most suitable language (rather than just the first one in the list) is selected. - Now failures of the test case because of a missing Set-Cookie header are more informative.
This commit is contained in:
parent
b9937e6859
commit
0edee4d066
|
@ -1107,15 +1107,25 @@ TEST_F(ServerTest, UserLanguageControl)
|
||||||
/* expected <h1> */ "Not Found"
|
/* expected <h1> */ "Not Found"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"The value of the Accept-Language header is not currently parsed.",
|
"Most suitable language is selected from the Accept-Language header",
|
||||||
// In case of a comma separated list of languages (optionally weighted
|
// In case of a comma separated list of languages (optionally weighted
|
||||||
// with quality values) the default (en) language is used instead.
|
// with quality values) the most suitable language is selected.
|
||||||
/*url*/ "/ROOT/content/zimfile/invalid-article",
|
/*url*/ "/ROOT/content/zimfile/invalid-article",
|
||||||
/*Accept-Language:*/ "test;q=0.9, en;q=0.2",
|
/*Accept-Language:*/ "test;q=0.9, en;q=0.2",
|
||||||
/*Request Cookie:*/ NO_COOKIE,
|
/*Request Cookie:*/ NO_COOKIE,
|
||||||
/*Response Set-Cookie:*/ "userlang=test",
|
/*Response Set-Cookie:*/ "userlang=test",
|
||||||
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
|
/* expected <h1> */ "[I18N TESTING] Content not found, but at least the server is alive"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Most suitable language is selected from the Accept-Language header",
|
||||||
|
// In case of a comma separated list of languages (optionally weighted
|
||||||
|
// with quality values) the most suitable language is selected.
|
||||||
|
/*url*/ "/ROOT/content/zimfile/invalid-article",
|
||||||
|
/*Accept-Language:*/ "test;q=0.2, en;q=0.9",
|
||||||
|
/*Request Cookie:*/ NO_COOKIE,
|
||||||
|
/*Response Set-Cookie:*/ "userlang=en",
|
||||||
|
/* expected <h1> */ "Not Found"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::regex h1Regex("<h1>(.+)</h1>");
|
const std::regex h1Regex("<h1>(.+)</h1>");
|
||||||
|
@ -1130,6 +1140,7 @@ TEST_F(ServerTest, UserLanguageControl)
|
||||||
}
|
}
|
||||||
const auto r = zfs1_->GET(t.url.c_str(), headers);
|
const auto r = zfs1_->GET(t.url.c_str(), headers);
|
||||||
if ( t.responseSetCookie ) {
|
if ( t.responseSetCookie ) {
|
||||||
|
ASSERT_TRUE(r->has_header("Set-Cookie")) << t;
|
||||||
EXPECT_EQ(t.responseSetCookie, getHeaderValue(r->headers, "Set-Cookie")) << t;
|
EXPECT_EQ(t.responseSetCookie, getHeaderValue(r->headers, "Set-Cookie")) << t;
|
||||||
} else {
|
} else {
|
||||||
EXPECT_FALSE(r->has_header("Set-Cookie"));
|
EXPECT_FALSE(r->has_header("Set-Cookie"));
|
||||||
|
|
Loading…
Reference in New Issue