Commit graph

162 commits

Author SHA1 Message Date
Umherirrender
134045b9aa tests: Swap assertion order in unit tests
Changes from patch set Icb93c79f4843b59dae80d3eda1a880457a1a68f2
Also some swaps from assertEquals to assertSame/True/False/Null

Change-Id: Ife497ae6cb1888b77eb25e85b76df72adc65641a
2021-08-04 20:21:01 +02:00
Aryeh Gregor
b19db60c70 Hard-deprecate Title::isNamespaceProtected
No callers, deprecated in 1.34.

Change-Id: If2e1c762f91e3c8255fbb58b7c9f01e8929a7fa2
2021-07-29 17:15:33 +03: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
7b556a5761 Move some Title tests to unit tests
Tests for the following methods don't need integration:
- legalChars()
- convertByteClassToUnicodeClass()
- newFromTitleValue()
- newFromLinkTarget()
- castFromLinkTarget()

Change-Id: I2ec6505088c74a90da9d0b8305ce94d81cc0562a
2021-07-09 23:18:57 +00:00
DannyS712
809798bd6d TitleTest::provideCastFromPageReference() remove unused $fake
Change-Id: I2d5b51a291cdfefcaaf8cf07de155a890e72a677
2021-07-05 07:14:29 +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
Petr Pchelko
695e61ce14 Clean up hard deprecated Title methods
Depends-On: If27bb6b5142d09bc9293d080e97b6642462219f4
Change-Id: I37f012e53d1c881292a19aac87eb107636c6bfbe
2021-05-11 07:41:18 -07:00
DannyS712
31676abea5 Add DummyServicesTrait::getDummyInterwikiLookup
Replacing the mock InterwikiLookup used in
MediaWikiTitleCodecTest revealed that that test was,
because of the mock not behaving correctly, testing the
wrong thing - interwiki prefixes are *not* case sensitive,
and are always converted to lowercase in the actual
ClassicInterwikiLookup. Fixed those expectations.

Change-Id: I242431e88860b7700a9f93f77a0fe195fd748800
2021-05-05 10:57:59 -07:00
jenkins-bot
ca96e2c575 Merge "Hard deprecate Title::isWatchable()" 2021-04-30 18:51:14 +00:00
Cindy Cicalese
ca328d272f Hard deprecate Title::isWatchable()
Bug: T281497
Depends-On: I271960cbbbbb5db73aae36414a4c18c14940b6e1
Depends-On: I0f7a82191eae8edd4c0c1d16d89c81e601ae5c80
Change-Id: Ibb83ac71fc2214dcc71f73f009d137a2e5c80d0d
2021-04-29 14:43:00 -04: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
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00:00
daniel
5faa080374 Introduce PageReference
This explores the idea of a PageReference type which represents a
namespace/dbkey pair.

Every ProperPageIdentity is a PageReference. Some LinkTargets can be
mapped to a PageReference.

Bug: T279522
Change-Id: Id8b0c781fce329adcc4770f4840b2ba0108f6898
2021-04-13 23:32:20 +02:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
jenkins-bot
bee15a1689 Merge "title: Fix Title::findSubpageDivider() destroying certain strings" 2021-03-31 07:49:07 +00:00
Petr Pchelko
877720d7b4 Make Title::isWatchable more strict
We can't really watch invalid titles, since they
definitely can not exist in the database, so having
them in user watchlist doesn't make much sence either.

Bug: T278735
Change-Id: I411ca9227da8050d026a57db690824afd3423a89
2021-03-30 15:51:55 -06:00
jenkins-bot
0949c7ac20 Merge "WikiPage: don't record bad redirects." 2021-03-25 17:10:22 +00:00
daniel
935c10f86c WikiPage: don't record bad redirects.
Bad redirects in the database led to fatal errors when attempting to
resolve the redirect when visiting the page. This patch does three
things to address this:
* change Title::isValidRedirectTarget to actually check whether the
target is a valid title.
* change WikiPage::recorddRedirectEntry to reject invalid redirect
targets
* change WikiPage::getRedirectURL to ignore invalid redirect target
that may be present in the database.

