Commit graph

39 commits

Author SHA1 Message Date
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Amir Sarabadani
440297fa3a Clean up most of b/c for phpunit4
We don't support phpunit4 anymore:
https://w.wiki/9UT

Change-Id: Ia7c932998f1a49af1e322ab9e1dc249b7bd2e8b2
2019-10-06 00:14:35 +02:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Aryeh Gregor
ed625e11cd Hard-deprecate Title::moveTo and friends
moveSubpages wasn't officially deprecated at all before this release,
but there were no callers in codesearch outside core, so it should be
safe to hard-deprecate.

Bug: T208775
Change-Id: Icea9f1dc45d8bd8c96cc159d631f18c394aab4b7
2019-05-28 11:52:36 -05:00
James D. Forrester
76617a7771 Title: Test the ->equals() method more thoughroughly
Move from TitleMethodTest to TitleTest for simplicity with duplicating
into TitleValueTest. We're not using the language- and namespace-specific
test setup with these tests anyway.

Change-Id: Ieec78c35f04faea5e01da8d39ed88f7c4876ac84
2019-03-21 16:54:58 -07:00
daniel
337311662d Fix Title::getFragmentForURL for bad interwiki prefix.
Calling Title::getLinkURL or any other method that relies on
getFragmentForURL on a title with an unknown interwiki prefix
was triggering a fatal error. With this patch, that situation is
handled more gracefully.

Bug: T204800
Change-Id: I665cd5e983a80c15c68c89541d9c856082c460bb
2019-01-23 11:17:21 +01:00
Aaron Schulz
c4d9d51506 Clear the title cache in MutableRevisionRecordTest
Also do so in various other test classes.

Follows-up 170c49d61c. Fixes Travis CI regression:

> 1) MediaWiki\Tests\Revision\MutableRevisionRecordTest::testSetGetPageId
> Failed asserting that 2 is identical to 0.
> tests/phpunit/includes/Revision/MutableRevisionRecordTest.php:129

Change-Id: I41c8bda8e620ebe7608a393d81f3b0f13af68ba7
2018-10-25 21:16:27 +00:00
Aryeh Gregor
63d7f2ad13 Automatically reset namespace caches when needed
This avoids error-prone code written separately in every test.  In
addition to no existing tests resetting the TitleFormatter (more
services probably need to be reset as well), they mostly reset only the
namespace cache on $wgContLang, which wouldn't help for any other
language.

The parser test runner still doesn't do this, but maybe it should.

Change-Id: I44b7a1aec48f14b0950907fa14bd0df80f674296
2018-08-01 16:30:08 +03:00
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
James D. Forrester
2ae7d6b580 Add protection for User: JSON pages in the same manner as JS & CSS ones
Also recognise MediaWiki: JSON pages (with the existing protection of
the editinterface right).

Bug: T76554
Change-Id: Idba166d82ee6dd507d7345c9bdbefc8ca78ed7b4
2018-03-29 14:33:46 +00:00
James D. Forrester
6d4e15476c Title: Refactor JS/CSS page handling to be more sane
Change-Id: Ia7837dc614dcc8896a7d4b6d663dc45b6bd4f7ee
2018-02-16 17:35:12 +00:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
0c77841534 Add @covers tags to miscellaneous tests
Change-Id: I7e65c1734aef01cd6395ee65204a0158d1635b0c
2017-12-24 23:29:00 -08:00
Brad Jorsch
2d9f29a846 Improve namespace handling in tests
MWNamespace has three internal caches, only one of which can be cleared
(and that somewhat oddly by passing a boolean to
MWNamespace::getCanonicalNamespaces()).

This change introduces a MWNamespace::clearCaches() method to clear all
three caches. It also adds some resetting in tests that seemed to be
missing it.

Change-Id: I1dcfcd8713888b3ff8fc75e95329ba72bd95d0c9
2017-09-29 05:21:47 +00:00
Kunal Mehta
1f53b6ee6a Title: Make getOtherPage() check canHaveTalkPage()
Practically this doesn't make any difference, but once it's possible for
namespaces to not have talk pages, this function would have returned an
invalid Title.

Bug: T165149
Change-Id: I940433c22193d406d8b4a6cab0e6ad37e88e62c6
2017-09-06 19:52:34 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
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
2016-02-17 01:33:00 -08:00
daniel
a43af3bc0e Reset Title cache when importing titles.
WikiImporter now uses NaiveImportTitleFactory, which in turn uses Title::makeTitleSafe,
bypassing the internal title cache. To avoid (potentially cached) Title objects obtained
via Title::newFromText getting out of sync, WikiImporter now clears the title
cache in addition to clearing the LinkCache.

NOTE: a test for this is provided by I2be12fa7d439b.

Bug: T89307
Change-Id: Ib50c48d4797fc21c62090c0be69e87f7e7d07428
2015-05-24 17:55:08 +02:00
umherirrender
a925980036 Make TitleMethodsTest a LangTestCase
With I40a51c14ce07c301c15c6c2128cc18bb12e71103 a compare of namespaces
was added which fails when content language is not en.

