Commit graph

309 commits

Author SHA1 Message Date
Paladox
a9c0d73718 Update tests/phpunit/MediaWikiTestCase.php with support for apcu
Change-Id: I22d54e96c2c002ea53dabfd2772d2ba4c7eb96b1
2017-01-19 03:43:16 +00:00
jenkins-bot
37c0e98410 Merge "Add LoadBalancer::getMaintenanceConnectionRef() method" 2016-12-16 03:22:45 +00:00
Seb35
6728bbb819 The automatic test in MediaWikiTestCase was marked as risky
MediaWikiTestCase::testMediaWikiTestCaseParentSetupCalled is
marked as risky when strict code coverage is activated in
PHPUnit (--coverage-html ../../docs/code-coverage
--strict-coverage --debug -v).

This patch adds the annotation @coversNothing to disable
code coverage on this test. As an automatically-added test,
it must adapt to a number of different environments, so it
is not feasible to add the exhaustive list of @uses classes.

Bug: T152923
Change-Id: Ic670ff2d89f1c5df500c0d10b153d4efd013d7f4
2016-12-11 21:16:11 +01:00
Aaron Schulz
fe59c39da9 Add LoadBalancer::getMaintenanceConnectionRef() method
This is useful when IMaintainableDatabase methods are needed
for foreign wiki connections to things like external store.

Also:
* Set visibility for ExternalStoreDB methods.
* Cleaned up various type hints and comments.

Change-Id: Ie35b1ff21032cc4e78912dc499486da23aeba041
2016-12-10 15:35:09 -08:00
addshore
d544acdbbb Allow stashing of unset globals in MWTestCase
Change-Id: I6a1cf9a2e436978a6068cecdaf74aa58b31100ab
2016-11-18 14:59:49 +00:00
Sam Wilson
66e215baee Remove spaces after cast operators
This fixes the outstanding mis-spaced cast operators to bring them
into line with the coding standards on mediawiki.org (and with the
more common usage within this codebase).

Bug: T149545
Change-Id: Ib7bcf95bbee83d20c05f6d621ce7b4e1fb58a347
2016-10-31 13:57:39 +00:00
Stanislav Malyshev
d10813b685 Disable reportDupes for unit tests
Bug: T147697
Change-Id: Ibd5901767be0d12d2aa50a4fc48b117711e6cf98
2016-10-08 23:11:43 +00:00
Aaron Schulz
514d759b58 Add the main stash, WAN, and server caches to MediaWikiServices
Leave getLocalServerInstance() array fallback logic.

Restores 6d99fa5824
Which got reverted by 7ab9283292.

Change-Id: Id1f48e10753d6aaf64eecb4d3c2228740abc1340
2016-10-03 18:36:06 +00:00
Hashar
7ab9283292 Revert "Add the main stash, WAN, and server caches to MediaWikiServices"
$ php maintenance/eval.php
 > $wgMessageCacheType = CACHE_ACCEL;

 > wfGetMessageCacheStorage();
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 93
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 125
 PHP Notice:  Array to string conversion in includes/objectcache/ObjectCache.php on line 133
 Caught exception InvalidArgumentException: Invalid object cache type "Array" requested. It is not present in $wgObjectCaches.
 #0 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(Array)
 #1 includes/objectcache/ObjectCache.php(287): ObjectCache::getInstance(Array)
 #2 [internal function]: ObjectCache::getLocalServerInstance(Array)
 #3 includes/objectcache/ObjectCache.php(181): call_user_func('ObjectCache::ge...', Array)
 #4 includes/objectcache/ObjectCache.php(137): ObjectCache::newFromParams(Array)
 #5 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(3)
 #6 includes/GlobalFunctions.php(3430): ObjectCache::getInstance(3)
 #7 maintenance/eval.php(78) : eval()'d code(1): wfGetMessageCacheStorage()
 #8 maintenance/eval.php(78): eval()
 #9 {main}

This reverts commit 6d99fa5824.

Change-Id: I4d756eb6f66318a12d8cbbc1ba546397be8a29bf
2016-09-29 10:46:48 +02:00
Aaron Schulz
6d99fa5824 Add the main stash, WAN, and server caches to MediaWikiServices
Also removed unused getLocalServerInstance() b/c $fallback logic.

Change-Id: Ifa5f798de10783741a7b079f22d283bb9cb7f4c0
2016-09-28 15:35:44 -07:00
Aaron Schulz
5bbac35ed1 Replace DatabaseBase:: with Database:: and update type hints
Change-Id: I3919b04eb2de4fa0bf8a02239fb5bbf17d347511
2016-09-27 04:20:03 +00:00
Aaron Schulz
508d3b21ea Remove unused Database::isView()/clearViewsCache() methods
Also make getLazyMasterHandle() protected.

Change-Id: Id6b48ff976a800052c22e90b572695ab3b8beb7e
2016-09-23 20:32:36 -07:00
Aaron Schulz
e37bb560c4 Avoid DatabaseBase type errors in setupDatabaseWithTestPrefix()
Change-Id: I94cc0672a487d547a09c27997fe36274d7d62977
2016-09-23 23:30:47 +00:00
Aaron Schulz
ff5abb66b4 Migrate callers to new MWFileProps::getPropsFromPath() method
* FSFile should not be responsible for handling this much logic.
* Make more MediaHandler classes aware of the fact that an object
  other than File might be passed in. Use the FSFile instead of a
  useless empty stdClass object.
* Also added more fields to FSFile::placeholderProps to make it
  more complete.

Change-Id: I9fe764b2a7261af507c6555e6a57273cf7d00d36
2016-09-22 00:33:46 +00:00
Niklas Laxström
64670b28d2 PrefixSearch: Implement searching in multiple namespaces
I thought there was just an issue with capitalization, but in fact the
code explicitly only searched one namespace anyway. Fixed that while
taking capitalization differences in namespaces into account.

This by extend also brings support for multiple namespaces to the
opensearch API.

Follows-up I3487bb69.

Bug: T67752
Bug: T32323
Change-Id: I4bec7b5548fc27ac51a1b4d4961c3bbc31eb7337
2016-09-15 14:48:35 +02:00
Tim Starling
6117fb244f Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.

Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.

General:

* Split out the pre-Setup.php global variable configuration from
  phpunit.php into a new class called TestSetup, also called it from
  parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
  Maintenance.
* In Setup.php improved "caches" debug output.

PHPUnit frontend:

* Delete the entire contents of NewParserTest and replace it with a
  small wrapper around ParserTestRunner. It doesn't inherit from
  MediaWikiTestCase anymore since integrating the setup code was an
  unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
  instantiable TestSuite class instead of just a static method. Got rid
  of the eval(), just construct TestCase objects directly with a
  specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
  support them anymore. Note that --filter now works just as well as
  --regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
  for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
  once, as is implied by the documentation.

parserTests.php frontend:

* Made parserTests.php into a Maintenance subclass, moved CLI-specific
  code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
  backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
  to the old default behaviour

Test file reading and interpretation:

* Rename TestFileIterator to TestFileReader, and make it read and buffer
  an entire file, instead of iterating.
