Commit graph

30 commits

Author SHA1 Message Date
Timo Tijhof
86a771beff Message: Clean up unit tests and improve code coverage
* 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
2015-04-02 08:36:19 +01:00
Erik Bernhardson
d55fedfba8 Introduce Message::plaintextParam
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
2014-09-30 12:51:29 -07:00
Erik Bernhardson
c9a3ecef59 Message: Correct output of wfMessage( 'non-existent-msg' )->text()
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
2014-09-23 21:06:22 +00:00
Timo Tijhof
96771e3a65 test: Clean up data providers that should be static
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
2014-09-18 12:52:44 -07:00
daniel
cff86194ff Consistent handling of multiple keys in Message
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
2014-08-06 12:29:28 +01:00
umherirrender
d15f1cc5e1 Break some long lines in maintenance, skins, tests
Change-Id: I5d86ad3e0c90e09440268a670f5af3e2bf080612
2014-07-24 19:03:17 +02:00
Siebrand Mazeland
d5df012a13 Pass phpcs-strict on some test files (3/x)
Change-Id: I44172b512cd9b6c43806dad697e449bf06897305
2014-04-24 18:51:39 +02:00
daniel
c95bc7fe90 Changing a message's lang must reset cached text.
Without this patch, it's not possible to get text in different
languages from the same Message object.

Change-Id: I0bb915b0d9205e78ac4599ced5efacacf2cf0240
2014-04-16 12:17:47 +02:00
aude
78937428b6 Add getLanguage method to Message
This allows to more easily test code where language is set,
Message::inLanguage() is called, etc.

Change-Id: If8f9697480f5d084f755990fdc0f2a1e18f056bc
2014-03-28 18:04:12 +01:00
aude
3df8366e9a Allow to optionally set language in Message constructor
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
2014-03-28 17:59:48 +01:00
umherirrender
2000672ac3 Fixed spacing
- 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
2014-03-20 20:37:30 +00:00
jenkins-bot
f6fe1b181e Merge "Add test for Message::params" 2014-03-06 20:12:18 +00:00
addshore
a9fb88abb0 Split MessageTest::testMessageParamTypes
Change-Id: I2099fa8a27a88bceb77c25e1ee08fb71eca318dc
2014-03-06 20:36:29 +01:00
addshore
c83f5d02ef Add test for Message::params
Change-Id: I66098828d72ac6cb594bf886d5a7f61a8616a1a0
2014-03-06 20:23:22 +01:00
addshore
aea1b27db0 @covers tags for more test classes
Change-Id: I19d49c279646a4b4c595700e53b790ba4eb9521e
2013-10-24 20:35:04 +01:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
parent5446
0f88ab3d4e Added more Message parameter functions
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
2013-10-19 14:34:14 +02:00
umherirrender
3b2c99d768 MessageTest: Split test and use setMwGlobals
Change-Id: I9d7f16ed519622d5ac947da8538449f520eb0eae
2013-03-21 20:05:39 +01:00
Niklas Laxström
98345b9738 Add test for substitution of params with multiple digits
Change-Id: I293bcdeecd5ee83cf05887aa06dc86b5589398eb
2013-01-03 09:45:22 +00:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
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
2012-10-09 03:01:51 +02:00
Santhosh Thottingal
b91ffd7b09 Add phpunit testcases for Bug 30681
- The fix was done in https://gerrit.wikimedia.org/r/3842

Change-Id: I9874604828c1ae4ce0948ed7533a57dea9ac736d
2012-03-28 15:36:23 +05:30
Sam Reed
fb32210aee Whitespace/documentation 2011-09-14 15:07:20 +00:00
Platonides
c7137c50a4 Follow up r89585. Clean up after the test, expand inContentLanguage() comment. 2011-06-06 21:24:23 +00:00
Niklas Laxström
73776c92ee Fix for bug 29274 - Message class ignores $wgForceUIMsgAsContentMsg
Also added tests, which pass
2011-06-06 17:55:19 +00:00
Platonides
10cd6f1b6a Fix the old XmlTest.php test bug in the dateMenu() when the wiki is configured for a languange other than English
Other tests were running before and messing with the Language objects.
2011-05-01 19:32:49 +00:00
Niklas Laxström
efc2002d3d Tests for r81878 2011-02-10 10:10:44 +00:00
Alexandre Emsenhuber
51c6afc751 * Replaced $wgMessageCache by MessageCache::singleton(); since we only use 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
2011-01-26 15:42:04 +00:00
Chad Horohoe
447529064b * verbose and color default output from phpunit
* Make a bunch of tests subclass MediaWikiTestCase
* Parser tests and ResourceLoaderTest can't subclass it yet due to various issues
2010-12-28 18:17:16 +00:00
X!
eb0611a171 assertType() is deprecated, switching usages tp assertInternalType() and assertInstanceOf() 2010-12-28 15:13:42 +00:00
Chad Horohoe
23f69f10ed Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. 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. 2010-12-14 16:26:35 +00:00