aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/MessageTest.php
Commit message (Collapse)AuthorAgeFilesLines
...
* Message: Fix buggy parameter handling in Message::params()Brad Jorsch2016-12-071-4/+26
| | | | | | | | | | Message::params() wants to take parameters either varargs-style or as a single array. But it also detects "special" parameters like those returned from Message::numParam() as an array of parameters instead of as a single "special" parameter. Bug: T152603 Change-Id: Idef2437470eee843a17ff23f4cefe8f3132988bd
* Add Message::listParam()Brad Jorsch2016-11-301-0/+102
| | | | | | | | | | | | | | | | | | | | | | This allows for passing a list of values that will be turned into a list in the context of the language for which the Message is being processed. For example, currently you'd have to do $msg = new Message( 'something', [ $language->commaList( $list ) ] ); which isn't going to give correct results if the message is later changed to a different language with a different value for 'comma-separator'. Now, you can do this instead $msg = new Message( 'something', [ Message::listParam( $list, 'comma' ) ] ); and it will be listified properly no matter what language is later used to parse $msg. Change-Id: I66868c61832260870449998fef14c842f17753ee
* Better handling of Message objects as Message parametersBrad Jorsch2016-11-141-0/+28
| | | | | | | | If a Message object is a parameter of another Message object, it should use the same language, use-database flag, and so on as the outer Message when it's being stringified. Change-Id: I92762a1a63c90a16e8581edc96bd1da699880157
* More robust, cleaned up MessageTestThiemo Mättig2016-11-111-62/+61
| | | | | | | | | | | | | | | This is a direct follow up to my comments in Ia6ec10d. Relevant for T146416 are the two messages I added. They explain why these assertions are duplicated. assertEquals behaves bogus when used with strings, especially when used with formatters and parsers, which is the case here. For example, assertEquals( '9a', 9 ) succeeds. assertEquals is useful when comparing objects. Bug: T146416 Change-Id: Ie8df41b3ce6678f3add55bab6701b56b66447a2e
* Deprecate Message::$format (mostly)Gergő Tisza2016-11-101-17/+25
| | | | | | | | | | | | | | | | | | | Message::__toString() used the same formatting mode that the last explicit transformation used: $msg = new Message( 'foo' ); echo $msg; // escaped echo $msg->plain(); echo $msg; // not escaped This is not particularly useful and makes code review hard, so let's get rid of it. The same behavior with $msg->toString() is left intact (and logged) for now. Bug: T146416 Change-Id: Ia9b2a1dcf09d52348b2c6d8299fd849b809f6e74
* Add Message test for implicit formattingGergő Tisza2016-11-091-0/+29
| | | | Change-Id: Ia6ec10d0d6da8c2b323054642e206c722d17f0b0
* Make non-existent messages be html safe regardless of output formatBrian Wolff2016-06-291-8/+10
| | | | | | | | | | | | | | | | | | | | | | If you have a non-existent message in the output, chances are its user-controlled. If the message has the ->plain() or ->text() format, the output used to be not safe for html. Obviously people should not be using those format types where html is being outputted, but sometimes that happens. I think we should prioritize always being safe over the fallback content not potentially being double escaped. Additionally switch the enclosing brackets to be fancy unicode characters, to sidestep the escaping issue on the enclosing brackets. So previously, wfMessage( 'script>alert(1)</script' )->text() would have outputted <script>alert(1)</script>. Now it outputs ⧼script&gt;alert(1)&lt;/script⧽. No sane message key will include < or >, so this would really only come up if the user can control the message key name. This goes somewhat against T68199. Change-Id: Ic8a60892b8e847e6021494c10968814aac391731
* Allow Message::newFromSpecifier to handle ApiMessagesBrad Jorsch2016-06-281-0/+5
| | | | | | | | | | Instead of constructing a new Message from the Message as a MessageSpecifier, just clone the existing Message which will preserve subclass data. Also, make use of this to simplify the logic in ApiBase::parseMsg(). Change-Id: I9545acb8da752c0c21e16d8b1d37d8802fcb329d
* Fix Message::newFromSpecifier for nested RawMessageGergő Tisza2016-06-071-0/+1
| | | | | | | This can happen e.g. when something processes Status contents and expects [$key, $param1, ...] and instead gets [$messageObject] Change-Id: I346b35e08bd38ce231e16d0616438ea408b55bff
* Unify HTMLForm message handlingGergő Tisza2016-05-021-0/+25
| | | | | | | Improves Ida647973a which unified message handling for form fields but did not make the functionality available to HTMLForm itself. Change-Id: I2e6195ba13afbd8b993acb47409fab1be91c547e
* Revert "Allow reset of global services."Catrope2016-04-111-3/+3
| | | | | | | | Completely breaks login. This reverts commit 8e7a0a0912bb98a4a12375b354e23f03262bf213. Change-Id: Ide7ab5632e987e81374c21173df6ab3998649df7
* Allow reset of global services.daniel2016-04-111-3/+3
| | | | | | | | | | | | This change provides a mechanism to reset global service instances in an orderly manner. There are three use cases for this: * the installation process * forking processes * integration tests (which must of the existing phpunit tests are) Depends-On: I5d638ad415fc3840186a0beaa09ac02ea688539b Change-Id: Ie98bf5af59208f186dba59a9e971c72ea0b63e69
* phpunit: Abstract user-lang override in MediaWikiTestCaseTimo Tijhof2016-03-091-3/+3
| | | | | | | | | | | Removed redundant set up in these classes (same as their paren class MediaWikiLangTestCase does already). * BlockTest * ExportTest * MWTimestampTest * TitlePermissionTest Change-Id: I28d18cb797bb249981727b02dffce4f0d8682b02
* Convert all array() syntax to []Kunal Mehta2016-02-171-110/+110
| | | | | | | | | | Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
* Merge "Allow constructing a Message from a MessageSpecifier"jenkins-bot2015-07-201-0/+11
|\
| * Allow constructing a Message from a MessageSpecifierBrad Jorsch2015-04-211-0/+11
| | | | | | | | | | Bug: T91986 Change-Id: Id6a9862d23c2b71da2c8b34acdd19b8247ac5301
* | Improve serialization of Message, TitleBrad Jorsch2015-07-071-0/+22
|/ | | | | | | | | | This allows them to be stored in the session, for example. Note that properly serializing a Message requires that all its parameters be serializable as well; we don't attempt to account for that here. Change-Id: I3a42a2a883e8eef900eeb02355fc3b064411f642
* Message: Clean up unit tests and improve code coverageTimo Tijhof2015-04-021-114/+242
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove unnecessary use of ReflectionClass. It was testing internal properties that aren't part of the API. Using the getters instead. * Remove need for func_get_args that was making the test more complex and the data provider hard to read. Simply maintain it as array of expected params and array of variadic arguments. * Rename tests to more closely match tested methods. * Rename data providers to provide*, and make them static. * Reorder tests to more closely match logical order of the class. * Improve line coverage from 31% to 67%. Also: * Remove testParams (dupes testConstructorParams). * Add tests for RawMessage class. * Add tests for transformation and parsing. * Add tests for wfMessage(). * Add tests for Message::newFrom*. * Add tests for "$*" replacement. * Add tests for __toString. Change-Id: I2b183a66f9e9f51bd800088e174b1ae4d3284d8d
* Introduce Message::plaintextParamErik Bernhardson2014-09-301-0/+49
| | | | | | | | | | | | | | | | | | | | | I have run into numerous issues trying to utilize unsafe user provided content as an argument to a Message instance. Specific cases are enumerated in MessageTest.php Typically the solution to using user provided text is to use Message::rawParam, but this pushes escaping of the parameter to the caller. This patch introduces Message::plaintextParams which handles escaping of the string parameter to match the requested output format. The functionality is: * plain and text: exactly like rawParams() * escaped, parse and parseAsBlock: escape it but don't do brace expansion Additionaly, similar to Message::rawParam, plaintext parameters are not valid parser function arguments. Change-Id: I320645cd23c98fea4bfc32ab22b7ef8d320957cb
* Message: Correct output of wfMessage( 'non-existent-msg' )->text()Erik Bernhardson2014-09-231-1/+7
| | | | | | | | | | | The output of Message::text() should always be acceptable to pass into external html escaping, such as when the response is returned over an API request and escaped by the client side code. Calling ->text() on a non-existent key was returning the entity encoded value which leads to double encoding down the line, this patch fixes that oversight. Bug: 66199 Change-Id: Ieec94d4e4c7e5c36e5e68bbf01792e96368e54e0
* test: Clean up data providers that should be staticTimo Tijhof2014-09-181-2/+2
| | | | | | | | | | | | | | | | | | Follows-up b36d883. By far most data providers are static (and PHPUnit expects them to be static and calls them that way). Most of these classes already had their data providers static but additional commits sloppily introduced non-static ones. * ResourceLoaderWikiModuleTest, 8968d8787f. * TitleTest, 545f1d3a73. Odd unused method 'dataTestIsValidMoveOperation' was introduced in 550b878e63. * GlobalVarConfigTest, a3e18c3670. Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
* Consistent handling of multiple keys in Messagedaniel2014-08-061-0/+48
| | | | | | | | Message objects may be constructed with a list of keys as a simple fallback mechanism. This patch assures consistent handling of this case. Change-Id: I458c0af3114754ddf3d721f6c374e249f482e4cf
* Break some long lines in maintenance, skins, testsumherirrender2014-07-241-1/+2
| | | | Change-Id: I5d86ad3e0c90e09440268a670f5af3e2bf080612
* Pass phpcs-strict on some test files (3/x)Siebrand Mazeland2014-04-241-10/+43
| | | | Change-Id: I44172b512cd9b6c43806dad697e449bf06897305
* Changing a message's lang must reset cached text.daniel2014-04-161-6/+19
| | | | | | | Without this patch, it's not possible to get text in different languages from the same Message object. Change-Id: I0bb915b0d9205e78ac4599ced5efacacf2cf0240
* Add getLanguage method to Messageaude2014-03-281-0/+18
| | | | | | | This allows to more easily test code where language is set, Message::inLanguage() is called, etc. Change-Id: If8f9697480f5d084f755990fdc0f2a1e18f056bc
* Allow to optionally set language in Message constructoraude2014-03-281-0/+35
| | | | | | | | | | | | | This helps with testability to not have to rely on $wgLang and setting globals in tests. This also provides convenience, so one does not necessarily need to call Message::inLanguage() if language is known at time of constructing the message object. Also added tests to cover this change. Change-Id: I14ee98972c7be954e04398ece9e6103f96ab60dd
* Fixed spacingumherirrender2014-03-201-1/+1
| | | | | | | | - Added spaces after if/foreach/catch - Added new line before end of file - Added or removed spaces before/after parenthesis, comma - Added spaces around string concat Change-Id: I0590070f1b3542108e242730e8d9a3ba9831e94f
* Merge "Add test for Message::params"jenkins-bot2014-03-061-0/+27
|\
| * Add test for Message::paramsaddshore2014-03-061-0/+27
| | | | | | | | Change-Id: I66098828d72ac6cb594bf886d5a7f61a8616a1a0
* | Split MessageTest::testMessageParamTypesaddshore2014-03-061-10/+39
|/ | | | Change-Id: I2099fa8a27a88bceb77c25e1ee08fb71eca318dc
* @covers tags for more test classesaddshore2013-10-241-0/+34
| | | | Change-Id: I19d49c279646a4b4c595700e53b790ba4eb9521e
* Fix scope on all /phpunit test methodsaddshore2013-10-241-10/+10
| | | | Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
* Added more Message parameter functionsparent54462013-10-191-0/+50
| | | | | | | | | Similar to numParams(), added functions for other parameters that can be formatted by the Language class. Adds functions for expiry, size, timePeriod, duration, and bitrate parameters so that the formatting doesn't have to be done at the caller. Change-Id: I7b435fcc11824ead55e4c0f5512418187eae9a6f
* MessageTest: Split test and use setMwGlobalsumherirrender2013-03-211-4/+10
| | | | Change-Id: I9d7f16ed519622d5ac947da8538449f520eb0eae
* Add test for substitution of params with multiple digitsNiklas Laxström2013-01-031-0/+7
| | | | Change-Id: I293bcdeecd5ee83cf05887aa06dc86b5589398eb
* Clean and repair many phpunit tests (+ fix implied configuration)Timo Tijhof2012-10-091-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
* Add phpunit testcases for Bug 30681Santhosh Thottingal2012-03-281-0/+2
| | | | | | - The fix was done in https://gerrit.wikimedia.org/r/3842 Change-Id: I9874604828c1ae4ce0948ed7533a57dea9ac736d
* Whitespace/documentationSam Reed2011-09-141-1/+1
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/97060
* Follow up r89585. Clean up after the test, expand inContentLanguage() comment.Platonides2011-06-061-2/+7
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/89612
* Fix for bug 29274 - Message class ignores $wgForceUIMsgAsContentMsgNiklas Laxström2011-06-061-0/+8
| | | | | | | Also added tests, which pass Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/89585
* Fix the old XmlTest.php test bug in the dateMenu() when the wiki is ↵Platonides2011-05-011-10/+1
| | | | | | | | | | configured for a languange other than English Other tests were running before and messing with the Language objects. Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/87210
* Tests for r81878Niklas Laxström2011-02-101-1/+9
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/81882
* * Replaced $wgMessageCache by MessageCache::singleton(); since we only use ↵Alexandre Emsenhuber2011-01-261-2/+2
| | | | | | | | | | | one instance of this class (as for ParserCache, LinkCache) * MessageCache::singleton() calls wfGetMessageCacheStorage() directly instead of using $messageMemc, just in case this would be called before that variable is set * Per TimStarling: also removed deprecated methods in MessageCache class: addMessages() and related, [get|set|enable|disable]Transform(), loadAllMessages(), loadMessageFile() and some others. Same for the legacyData stuff in LocalisationCache that was only used by MessageCache::addMessages() and related. * Converted remaining extensions Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/81027
* * verbose and color default output from phpunitChad Horohoe2010-12-281-1/+1
| | | | | | | | * Make a bunch of tests subclass MediaWikiTestCase * Parser tests and ResourceLoaderTest can't subclass it yet due to various issues Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/79117
* assertType() is deprecated, switching usages tp assertInternalType() and ↵X!2010-12-281-2/+2
| | | | | | | assertInstanceOf() Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/79107
* Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. ↵Chad Horohoe2010-12-141-0/+50
They're not strictly maintenance scripts, and some people want to do a selective checkout that doesn't include the tests. There's still debate on whether we should include these in the release downloads, but we had a pretty firm consensus to move this. Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/78383