3
final class PhabricatorLocaleScopeGuardTestCase
4
extends PhabricatorTestCase {
6
public function testLocaleScopeGuard() {
7
$original = PhabricatorEnv::getLocaleCode();
9
// Set a guard; it should change the locale, then revert it when destroyed.
10
$guard = PhabricatorEnv::beginScopedLocale('en_GB');
11
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
13
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
15
// Nest guards, then destroy them out of order.
16
$guard1 = PhabricatorEnv::beginScopedLocale('en_GB');
17
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
18
$guard2 = PhabricatorEnv::beginScopedLocale('en_A*');
19
$this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode());
21
$this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode());
23
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
25
// If you push `null`, that should mean "the default locale", not
26
// "the current locale".
27
$guard3 = PhabricatorEnv::beginScopedLocale('en_GB');
28
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
29
$guard4 = PhabricatorEnv::beginScopedLocale(null);
30
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
32
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
34
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());