Bug: T278367
Change-Id: Ib17ebfb99fa17b846302438c675a968a1ec0f488
2021-03-24 22:15:22 +00:00
daniel
d4b380ab27 Introduce PageSelectQueryBuilder
Change-Id: Ibcb37affa9ba1c891bc62964a3dd34b67214cfa1
2021-03-24 19:15:01 +01:00
DannyS712
a48bb43b55 Add more tests for creating Title objects
Bug: T241406
Change-Id: I4733fbb9765dc43f7b8d8fbe64a46877f6cde04f
2021-03-07 19:16:07 +00:00
Peter Ovchyn
7d8bf01855 Clean up Title deprecated methods of mediawiki core
This patch hard-deprecates the following methods,
that are overdue for hard deprecation:

- ::getPreviousRevisionID
- ::getNextRevisionID
- ::getFirstRevision
- ::getEarliestRevTime

Also, it removes the following methods:
- ::countRevisionsBetween
- ::getAuthorsBetween

Bug: T274151
Change-Id: If022b907652efdad84180476649a612059c6ef18
2021-02-28 21:08:11 +02: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
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
daniel
10ccdb2281 Define equality for PageIdentity and LinkTarget
Bug: T272420
Change-Id: I2e0eb21989e2d733088ab77d7461bf003c2905eb
2021-01-19 23:07:37 +00:00
James D. Forrester
a8fe6c9841 Revert "Define equality for PageIdentity and LinkTarget"
This reverts commit 36f1adf670.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I26c6fd656c75a6b209fb17965dc9109edf68642b
2021-01-15 12:30:14 -08:00
daniel
36f1adf670 Define equality for PageIdentity and LinkTarget
This allows Title and WikiPage objects to be compared with PageIdentity
and LinkTarget instances consistently.

Change-Id: I1bbd15d17d046359393ecfc1acd2778273260a95
2021-01-15 17:53:28 +01:00
daniel
1a60008a9a Introduce PageIdentity interface
PageIdentity is intended as a lightweight alternative to Title,
similar to LinkTarget, but providing a page ID. It follows the precedent
of UserIdentity.

Bug: T208776
Change-Id: Iaed4871e0d32c67d4fb13e487625527f6a21e9c5
2021-01-14 13:18:05 -06: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
C. Scott Ananian
3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00
DannyS712
3503537452 TitleTest::testIsWatchable should call isWatchable
Instead of ::canHaveTalkPage
Likely a copy-paste error

Change-Id: I46c0ebd6267f8631907c011bca525572313154c1
2020-12-21 11:44:10 +00:00
Reedy
24a33520fe Correct position of $expected and $actual in TitleTest::testGetCascadeProtectionSources()
Change-Id: Ie72832ea6d672607c1e67ebf52601892af196ab2
2020-10-03 18:23:00 +01:00
DannyS712
eea7e16df4 Remove deprecated title permissions functions
Title::userCan, ::quickUserCan, and ::getUserPermissionsErrors, hard deprecated in 1.35

Bug: T246138
Change-Id: Iee990a16c15bd827cf631fb5ff683367082d2ebe
2020-08-26 21:21:11 +00:00
Thiemo Kreuz
ea7397e071 title: Fix Title::findSubpageDivider() destroying certain strings
This helper method was introduced in I3d8c6f6. I found this bug while
working on I0a5be39. The method was cutting off strings like "/subpage"
into "ubpage".

I made sure no existing test case changed, as you can see.

I also tried to document the basic idea:

The first character can never be a subpage divider, even if it is a
slash, because this would result in an empty base. The code tries to
skip initial slashes and use the first non-empty substring as the base.
However, if there is nothing but slashes, the worst-case fallback is
to use the first slash as if it is the base.

I think there are still 2 different ways to split the following
edge-cases:
* "//foo" could become:
  a) base "/" + divider + subpage "foo", or
  b) base "//foo" with NO subpage.
* "//" could become:
  a) base "/" + divider + empty subpage, or
  b) base "//" with NO subpage.

Personally, I would pick b). But there was a test case already that
forced me to stick to a).

