Allow `languageinheader` query param to fully control treatment of languages

Before this commit the `languageinheader` query param would only take
effect if the A/B test was enabled AND the query param was set. Per
T282543, we want the query param to take effect regardless of the state
of the language/AB test config.

To see new treatment, set `languageinheader=1`.
To see old treatment, set `languageinheader=0`.

Bug: T282543
Change-Id: I6a06e90b6e46a6fd7506a5ddeaf071b893ebfe8e
This commit is contained in:
Nicholas Ray 2021-05-13 11:55:20 -06:00
parent 50430ea06a
commit de5a640c0b
2 changed files with 36 additions and 5 deletions

View File

@ -91,15 +91,14 @@ final class LanguageInHeaderTreatmentRequirement implements Requirement {
* @throws \ConfigException
*/
public function isMet() : bool {
if ( $this->request->getCheck( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER ) ) {
return $this->request->getBool( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER );
}
if (
(bool)$this->config->get( Constants::CONFIG_LANGUAGE_IN_HEADER_TREATMENT_AB_TEST ) &&
$this->user->isRegistered()
) {
if ( $this->request->getCheck( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER ) ) {
return $this->request->getBool( Constants::QUERY_PARAM_LANGUAGE_IN_HEADER );
}
$id = null;
if ( $this->centralIdLookup ) {
$id = $this->centralIdLookup->centralIdFromLocalUser( $this->user );

View File

@ -234,6 +234,38 @@ class LanguageInHeaderTreatmentRequirementTest extends \MediaWikiUnitTestCase {
false,
'Even logged in users get old treatment when A/B test enabled and query param set to "0"'
],
[
// Is language enabled
[
'logged_in' => false,
'logged_out' => false,
],
// is A-B test enabled
false,
1,
// use central id lookup?
false,
// `languageinheader` query param
"1",
true,
'Users get new treatment when query param set to "1" regardless of state of A/B test or config flags'
],
[
// Is language enabled
[
'logged_in' => false,
'logged_out' => false,
],
// is A-B test enabled
false,
1,
// use central id lookup?
false,
// `languageinheader` query param
"0",
false,
'Users get old treatment when query param set to "0" regardless of state of A/B test or config flags'
],
];
}