Commit graph

136 commits

Author SHA1 Message Date
jenkins-bot
25572c28f8 Merge "tests: Handle dynamic created properties on test classes" 2023-01-13 21:50:49 +00:00
Umherirrender
abf2ea44e8 tests: Handle dynamic created properties on test classes
- Declare missing properties
- Remove unused or avoid set of properties
- Add AllowDynamicProperties

Bug: T314099
Change-Id: Ie631894f2ffbb616f6dd09851405d681f3eb8fcd
2023-01-13 21:03:42 +00:00
Derick Alangi
99d989087d jobqueue: Warm parsoid parser cache using a job
This patch introduces ParsoidParserCachePrewarm job
that is used to warm PC with parsoid outputs in order
to speed up page reads on large wikis.

Bug: T322427
Change-Id: Ib63a02d3cf5348b36f4f166ff6939f4d2e7fef6f
2023-01-11 15:15:15 +01:00
Kevin Israel
d2ffc38ff8 tests: Set serialize_precision=-1 in TestSetup
Starting in PHP 7.1, this is now the default[1][2], and results in the
"shortest string that yields d when read in and rounded to nearest."[3]

As such, it would generally be the best choice for tests. The existing
value of 17 has been used only because it was the default at the time
(October 2015, see commit 71443707ad), and -1 for "dtoa mode 0"
simply was not an option yet.

[1]: https://wiki.php.net/rfc/precise_float_value
[2]: https://www.php.net/manual/en/migration71.other-changes.php#migration71.other-changes.ini-file-handling
[3]: https://github.com/php/php-src/blob/php-8.1.13/Zend/zend_strtod.c#L3713-L3714

Change-Id: I95c3c36c90be5aa0af22c3c77ce67641b81786d7
2022-12-14 23:18:13 -05:00
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
jenkins-bot
1d045146d0 Merge "Make use of the new PageUpdateStatus" 2022-12-01 10:45:32 +00:00
daniel
166b569444 Make use of the new PageUpdateStatus
PageUpdateStatus provides clean access the the newly created
RevisionRecord.

Depends-On: Ia08c586198082ea47e8313d0d41835f9830fb29e
Change-Id: Id6963842321c4eaa3d7d029ad0b769f73433c103
2022-11-30 17:56:58 +00:00
Tim Starling
28750729bd Miscellaneous PHP version related cleanups
MediaWikiTitleCodec: I removed the comment about dbkey being
"conveniently nullified" since that is no longer correct. The first
preg_replace() can return null, and that is guarded. The second
preg_replace() hopefully can't return null, because if it does, trim()
will generate a deprecation notice on PHP 8.1.

Some other self-explanatory changes.

Change-Id: Iad0ace821eba782c3033ec8abfeac461ac4e8ace
2022-11-21 10:11:53 +11:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
libraryupgrader
b70581e4ca
build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 38.0.0 → 39.0.0
  The following sniffs are failing and were disabled:
  * MediaWiki.PHPUnit.AssertEmpty.AssertEmptyUsed

* php-parallel-lint/php-console-highlighter: 0.5 → 1.0.0
* php-parallel-lint/php-parallel-lint: 1.3.1 → 1.3.2

npm:
* grunt-banana-checker: 0.9.0 → 0.10.0
* grunt: 1.5.2 → 1.5.3
* karma: 6.3.15 → 6.4.1
* async: 2.6.3 → 2.6.4
  * https://github.com/advisories/GHSA-fwr7-v2mv-hh25
* got: 11.8.3 → 11.8.5
  * https://github.com/advisories/GHSA-pfrx-2q88-qq97

