From 990fd8f0b29f54e583ace8d613bed9d28c0c6485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 15 Jul 2022 02:46:52 +0200 Subject: EditPage: Disentangle edit summary and section title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Constraint/EditConstraintFactoryTest.php | 1 - .../NewSectionMissingSubjectConstraintTest.php | 44 ++++++++++++++++++++++ .../NewSectionMissingSummaryConstraintTest.php | 44 ---------------------- .../Constraint/SpamRegexConstraintTest.php | 2 - 4 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSubjectConstraintTest.php delete mode 100644 tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSummaryConstraintTest.php (limited to 'tests/phpunit/unit/includes/editpage') diff --git a/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintFactoryTest.php b/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintFactoryTest.php index d53aee0fbf39..b0e258a01893 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintFactoryTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintFactoryTest.php @@ -92,7 +92,6 @@ class EditConstraintFactoryTest extends MediaWikiUnitTestCase { SpamRegexConstraint::class, $factory->newSpamRegexConstraint( 'EditSummary', - 'new', 'SectionHeading', 'Text', 'RequestIP', diff --git a/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSubjectConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSubjectConstraintTest.php new file mode 100644 index 000000000000..ee2082abf19e --- /dev/null +++ b/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSubjectConstraintTest.php @@ -0,0 +1,44 @@ +assertConstraintPassed( $constraint ); + } + + public function testFailure() { + $constraint = new NewSectionMissingSubjectConstraint( '', false ); + $this->assertConstraintFailed( $constraint, IEditConstraint::AS_SUMMARY_NEEDED ); + } + +} diff --git a/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSummaryConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSummaryConstraintTest.php deleted file mode 100644 index f26b0ee1e0db..000000000000 --- a/tests/phpunit/unit/includes/editpage/Constraint/NewSectionMissingSummaryConstraintTest.php +++ /dev/null @@ -1,44 +0,0 @@ -assertConstraintPassed( $constraint ); - } - - public function testFailure() { - $constraint = new NewSectionMissingSummaryConstraint( '', false ); - $this->assertConstraintFailed( $constraint, IEditConstraint::AS_SUMMARY_NEEDED ); - } - -} diff --git a/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php index ce39e9869490..b6b3d559624c 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php @@ -62,7 +62,6 @@ class SpamRegexConstraintTest extends MediaWikiUnitTestCase { $logger, $spamChecker, $summary, - 'new', $sectionHeading, $text, 'Request-IP', @@ -95,7 +94,6 @@ class SpamRegexConstraintTest extends MediaWikiUnitTestCase { $logger, $spamChecker, $summary, - '', $sectionHeading, $text, 'Request-IP', -- cgit v1.2.3