diff options
author | Timo Tijhof <krinklemail@gmail.com> | 2020-04-16 01:46:47 +0100 |
---|---|---|
committer | Kunal Mehta <legoktm@debian.org> | 2023-05-19 15:48:40 +0300 |
commit | 34dc4e6d26b5ea00313d6f4edd02bdd491f79ef2 (patch) | |
tree | 1bc65ec973ded539bd49e49964ff7d3743300cfc /tests/phpunit/includes/changes/RecentChangeTest.php | |
parent | 44504ffaff7933ff638f5bb0dd62bb253970f78b (diff) | |
download | mediawikicore-34dc4e6d26b5ea00313d6f4edd02bdd491f79ef2.tar.gz mediawikicore-34dc4e6d26b5ea00313d6f4edd02bdd491f79ef2.zip |
rcfeed: Add 'notify_url' and 'title_url' to MachineReadableRCFeedFormatter
* Move the current URL logic from IRCColourfulRCFeedFormatter
to a new method RecentChange::getNotifyUrl (covered by tests now).
* Re-use this method in MachineReadableRCFeedFormatter so that
the diff/patrol/rcid etc URL is also available in the modern
JSON-based EventStreams service. And in particular to allow
porting of the legacy irc.wikimedia.org backend to a much simpler
one that is based on this.
* Also expose a title_url field which was previously missing,
and made consumption of the data needlessly difficult.
Bug: T234234
Depends-On: Id740134ef30b2276688d7b7caedb6bb652158761
Change-Id: Ic3e0aebdb61b5c0e5fbed08656db4a1e90b67518
Diffstat (limited to 'tests/phpunit/includes/changes/RecentChangeTest.php')
-rw-r--r-- | tests/phpunit/includes/changes/RecentChangeTest.php | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php b/tests/phpunit/includes/changes/RecentChangeTest.php index bdc0ee7f7b66..49354e2ab8b5 100644 --- a/tests/phpunit/includes/changes/RecentChangeTest.php +++ b/tests/phpunit/includes/changes/RecentChangeTest.php @@ -33,6 +33,17 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase { $this->user = new UserIdentityValue( $user->getId(), $user->getName() ); $this->user_comment = '<User comment about action>'; + + $this->overrideConfigValues( [ + MainConfigNames::CanonicalServer => 'https://example.org', + MainConfigNames::ServerName => 'example.org', + MainConfigNames::ScriptPath => '/w', + MainConfigNames::Script => '/w/index.php', + MainConfigNames::UseRCPatrol => false, + MainConfigNames::UseNPPatrol => false, + MainConfigNames::RCFeeds => [], + MainConfigNames::RCEngines => [], + ] ); } public static function provideAttribs() { @@ -369,6 +380,84 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase { } /** + * @covers RecentChange::getNotifyUrl + */ + public function testGetNotifyUrlForEdit() { + $rc = new RecentChange; + $rc->mAttribs = [ + 'rc_id' => 60, + 'rc_timestamp' => '20110401090000', + 'rc_namespace' => NS_MAIN, + 'rc_title' => 'Example', + 'rc_type' => RC_EDIT, + 'rc_cur_id' => 42, + 'rc_this_oldid' => 50, + 'rc_last_oldid' => 30, + 'rc_patrolled' => 0, + ]; + $this->assertSame( + 'https://example.org/w/index.php?diff=50&oldid=30', + $rc->getNotifyUrl(), 'Notify url' + ); + + $this->overrideConfigValue( MainConfigNames::UseRCPatrol, true ); + $this->assertSame( + 'https://example.org/w/index.php?diff=50&oldid=30&rcid=60', + $rc->getNotifyUrl(), 'Notify url (RC Patrol)' + ); + } + + /** + * @covers RecentChange::getNotifyUrl + */ + public function testGetNotifyUrlForCreate() { + $rc = new RecentChange; + $rc->mAttribs = [ + 'rc_id' => 60, + 'rc_timestamp' => '20110401090000', + 'rc_namespace' => NS_MAIN, + 'rc_title' => 'Example', + 'rc_type' => RC_NEW, + 'rc_cur_id' => 42, + 'rc_this_oldid' => 50, + 'rc_last_oldid' => 0, + 'rc_patrolled' => 0, + ]; + $this->assertSame( + 'https://example.org/w/index.php?oldid=50', + $rc->getNotifyUrl(), 'Notify url' + ); + + $this->overrideConfigValue( MainConfigNames::UseNPPatrol, true ); + $this->assertSame( + 'https://example.org/w/index.php?oldid=50&rcid=60', + $rc->getNotifyUrl(), 'Notify url (NP Patrol)' + ); + } + + /** + * @covers RecentChange::getNotifyUrl + */ + public function testGetNotifyUrlForLog() { + $rc = new RecentChange; + $rc->mAttribs = [ + 'rc_id' => 60, + 'rc_timestamp' => '20110401090000', + 'rc_namespace' => NS_MAIN, + 'rc_title' => 'Example', + 'rc_type' => RC_LOG, + 'rc_cur_id' => 42, + 'rc_this_oldid' => 50, + 'rc_last_oldid' => 0, + 'rc_patrolled' => 2, + 'rc_logid' => 160, + 'rc_log_type' => 'delete', + 'rc_log_action' => 'delete', + ]; + $this->assertSame( null, $rc->getNotifyUrl(), 'Notify url' ); + } + + /** * @return array */ public static function provideIsInRCLifespan() { @@ -519,7 +608,6 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase { * @covers RecentChange::doMarkPatrolled */ public function testDoMarkPatrolledPermissions_NoRcPatrol() { - $this->overrideConfigValue( MainConfigNames::UseRCPatrol, false ); $rc = $this->getDummyEditRecentChange(); $errors = $rc->doMarkPatrolled( $this->mockRegisteredUltimateAuthority() ); $this->assertContains( [ 'rcpatroldisabled' ], $errors ); @@ -529,6 +617,7 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase { * @covers RecentChange::doMarkPatrolled */ public function testDoMarkPatrolled() { + $this->overrideConfigValue( MainConfigNames::UseRCPatrol, true ); $rc = $this->getDummyEditRecentChange(); $errors = $rc->doMarkPatrolled( $this->mockUserAuthorityWithPermissions( $this->user, [ 'patrol', 'autopatrol' ] ) |