aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/editpage/Constraint
Commit message (Collapse)AuthorAgeFilesLines
* editpage: Refactor user right, rate limit and block checks to use AuthorityBartosz Dziewoński2025-04-055-267/+120
| | | | | | | | | | | | | | | | | | | | | Replace EditRightConstraint, UserBlockConstraint, and most of UserRateLimitConstraint with the new AuthorizationConstraint. Instead of many separate checks, everything is now handled by one authorizeWrite() call. Move 'editcontentmodel' rate limit to ContentModelChangeConstraint (by making it use authorizeWrite()). Keep 'linkpurge' rate limit in a separate check, renamed from UserRateLimitConstraint to LinkPurgeRateLimitConstraint, since the way it works in unusual and not portable to Authority without more refactoring in EditPage. AuthorizationConstraint needs some special handling to produce the idiosyncratic result codes required by EditPage, but luckily PermissionStatus gives us everything we need for that. Bug: T271975 Bug: T386346 Change-Id: Ic9f6f2fbd29efa3e349517013da540a363c263b5
* editpage: Make BrokenRedirectConstraint provide its own error messageSomeRandomDeveloper2025-02-211-2/+4
| | | | | | | | | Generate the error message in the getLegacyStatus function in the constraint class instead of EditPage. The submit button label has to be passed to the edit constraint since the logic for determining it it resides in EditPage. Bug: T384399 Change-Id: Id2a9ab57198dfa4df07f91b067944e9f9fefb81a
* Fix broken redirect warning showing for special or interwiki targetsSomeRandomDeveloper2025-01-221-1/+1
| | | | | | | | | Using Title::exists does not account for special or interwiki pages which are also valid redirect targets. Using Title::isKnown instead does no longer cause the warning to appear when redirecting to a special page or an interwiki link. Bug: T384393 Change-Id: I35e4c72b0e21aaa36c1f8b1ac85fa819d353945e
* Add a warning when trying to create a double redirectSomeRandomDeveloper2025-01-171-0/+99
| | | | | | | | Shows a warning when trying to create a redirect that points to another redirect. Bug: T326056 Change-Id: Ieb51dde88ce6c23753f74191a85cd40f0bfbd864
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-171-1/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* Add a warning when trying to create a broken redirectSomeRandomDeveloper2024-11-261-0/+78
| | | | | | | | Shows a warning when trying to create a redirect that points to a nonexistent page. Update api tests to create the targets before the redirects. Bug: T326057 Change-Id: Ib530f17527aa8e14b8865086faa8d9feff6116ef
* Use explicit nullable type on parameter argumentsAndre Klapper2024-10-231-1/+1
| | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead. Followup to e662614f, using PHPStan. Bug: T376276 Change-Id: I60d639b042b537bf2f531cc132f1b75a66b85acb
* tests: Use namespaced classesUmherirrender2024-10-214-0/+5
| | | | | | | | Changes to the use statements and some additions are done automatically via script This also updates @covers tag for the namespaced classes Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
* Move section-check logic to ExistingSectionEditConstraintDannyS7122024-07-121-0/+15
| | | | | | | | | Instead of conditionally adding it, move the check for the section being new or not into the constraint, to reduce the logic needed in EditPage::internalAttemptSave(). Bug: T157658 Change-Id: If16f5a097dd38c5206f748fa4fb8dc6e56cf09cb
* Move AS_REVISION_WAS_DELETED handling into constraintDannyS7122024-07-121-1/+12
| | | | | | | | Use the renamed ExistingSectionEditConstraint, and just make the content it gets nullable. Bug: T157658 Change-Id: I6e077f1e54ea05f77b431a7437c4a56c9dc56306
* Rename AutoSummaryMissingSummaryConstraintDannyS7122024-07-121-6/+6
| | | | | | | | | In preparation for also handling the AS_REVISION_WAS_DELETED failure in the constraint, rename it in a separate commit so that git can more easily track the change. Bug: T157658 Change-Id: Id55b40d8e327429fbaf45a96c0b00caaa9110da1
* EditPage::internalAttemptSave() - move more logic to constraintsDannyS7122024-07-112-4/+14
| | | | | | | | | Instead of conditionally adding the NewSectionMissingSubjectConstraint and MissingCommentConstraint based on creating a new section, always add those and have the constraints themselves just pass if not creating a new section Bug: T157658 Change-Id: Ie5bf352bd714b6b706445f4f02c986706f26bb1f
* Replace some uses of deprecated PermissionManager::getPermissionErrors()Bartosz Dziewoński2024-06-271-8/+8
| | | | | | | | | getPermissionStatus() does the same thing but better. A lot of things use the legacy error arrays though, we're nowhere near removing it. Change-Id: Iff60dbb0593329a584d003b2407bbf24d5b22aea
* tests: Use namespaced classes (2)Umherirrender2024-06-131-0/+1
| | | | | | | Changes to the use statements done automatically via script Addition of missing use statement done manually Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
* Update tests for PHPUnit 9.6 (part 2)Daimona Eaytoy2024-01-171-5/+4
| | | | | | | - Avoid withConsecutive() Bug: T342110 Change-Id: Iedda49765cbceeb10ccd72d0248f3cda9241da1e
* Update tests for PHPUnit 9.6 (part 1)Daimona Eaytoy2024-01-161-6/+11
| | | | | | | | | - Avoid defining abstract test classes (ending in "Test") - Avoid withConsecutive() - Avoid getMockClass() Bug: T342110 Change-Id: I131e0d85bd14e75aaebd6f212b2e64a45d4c73a2
* EditPage: replace usage of User::pingLimiterdaniel2024-01-022-48/+30
| | | | | | Using RateLimiter::limit instead. Change-Id: Ia27cba5023994bfdc61f6d27702eeb98502d6dd4
* tests: Use namespaced classesUmherirrender2023-12-111-0/+2
| | | | | | | Changes to the use statements done automatically via script Addition of missing use statements and changes to docs done manually Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
* Change EditPage 'edit' rights check to do per page instead of generalBrian Wolff2023-11-042-61/+111
| | | | | | | | | | | | | | Previously the edit rights check would fail if you didn't have edit rights in general. This made it difficult to write custom permission extensions that want to give users edit rights to a few specific pages while not giving rights in general. This check goes back to 2005 when the edit rights system was first introduced a2a28a34c1fc. Presumably per-page permissions didn't exist yet. Bug: T342515 Change-Id: Ibcf0e18c44912abdd02a676a551da3cc7ed22ee0
* Bump codesniffer to 42.0.0Amir Sarabadani2023-09-271-8/+4
| | | | | | Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray. Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-193-0/+3
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* rdbms: Move ReadOnlyMode and ConfiguredReadOnlyMode to rdbms libraryAmir Sarabadani2023-05-042-2/+2
| | | | | | | | | | | | The db/ directory does not have an owner and it's a mess in general. These classes don't depend on anything in core except the rdbms library. Let's simply move it there. In other words, Krinkle made me do it. Since the class was moved in I6202e52ba73 merged less than a week ago, no need to alias anything. Bug: T321882 Change-Id: I24ceeb8bf765a50f441270136acd612359d50aa2
* Reorg: Move ReadOnlyMode classes to db/Amir Sarabadani2023-04-282-0/+2
| | | | | | | | They are not suitable to go to rdbms library as they depend on mediawiki pieces, the second best place is the db/ directory. Bug: T321882 Change-Id: I6202e52ba7306d74261206c2ba7930c5f1a0a18e
* tests: Make some PHPUnit data providers staticTim Starling2023-03-242-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
* Reorg: Namespace the Title classJames D. Forrester2023-03-029-0/+9
| | | | | | | | | | | | | | | | | | | 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
* unit tests: Use MainConfigNames constant to refer configsUmherirrender2022-08-171-1/+2
| | | | | | | When creating ServiceOptions objects or fake HashConfigs use the constant to refer the config name Change-Id: I59a29f25b76e896c07e82156c6cc4494f98e64cc
* EditPage: Disentangle edit summary and section titleBartosz Dziewoński2022-07-193-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, `$this->summary` was used for two different purposes. Usually it was just the summary. But when `$this->section` was 'new', then it was actually the section title most of the time – unless `$this->sectiontitle` was also set (in which case it took priority), and until it was replaced by the real edit summary (near the end of the processing, after copying the section title to the page content and before saving changes). Unsurprisingly some of the code didn't handle this duality correctly, causing T191722 and T311533. Now `$this->summary` is always the summary, and when `$this->section` is 'new', then `$this->sectiontitle` is always the new section title. The only place where this duality remains is in the input attributes and query parameters, where 'wpSummary' is still used for both the summary and the section title inputs (only one of them can appear, depending on whether `$this->section` is 'new'). It would be an unreasonable backwards-compatibility break to change this, and the code handling this is somewhat isolated from the rest of the logic. Bug: T191722 Bug: T311533 Change-Id: I5313ca9a045d112ece390b011a34192220e2abc1
* CreationPermissionConstraintTest: remove unused $titleDannyS7122022-06-291-3/+0
| | | | | Follow-up: I12a2f71f52a1ba7e94bf325621e62ed0e255601b Change-Id: Idb7c9afefb2faea5da61d52fa5ff81bf1522adde
* Improve error messages in EditFilterMergedContentHookConstraintDaimona Eaytoy2022-03-222-113/+3
| | | | | | | | | | | | Use multiple error boxes instead of a wikitext list of error messages, as the latter has several issues (as reported on phab). Also, remove the edit-error-* messages as they don't seem to add any value. Also, don't use the passed-in context, inject what the class actually needs instead (but keep the context for the hook). Bug: T303060 Bug: T230229 Change-Id: I2806e57826e7ab062b45dd1d9972b05fd6baeafb
* Add convenience methods for asserting status.daniel2022-03-161-3/+3
| | | | | | | This ensures that assertions work in a uniform way, and provides meaningful messages in cause of failure. Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
* Tests: use UserIdentityValue instead of mock User objectsDannyS7122021-05-031-5/+3
| | | | | | | - ParserMethodsTest for creating ParserOptions - SimpleAntiSpamConstraintTest Change-Id: I5f8ffbee5ee1ff8e08cae7e6ace30ff7b186539c
* Merge "Remove unnecessary ->equalTo() from tests"jenkins-bot2021-04-234-9/+9
|\
| * Remove unnecessary ->equalTo() from testsThiemo Kreuz2021-04-234-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | This is the default anyway when using ->with(). The test code becomes so much more readable without this, I would like to argue. Let it just say "with these values". Because of the way I split my changes into multiple patches there are a few other changes in this patch I could not split, e.g. removing unnecessary ->any(). This is the default anyway and doesn't make the test more specific. Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
* | Remove some meaningless $this->equalTo() from testsThiemo Kreuz2021-04-223-29/+11
|/ | | | | | This is the default behavior anyway when using ->with(). Change-Id: I64b6474280eb7da122eb22fc0afa28cca81e96c5
* phpunit: Mass-replace setMethods with onlyMethods and adjustDaimona Eaytoy2021-04-164-13/+7
| | | | | | | | | | | | 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
* Set $status->value in ↵Func2021-04-151-2/+2
| | | | | | | | | | | EditFilterMergedContentHookConstraint::checkConstraint() properly to display error message When hook handler return false and use $status->fatal() to put up a error, we should set $status->value to self::AS_HOOK_ERROR_EXPECTED to show edit form and display error message. Bug: T273354 Change-Id: I02d643c5cb1978da8ab749856493d75137b6cb02
* Update creation of edit constraints following switch to AuthorityDannyS7122021-03-221-23/+0
| | | | | | | | | No longer need the factory for many of them Bug: T271977 Bug: T157658 Follow-up: I12a2f71f52a1ba7e94bf325621e62ed0e255601b Change-Id: I5019ea46bccb1f23643424c2798061a25eb3f623
* Convert EditConstraints to AuthorityPetr Pchelko2021-03-035-182/+81
| | | | | Bug: T271977 Change-Id: I12a2f71f52a1ba7e94bf325621e62ed0e255601b
* tests: Remove @param docs from test code that just repeat the signatureThiemo Kreuz2021-01-211-4/+0
| | | | | | | | | | | | | | These are not only 100% identical to the actual code, but also: * It's error-prone. Some are already wrong. * These test…() functions are not meant to be called from anywhere. What is the target audience for this documentation? * There is a @dataProvider. What such @param tags actually do is document the provider, but in an odd place. Just looking at the provider should give the same information. * The MediaWiki CodeSniffer allows to skip @param when there is a @dataProvider, for the reasone listed. Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
* Merge "Add tests for EditConstraintFactory"jenkins-bot2020-12-261-0/+125
|\
| * Add tests for EditConstraintFactoryDannyS7122020-12-261-0/+125
| | | | | | | | | | Bug: T157658 Change-Id: I175afe4d1217f9e57aaa8e8d8f93c70736dac801
* | Bring SpamRegexConstraint test coverage to 100%DannyS7122020-12-261-1/+1
|/ | | | | Bug: T157658 Change-Id: I89d08059937d2a84de0cbc53fd4ac56153018e40
* ImageRedirectConstraint: accept Content objectsDannyS7122020-12-091-22/+25
| | | | | | | More common interface for constraints Bug: T157658 Change-Id: Ia50c3fb647ed803a69f5e4511047f1ab88e43bf7
* UserRateLimitConstraint: move detection of content model change to constraintDannyS7122020-12-011-4/+12
| | | | | | | | | | A step towards a more common interface between the different constraints, detect whether the content model changes within the UserRateLimitConstraint rather than relying on EditPage to inject the answer Bug: T157658 Change-Id: Ifa35cbabe74df458784a10b3d2815a1e8e7dcdf8
* Move more logic into edit constraintsDannyS7122020-12-011-3/+26
| | | | | | | | | Specifically, remove the conditional processing of ContentModelChangeConstraint and ChangeTagsConstraint in favor of early returns within the constraints Bug: T157658 Change-Id: I377c0e3d9611d2da0a2d0f9bca055d65a1bec7e6
* Add AccidentalRecreationConstraintDannyS7122020-11-161-0/+47
| | | | | Bug: T157658 Change-Id: Ia9346ceb06ca060cd6e953b1d5b358aabc853eb3
* EditPage: Add two more constraintsDannyS7122020-11-112-0/+151
| | | | | | | | - AutoSummaryMissingSummaryConstraint - SelfRedirectConstraint Bug: T157658 Change-Id: I0bc29d81ec3df6228a04f41df66b53b113792e38
* Merge "EditPage: Move $sectionHeadingToCheck handling to SpamRegexConstraint"jenkins-bot2020-11-111-0/+2
|\
| * EditPage: Move $sectionHeadingToCheck handling to SpamRegexConstraintDannyS7122020-11-111-0/+2
| | | | | | | | | | | | | | | | Cleaner and simpler if the constraint takes care of determining how to handle the section title Bug: T157658 Change-Id: I45de1aca77fe1ddcd3d94b6ca964328d9911b440
* | Move EditPage::runPostMergeFilters to a constraintDannyS7122020-11-101-0/+112
|/ | | | | Bug: T157658 Change-Id: I071163d6d2538948693527c36e8e59281f528402