Change-Id: I1d7bc9c9599b48d2bd837617cad409a31adb362a
2022-10-07 21:09:37 +03:00
Umherirrender
f1db4bed17 tests: Use MediaWikiIntegrationTestCase::editPage for edits
Change-Id: I1db7294635bb85e03841c4f7b100e2243ddf013b
2022-09-23 22:49:59 +02:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Thiemo Kreuz
67c56155c7 Replace trivial usages of code in strings with concatenation
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.

Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
2022-08-26 12:26:44 +00:00
Derick Alangi
175832a8e9 Migrate usage of setMwGlobals() to overrideConfigValue(s)
Change-Id: I49d97864d8f9d8cadf01b0c0dc653fbac4ca9e94
2022-08-01 06:16:22 +01:00
C. Scott Ananian
35cb2e524b tests: don't assume wgLanguageCode is 'en'
Change-Id: Ic748489309a1c8ff0f916b3f55aacc93ca128ea3
2022-07-21 19:32:41 -04:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
daniel
b1e3100feb RefreshLinksJob: assert proper title
If a RefreshLinksJob is created with an improper/invalid title,
executing the job later will fail with a PageAssertionException
while trying to create a WikiPage for that title. Better check
the title when constructing the job, so the offending code is on the
stack when it happens.

Bug: T293291
Depends-On: I7dcfac0eacdd5b22bdf443e88f8e6ddb883b92cc
Change-Id: I77a622591836873415f097453da01ca7e61c41be
2022-02-09 20:39:08 +01:00
Func
7f74a2e50c Clean up tests that misused the parameters of assertSame/Equals
Expected value is the first parameter to assertSame() or assertEquals().
And turn to use assertCount() for some assertions aginst count of array.

Based on code search `assert(?:Same|Equals)\(.+,.+expected` and I look
through files roughly, so some assertions that don't contains 'expected'
are also fixed. In the meantime, some assertions that I am not clear
about are not touched.

Change-Id: I75798b60d29fd19b33f4fdf34ed3c788db420d01
2022-02-08 07:21:10 +00:00
jenkins-bot
fc6b80b464 Merge "Replace deprecated JobQueueGroup::singleton()" 2022-01-27 22:17:12 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Alexander Vorwerk
9f9426697c Replace usages of deprecated wfWikiID()
The global function wfWikiID() is deprecated since 1.35 and it's usages
should be replaced with WikiMap::getCurrentWikiId().

Bug: T298059
Change-Id: I22d96b7aec17323d15a9bc401d4511ad2ee14165
2021-12-21 02:05:55 +00:00
Daimona Eaytoy
0e558da7b8 Change return format of DeletePage again
In retrospect, I rushed the previous patch: we really need a way to tell
which deletion an ID belong to (and whether it was scheduled). So make
both result getters return an array with known keys that can be used
programmatically. Right now the class can only delete a single page, and
thus there's a single constant and this change is effectively a noop.

The deletionWasScheduled() method, introduced in 1.37, was
hard-deprecated out of an abundance of caution. There are no known uses
on codesearch, so it can probably just be removed in the next release.

Also reorder constructor params to DeletePage -- BacklinkCacheFactory is
a service injected by the factory, hence it shouldn't be grouped
together with value objects injected by the caller.

Change-Id: I32679b7cacc638ec3e9dc5b8dfe9bcc794b22ecf
2021-11-29 15:09:42 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Derick Alangi
db43511e6a Title: Make use of BacklinkCacheFactory service
Change-Id: I48161585de6f329ec4037156234e0b07b3b837e6
2021-09-09 14:04:02 +01:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
jenkins-bot
5127fe1b43 Merge "Add MediaWikiIntegrationTestCase::runJobs() and use it" 2021-05-05 03:15:17 +00:00
Tim Starling
0e05879d7e Add MediaWikiIntegrationTestCase::runJobs() and use it
JobRunner catches all exceptions and hides them in the status array,
meaning that it is not obvious when a job fails during a test case.
So, introduce MediaWikiIntegrationTestCase::runJobs(), which runs jobs
and asserts various things about the returned status array.

Depends-On: I4f4790c5d16a0767790eeff202e0be8fcdaeda93
Depends-On: I118f9e3f8950fd82d7b02baed6705b29fd6ab7d5
Change-Id: I63603aa158f77df4b40add096cb248f3b24979f4
2021-05-05 02:51:30 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
DannyS712
a2d3a0f599 Hard deprecate JobQueue::getWiki
Deprecated since 1.33 and unused

Change-Id: I1ee72782facc0c0e432128bd9abf5bbb90f59a4b
2021-04-08 17:15:52 +00:00
DannyS712
1795bd1bac tests: Use data provider for UserEditCountInitJobTest cases
Reduces code duplication.