Change-Id: I21466231e10e6cd5969c8c9bfd4824bf9c47e6d8
2014-12-30 10:22:56 +01:00
Kunal Mehta
24c000ea80 Add and use Title::getOtherPage()
Change-Id: I40a51c14ce07c301c15c6c2128cc18bb12e71103
2014-12-04 17:45:05 -08:00
umherirrender
7ff005407e Remove colon after @deprecated/@param/@todo/@note
Change-Id: I4e66dad85eecf7e8e03ac760af900395e1bc11b6
2014-07-24 11:30:25 +02:00
aude
71cf107f99 Make setUp and tearDown protected in tests
These are protected in the parent MediaWikiTestCase and
PHPUnit_Framework_TestCase. No good reason to make them public.

Change-Id: I45ecc0e4209f0c3b27e63a550112e4e0ddf6e530
2013-11-24 01:48:09 +01:00
addshore
fb16eb2abe Add more @covers tags and test cleanup
Other cleanup includes
 - Adding method scopes
 - Fixing php comments
 - Adding todos

Change-Id: I0a231008e6a59110ffcab6af1bd8c4d3ee13f21d
2013-10-22 08:59:42 +00:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
umherirrender
7d8a184bac Tests: Fix case of some methods
Change-Id: Iab247f805410f2e9157d325edd80880538a3e54c
2013-03-22 17:44:34 +01:00
umherirrender
0fc445c19b Adding missing @group Database to unit tests
Reasons:
* Signature parsing
* GenderCache
* Using TestUser class (inside ApiTestCase)

Change-Id: Iea4e9f9cafaa3afe7da8b922644061d3d575afe3
2012-12-09 10:27:56 +01:00
Platonides
84e1e6b5ae Removal of unused globals.
Change-Id: I870665d18f955a245222cfceca4665897277e7e4
2012-11-26 22:15:11 +01:00
Antoine Musso
c6ea55bf54 tests: always call parent setUp
Some class extending MediaWikiTestCase did not call its setUp method. We
most probably always want to do it since MediaWikiTestCase::setUp() does
garbage collection and might do more in the future.

Change-Id: I68dde370a62c8f4a779836ca0c4ad06844fdc916
2012-10-23 19:04:40 +02:00
daniel
329d5b3516 Merge branch 'Wikidata' into master.
This introduces the ContentHandler facility into MediaWiki,
see docs/contenthandler.txt.

For convenient review, a squashed version is available at
https://gerrit.wikimedia.org/r/27191

The ContentHandler facility is a major building block of the Wikidata project.
It has been discussed repeatedly on wikitech-l.

Change-Id: I3804e2d5f6f59e6a39db80744bdf61bfe8c14f98
2012-10-09 11:34:24 +02: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
daniel
63f42295c3 Don't assume main namespace contains wikitext
Change-Id: Ie5bb593f850ab97b2e63f064e3fc52bc17edfdd1
2012-09-20 16:18:30 +02:00
daniel
01f36b721f merged latest master 2012-05-14 23:24:18 +02:00
daniel
cbc2014b2d Use integers for content_model and content_format.
Representing content_model and content_format as integers in the
database was suggested by Asher mainly to save space.

This change entails some refactoring and renaming, but no big
change in logic.
2012-05-14 10:22:52 +02:00
daniel
d85bbb1074 Adding more tests for Title.
This introduces tests for isCssJsSubpage, isCssOrJsPage, and isWikitextPage.

New tests are added to avoid regressions when the ContentHandler facility is introduced.

Change-Id: I68987490b01242cc0bcdc0d9dfaa99f1227f71a0
2012-05-02 19:32:56 +02:00
daniel
db596107a4 spaces -> tabs 2012-04-26 12:11:34 +02:00
daniel
ce4a6e26ea reset namespace caches when testing extra namespace handling 2012-04-26 12:11:01 +02:00
daniel
57cf7bd82c more tests for Title 2012-04-19 12:55:46 +02:00
Reedy
9e33a6c740 assertEquals is $expected, $actual, not $actual, $expected
Fix Title related tests that are the wrong way round (noticed by Daniel Kinzler
when creating more tests, and wondering why phpunit was making error messages
that didn't make any sense!)

public static function assertEquals($expected, $actual, $message = '',
    $delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE)

Change-Id: I09aeb7cb7edb8e486ccf2f54673f91cd9704cd3b
2012-04-18 16:03:46 -07:00
daniel
e02f9b1706 first test cases. found and fixed a bug in Title::isCssJsSubpage 2012-04-18 15:02:21 +02:00
Daniel Friesen
3414e91bae Implement a number of namespace related equals functions:
* MWNamespace::equals to test equivalence of two namespaces (forward compatible with any changes we may make like introducing namespace keys like 'USER')
* MWNamespace::subjectEquals to test equivalence of the subject of two namespaces e.g.: MWNamespace::subjectEquals( NS_USER, $ns ); instead of testing for equivalence to both NS_USER and NS_USER_TALK
* Title::inNamespace to use instead of $title->getNamespace() == NS_???
* Title::inNamespaces for use like $title->inNamespaces( NS_USER, NS_PROJECT ) when you only care if it's in one of a number of namespaces (also accepts an array)
* Title::hasSubjectNamespace for use instead of testing for equivalence to both the subject and talk such as NS_USER and NS_USER_TALK.

Include phpunit tests for all this new code, and also add some tests for some existing code.
2011-11-22 13:34:55 +00:00