* The previous code had an associative array representation of test
  specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
  unnecessary now that all extensions use ParserFirstCallInit. Resurrect
  an old interpretation of the feature which was accidentally broken: if
  a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
  human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
  articles in them. This greatly speeds up execution time when --regex
  matches a small number of tests. It may possibly break extensions, but
  they would have been randomly broken anyway since there is no
  guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
  link formatting, life is complicated enough already. It can go in
  OutputPageTest if that's a thing we really need.

Result recording and display:

* Make TestRecorder into a generic plugin interface for progress output
  etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
  a long inheritance chain. All test recorders now directly inherit from
  TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
  frontend. Most events are ignored since they are never emitted in the
  PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.

Setup and teardown:

* Introduce a new API for setup/teardown where setup functions return a
  ScopedCallback object which automatically performs the corresponding
  teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
  here which was simply copied from Setup.php without review, and had
  nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
  performance, give staticSetup() precedence in cases where they were
  both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
  from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
  don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
  I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
  customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
  handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
  now! Also, the relevant parser tests were removed from the Math
  extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
  allows setup/teardown to be done once for each batch of articles
  instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
  copied in from Setup.php in 2010, and are redundant since we do
  actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
  this alone.

Fuzz tests:

* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
  where they used to reside.

Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-12 16:11:42 +10:00
Aaron Schulz
402603e12f Use memory job queue for unit tests
Change-Id: I13586b9873bf09acd4a458a7af75a25d9b980fca
2016-09-11 17:23:54 -07:00
Aaron Schulz
80899f4853 Run database-using tests in MySQL STRICT mode
Change-Id: Ib2873913102d7a7fcd84d1860725fb501cb41b64
2016-09-07 07:33:29 +00:00
Aaron Schulz
0622fbb077 Set "run when DBs idle" DeferredUpdates logic in Maintenance
* This is a more robust version of the one inside
  DeferredUpdates (checking all DBs), which will be 
  replaced in a later commit.
* Make sure the listener is restored when the LB gets
  torn down in tests. Also, it should respect the
  $wgCommandLineMode value as tests can change it.

Change-Id: I1e3faa5a058df44e2d27ab5ac185930867eb68ac
2016-09-01 22:09:21 +00:00
jenkins-bot
356b3420d6 Merge "Make content handlers assemble content for search" 2016-08-04 15:54:36 +00:00
Kunal Mehta
b4596edd00 Introduce MediaHandlerFactory to create MediaHandler objects
This will allow further refactoring of override logic in parser tests.

Ideally the factory class would not use $wgMediaHandlers directly, but
that ends up breaking too many tests for now.

Change-Id: I34a63ee7089ff26f86f3dd6f3cd1a37928bc4005
2016-08-03 16:47:41 -07:00
Stanislav Malyshev
add1ebe2ab Make content handlers assemble content for search
Bug: T89733
Change-Id: Ie45de496ecc826211d98eea3a410c7639b4be0a4
2016-07-26 13:08:45 -07:00
Ori Livneh
b19ff38846 Clean-up of MediaWikiTestCase::checkHasGzip()
* Move the method from MediaWikiTestCase to DumpTestCase. Only subclasses of
  DumpTestCase use it, and it is not sufficiently well-designed to be a part
  of MediaWikiTestCase. (I'd want something more generic, like
  "$this->markSkippedUnlessExecutable()", rather than a method dedicated solely
  to establishing the availability of the gzip binary.)
* Fix it so that the result of the check is actually cached. It wasn't,
  previously, because of how 'static' works in PHP.
* Be content with checking that gzip is in $PATH instead of actually executing
  it.

Change-Id: Iec687a6bfe75912e1875afc3abb4fb6197a0b3aa
2016-06-01 10:44:23 -07:00
Timo Tijhof
3bbccc8da6 User: Simplify process cache by using WANObjectCache::getWithSetCallback
Follows-up 7d67b4d919, 9c733318.

* Convert loadFromId() to use getWithSetCallback() and centralise
  cache access logic there instead of spread between loadFromCache()
  and saveToCache().

* Remove process cache from User class (added in 9c733318).
  Instead, tell WANObjectCache to process-cache the key for 30 seconds.

* No need to deal with process cache in purge() because load uses slaves by
  default and may be lagged. Reads that require READ_LATEST already bypass
  the cache.

* Remove saveToCache() and move logic to loadFromCache().
  It was technically a public method, but marked private and no longer used
  in any extensions.

* Remove redundant isAnon() check in loadFromCache().
  This is already done by loadFromId() and loadFromDatabase().

* Remove hasOrMadeRecentMasterChanges() check. It was used to add READ_LATEST
  to the flags. However, this check only occurred if either READ_LATEST was
  already set, or after consulting cache. Which means in general, it never
  does anything. If we want to keep this, we should probably move it higher up.

* Let WANObjectCache handle cache version. That way, there is no longer separate
  logic for "populate cache" and "cache lookup failed". Instead, there is
  just "get data" that tries cache first.

  I've considered moving the version into the cache key (like we do elsewhere)
  but that would be problematic here since User cache must be purgeable
  cross-wiki and other wikis may run a different version (either in general,
  or even just during a deployment). As such, the key must remain unchanged when
  the version changes so that purges from newer wikis affect what older wikis see
  and vice versa.

Change-Id: Icfbc54dfd0ea594dd52fc1cfd403a7f66f1dd0b0
2016-05-31 21:13:08 -07:00
Ori Livneh
e638075936 Whenever possible, reuse User objects in unit tests
The unit tests spend nearly half of their run time resetting the user table for
each test. But the majority of tests do not depend on the user table having the
exact value that the setup code resets it to, and do not need to modify the
user objects they require to run.

Fix that by providing an API for tests to get User objects, and to indicate
whether the User object will be subject to destructive modification or not.
This allows User objects to be reused across multiple unit tests.

Change-Id: I17ef1f519759c5e7796c259282afe730ef722e96
2016-05-26 20:42:31 +00:00
jenkins-bot
80975c2b4e Merge "In MediaWikiTestCase::stashMwGlobals(), prefer shallow copies" 2016-05-18 19:03:40 +00:00
Ori Livneh
49b162cac1 In MediaWikiTestCase::stashMwGlobals(), prefer shallow copies
MediaWikiTestCase::stashMwGlobals() performs a deep copy of globals by
serializing and then unserializing them. This is actually unwarranted in the
common case of simple scalar values and flat arrays -- and it's expensive, too.
So before attempting a deep copy, first check if a shallow copy will do.

Change-Id: Iaba1c8e1f6bae9de0a7a1fb411cac94f7e4dfb23
2016-05-18 10:36:44 -07:00
jenkins-bot
94117ad9c1 Merge "Speed up password-handling in the unit tests" 2016-05-18 12:46:28 +00:00
Brad Jorsch
d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00
Ori Livneh
61096dd7ac Speed up password-handling in the unit tests
* Speed up password generation and verification by setting MWOldPassword as the
  default password type. Do this once, in MediaWikiTestCase::makeTestConfig(),
  rather than in five different places.
* Rename '$pwhash' to '$passwordHash', for consistency. It's ugly to have both
  '$passwordFactory' and '$pwhash' in the same scope.
* Make TestUser::setPasswordForUser() check first whether the desired password
  is already set. This is actually the common case, since the password is reset
  in the setup code for every test, but only a few tests actually change the
  password.

