aboutsummaryrefslogtreecommitdiffstats
path: root/includes/actions
diff options
context:
space:
mode:
authorBartosz Dziewoński <dziewonski@fastmail.fm>2024-11-03 23:21:06 +0100
committerBartosz Dziewoński <dziewonski@fastmail.fm>2024-11-04 00:27:24 +0100
commit1a54b72326e67402c56ff22d9253b4ab5c261b2f (patch)
tree514b568cd0b071f2b4ca30386c004b62bb5cea32 /includes/actions
parent72db9047bf68db74489d209910569e0d8ac84981 (diff)
downloadmediawikicore-1a54b72326e67402c56ff22d9253b4ab5c261b2f.tar.gz
mediawikicore-1a54b72326e67402c56ff22d9253b4ab5c261b2f.zip
WatchAction: Make onSuccess() easier to test
Instead of mocking everything, extract the part of the code we want to test into a helper function. Change-Id: I682ba4d2ab679e8d2e99ea9eb11175338c83da55
Diffstat (limited to 'includes/actions')
-rw-r--r--includes/actions/WatchAction.php9
1 files changed, 7 insertions, 2 deletions
diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php
index 10e1569cc72b..ddd4d046ed59 100644
--- a/includes/actions/WatchAction.php
+++ b/includes/actions/WatchAction.php
@@ -29,6 +29,7 @@ use MediaWiki\Watchlist\WatchedItem;
use MediaWiki\Watchlist\WatchedItemStore;
use MediaWiki\Watchlist\WatchlistManager;
use MediaWiki\Xml\XmlSelect;
+use Wikimedia\Message\MessageValue;
use Wikimedia\ParamValidator\TypeDef\ExpiryDef;
/**
@@ -232,9 +233,13 @@ class WatchAction extends FormAction {
* 8. addedwatchexpiryhours-talk
*/
public function onSuccess() {
+ $submittedExpiry = $this->getContext()->getRequest()->getText( 'wp' . $this->expiryFormFieldName );
+ $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
+ }
+
+ protected function makeSuccessMessage( string $submittedExpiry ): MessageValue {
$msgKey = $this->getTitle()->isTalkPage() ? 'addedwatchtext-talk' : 'addedwatchtext';
$params = [];
- $submittedExpiry = $this->getContext()->getRequest()->getText( 'wp' . $this->expiryFormFieldName );
if ( $submittedExpiry ) {
// We can't use $this->watcheditem to get the expiry because it's not been saved at this
// point in the request and so its values are those from before saving.
@@ -259,7 +264,7 @@ class WatchAction extends FormAction {
$msgKey = $isTalk ? 'addedwatchexpiryhours-talk' : 'addedwatchexpiryhours';
}
}
- $this->getOutput()->addWikiMsg( $msgKey, $this->getTitle()->getPrefixedText(), ...$params );
+ return MessageValue::new( $msgKey )->params( $this->getTitle()->getPrefixedText(), ...$params );
}
public function doesWrites() {