| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\RCFeed\FormattedRCFeed; |
| 5 |
use MediaWiki\RCFeed\JSONRCFeedFormatter; |
| 6 |
use MediaWiki\SpecialPage\SpecialPage; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class RCFeedIntegrationTest extends MediaWikiIntegrationTestCase { |
| 19 |
protected function setUp(): void { |
| 20 |
parent::setUp(); |
| 21 |
$this->overrideConfigValues( [ |
| 22 |
MainConfigNames::CanonicalServer => 'https://example.org', |
| 23 |
MainConfigNames::ServerName => 'example.org', |
| 24 |
MainConfigNames::ScriptPath => '/w', |
| 25 |
MainConfigNames::Script => '/w/index.php', |
| 26 |
MainConfigNames::DBname => 'example', |
| 27 |
MainConfigNames::DBprefix => self::dbPrefix(), |
| 28 |
MainConfigNames::RCFeeds => [], |
| 29 |
MainConfigNames::RCEngines => [], |
| 30 |
] ); |
| 31 |
} |
| 32 |
|
| 33 |
public function testNotify() { |
| 34 |
$feed = $this->getMockBuilder( FormattedRCFeed::class ) |
| 35 |
->setConstructorArgs( [ [ 'formatter' => JSONRCFeedFormatter::class ] ] ) |
| 36 |
->onlyMethods( [ 'send' ] ) |
| 37 |
->getMock(); |
| 38 |
|
| 39 |
$feed->expects( $this->once() ) |
| 40 |
->method( 'send' ) |
| 41 |
->willReturn( true ) |
| 42 |
->with( $this->anything(), $this->callback( function ( $line ) { |
| 43 |
$this->assertJsonStringEqualsJsonString( |
| 44 |
json_encode( [ |
| 45 |
'id' => null, |
| 46 |
'type' => 'log', |
| 47 |
'namespace' => 0, |
| 48 |
'title' => 'Example', |
| 49 |
'title_url' => 'https://example.org/wiki/Example', |
| 50 |
'comment' => '', |
| 51 |
'timestamp' => 1301644800, |
| 52 |
'user' => 'UTSysop', |
| 53 |
'bot' => false, |
| 54 |
'notify_url' => null, |
| 55 |
'log_id' => 0, |
| 56 |
'log_type' => 'move', |
| 57 |
'log_action' => 'move', |
| 58 |
'log_params' => [ |
| 59 |
'color' => 'green', |
| 60 |
'nr' => 42, |
| 61 |
'pet' => 'cat', |
| 62 |
], |
| 63 |
'log_action_comment' => '', |
| 64 |
'server_url' => 'https://example.org', |
| 65 |
'server_name' => 'example.org', |
| 66 |
'server_script_path' => '/w', |
| 67 |
'wiki' => 'example-' . self::dbPrefix(), |
| 68 |
] ), |
| 69 |
$line |
| 70 |
); |
| 71 |
return true; |
| 72 |
} ) ); |
| 73 |
|
| 74 |
$this->overrideConfigValue( |
| 75 |
MainConfigNames::RCFeeds, |
| 76 |
[ |
| 77 |
'myfeed' => [ |
| 78 |
'class' => $feed, |
| 79 |
'uri' => 'test://localhost:1234', |
| 80 |
'formatter' => JSONRCFeedFormatter::class, |
| 81 |
], |
| 82 |
] |
| 83 |
); |
| 84 |
$logpage = SpecialPage::getTitleFor( 'Log', 'move' ); |
| 85 |
$user = $this->getTestSysop()->getUser(); |
| 86 |
$rc = RecentChange::newLogEntry( |
| 87 |
'20110401080000', |
| 88 |
$logpage, |
| 89 |
$user, |
| 90 |
'', |
| 91 |
'127.0.0.1', |
| 92 |
'move', |
| 93 |
'move', |
| 94 |
Title::makeTitle( 0, 'Example' ), |
| 95 |
'', |
| 96 |
LogEntryBase::makeParamBlob( [ |
| 97 |
'4::color' => 'green', |
| 98 |
'5:number:nr' => 42, |
| 99 |
'pet' => 'cat', |
| 100 |
] ) |
| 101 |
); |
| 102 |
$rc->notifyRCFeeds(); |
| 103 |
} |
| 104 |
} |