Bug: T229443
Change-Id: I4914b57c81ce6c7fdf10746f0da902c65f0ac2c9
2020-07-28 12:49:55 +02:00
Daimona Eaytoy
719e185357 title: Make getSubpageText() return the title text if there's no subpage
This is for consistency with the previous behaviour.

Follow-up: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac

Bug: T256922
Change-Id: I0928f85c862d3b2baf49317a206ca140a1ab3c16
2020-07-02 00:08:51 +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
daniel
03397e46c5 Title: fix subpage split for degenerate cases
This ensures that getBaseText and getRootText always
return a valid title, even for degenerate cases like "/" or
"//foo//bar//baz//".

Bug: T229443
Change-Id: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac
2020-06-22 12:58:29 +02:00
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
Timo Tijhof
2f35c3ae67 HtmlCacheUpdater: Add getUrls() method and support selective purging
* Move the Title::getCdnUrls() logic to the new HtmlCacheUpdater service.

* Introduce a runtime option to decide whether this is for a direct
  revision or a cascading LinksUpdate.

Bug: T250261
Change-Id: I514b9052761e0d949234996e97fdef255582df86
2020-04-30 18:16:07 +00:00
Timo Tijhof
f2be921509 title: Remove broken handling of language variant in getCdnUrls()
* This currently produced urls like "index.php?title=…&<langcode>"
  which don't actually do anything. The proper syntax is "variant=langcode".
  These danging variants were nothing but PURGE noise, as random
  as e.g. purging a url like "…&rand123" would have been.

* Regardless of all this, page views with a language variant don't
  actually emit a public cache header right now in MediaWiki, which
  means there is not actually anything to purge from the CDN in the first
  place. Revisiting whether we want to start caching them (and then
  where/when to purge them) is subject of T250511, which can happen
  after this logic is moved to the HtmlCacheUpdater service.

Bug: T250511
Bug: T250261
Change-Id: I497cb2be2e9f16156cf02afeb437bdca1b2cc1fd
2020-04-20 18:55:17 +00:00
Timo Tijhof
2ed2d49aad title: Add unit tests for Title::getCdnUrls()
Bug: T250261
Change-Id: I73c368ab81b62fa7363f4b06438f717822cc06b9
2020-04-17 18:39:53 +01:00
DannyS712
1948049498 Hard deprecate Title::userCan and ::quickUserCan
Bug: T244923
Bug: T244927
Change-Id: I1a064aeb3fc87573af50ae5b14793e750696371d
2020-02-22 01:53:03 +00:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Vedmaka
0b20d225ec
Adds missing PHPUnit tests for the following Title methods:
- Title::loadRestrictions
- Title::loadRestrictionsFromRows
- Title::getRestrictions
- Title::getAllRestrictions
- Title::getRestrictionExpiry
- Title::getTitleProtection
- Title::isSemiProtected
- Title::deleteTitleProtection
- Title::isProtected
- Title::isNamespaceProtected
- Title::isCascadeProtected
- Title::getCascadeProtectionSources

Bug: T218395
Change-Id: I124e44af8f90c4a8345201c9973082d7aa97f27e
2019-11-07 23:42:25 +03:00
jenkins-bot
1bc7bc958c Merge "tests: Add explicit return type void to setUp() and tearDown()" 2019-11-01 02:08:24 +00:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Petr Pchelko
e4b7fc3570 Hard deprecate User::isEveryoneAllowed
The method was soft-deprecated in 1.34. It's not used in any WMF
installed extensions or the tarball, so it can be hard deprecated.

Bug: T220191
Change-Id: I2f48d62a8dd3592918a6197168d31a1e08bd2a3e
2019-10-30 11:17:19 -07:00
Max Semenik
665b7758c5 tests: getMock() is deprecated
Bug: T192167
Change-Id: I94a4674103b0946d208ff0c28f260506048cb211
2019-10-22 14:20:25 -07:00
jenkins-bot
05ce3b7740 Merge "Title: make newFromText, isValid, and canExist behave consistently." 2019-10-08 13:54:57 +00:00