Commit graph

137 commits

Author SHA1 Message Date
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
Kosta Harlan
37306f5efb
ApiEditPageTest#testCreateImageRedirectAnon: Disable temp user feature
Why:

- The test checks for anon edit functionality specifically

What:

- Disable temp user feature for this test

Bug: T365669
Change-Id: I856ff3cb5ed64fd2d46a7cffc5084415f66ee536
2024-06-27 13:42:52 +02:00
Kosta Harlan
6a938585b3 ApiEditPageTest: Set a user in method call that generates log entry
Why:

- When temp accounts are enabled, creation of new log entries needs to
  be associated with a named user account or temp account

What:

- Set the context user to a regular account before calling
  ::setVisibility on a list from RevisionDeleter

Bug: T365669
Change-Id: I1be6924a92309ea5da75df37910949440e23c937
2024-06-26 10:27:51 +00:00
Ebrahim Byagowi
ccde5085de Add namespace and deprecation alias to JavaScriptContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I87c17327911e28a461feaf2ff46242454cff257a
2024-05-17 13:51:18 +03:30
Amir Sarabadani
c04f1d64d6 Remove IDBAccessObject from being implemented in many classes
This is inconsistent with the access pattern of other constants in
MediaWiki. it's also confusing (e.g. it's unclear to a newcomer why
UserFactory is implementing IDBAccessObject) and it's prone to clashes
(e.g. BagOStuff class has a clashing constant).

It has been already announced: https://w.wiki/9DAX

Bug: T354194
Change-Id: Ic2357634b8385d65b55db2b557191419b06c40e0
2024-02-19 10:50:02 +01:00
Reedy
75640200fb tests: Namespace api tests
Bug: T357823
Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
2024-02-18 15:47:04 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Atieno
b531666770 Remove indirect calls to IDBAccessObject::READ_* constants
We are getting rid of the schema of implementing this interface and
calling self::READ_* constants, it's confusing, inconsistent, prone to
clashes and isn't really useful for non-ORM systems (which we are not)

Bug: T354194
Change-Id: I4c722807b27db4e59f5ba3acc3ddb57fca9140b1
2024-01-29 21:00:03 +03:00
Umherirrender
16a436ce6c tests: Remove cleanup of blocks, done by ChangedTablesTracker
In DatabaseBlockTest changed from addDBDataOnce() to addDBData() as
ChangedTablesTracker cannot reset tables changed by addDBDataOnce()
between each test run.

Remove also User::clearInstanceCache done together with the deletion as
the TestUser class is calling this already between tests.

Change-Id: Ibd5e544138a2a9b554abc2dea54a5db38f9a828f
2024-01-20 11:41:15 +01:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Ammarpad
42e166dd83 StatusValue: Allow passing arbitrary data to augment result
This allows extensions and hooks to pass around additional data
about the operation result arbitrarily to supplement value and errors.

When two StatusValue instances are to be merged, it's responsibility
of the caller to ensure either only one has this extra data or none,
but never both (since the type is unrestricted). If necessary, the
caller should merge them before invoking StatusValue::merge.

Bug: T326479
Change-Id: Ibe3f1f8b81bcfcb18551d3ca4cda464e4bdbcbce
2023-11-28 14:58:22 +01:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05:00
Tim Starling
cc40f0a12d Migrate callers of DatabaseBlock methods moved to DatabaseBlockStore
* Migrate callers of DatabaseBlock methods newListFromTarget,
  newFromID, newFromTarget, doAutoblock.
* Deprecate DatabaseBlock methods newFromID and getAutoblockExpiry.
  These are the methods with no extension callers in code search.

Bug: T255433
Change-Id: If0358459f53d32e7fe984c2fb8b61e0088f28922
2023-11-06 12:03:51 +11:00
Adam Wight
1f32fc9073 api: Make ApiEditPageTest stop using $originalRevId incorrectly
None of these tests are using the doUserEditContent param as intended.
This is only for undos, not for indicating the parent revision.

Change-Id: I24a11fb7b960dfdc801b31207c2a55501e068e80
2023-09-26 08:54:57 +02:00
Amir Sarabadani
abbb4281cb tests: Migrate more cases to SQB
Bug: T344971
Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
2023-09-21 18:30:37 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Umherirrender
7cdd690465 tests: api: Replace Title::newFromText with Title::makeTitle
Parsing titles is expensive, it happens in the test function itself via
Title::newFromText and also the called editPage() needs to parse the
title, better to pass the title object there.
Title::newFromText has a cache, that share the title object between the
api code and the test code.

Use independent title objects for testing. This requires some
Title::READ_LATEST to ensure the changed database after the api call is
used.

Change-Id: I00c14e270a5f4078f80d78696ca2e39acf138e95
2023-07-30 17:15:09 +02:00
Umherirrender
8f273a9dfa tests: api: Replace some static function with services
Replace User::, Title:: ContentHandler:: calls
to the corresponding services

Change-Id: I57e47221a00eafac9f171215019cf25e19e1808e
2023-07-29 11:58:54 +02:00
Daimona Eaytoy
346cb7630b Replace usages of ApiTestCase::$users
Ideally we'd use Authority, but that doesn't always work, so just call
the getTest* methods directly.

