/** * tests the getLanguage function. * NOTE: Static vars are involved here. * Assertions: * getLanguage with no parameters returns english (if none of the * previous tests set the var differently. Static vars have tricky initial * conditions...) * Passing getLanguage a different language than the one previously in * use will cause the var to reset to the explicit language. Messages should * be sent in the new language. */ function testGetLanguage() { $messageKey = 'contributiontracking'; $messageBG = 'Проследяване на дарението'; $messageEN = 'Contribution tracking'; $code = ContributionTrackingProcessor::getLanguage(); $this->assertEquals($code, 'en', "Default language is not US (or your test has a hangover)"); $params['language'] = 'bg'; $code = ContributionTrackingProcessor::getLanguage($params); $this->assertEquals($params['language'], $code, "Returned language is not the one we just sent."); $message = ContributionTrackingProcessor::msg($messageKey); $this->assertEquals($message, $messageBG, "Returned language is not the one we just sent."); $params['language'] = 'en'; $code = ContributionTrackingProcessor::getLanguage($params); $this->assertEquals($params['language'], $code, "Returned language is not the one we just sent."); $message = ContributionTrackingProcessor::msg($messageKey); $this->assertEquals($message, $messageEN, "Returned language is not the one we just sent."); }
/** * Gets a message in the local language * @param string $key Message key * @return string translated message */ static function msg($key) { return wfMsgExt($key, array('escape', 'language' => ContributionTrackingProcessor::getLanguage())); }