aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/StatusTest.php
Commit message (Collapse)AuthorAgeFilesLines
* tests: Move test cases from /includes/ into sub folderUmherirrender2023-09-131-1140/+0
| | | | | | | Follow move of the tested class Most moves are part of T321882 Change-Id: I74ab45d6a5331dcb2ff0b65dc2cc7c6315146646
* Reorg: Move Status to MediaWiki\Status\Amir Sarabadani2023-08-251-11/+12
| | | | | | | | | | 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
* Status::getPsr3MessageAndContext: Special-case rawmessageGergő Tisza2023-04-051-3/+20
| | | | | | | | | Do not try to parametrize rawmessage, which is intended to be used like RawMessage (but avoids the latter's unexpected behavior when e.g. copying to another message). Bug: T334012 Change-Id: I6e6bf09bb7b7a599a52311965a5542be92e67fac
* tests: Make some PHPUnit data providers staticTim Starling2023-03-241-2/+2
| | | | | | | | | | | | | 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
* Status: Add method for PSR-3 formatting of status objectsGergő Tisza2023-02-171-0/+65
| | | | Change-Id: Id76f55460ff10de9801f484d51fd8d504eaf9040
* Add StatusValue::hasMessagesExcept()Gergő Tisza2023-02-071-0/+18
| | | | | | | | Opposite check of StatusValue::hasMessage(), to ignore known-to-be-irrelevant errors. Bug: T272081 Change-Id: If0aaba4c607663b3b38ebfdc66ed3edbce6bd7d8
* Reorg: Move RawMessage to under language/Amir Sarabadani2022-12-161-0/+1
| | | | | | | | | | To follow Message. This is approved as part of RFC T166010. Also namespace it but doing it properly with PSR-4 would require namespacing every class under language/ and that will take some time. Bug: T321882 Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
* Use short array destructuring instead of list()Tim Starling2022-10-211-1/+1
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Make StatusValue accept MessageValue.daniel2022-09-011-2/+6
| | | | | | | | This allows us to use MessageValue in more places. In particular, it improves code re-use between REST handlers (which use MessageValue) and old style API modules (which use Status a lot). Change-Id: I14f1d4444b725273675dd229d716ac6396752c90
* StatusValue: include type in toString outputdaniel2022-06-101-0/+5
| | | | | | | | | | | | | | | | | | | | StatusValue::toString generates tabular output. This output should contain the type of each entry (error or warning). The index number is not relevant and can be omitted. Example output: <OK, collected 2 message(s) on the way, no value set> +----------+---------------------------+--------------------------------------+ | warning | foo | Lorem ipsum dolor sit amet, consecte | | | | tur adipisici elit, sed eiusmod temp | | | | or incidunt ut labore et do... | | error | bar | [ [ a, b, c ], ABCDEFGHIJKLMNOPQRSTU | | | | VWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABC | | | | DEFGHIJKLMNOPQRSTUVWXYZ ABC... | +----------+---------------------------+--------------------------------------+ Change-Id: Ia86159da2020518062e3fadc7b40da935342357f
* UserAuthority: Fix wikitext escaping for block errorsTaavi Väänänen2022-05-041-0/+14
| | | | | | | | | | | | | Status and Message behave differently when given a list of message parameters. Since the errors generated by PermissionManager is intended to be used by Message, we need to update UserAuthority to do that. Fixed StatusValue::replaceMessage to support MessageSpecifier objects like StatusValue::hasMessage does. This is so that the block message formatting in ApiBase does not break. Bug: T306494 Change-Id: I26405c680839b4679709e750d6d54e699c1efa66
* Add convenience methods for asserting status.daniel2022-03-161-2/+13
| | | | | | | This ensures that assertions work in a uniform way, and provides meaningful messages in cause of failure. Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
* Clean up tests that misused the parameters of assertSame/EqualsFunc2022-02-081-4/+4
| | | | | | | | | | | | 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
* StatusValue: improve toString formattingGergő Tisza2021-11-251-0/+16
| | | | | | | | Don't just cut off the message key at 25 characters, it makes debugging very annoying. But do cut off the parameter at some reasonable length, it could be arbitrarily large. Change-Id: I8a2665434d6370477eb36a6827eb634e230d280a
* Use correct default value when calling Status::getWikiTextUmherirrender2021-10-161-1/+1
| | | | | | Both parameter have a default of false, not null. Change-Id: I5754895347db244eee155f8cf5965df5f4fd2d1a
* phpunit: Mass-replace setMethods with onlyMethods and adjustDaimona Eaytoy2021-04-161-1/+1
| | | | | | | | | | | | 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
* Fix spacing after yield and use statementsUmherirrender2021-03-261-1/+1
| | | | Change-Id: Iacb93e96168ec0cd895130c5c8f66b6b44317e34
* Tests: Mark more more closures as staticUmherirrender2021-02-091-1/+1
| | | | | | | Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208 Bug: T274036 Change-Id: I695873737167a75f0d94901fa40383a33984ca55
* Tests: Mark more closures as staticReedy2021-02-071-3/+3
| | | | | Bug: T274036 Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
* Status/StatusValue errors/warnings should be uniqueCindy Cicalese2021-02-061-0/+234
| | | | | | Bug: T272100 Depends-On: I4a45d2db5de350384e7f57a728b2089f29dc1767 Change-Id: Idfc93029ef177b92830866de941394b383fcbb34
* build: Update mediawiki/mediawiki-codesniffer to 35.0.0Umherirrender2021-01-311-3/+3
| | | | Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
* [StatusTest] Replace ReflectionMethod with TestingAccessWrapperUmherirrender2020-10-301-17/+10
| | | | | | TestingAccessWrapper wraps the reflection codes and avoids invoke() etc. Change-Id: I2cfa6c1f28228a431e6783b18f7549c1507c022f
* Remove documentation that literally repeats the codeThiemo Kreuz2020-10-271-4/+0
| | | | | | | | | | | | | | | 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
* Add getMockMessage to MediaWikiTestCaseTraitKosta Harlan2020-05-201-17/+1
| | | | | | | | | 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
* phpunit: Change optional params before required params to also be requiredMax Semenik2020-03-291-1/+1
| | | | | Bug: T248078 Change-Id: I7e1d4229d84f5960fd496f281084dbec4739da4c
* Make use of PHPUnit's assertCount feature where possibleThiemo Kreuz2020-03-021-1/+1
| | | | | | | … and avoid assertEmpty() on arrays, in favor of a much more strict assertSame( [] ). Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
* Autofix 94 PHPUnit 8 compat issuesDaimona Eaytoy2019-12-131-1/+1
| | | | | | | | Done automatically using the master version of MW codesniffer and running composer fix. Bug: T192167 Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
* Do not run wfEscapeWikiText on array in Status classUmherirrender2019-12-021-0/+17
| | | | | | | | Message params could be more complex than a string For example by use of Message::numParam() Bug: T237559 Change-Id: I1be2ad3f73f189f69f955d1c4e1da75652e5e8ff
* Allow injecting a message localizer into StatusGergő Tisza2019-10-301-0/+22
| | | | | | | | | | | | 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
* Make Status::wrap and StatusValue::splitByErrorType work togetherGergő Tisza2019-10-071-0/+20
| | | | | | | | | | | | 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
* tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()Thiemo Kreuz2019-10-041-1/+1
| | | | | | | | | | | | | 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
* Use [...] instead of array(...) in PHP comments and documentationFomafix2019-06-171-1/+1
| | | | Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
* RFC T157418: Trim whitespace in table cells, list items, headingsSubramanya Sastry2018-03-161-4/+4
| | | | | | | | | | | | | | | | | | | | * 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
* Use ::class to resolve class names in testsUmherirrender2018-01-261-11/+11
| | | | | | | This helps to find renamed or misspelled classes earlier. Phan will check the class names Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
* Remove useless StatusTest::testCanConstruct()Kunal Mehta2017-12-281-5/+0
| | | | | | | Neither Status, nor StatusValue have constructors, so there's not much point testing whether the object can be constructed. Change-Id: I170940889b5da5198ef4576d04786f84c293dd01
* tests: Fix invalid @covers value in StatusTest.phpTimo Tijhof2016-09-221-8/+25
| | | | | | | | | | | | | | | 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
* Show warnings in HTMLForm and warnings as warnings on Login/Signup formFlorian2016-09-171-0/+62
| | | | | | | | | | | | | | | | | | | | | | 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
* Make non-existent messages be html safe regardless of output formatBrian Wolff2016-06-291-8/+8
| | | | | | | | | | | | | | | | | | | | | | 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
* Allow passing a language into Status::getWikiText() etc.Brad Jorsch2016-03-091-26/+57
| | | | | | | | | 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
* Fix use of RawMessage in Status::getMessage()Brad Jorsch2016-03-021-8/+30
| | | | | | | RawMessage::__construct() takes a single array of params, it's not varargs-style like wfMessage(). Change-Id: I63950ee16e359aa2627228350e27d9e94bb6e8ce
* Convert all array() syntax to []Kunal Mehta2016-02-171-88/+88
| | | | | | | | | | 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
* Switch name to username in @author tagsaddshore2016-01-271-1/+1
| | | | | | | From now on I will simply use addshore everywhere to keep things uniform... Change-Id: Iaf441b2d7a67a12c20529f0e9c7b47819f4abfae
* Fix issues identified by SpaceBeforeSingleLineComment sniffVivek Ghaisas2015-09-261-8/+8
| | | | Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
* StatusTest.php: Make lines shorter to make phpcs happierAmir E. Aharoni2015-09-261-1/+10
| | | | Change-Id: Ibe2034fb8d1849f3c0f98d4c4c3ffcb8277e416b
* Fix whitespace issues around parenthesesVivek Ghaisas2015-06-161-2/+2
| | | | | | | Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff. Bug: T102617 Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
* Fix magic getter for $status->okMark Holmquist2015-02-141-0/+11
| | | | | | | | | __get called a non-existant function which caused errors in file deletion. Also adds tests for $status->ok and $status->errors Change-Id: I8f5a21eb8d795e5e3f5a58f2384ad0dcbad749a2
* Split StatusValue out of Status class and put it in /libsAaron Schulz2015-02-101-1/+3
| | | | | | * Deprecated useless FileRepoStatus class Change-Id: I015635a9bf080ef6d98b2cff49b949c4378a859f
* Change @return to start with typeumherirrender2014-08-201-2/+2
| | | | | | | | | | | 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
* Cleanup some docs (tests)umherirrender2014-08-111-1/+1
| | | | | | | | | - 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
* Fixed spacingumherirrender2014-07-241-11/+11
| | | | | | | | | | - 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