Change-Id: I423f09ff7472b6cbde21cb709ea7c7ef9e298f18
2016-05-13 16:13:12 -07:00
daniel
d7410db0fd Allow reset of global services (redux).
(This is part of I6ec374ac9 wich was a re-submit of Ie98bf5af5
which got reverted by Ide7ab563)

This change provides a mechanism to reset global service instances
in an orderly manner. There are three use cases for this:

* the installation process
* integration tests (which most of the existing phpunit tests are)

In contrast to I6ec374ac9, this change does not cause singeltons
of legacy services to be reset. It is assumed that legacy services
use global state to access services and configuration, so any
change in confuguration would affect them immediately.

NOTE: the original I6ec374ac9 would cause session information to
get lost if the user session was creatsed before initialization
was complete. This was apparently triggered by the MobileFrontend
extension under some circumstances. Check with Addshore and Catrope.

Change-Id: Ie06782ffb96e675c0aa55dc26fb8f22037e8517d
2016-05-04 19:18:29 +02:00
Brad Jorsch
a754d43c06 Fix core DB data in unit testing
Iec4ed4c8 made it so addCoreDBData() only gets called once. Which is
nice, except for the fact that it means any test that puts
'user_groups' into $this->tablesUsed is going to cause UTSysop to no
longer be a sysop, so any later test that expects it to be one is going
to mysteriously fail.

The fix is to make resetDB() actually clear out the 'user' table when
requested, but then to re-call addCoreDBData() so UTSysop is still
there.

This might break extension tests if they're relying on the 'user' table
never being cleared even if it's specified in $this->tablesUsed, but
hopefully that's not often the case.

Bug: T132411
Change-Id: If251739fd486544f54a0c07edcc24aeef0998342
Depends-On: I0546a4f18e0751d209b6b7c6cd42973f25828313
Depends-On: I4924ae941b3844b39dd3f44c6986c3bf29b0d62a
2016-04-12 16:58:44 +00:00
Catrope
1162ed5f88 Revert "Allow reset of global services."
Completely breaks login.

This reverts commit 8e7a0a0912.

Change-Id: Ide7ab5632e987e81374c21173df6ab3998649df7
2016-04-11 13:40:28 -07:00
daniel
8e7a0a0912 Allow reset of global services.
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
2016-04-11 16:22:40 +02:00
Ori Livneh
d1c4eafef5 Request-local caching of image_redirect
LocalRepo::checkRedirect() cache image redirect checks in memory to avoid
unnecessary trips to memcached. Same idea as Idbd11637.

Change-Id: Idaa12376382aaa0bd8cb988240ec1da0b688359d
2016-03-25 12:09:10 -07:00
Ricordisamoa
1617e7822e Always use 'bool' instead of 'boolean' in Doxygen tags
Just like commit f86a5590aa

Change-Id: Ic9d08bca6524d6bb4baf5170c081ad0f3d738e28
2016-03-24 09:44:09 +01:00
Siebrand Mazeland
4afa4e7dce MediaWikiTestCase::assertException() was removed
Deprecated since 1.22. No uses in core or Gerrit extensions remaining.

Change-Id: Icae4077078c73d766d3c1c9e9e569922151296d9
2016-03-19 00:02:31 +00:00
Matthew Flaschen
9d74ee8bd8 Move dbSetup=true; follow-up d920237
See https://gerrit.wikimedia.org/r/#/c/274643/8/tests/phpunit/MediaWikiTestCase.php

I unintentionally changed it so dbSetup wasn't always set to true
(it was in the early return case in the old code, but not the new)

Bug: T95870
Change-Id: I2119b0233330b88a61d15fe4dc55fe855fce4b6a
2016-03-14 22:52:46 -04:00
Matthew Flaschen
d920237e37 Add support for External Store for unit tests
This allow running PHP tests with External Store DB configured.
This means it needs to do the unittest_ prefixing similar to the main
tables.

It could do resetting (truncating the tables) similar to the tablesUsed
functionality.  However, if External Store is truncated unconditionally,
revision, etc. also needs to be.  This can cause performance issues.
I was thinking of making resetting ES optional, but it wasn't needed
to pass any of the core tests, so I just left it out entirely for now.

Bug: T95870
Change-Id: If27435210d5a2165795dd759b17a7e51fe9bba10
2016-03-11 19:58:32 -05:00
daniel
a8995619c1 Avoid rebuilding database fixtures for every test run
This reduces the runtime of database-bound tests by about 40%
(on my system, from 4:55 to 2:47; results from Jenkins are
inconclusive).

The basic idea is to call addCoreDBData() only once, and have
a addDBDataOnce() that is called once per test class, not for
every test method lie addDBData() is. Most tests could be
trivially be changed to implement addDBDataOnce() instead of
addDBData(). The ones for which this did not work immediately
were left out for now. A closer look at the tests that still
implement addDBData() may reveal additional potential for
improvement.

TODO: Once this is merged, try to change addDBData() to
addDBDataOnce() where possible in extensions.

Change-Id: Iec4ed4c8419fb4ad87e6710de808863ede9998b7
2016-03-10 23:44:34 +00:00
Timo Tijhof
ecb47bfb8f phpunit: Abstract user-lang override in MediaWikiTestCase
Removed redundant set up in these classes (same as their paren
class MediaWikiLangTestCase does already).
* BlockTest
* ExportTest
* MWTimestampTest
* TitlePermissionTest

Change-Id: I28d18cb797bb249981727b02dffce4f0d8682b02
2016-03-09 16:55:50 +00:00
Timo Tijhof
46b04ec7ae Use static::class instead of get_called_class()
Available as of PHP 5.5 and more idomatic. Foo::class (explicit),
self::class (defined), and static::class (late bound).

Change-Id: I66937f32095a4e4ecde94ca20a935a3c3efc9cee
2016-02-29 22:43:58 +00: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
Gergő Tisza
a684a2a66b Add MediaWikiTestCase convenience method for mocking a logger
Change-Id: I2f96eddf9f010333ab515c980f4158dce410a13a
2016-02-10 13:32:52 -08:00
Brad Jorsch
2257fe4228 Revert "Remove SessionManager, temporarily"
This reverts commit 823db5d63dd5200d04c63da50ba6bf16f928e70b.

Change-Id: Ibb3e023e4eb6715295586dea87d0725c344a8271
2016-02-03 21:44:59 +00:00
Brad Jorsch
5083e810eb Remove SessionManager, temporarily
The plan here is to take it out of 1.27.0-wmf.12 and put it back in
1.27.0-wmf.13.

Since BotPasswords depends on SessionManager, that's getting temporarily
removed too.