Change-Id: Id29676cabdbee372f9b2cc23f8658fe671a45cf8
2021-03-27 02:13:13 +00:00
DannyS712
93683ba570 CategoryMembershipChangeJobTest: fix extra underscore
Change-Id: I014835be5be8c6ce973b2e68d188e0f6abad4b4b
2021-03-22 16:12:41 +00:00
DannyS712
24afc63e49 Remove constructors from test classes
Tests should put their setup code in ::setUp(),
rather than __construct

Change-Id: I622f017f3c78a72acc65310f37d61dbec2a5da79
2021-03-08 03:31:25 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Thiemo Kreuz
20b2c5000d Make use of array deconstruction directly in foreach, if possible
Deconstructing non-sparse, numerically indexed arrays directly in
foreach (a.k.a. using the list() syntax in foreach) is possible since
PHP 5.5.

The possibility to use string array keys as well as non-sequential
numeric keys in array deconstruction was added in PHP 7.1.

Change-Id: I56a48552a45f61cedc291b306cad8548fc70d485
2020-11-12 18:38:06 +00:00
Ammar Abdulhamid
f433cd6958 Replace deprecated Title::isDeletedQuick()
Bug: T261880
Change-Id: Iec7278759accde4372a3230c7e122269d163365c
2020-11-03 10:32:17 +00:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +01:00
Timo Tijhof
45dff9dfff UserEditTracker: Minor code clean up and follow-ups
* Remove ILoadBalancer from UserEditCountInitJob constructor,
  since it is not a parameter and not a Job property.
  It is not needed during Job construction.

* Use ConvertibleTimestamp instead of MWTimestamp since no
  MW-specific methods or behaviours are needed here.

* I don't know if UserEditCountInitJob is always safe to de-duplicate,
  but this should be decided in the Job class, and is not the
  responsibility of calling code that creates/queues a job.
  I don't know for sure why this is publicly part of JobSpecification,
  but I guess it is there for internal use when serialising jobs,
  not for external use in the way it was used here.

  I'm assuming for now that its use means it is safe and I moved it to the
  UserEditCountInitJob class. If this is not the case and de-dupability is
  actually dependent on the parameters, then that logic should reside
  in the UserEditCountInitJob constructor.

* Document for which internal use clearUserEditCache() is public.
  This way during refactoring the method can be easily found and
  made private if that caller is no longer needed.

* Remove needless Job::factory() indirection in the
  UserEditCountInitJob test suite. This added overhead that is not
  part of the test's purpose, and also risks making the test break
  because Job::factory() allows types to be mapped to different
  implementations. But, this test suite is meant to cover the
  UserEditCountInitJob class implementation specifically.

Change-Id: I6fef4d297b1c0169f95906822e30b4addab7eaf4
2020-09-18 02:21:11 +00:00
Máté Szabó
90c2840cca UserEditTracker: Do not try to initialize edit count in read-only mode
The method UserEditTracker::getUserEditCount (as well as the old User class
logic it replaced) calculates the user's edit count and writes it to the
database if it was not computed yet. However, it attempts this write even if
MediaWiki is in read-only mode, causing errors as this method is frequently
called on read requests as well.

As a fix, move the edit count initialization to the job queue, which will avoid
trying to open a source DB connection (and thus cause a read-only error) on
installs that do not use the DB-based job queue. This change requires a
workaround in UserGroupManagerTest.

Bug: T259719
Change-Id: I6d1c8e9038ae1f98f47bdb2495aecc21654b24c0
2020-08-06 00:50:41 +02:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
DannyS712
e36fc3a8dd Remove use of the Revision object returned in WikiPage::doEditContent
Each file's changes are independent and can be reviewed separately

Bug: T251853
Bug: T254952
Change-Id: I197c3db4cfb2ead920c8e6071120ae29543ee404
2020-06-09 23:38:03 +00:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).

Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.

Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
2020-05-30 14:56:28 +00:00
Reedy
a8b006426e Fix tests/ PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I0beed1a35e046705fb84c9d1f63cf92afd009bb4
2020-05-16 04:30:21 +01:00