Commit graph

63 commits

Author SHA1 Message Date
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
Umherirrender
d01d47683c Fix spacing after yield and use statements
Change-Id: Iacb93e96168ec0cd895130c5c8f66b6b44317e34
2021-03-26 23:55:58 +01: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
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Cindy Cicalese
546ae552a9 Status/StatusValue errors/warnings should be unique
Bug: T272100
Depends-On: I4a45d2db5de350384e7f57a728b2089f29dc1767
Change-Id: Idfc93029ef177b92830866de941394b383fcbb34
2021-02-06 10:26:29 -05:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Umherirrender
e2613e9f1d [StatusTest] Replace ReflectionMethod with TestingAccessWrapper
TestingAccessWrapper wraps the reflection codes and avoids invoke() etc.

Change-Id: I2cfa6c1f28228a431e6783b18f7549c1507c022f
2020-10-30 14:02:10 +00:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Kosta Harlan
82cf3a3cfd Add getMockMessage to MediaWikiTestCaseTrait
This patch adds two more commonly used methods for params/rawParams to
getMockMessage and relocates the functionality to the MediaWikiTestCaseTrait.

Follows-Up: Ia94521b786

Change-Id: If9a6ccf1885ba11fbf3fb1b586006118462c1410
2020-05-20 21:52:11 +02:00
Max Semenik
84f15a0a79 phpunit: Change optional params before required params to also be required
Bug: T248078
Change-Id: I7e1d4229d84f5960fd496f281084dbec4739da4c
2020-03-29 15:45:17 +00:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Umherirrender
c4d4d81ae4 Do not run wfEscapeWikiText on array in Status class
Message params could be more complex than a string
For example by use of Message::numParam()

Bug: T237559
Change-Id: I1be2ad3f73f189f69f955d1c4e1da75652e5e8ff
2019-12-02 13:51:11 +01:00
Gergő Tisza
dd01c6dd64
Allow injecting a message localizer into Status
The coupling of Status with the global request context for
Message object creation is a common pain point in unit tests and
in no-session code. As a short term solution (until Status is
properly deprecated) allow injecting a different localizer.

Also refactor the code a bit to get rid if the explicit need for
the context language (which is already implicit in the localizer).

Change-Id: I82a2e4a83743546a934fb938b94e877a2471a3d2
2019-10-30 17:10:22 -07:00
Gergő Tisza
773a732a8d
Make Status::wrap and StatusValue::splitByErrorType work together
Status::wrap creates a new status object with most of its fields
references to the wrapped StatusValue. (This seems like a bad idea
but fixing it would potentially introduce subtle behavior changes
in a lot of code, so it is not attempted at this time.) When
splitting such a Status object by error type, the cloning causes
the error arrays of the new Status objects to be references to the
old one so writing them will result in a mess.

Change-Id: I9801647c39578a76be66f6e8c3c06c352660ca1e
2019-10-07 13:36:15 +02:00
Thiemo Kreuz
e4272518f7 tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()
assertEquals( false, … ) still succeeds when the actual value is 0, null,
an empty string, even an empty array. All these should be reported as a
failure, I would argue.

Note this patch previously also touched assertSame( false ). I reverted
these. The only benefit would have been consistency within this codebase,
but there is no strict reason to prefer one over the other. assertFalse()
and assertSame( false ) are functionally identical.

Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
2019-10-04 00:30:36 +00:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Subramanya Sastry
30495ea1f9 RFC T157418: Trim whitespace in table cells, list items, headings
* Matmarex had implemented this for wikitext headings in b3dd3881.
* This patch extends this to wikitext list items and wikitext table cells.
* Updated RELEASE NOTES.

tests/parser/parserTests.txt:
* All whitespace removed in output of list items, table cells, and
  headings. Removed corresponding whitespace in the input wikitext
  except for a few tests where the whitespace is significant "| +"
  or "| -", for example.
* Updated output of html/parsoid sections as well.
* Added new tests to spec white-space trimming behavior.