This reverts the following commits:
* 6acd424e0d SessionManager: Notify AuthPlugin before calling hooks
* 4d1ad32d8a Close a loophole in CookieSessionProvider
* fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
* 058aec4c76 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php
* b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
* 13f2f09a19 SECURITY: Fix User::setToken() call on User::newSystemUser
* 305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
* 7c4bd85d21 RequestContext::exportSession() should only export persisted session IDs
* 296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
* 94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
* 46a565d6b0 Avoid false "added in both Session and $_SESSION" when value is null
* c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
* 4eeff5b559 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure'
* 7491b52f70 Call session_cache_limiter() before starting a session
* 2c34aeea72 SessionManager: Abstract forceHTTPS cookie setting
* 9aa53627a5 Ignore auth cookies with value 'deleted'
* 43f904b51a SessionManager: Kill getPersistedSessionId()
* 50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
* f640d40315 SessionManager: Notify AuthPlugin when auto-creating accounts
* 70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
* bfed32eb78 Do not raise a PHP warning when session write fails
* 722a7331ad Only check LoggedOut timestamp on the user loaded from session
* 4f5057b84b SessionManager: Change behavior of getSessionById()
* 66e82e614e Fix typo in [[MediaWiki:Botpasswords-editexisting/en]]
* f9fd9516d9 Add "bot passwords"
* d7716f1df0 Add missing argument for wfDebugLog
* a73c5b7395 Add SessionManager

Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 22:06:49 +00:00
addshore
96e1167d92 Give TestCase::checkHasDiff3 a better name
This method actually marks the test it is called
from as skipped if Diff3 is not confugured.

The new name "markTestSkippedIfNoDiff3" better
reflects that.

Change-Id: I1dffeba0aceb312b3a82216f0b55227e24bc2e34
2016-01-28 12:46:11 +01:00
Brad Jorsch
a73c5b7395 Add SessionManager
SessionManager is a general-purpose session management framework, rather
than the cookie-based sessions that PHP wants to provide us.

While fallback is provided for using $_SESSION and other PHP session
management functions, they should be avoided in favor of using
SessionManager directly.

For proof-of-concept extensions, see OAuth change Ib40b221 and
CentralAuth change I27ccabdb.

Bug: T111296
Change-Id: Ic1ffea74f3ccc8f93c8a23b795ecab6f06abca72
2016-01-12 21:57:01 +00:00
Aaron Schulz
93c4cfd71f Cleanup test jobs better
Change-Id: Id89bb6e9056485b51c66569a57cb91bdf9d2d91f
2015-12-11 15:45:05 -08:00
Aaron Schulz
dfa8006f68 Fix transaction warnings on test cleanup rollback()
Change-Id: I85f607c7562474d57f515a947181884fccae735c
2015-10-21 12:13:22 -07:00
jenkins-bot
103291b11e Merge "Remove empty line comments" 2015-10-14 08:27:40 +00:00
umherirrender
977c810302 Remove empty line comments
Remove empty line comments as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: I5d694f7a7d3bc97e16300ba03c60ad17f3c912a5
2015-10-14 09:46:44 +02:00
Brad Jorsch
3d0b4fea3d User: Mostly remove password handling
AuthManager is coming, which will make it easier to add alternative
methods of authentication. But in order to do that, we need to finally
get around to ripping the password-related bits out of the User class.

The password expiration handling isn't used anywhere in core or
extensions in Gerrit beyond testing for expired passwords on login and
resetting the expiry date on password change. Those bits have been
inlined and the functions removed; AuthManager will allow each
"authentication provider" to handle its own password expiration.

The methods for fetching passwords, including the fact that mPassword
and other fields are public, has also been removed. This is already
broken in combination with basically any extension that messes with
authentication, and the major use outside of that was in creating
system users like MassMessage's "MediaWiki message delivery" user.

Password setting methods are silently deprecated, since most of the
replacements won't be available until AuthManager. But uses in unit
testing can be replaced with TestUser::setPasswordForUser() immediately.

User::randomPassword() and User::getPasswordFactory() don't really
belong in User either. For the former a new PasswordFactory method has
been created, while the latter should just be replaced by the two lines
to create a PasswordFactory via its constructor.

Bug: T47716
Change-Id: I2c736ad72d946fa9b859e6cd335fa58aececc0d5
2015-10-13 16:10:41 -06:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Amir E. Aharoni
f1efaf92e2 MediaWikiTestCase.php: Make lines shorter to make phpcs happier
Change-Id: I92ef73509e09c34f8b44a576e113a94f713b7d0d
2015-09-26 14:31:54 +00:00
Timo Tijhof
74433a3ca8 phpunit: Set $wgMainStash to 'hash' during test execution
Also clean up the other cache settings to match their order
as defined in DefaultSettings.php.

Don't disable MessageCacheType, ParserCacheType etc. This could
prevent bugs from happening during tests. They are enabled by default
in MediaWiki with CACHE_ANYTHING. At least let them use 'hash'
during tests to resemble a more realistic environment.

Change-Id: Id9edf33c600db3ac4d837e1674a8eb2f5363a4f8
2015-09-25 04:57:31 +00:00
jenkins-bot
58410c60d5 Merge "phpunit: Replace APC with HashBagOStuff during a test" 2015-09-25 00:32:55 +00:00
umherirrender
271da88127 Some bugzilla.wikimedia.org -> phabricator.wikimedia.org changes
Changed some old bugzilla links to new phabricator links in comments,
test data and error message. This reduces the need for redirects from
old bugzilla to new phabricator from our source code.

Change-Id: Id98278e26ce31656295a23f3cadb536859c4caa5
2015-09-24 17:17:25 +02:00
Timo Tijhof
0d9a48a4c3 phpunit: Replace APC with HashBagOStuff during a test
* Ensures values don't survive the unit test run.
* Ensures a clean state for each test.

Change-Id: I94e1ac14096fb4c4071fe9960d9465e60f27a89d
2015-09-24 13:24:53 +01:00
Tim Starling
2c6c954e23 Abstract and refactor Tidy support
* Split tidy implementations into a class hierarchy
* Bring all tidy configuration into a single associative array and
  deprecate the old configuration.
* Remove $wgAlwaysUseTidy

This is preparatory to replacement of Tidy (T89331). I used the name
"Raggett" for things relating to Dave Raggett's Tidy, since if we use
"tidy" to mean the new abstract system as well as Raggett's tidy, it
gets confusing.

Change-Id: I77af1a16cbbb47fc226d05fb9aad56c58e8910b5
2015-09-10 20:18:52 -07:00
Brad Jorsch
4379362154 Fix so wfResetOutputBuffers doesn't break unit tests
If something being unit tested calls wfResetOutputBuffers(), it'll break
PHPUnit's attempt to capture output in order to fail tests. In the old
version we're currently using for Jenkins it will throw a warning
"ob_end_clean(): failed to delete buffer. No buffer to delete", while in
newer versions it'll detect that its buffer was removed and fail the
test as risky instead.

The solution here is to have MediaWikiTestCase add a buffer with a known
name in setUp() (and remove it in tearDown()), and have
wfResetOutputBuffers() stop when it sees that known name on the stack.

Bug: T109843
Change-Id: I8acd91ec9dd9c6d78a5d91d96202249f571d5d83
2015-08-21 12:24:07 -04:00
Aaron Schulz
c2e45cdde1 Made DB ignoreErrors() method protected
* This should *only* ever be used internal for error suppression,
  such as in the exception reporting methods. Having it public
  means callers have to worry (in theory) about whether the
  DB handles errors one way or a totally different way even
  though there is really only meant to be one.