Change-Id: I7f8393bb754beeb319b5555b5dac05265e376a22
2023-07-25 12:12:58 +00:00
Daimona Eaytoy
4c72c161d8 Deprecate MediaWikiIntegrationTestCase::$users
This property shouldn't be needed in modern code, where most things can
use Authority. So much so because TestUser adds a dependency on the
database, but many tests that use TestUser don't even need the database.
ApiTestCase, in particular, sets this property in setUp, thus adding a
database dependency to all API tests, including those that don't need
users or the database at all.

Deprecate the property and replace existing usages in core. The one in
ApiTestCase is much harder to migrate, but this patch replaces the array
with an anonymous ArrayAccess class to allow lazy initialization and
remove DB dependencies.

Bug: T155147
Change-Id: I59c4ed1f6a7572d3a92387b15b8e56625bc376a2
2023-07-25 12:12:43 +00:00
Amir Sarabadani
77342327ee tests: Migrate calls to Database::update to UpdateQueryBuilder
Bug: T330640
Change-Id: I30f9e84658fbd996b5512e96dda3f6412ebf3a20
2023-07-14 15:40:11 +02:00
Amir Sarabadani
614cd41507 tests: Migrate Database::delete calls to DeleteQueryBuilder
Bug: T340065
Change-Id: I92e85efd5d23d100a5df38aedb8edaecc5cbfc65
2023-07-14 14:48:42 +02:00
Umherirrender
ddfcebc584 api tests: Call editPage() with WikiPage when used for same page
When calling editPage() with a string it converts it to a WikiPage each
time it is called. When edit a page only once that is okay,
but when adding more revision to the same page it is better to pass a
WikiPage instead to allow reuse of internal states of WikiPage to speed
up the tests

Bug: T225730
Change-Id: I7a0e7e3e75ade5d6abe8e62a03a029190f3b6da8
2023-06-24 18:07:34 +00:00
Bartosz Dziewoński
1048db795b API tests: Assert error codes, not error messages
Error messages are not guaranteed to be stable, and these tests
prevent us from improving them.

Error codes are supposed to be stable, so we should be asserting
that they do not change (especially since many of them are
dynamically generated by the dodgy code in ApiMessageTrait).

Introduce helpers assertApiErrorCode() and expectApiErrorCode()
to be used instead of the usual PHPUnit assertions/expectations
for this case.

Change-Id: I752f82f29bf5f9405ea117ebf9e5cf70335464ad
2023-04-26 19:36:29 +02:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Umherirrender
fd516a98e1 Fix whitespaces after comma
Change-Id: Ide6de0a53661e6f650099d7b1f274a02699441df
2022-12-15 01:24:14 +01: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
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Umherirrender
ef0623ec06 tests/api: Add TestUser::getAuthority and use it
Change-Id: Icfb66f9927c8e67582010a208538b0b5e0ba353f
2022-08-06 23:15:27 +02:00
jenkins-bot
e5742b4820 Merge "Fix edit API adding empty section title when creating new pages" 2022-07-19 19:41:10 +00:00
Derick Alangi
a3a2ed268a tests: Use overrideConfig(Value|Values) where needed
This patch covers: tests/phpunit/includes/actions/ and
tests/phpunit/includes/api/.

Change-Id: I60d8fb7b8a63b423606db935fa0d24cf859b2512
2022-07-12 22:24:50 +00:00
Bartosz Dziewoński
add6c49e01 Fix edit API adding empty section title when creating new pages
WikitextContent methods replaceSection() (used when adding a section
to an existing page) and addSectionHeader() (used when creating a new
page) behaved inconsistently - the former would omit the heading
syntax when the section title was empty, but the latter would not.
They both omit it now.

Some callers of addSectionHeader() handled this case, but others did
not, which caused T311489. (I am removing the checks now, since the
change makes them redundant.)

Bug: T311489
Change-Id: Icd59bcf2b75bf50865f19fac92bddabe0c183dcc
2022-07-05 21:06:06 +00:00
Umherirrender
8b1a3d13eb tests: Use WikiPageFactory to create WikiPage object
Bug: T259948
Change-Id: I9afcf3b845306f81ee5ca156553256e6c38df3a0
2022-06-26 23:21:02 +02:00
Bartosz Dziewoński
c5958b8d0a Fix edit API using summary as section title incorrectly
'summary' must only be used as the section title when 'sectiontitle'
is not provided. Otherwise the provided section title must be used,
even if it is empty.

Bug: T54747
Change-Id: Id86d5cdd9e04cf1b2f3fbf243a4b250e2924cf87
2022-06-13 22:57:25 +00:00
Bartosz Dziewoński
144151b025 Add edit API tests for combining 'summary' and 'sectiontitle'
Bug: T54747
Change-Id: I1f6b5747347701161576e491c10dd7719bebb0a4
2022-06-14 00:54:36 +02:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Daimona Eaytoy
2688c59606 tests: Replace usages of deprecated WikiPage::doDeleteArticleReal
Add a new helper to MediaWikiIntegrationTestCase, since deleting pages
seems to be pretty common in tests.

Some calls to WikiPage::factory were also updated to use WikiPageFactory.

Change-Id: I5b5100273a00ac292a1900022ca79708fa254347
2022-01-17 15:38:02 +00:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +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
Petr Pchelko
ac935cb758 Make SlotRecordTest a unit test
Change-Id: I4f5a4bf3703fc490c6c4de45f5a7947b7726aaa1
2021-10-19 20:31:55 -07: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
jenkins-bot
6eb8c5a6da Merge "Use IEC prefixes instead of SI prefixes for byte sizes (docs+backend)" 2021-06-29 10:34:41 +00:00