Commit graph

11 commits

Author SHA1 Message Date
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
thiemowmde
021f2f6c32 Add __debugInfo to MediaWikiTestCaseTrait::createNoOpMock
I keep running into this whenever I use createNoOpMock. I think it's
XDebug that's calling this method, and then PHPUnit flooding the
console with extremely long stack traces.

We pretty much never do anything custom with this method:
https://codesearch.wmcloud.org/search/?q=__debugInfo&files=%5C.php%24

Change-Id: Ib2ab86fb243555f5e4449ed72cb032cb465e415d
2024-04-10 14:25:07 +02:00
Reedy
19c8ca74c2 tests: Add or fix Parser test namespaces
Bug: T357823
Change-Id: I1d07ff559f4607ba98bc834a1432e014f3ebdd35
2024-02-16 22:39:13 +00: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
thiemowmde
9a3d6ecd03 Add PHPUnit test for MagicWord class
This is much more trivial than e.g. MagicWordArray. Still deserves
it's own test, in my opinion.

Change-Id: I1c19c9c1e51fd210a3827a2200153686f7205eee
2023-11-21 16:13:39 +00:00
jenkins-bot
93b7d14a16 Merge "Make MagicWordArray not fail on old revs with broken UTF-8" 2023-10-27 19:13:18 +00:00
thiemowmde
6f32dc8a8d Make MagicWordArray not fail on old revs with broken UTF-8
Garbage in, garbage out. When the wikitext is broken, it's still
helpful if the user can see the broken wikitext. Even if it's not
fully parsed. It's not the job of this class to fix broken UTF-8.
The worst thing that can happen is that the wikitext contains some
unparsed magic words. However, this is really only relevant for
very old revisions (20 years old, see T321234). It's very normal
that old revisions can't be 100% parsed any more, most notably
because of deleted templates. This here is not much different.

Bug: T321234
Change-Id: I0ce40f6575668847ef309599ee32de52190ab212
2023-10-27 16:45:10 +00:00
thiemowmde
c5541bfa71 parser: Replace exception with /J modifier in MagicWordArray
The extra code that scans for duplicates and throws an exception was
added via I95dea67 in 2017. I'm not entrirely sure why. This should
be impossible in all relevant real-world scenarios. Maybe it happened
in a local dev scenario?

Even if, duplicates are harmless. Let me explain:

The only way a duplicate can end here is when the same magic word is
added twice to the $this->names array. The only thing that happens
then is that the resulting regex contains one of the sub-patterns
twice. It doesn't matter which one matches. We know these subpatterns
are identical. Unfortunately the PCRE compiler doesn't know and
assumes duplicate names are a problem. We have two options to fix
this: Strip duplicates in $this->names with array_unique() or tell
the PCRE compiler that duplicates are ok with the /J modifier.

I would like to avoid the extra, potentially expensive array_unique()
because, as said, duplicates never happen in real-world scenarios.

The /J modifier is supported since PHP 7.2.

Change-Id: I5f113abdbb44354fcc01be7f36fbc7d07f75876c
2023-10-27 12:48:03 +02:00
Timo Tijhof
08ddbf3465 parser: deprecate unused MagicWord::getId, improve docs and tests
* MagicWord::getId was added in r24808 (164bb322f2) but never used.
  At the time, access modifiers like 'private' were not yet in use.
  Deprecate the method with warnings, for removal in a future release.

* Fix zero coverage for MagicWord, due to constructor being
  internal, this is only intended to be created via array and
  factory classes. Let their tests cover this class.

* Remove redundant file-level description and ensure the class desc
  and ingroup tag are on the class block instead.
  Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+message:ingroup

* Mark constructor `@internal` (was already implied by
  stable interface policy), and explain where to get the object
  instead.

* Mark load() `@internal`. Method was introduced in 1.1 when the
  class (and PHP) did not yet use visibility modifiers for private
  methods. The only way to get an instance of MagicWord
  (MagicWordFactory::get) already calls load(), the method is not
  a no-op if called a second time, and (fortunately) there exist no
  callers to this outside this class that I could find.

* MagicWordArray::getBaseRegex was marked as internal
  in change I17f1b7207db8d2203c904508f3ab8a64b68736a8.

Change-Id: I4084f858bb356029c142fbdb699f91cf0d6ec56f
2023-10-26 16:07:20 +01:00
thiemowmde
6cc9f835c2 parser: Add more complex MagicWordArray test cases
The tests we added before create only MagicWordArray objects with a
single magic word. Here we are testing actual arrays of magic words.

Change-Id: I5880cca2a1e1ecf7018edd22c11229da5d5baffd
2023-10-19 17:22:59 +02:00
thiemowmde
97e269836f Add missing PHPUnit test for MagicWordArray class
I think this code is effectively covered by the parser tests that use
magic words. Still it worried me more and more to make changes to
this code without dedicated unit tests.

Change-Id: Id72e1d7ef4736e4d0672798d720465648d91b3ba
2023-10-06 15:00:07 +00:00