Change-Id: I5916830d1bd53ee948308f394e55c17dd515ad33
2015-07-21 14:18:04 -07:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Max Semenik
08762b02de Minor cleanups
* Declare undeclared variables
* Kill unused variables
* Fix comments including PHPDoc

Change-Id: I60015f6b6740aa9088bda3745f4dc4e65e29fcb1
2015-04-02 16:22:42 +00:00
Timo Tijhof
3ba8243cd6 MediaWikiTestCase: Consistently use UTSysop user in setup/teardown
Change-Id: I42d108ca11246725d936e505508b73a9ae7553c6
2015-03-25 18:56:14 +00:00
Timo Tijhof
48d715148b Use MediaWikiTestCase methods for tempdir in unit tests
* Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory
  instead of wfTempDir().

  The upload api tests wrote a tempnam() file directly (where
  wfTempDir() is typically shared with other systems and concurrent
  runs). Use MediaWikiTestCase::getNewTempFile and
  getNewTempDirectory instead.

  This also ensures its removal by the teardown handler without
  needing manual unlink() calls. And it doesn't rely on the test
  passing. (Many unlink calls where at the bottom of tests,
  which wouldn't be reached in case of failure).

* For the upload test, the presistent storing of
  'Oberaargletscher_from_Oberaar.jpg' (downloaded from Commons)
  was removed. Note that this didn't work for Jenkins builds anyway
  as Jenkins builds set $wgTmpDirectory to a unique directory
  in tmpfs associated with an individual build.

* For filebackend tests, moved directory creation from the dataProvider
  to the main test.

  Implemented addTmpFiles() to allow subclasses to register
  additional files (created by other means) to be cleaned up also.

  Removed unused $tmpName and $toPath parameters in data
  provider for FileBackendTest::testStore. And fixed weird double
  $op2 variable name to be called $op3.

* Skipped parserTest.inc, MockFileBackend.php, and
  UploadFromUrlTestSuite.php as those don't use MediaWikiTestCase.

Change-Id: Ic7feb06ef0c1006eb99485470a1a59419f972545
2015-02-11 03:49:02 +00:00
Chad Horohoe
4a6acde115 Remove last profiling data from unit tests
Change-Id: I66255ef5364f4eebafadbed663e0945e13f31969
2015-02-10 13:15:17 -08:00
Chad Horohoe
950368c7e8 Remove phpunit profiling. It doesn't make any sense
Change-Id: I7aa98ddc0a80f931a685e2946e61aa4a7dfdabff
2015-02-10 18:50:52 +00:00
Chad Horohoe
aa21e125a3 Remove obvious function-level profiling
Xhprof generates this data now. Custom profiling of various
sub-function units are kept.

Calls to profiler represented about 3% of page execution
time on Special:BlankPage (1.5% in/out); after this change
it's down to about 0.98% of page execution time.

Change-Id: Id9a1dc9d8f80bbd52e42226b724a1e1213d07af7
2015-01-07 11:14:24 -08:00
Ricordisamoa
fc5fd5c37a Typo fixes and non-code tweaks
Skipped replacements:
* prefered → preferred
* prolly → probably

Skipped files:
* resources/lib/jquery.ui/jquery.ui.mouse.js
* resources/lib/jquery/jquery.form.js

Change-Id: Ib7923f362ddfca1b892bf5d601785d6b5aa5d44c
2014-12-12 18:31:15 +00:00
Nik Everett
2ec9915816 Handle redirects during prefix search exact match
Prefix search attempts to find exact matches to the user's query that aren't
returned by plugins.  In some cases, like when the exact match is a redirect
and the target of the redirect is also in the search results, it would result
in multiple results in prefix search going the same place.  This looks really
silly when the top hit is "Barack obama" (a redirect) and the next one is
"Barack Obama" (the target of the redirect).

This handles a bunch of cases to do with redirects in the matches and when
the exact match is a redirect.

Bug: 736731
Change-Id: I49fe1ccec84bd5d1f44c6b91b260abf50f2cc3a1
2014-11-21 14:47:32 -05:00
MZMcBride
627ccbcd7b Minor code comment tweaks for spelling and consistency
Change-Id: I51391f45d0f81e4245ccc0e435a71ccd5b0e3ca3
2014-11-08 14:07:19 -05:00
Erik Bernhardson
49cfcf3715 Clear DeferredUpdates state via setUp()
Best practices for phpunit say 'more setUp, less tearDown' which typically means
that tests are not responsible for cleaning up after themselves, rather tests
are in charge of setting the world up exactly as they expect it.  Part of this
expectation is that mediawiki does not maintain state between tests.

This patch clears DeferredUpdates from MediaWikiTestCase::setUp() because it has
internal global state.  This prevents state from leaking between test cases.

Bug: 72922
Change-Id: I57e6e89aa51c78bbf9d7f5151122b9e267d1a03e
2014-11-03 13:43:53 -08:00
jenkins-bot
cf93d76c03 Merge "Remove hitcounters and associated code" 2014-10-20 21:12:54 +00:00
Chad Horohoe
90d90dad6e Remove hitcounters and associated code
The hitcounter implementation in MediaWiki is flawed
and needs removal. For proper metrics, it is suggested to use
something like Piwik or Google Analytics.

RFC: https://www.mediawiki.org/wiki/Requests_for_comment/Removing_hit_counters_from_MediaWiki_core
Change-Id: I0e5006a7e8a09c800f8fa4effa9399e8afdd7a57
2014-10-20 13:01:55 -07:00
Marius Hoch
23ec64745c Also provide assertNotTag in MediaWikiTestCase
And mark that and assertTag as deprecated to avoid
new usages.

Bug: 69505
Change-Id: Ibfe78fd1914adfb08b29f61c59c43899bd8840d2
2014-10-17 20:14:35 +02:00
Timo Tijhof
bfa6b4cab4 MediaWikiTestCase: Centralise insertPage() logic from SearchEngineTest
Make it re-usable for other tests and update SearchEngineTest to
use the addDBData (which is called automatically) instead of
manually keeping track of the state.

Change-Id: I75a6951545d9824e71e00f0f96936c53b400dce6
2014-09-22 14:56:32 -07:00
Marius Hoch
3cbaac08cd MediaWikiTestCase: Enforce children call parent::tearDown
Can't be implemented as a test case because that's not being
run before MediaWikiTestCase::tearDown.
Also there's no parent destructor, so no need to call one.

Also fixed BagOStuffTest.

Change-Id: Ifd8659b6c8a748c6716099f8822e2c50ab51bda7
2014-09-14 21:21:40 +02:00
umherirrender
63dc5abc9a Fixed spacing
- Added space after reserved words: function, foreach, if
- Combined 'else if' into elseif
- Added braces to one-line statements
- Added spaces after comma, before parentheses

Change-Id: Ie5bbf680d6fbe0f0872dab2700c16b1394906a72
2014-08-27 18:31:50 +02:00
addshore
dba0522f70 Override phpunit assertTag method to stop errors
This method throws a deperecation error in phpunit
that we dont want to see (and dont want to break
travis tests).

Nothing this method uses is beign deprecated thus
we can override the method and not need to worry
about the error or it vanishing in the future!

Bug: 69505
Change-Id: I0eb63be390b4fdf416635dd8e8a2ad94615e6a47
2014-08-17 21:41:18 +00:00
umherirrender
26837cd280 Cleanup some docs (tests)
- Swap "$variable type" to "type $variable"
- Fixed spacing inside docs
- Makes beginning of @param/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: Ia041964250d8b7c0349d79dc9b131c5b8696e795
2014-08-11 20:06:52 +02:00
addshore
892a992ab8 Remove MediaWikiPHPUnitCommand
All functionality has been moved to other places

Change-Id: I6b6b0ef846bc63108c4dff9e17098432fd9d1697
2014-08-02 21:35:34 +00:00
umherirrender
7ff005407e Remove colon after @deprecated/@param/@todo/@note
Change-Id: I4e66dad85eecf7e8e03ac760af900395e1bc11b6
2014-07-24 11:30:25 +02:00
Max Semenik
da300d4432 Fix DjVu tests isolation
Change-Id: I97177572fc025c5ab4361146253d7df9c487c291
2014-07-15 16:56:34 -07:00
Max Semenik
859aa19359 Reset RequestContext between tests
Its state can change when people do something with objects it returns or
when they alter globals like $wgRequest. By resetting this singleton, we
ensure that no such change will propagate outside of a test.

Change-Id: I7e8598716d810a09c17f80a05deecab617b62346
2014-06-27 10:59:47 -07:00
Siebrand Mazeland
1fb1fa4601 Pass phpcs-strict on some test files (1/x)
Change-Id: I7f8dee09ac734cbc369441431841f2d4aa5d7f51
2014-04-24 17:05:32 +02:00
jenkins-bot
0e675650ae Merge "Fix "UTPage" creation in tests" 2014-04-22 17:56:32 +00:00
Andrew Garrett
7cba8b280e Fix "UTPage" creation in tests
Change-Id: If414c633a3abb6019f9d677b70e6bc790c0c241d
2014-04-22 17:52:20 +00:00
umherirrender
092cd8ee31 Fixed some @params documentation (tests)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: Ic8aaf0a93796b97d0fa4617c1f86ff59f4b36131
2014-04-17 20:43:42 +02: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
addshore
3dfdddeb94 Remove phpunit compatability function calls
phpunit.php now requires we run tests with
3.7.0+ so we no longer need these safety
calls

Change-Id: I15d215630fe4d8ab71fc97883dde2eed13d03678
2014-03-14 14:43:09 +01:00
addshore
2bc5c3b101 Cleanup MediawikiTestCase
Cleans docs
Adds since tags
Fixes typos
Removes totally unused stuff
Adds scopes

Change-Id: I80d542196a0f2265aacdd8ae89f919773832c14c
2014-03-09 15:12:05 +01:00
addshore
4b3b1000c0 Throw exception when trying to stash unset globals
If we are trying to stash an unset global then
throw an exception!

Also adds a test

Change-Id: I25f493a0a535201c08ca9624c2c650f61d9e256d
2014-03-09 14:52:40 +01:00
addshore
491993a2f5 Introduce stashMwGlobals method to MediaWikiTestCase
This method is factored out from the existing
seMwGlobals method.

The Doc from the initial method is also split and
improved and since tags has been added

Also adds tests

Change-Id: I0637194d637abf485a245b00587743f0f6dd495a
2014-03-09 14:49:15 +01:00
addshore
a3d8146e57 Catch Serialization Exception in MediaWikiTestCase
In the case that something is not serializable then
we should fall back and just set the value.

This is the case for Closures..
See
http://wikidata-jenkins.wmflabs.org/ci/job/wikidata-client-tests/748/console

Change-Id: Ib5f76932d60840a2f97671c134e18adc619974cd
2014-03-05 20:50:20 +01:00
addshore
6f5ea67f7f Make sure we don't use objects by ref in setMwGlobals
If we copy am object by ref into our temporary array
then this doesn't really make this method very useful
as the same object would be restored, with any changes
after the test has run.

Thus objects should be cloned when being dumped in
here, we use unserialize() and serialize() instead as
we would also want to clone the objects within the
object to avoid changes in there!

These is no point in adding an if is_object call so
we just serialize and deserialize everything!

Change-Id: I5e4ef114405888932014edae6b44afc6ee2c4863
2014-03-05 18:31:49 +00:00
Marius Hoch
5785c77a00 Ignore certain tidy warnings in assertValidHtmlDocument
Those aren't really useful, especially as tidy often
cries about parameters missing which have been
deprecated since HTML 4, so that these warnings have
no value for us.

Change-Id: Ic27c597aa988079ed08e152861bf1dee9581b829
2014-01-28 10:46:45 +00:00
jenkins-bot
f7afda4643 Merge "assertValidHtml for checking html in test cases." 2014-01-17 11:55:50 +00:00
daniel
df927f86c2 assertValidHtml for checking html in test cases.
implemented using tidy.

Change-Id: Idb98af785ca07ecd7afeebadf7396ecdc03a91bc
2014-01-17 12:42:35 +01:00
umherirrender
8138ad179d Fixed typo in comment in MediaWikiTestCase
Change-Id: I72214f134e0e94195cb56271c5fcb6997245fac6
2013-12-27 12:50:27 +01:00
daniel
08f91482c8 Detect leakage of error_reporting state in tests.
This causes PHPUnit test cases to fail if they changed the PHP 
error_reporting settings, and failed to restore it.

Change-Id: I34068eac94c974a461af0ff5753d9fcaa375f2e4
2013-11-16 22:03:20 +00:00
AlephNull
e9d53667f4 MySQL method to find out view + fix fatal in tests
We were missing a method to list out views defined in a database. This
patch adds in MysqlBase::isView() and MysqlBse::listViews().

Since listViews() cache its result in DatabaseBase::$allViews, we also
introduce a final DatabaseBase::clearViewsCache() to let us clear the
per process cache.

Finally, fixed fatal error when duplicating VIEWs in MySQL.

bug: 43571
Change-Id: I8650baa4b721fe69ea3e1d557dd76745c0c7754e
2013-11-07 09:43:59 +00:00
Tim Starling
d1bc243f65 Remove all instances of the word "iff"
It's elitist mathematical jargon. In all cases dealt with here, it adds
no additional meaning compared to "if", beyond what was already obvious
from context. Thus, its only purpose is to smugly demonstrate that the
author attended their second-year mathematics classes, at the expense of
causing confusion for everyone who doesn't have such a background.

If you really think you need to convey extra information beyond what
"if" gives you, the English language contains plenty of devices for doing
so, without resorting to neologisms.

Change-Id: Iae21095d02ec2935c10e94f532235c2671c115b1
2013-10-23 10:56:54 -07:00
jeroendedauw
35783c4635 Deprecate assertException in MediaWikiTestCase as it adds no value
setExpectedException, provided by PHPUnit itself, can and should be used instead

Change-Id: I06833eeeb492d2cc4e66b14aaebd5b2061a29e3a
2013-09-20 20:48:51 +00:00
Timo Tijhof
4bd5471ca3 docs: Remove odd colons after @todo
Most were this way already:
https://doc.wikimedia.org/mediawiki-core/master/php/html/todo.html

Ran a find/replace on the odd ones. Also made them all
lower case.

Change-Id: I70c6a69344ddebc603e9a1c1d87e3cc4f4f4c560
2013-05-15 06:23:40 +00:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
Siebrand Mazeland
6da93fc6f6 Update code formatting
Also update some previous inconsistencies pointed out by Krinkle in change IDs:
* Ide20743a2e84ff68549286120e6cff9d9f396f54
* I811ca957b6588085d67606ebc0cd4033a1e53839

Change-Id: Ife33b931870d0d7e04fcb40974997436d27f528f
2013-03-27 14:15:11 +01:00
umherirrender
8764b3aa7c Remove spaces in function signature
Change-Id: I45aea7a7af88cd913b2f485913620a8af0ab2fed
2013-03-18 20:44:43 +01:00
Antoine Musso
1b2c9970a6 acessor for MediaWikiTestCase::$useTemporaryTables
useTemporaryTables is marked private to prevent childs from overriding
the value which would cause a lot of madness whenever it forgot to reset
its status.  But that in turns prevents a child class from figuring out
whether we use temporary tables or not. The ActiveAbstract extension
test suite has such a requirement and hence need a proper accessor.

MediaWikiTestCase::usesTemporaryTables() is a public accessor to for the
private property MediaWikiTestCase::$useTemporaryTables.

Change-Id: I8016c49116a187d7523cc0d6190514f8a513eafb
2013-03-18 15:15:08 +00:00
Yuri Astrakhan
27d83878c0 Lots of spelling mistakes and phpdoc attributes
@throw->@throws
@returns->@return
@seealso->@see
@cover->@covers
etc

Change-Id: I9ae6bc3034e9790e2d66cd96473b923fe9ee7953
2013-03-10 23:16:28 -04:00
Siebrand Mazeland
ac63001d8e Update formatting
1 of n.

Change-Id: I852729f08bbb0c5e39c2db44362ccdc7f59dcc08
2013-02-14 12:22:13 +01:00
Antoine Musso
5a547ac784 test: helper to skip tests depending on 'gzip'
Some of our tests explicitly depends on the 'gzip' command line utility,
for example the Dumps test suite.  This patch adds up a simple helper
MediaWikiTestCase::checkHasGzip() which skips tests whenever gzip is
missing.

Change-Id: I5ded9a53d08dcf5f35e666f91e3f64e6e111af32
2013-01-29 09:52:21 +00:00
jenkins-bot
75ef257c29 Merge "pass codesniffer on tests/" 2013-01-28 23:47:45 +00:00
Antoine Musso
a7901801b4 test: helper to skip tests depending on a PHP ext
Some of our tests expect a specific PHP extension to be loaded to get
anything done, for example zlib or gd.  This patch creates a new helping
method that people can use to easily skip a test whenever a PHP
extension is not around: MediaWikiTestCase::checkPHPExtension()

Example usage:

 function testCompressFiles() {
   $this->checkPHPExtension( 'zlib' );
   ...
 }

Change-Id: Ia87317ca379b2d5d1d1fa4231f76033ee66086c2
2013-01-28 11:18:04 +00:00
Antoine Musso
0fd05285d7 pass codesniffer on tests/
Fix almost all occurences of the following sniffs:

Generic.CodeAnalysis.UselessOverridingMethod.Found
Generic.Formatting.NoSpaceAfterCast.SpaceFound
Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma
Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine
Generic.PHP.LowerCaseConstant.Found
PSR2.Classes.PropertyDeclaration.ScopeMissing
PSR2.Files.EndFileNewline.TooMany
PSR2.Methods.MethodDeclaration.StaticBeforeVisibility

Change-Id: I96aacef5bafe5a2bca659744fba1380999cfc37d
2013-01-28 12:14:26 +01:00
Aaron Schulz
fb8e4beca3 Merge "While testing, turn off DataBase::ignoreErrors." 2012-12-06 17:38:21 +00:00
daniel
abf22b914a While testing, turn off DataBase::ignoreErrors.
Database errors should cause an exception, not return false,
unless the test case, or the code under test, explicitely calls
ignoreErrors(true). The DB object should be reset to fail fast
and safe for every test.

Change-Id: Ifc2a720ec46a1843d9ffb1488c54743a0099ef9d
2012-12-05 17:13:21 +01:00
Antoine Musso
5b9f76aef7 test: detects parent setUp not being called
Our test classes often overload MediaWikiTestCase::setUp() but forget to
call their parent. This patch makes MediaWikiTestCase to flag whenever
its own setUp() is called and then simply assert it got called. Any
class failing the assertion is missing a call to its parent setup which
is easily fixed by adding: parent::setUp().

It would be nice to find a similar trick for tearDown().

Change-Id: Ia2afed6052eb3863d6c8e68c551cf03b33bb4be9
2012-12-05 16:44:41 +01:00
jeroendedauw
ba9a170df2 Added assertException method to MediaWikiTestCase
Change-Id: I3ce667b4405241c66c5a979863d1cea2cf39956b
2012-11-30 11:35:08 +01:00
Hashar
289c407957 Merge "Add MediaWikiTestCase::checkHasDiff3 and use it" 2012-11-23 10:27:47 +00:00
daniel
e2bb376dd7 Added profiling to test runner.
MediaWikiTestCase now calls wfProfileIn/wfProfileOut for each call
to a test function. This makes it easy to track down slow tests.

Change-Id: I5ff2fea957c082f41da37936fe44948ad006f573
2012-11-22 19:34:32 +01:00
umherirrender
9b3292e31a Add MediaWikiTestCase::checkHasDiff3 and use it
Some tests can only passed, when diff3 is enabled on the wiki, when not
the tests should marked as skipped. To avoid code duplicates inside
the test folder for the check, if diff3 is enabled, the new function
MediaWikiTestCase::checkHasDiff3 can be used.

Change-Id: Ie765da49a4a1358da78a3506e38772d61bcd010c
2012-11-22 17:45:50 +01:00
daniel
be39c351d4 Clean up database cloning for tests.
This change makes the operation for overlaying the wiki database
with a structurally equivalent test database statically accessible,
and adds a function to revert that operation.

This is a precondition to logging profiling info to the database
after the test run has finished.

Change-Id: I2e8335d50eefcc7a97c1cd122b509f0939eacc92
2012-11-16 19:48:33 +01:00
Nikerabbit
a9e9c0e3ff Merge "Stash global only once per test case." 2012-10-29 12:15:37 +00:00
daniel
7385890cfe Stash global only once per test case.
Make sure we only stash a given global only once per test case since we
do not want to override the original value.

This allows the same test to modify the same global multiple times,
while still preserving the original value to be restored after the
test case finished.

Change-Id: I9056d6d6879fb976a192960f661904287f9760a8
2012-10-29 11:07:06 +01:00
Timo Tijhof
a4aef7d495 Fix warnings and enforce conventions in ContentHandler tests.
Syntax:
* Call parent setUp from setUp.
* Set required globals for the test inside the test class instead
  of assuming the default settings.
* Data providers are called statically and outside setUp/tearDown
  ("public static function")
* Test function names should be prefixed with "test"
  ("testIsRedirect")
* Marked 2 functions as unused. JavascriptContentTest has 2 data
  providers for tests that don't exist in it (nor in TextContentText)
  but do exist in WikitextContentTest.

Style:
* Single quotes
* Remove odd comment "# =====" lines
* Consistent tree wrapping with arrays.
  array(
      array(
          .. ) );
  array(
      array(
          ..
      )
  );
  Some were closing on the previous line instead.
  Made it consistent now.
* Remove odd indentation to make nested arrays line up:
  array( 'foo' => array(  'bar' => true,
                          'baz' => array() ) )
  array( 'foo' => array(
      'bar' => true,
      'baz' => array()
  ) )

  We don't do this kind of indentation because it is fragile
  and becomes outdates when any of the earlier keys ("foo")
  change. Converted to a regular tree instead.

  Also triggered git warnings for mixing spaces with tabs, which
  is almost always an detector for this style.

* Not using @annotations in inline comments, reserved (and only
  parsed/meaningful) for block comments.

Follows-up 8b568be5e2

Change-Id: Ic55d539b9a58f448b550bcd98894d389764e0694
2012-10-25 22:37:32 +02:00
daniel
759518bdde Fixing dump tests for non-wikitext in NS_MAIN.
Change-Id: I7945a1b950d3b9b394a336813abc8cd1e288766f
2012-10-12 17:34:29 +02:00
daniel
4ec9459100 [Bug 40716] Fix SearchEngineTest etc with non-wikitext content.
Several core tests fail if there is non-wikitext content in the main namespace.
This change fixes SearchEngineTest and TitlePermissionTest for this case.
More fixes are to come.

Change-Id: I6a19b568c5700bc8584689de8f33e4b0b6ffc277
2012-10-12 13:09:08 +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
d1c8bf85f8 Fix HtmlTest, XmlTest; Add setMwGlobals method to base TestCase.
The HTML and XML test now set the globals they depend on
(instead of relying on the default settings).

Tests for the "other" scenarios still exist, globals are
overridden inline. They are automatically restored after each
test## function by PHPUnit from MediaWikiTestCase::tearDown.

Also fixed 2 other problems with the test suite:

* HtmlTest::testDropDefaults forgot to pass
  $message to the assertion from the provider ($case[3]).

* The data provider for HtmlTest::testDropDefaults was calling
  Html::element directly (instead of calling it within the test)
  which is problematic because data providers are expected to be
  static. PHPUnit calls them outside the setUp/tearDown flow.
  (also fixed the function to be public static, as PHPUnit
  expects).

That last one was crucial to make the test still pass correctly.

Updated the expected strings to what they are with these
fixed non-leakage settings.

Took wgHtml5 without xmlform as default. And added tests
for variations where it made sense.

Change-Id: Iccf6ea81f4bc2639273ab2ad101c58788ee49d45
2012-10-09 00:26:52 +02:00
daniel
bb51a58e57 Cleanup of Wikidata branch.
This cleans up several issues raised in comments to I3b2dad3a,
mostly style and merge artifacts.

Change-Id: I99f5e300a671db1353db151cd187ffd2e4478d03
2012-10-08 17:34:47 +02:00
daniel
c546fae8ed merge latest master into Wikidata branch
Change-Id: Id4e0f40c03679c13d8934a6add99b5cd86d0437d
2012-10-08 13:58:54 +02:00
jeroendedauw
430b31415f Replace remaining Array occurences with array
Change-Id: Id7c2fdd6814a8239acbe050d857b56350e691a49
2012-10-05 16:11:54 +02:00
jeroendedauw
5356dbd180 Switch on expected value, since the actual one can obviously be wrong
This gets rid of confusing error messages pointing to the provided type being invalid

Change-Id: Id283ef6e8fa6c3f18bc9ef3b740e8ec4bd181e3a
2012-09-24 15:15:43 +02:00
daniel
b6b686c13b merged master
Change-Id: I0ef7c7f33a5dc5855f38b20c03ddc5306f38ec66
2012-09-19 12:34:10 +02:00
Daniel Kinzler
e1dc9e8723 Merge "Added MediaWikiTestCase::assertTypeOrValue to facilitate common type checks" 2012-09-14 10:08:44 +00:00
Siebrand Mazeland
59ec5a325c Move api/ApiTestUser.php to TestUser.php and make available in MediaWikiTestCase class.
* Renamed class ApiTestUser to TestUser.

Change-Id: I1c3c659c3ba5c54a314d879132f760008983372d
2012-09-13 18:40:23 +00:00
jeroendedauw
ad6ccbcaf3 Added MediaWikiTestCase::assertTypeOrValue to facilitate common type checks
Also added MediaWikiTestCase::assertType which accepts both internal types, classes and interfaces

Change-Id: I168ef17ad2da3b744a106742760ef34cc683bf69
2012-09-13 20:22:03 +02:00
daniel
b6fe213226 merge latest master.
some tests fail due to logical changes, will fix that in a follow-up

Change-Id: I8a5e4087ecf674fbcf6327c5d168cd401be12400
2012-09-05 17:50:13 +02:00
daniel
cc5cc79148 Restore (some) globals after each test
Change-Id: I5fbf777c2bd4b1f88ba76d5cc42ad6df2eee4a9c
2012-09-05 15:04:07 +02:00
Antoine Musso
19d5ab2e8a test: new assertHTMLEquals()
Very trivial helper to compare HTML content. The method just add a
newline after each closing angle and then call assertEquals().

Change-Id: I5e6daa916a4fb452824616fa3c8a87bdb8038e8c
2012-09-03 10:47:36 +02:00
daniel
9994968774 merged master
Change-Id: Ib2b879c4daa17401eeeb50767c0e5a54254855c3
2012-08-29 15:20:15 +02:00
Daniel Kinzler
392af46809 Revert "merged master"
This reverts commit 67bfdc7a68
2012-08-29 13:14:49 +00:00
daniel
67bfdc7a68 merged master
Change-Id: Ib2b879c4daa17401eeeb50767c0e5a54254855c3
2012-08-29 12:06:38 +02:00
daniel
96f7db3f7b Avoid deprecation warnings in test cases.
a) when testing deprecated functions, use $this->hideDeprecated() to
suppress warnings.

b) use doEditContent() instead of doEdit()

Change-Id: Ifa9e0ef373ed72ef7d4a3c2dd558483af4a3fd55
2012-08-28 16:00:39 +02:00
daniel
167bea7e7e Clean up transactions after test.
MediaWikiTestCase::teardown() will now rollback any transactions
left open by a test case. This is intended to make sure tests do
not provide "interesting" results casued by transaction state
leaking from other tests.

Change-Id: Ia225251efd5aafbaa6674e2732ab1ba7761bfadc
2012-08-27 14:38:25 +02:00
daniel
29719f846b merging latest master
Change-Id: I36b7f2f63ab8c08f8412d521dc68ea45c8b67711
2012-08-20 16:55:28 +02:00
Aaron Schulz
d996871d6b Merge "Added utility method taking an array of elements and wrapping each element in it's own array." 2012-08-14 03:25:13 +00:00
Aaron Schulz
b701eb0713 Merge "Move method to its using test class rather then having a public static thing in the base test class" 2012-08-13 20:14:19 +00:00
Aaron Schulz
c638ca1914 Merge "Fix for assertArrayEquals. Was throwing fatal for object elements" 2012-08-13 20:09:10 +00:00