tests/phpunit/*:
* Fixed a few tests that used whitespace in list items and table cells.

Bug: T157418
Change-Id: I8ea34c7ab893c0c125c81d810feeb3c581e4bba1
2018-03-16 13:42:55 -05:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
99d73dc903 Remove useless StatusTest::testCanConstruct()
Neither Status, nor StatusValue have constructors, so there's not much
point testing whether the object can be constructed.

Change-Id: I170940889b5da5198ef4576d04786f84c293dd01
2017-12-28 08:53:04 +00:00
Timo Tijhof
e6e9e54be4 tests: Fix invalid @covers value in StatusTest.php
Uusally, phpunit issues a warning and continues to generate the
report but in this case it caused an early exit with no output.
Follows-up 3706dcb5c.

> Trying to @cover not existing method Status::getErrorsOnlyStatus.

Also:
* Increase coverage by adding @covers where missing.
* Use setOK() internally.
* Add test for 'ok' setter.

Change-Id: If6db634079c857f02b2594be199e6910ec49a52a
2016-09-22 18:29:28 +01:00
Florian
3706dcb5c7 Show warnings in HTMLForm and warnings as warnings on Login/Signup form
This commit changes the way how HTMLForm handles a Status object
when executed from a request. It now handles, beside the errors,
also the warnings of a Status object and prints them out, wrapped
in a warning box.

The LoginSignupPage uses this feature to show informative warnings
actually as warnings and not as more disturbing error messages.
Error messages should be reserved for errors and only for erros. An
AuthenticationProvider, which returns an UI AuthenticationResponse
can choose, if the given message is an error or a warning message.

This commit also addds a new function to Status, which allows a
developer to split the object into two new Status objects, where one only
contains the errors and the other only the warnings of the origin
Status object (splitByErrorType). StatusValue also has a new function,
splitByErrorType(), to support this.

Bug: T139179
Change-Id: I9a27911613e62b5c4cb86bea40696cb37c4f49c2
2016-09-17 16:33:39 +02:00
Brian Wolff
184658eb32 Make non-existent messages be html safe regardless of output format
If you have a non-existent message in the output, chances are its
user-controlled. If the message has the ->plain() or ->text()
format, the output used to be not safe for html. Obviously people
should not be using those format types where html is being outputted,
but sometimes that happens. I think we should prioritize always being
safe over the fallback content not potentially being double escaped.

Additionally switch the enclosing brackets to be fancy unicode
characters, to sidestep the escaping issue on the enclosing brackets.

So previously, wfMessage( 'script>alert(1)</script' )->text() would
have outputted <script>alert(1)</script>. Now it outputs
⧼script&gt;alert(1)&lt;/script⧽. No sane message key will include
< or >, so this would really only come up if the user can control
the message key name.

This goes somewhat against T68199.

Change-Id: Ic8a60892b8e847e6021494c10968814aac391731
2016-06-29 18:59:30 -04:00
Brad Jorsch
7c543bb6c2 Allow passing a language into Status::getWikiText() etc.
This also corrects a bug in MessageCache::parse() where it takes a
language code string but the Parser expects a Language object in
ParserOptions.

Bug: T128809
Change-Id: I3508c9e515e505890b3c62bc4a0982aa2a313782
2016-03-09 22:35:19 +00:00
Brad Jorsch
ca4bba6a98 Fix use of RawMessage in Status::getMessage()
RawMessage::__construct() takes a single array of params, it's not
varargs-style like wfMessage().

Change-Id: I63950ee16e359aa2627228350e27d9e94bb6e8ce
2016-03-02 12:36:22 -05: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
addshore
044f6418b1 Switch name to username in @author tags
From now on I will simply use addshore
everywhere to keep things uniform...

Change-Id: Iaf441b2d7a67a12c20529f0e9c7b47819f4abfae
2016-01-27 10:59:31 +01:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Amir E. Aharoni
3f5740ba03 StatusTest.php: Make lines shorter to make phpcs happier
Change-Id: Ibe2034fb8d1849f3c0f98d4c4c3ffcb8277e416b
2015-09-26 14:07:08 +00:00
Vivek Ghaisas
9f5b6f5aeb Fix whitespace issues around parentheses
Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff.

Bug: T102617
Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
2015-06-16 22:14:02 +03:00
Mark Holmquist
7a84402108 Fix magic getter for $status->ok
__get called a non-existant function which caused errors
in file deletion.

Also adds tests for $status->ok and $status->errors

Change-Id: I8f5a21eb8d795e5e3f5a58f2384ad0dcbad749a2
2015-02-14 00:05:41 +00:00
Aaron Schulz
c15caa6d53 Split StatusValue out of Status class and put it in /libs
* Deprecated useless FileRepoStatus class

Change-Id: I015635a9bf080ef6d98b2cff49b949c4378a859f
2015-02-10 00:39:05 +00:00
umherirrender
cd80906d4a Change @return to start with type
MediaWiki default is "@return type Description", so set a type after
return and start the description with a capital letter. Also use the
more common spelling of boolean.

See http://phpdoc.org/docs/latest/references/phpdoc/tags/return.html for
more about @return

Change-Id: I4e5198822fe92836f9cef9918a9fc1a1a1e0a043
2014-08-20 20:35:41 +02: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
umherirrender
4ee680a8b3 Fixed spacing
- Removed spaces after not operator (!)
- Removed spaces inside array index
- use tab as indent instead of spaces
- Add newline at end of file
- Removed spaces after casts

Change-Id: I9ba17c4385fcb43d38998d45f89cf42952bc791b
2014-07-24 11:53:04 +02:00
umherirrender
53c420e278 Fixed spacing
- use tab as indent instead of spaces
- Added space after closures "function"
- Added spaces around string_concat
- Added newline inside empty blocks
- Removed four spaces after comma

Change-Id: I4425b0c6a69b36f40acfea6511b8950cf09ce2b2
2014-07-20 21:41:41 +02:00
Gabriel Wicke
b33b5d5840 Update list item newline handling to follow Parsoid's model
This improves on commit 34bd573144 by matching
Parsoid's newline handling in the PHP parser. It is the outcome of a
discussion with Erwin, where we agreed that

* foo
* bar

should produce

<ul><li>foo</li>
<li>bar</li></ul>

See the discussion in https://gerrit.wikimedia.org/r/#/c/94443/

The original rendering issue this tried to address is no longer present after
a change to the template. The pure CSS solution is now working.

Bug: 39617
Bug: 56809
Change-Id: Ib7aa9449bbd994cb23b83b3f23cff944b1cddadf
2014-06-09 11:01:52 -07:00
Siebrand Mazeland
4916e08d8e Pass phpcs-strict on some test files (4/x)
Change-Id: Ifdbb431a6018c514b15ae71cc0c21b653a5e466d
2014-04-24 18:51:42 +02:00
daniel
8145672cd4 Allow Status::hasMessage to work with Message objects.
Change-Id: I52a468bc33f6c25630665ee8f987a25dc87659ee
2014-04-22 20:19:04 +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
Thiemo Mättig
2dd32c82ff Fix Status::getMessage accidentially returning string instead of Message
This mistake was introduced in commit
92e284d3fa and the reason for the two
disabled tests. I did not enabled the second test because of an
unrelated problem. The first enabled test already covers the fix.

The method should return Message objects only but did return a
string in that special case (multiple warnings set but no context
message key).

Unfortunatelly Status::getMessage does have many, many more
problems but I understand it's not a good idea to address them all
in a single confusing patch.

Change-Id: I0dc37e248f407019d5921aaaca3eabba338b0fd3
2014-03-17 18:46:00 +01:00
addshore
31ea82f68a Revert "Add getMessage tests with Short and Long Contexts"
Looking at the getMessage function the long and
short contexts should be strings not bools.

I was misslead by the defaults thus these tests
aren't actually testing much and should be removed
to avoid misslead more people!

This reverts commit cd9711ea35.

Change-Id: I889d42f720bf678a3543860893d0fedfca757dce
2014-03-06 21:20:29 +01:00
addshore
cd9711ea35 Add getMessage tests with Short and Long Contexts
Change-Id: Ib5a1a225b7244490fe9d3a5631d3757614174453
2014-02-27 12:00:26 +01:00
addshore
4b28a3746f Add test to complete coverage of getStatusArray
Change-Id: Ia2f9b5a723d85d19ee7a24fcf9b132d0289705f0
2014-02-22 12:00:18 +01:00
addshore
78be2c58d4 Add unit test for Status __wakeup
Change-Id: I5f116bc7df5932d6f5aeed7b81680cc08e243d0f
2014-02-22 11:42:13 +01:00
addshore
d11e2c18ce +Test for Status->CleanParams with a callback
Change-Id: I4e7570ea041d28303388c630b3ca07225faf8551
2014-01-25 16:14:49 +01:00
addshore
876b33bb4b Add test that covers Status::fatal
Change-Id: I7cb1e19569f77df5230808d7b35200b0ec9a6698
2014-01-25 16:11:57 +01:00
addshore
5a0aec1348 Add test for Status->merge with overrideValue true
Change-Id: I049c67e80277f8dbbbadae6e7a8f30d66066e7bf
2014-01-25 16:08:49 +01:00
umherirrender
2e871f7087 Fixed spacing
- Removed double spaces in arrays
- Added space after for
- Added spaces around string concat

Change-Id: Ifbcaf35f9bfef1f97226a38b5bd74c237f61c99e
2013-12-15 20:56:09 +01:00
Brad Jorsch
58a161fa35 Status::getHTML should actually return HTML
Currently it only returns wikitext with templates expanded (like
Message's text() method).

Bug: 45844
Change-Id: I24b5b098f15d0a4194817f31f63e37be1179aae6
2013-12-09 12:14:06 -05:00