Merge "Add tests for SkinTemplate::setupSkinUserCss"
[lhc/web/wiklou.git] / tests / phpunit / includes / rcfeed / RCFeedIntegrationTest.php
1 <?php
2
3 class RCFeedIntegrationTest extends MediaWikiTestCase {
4 protected function setUp() {
5 parent::setUp();
6 $this->setMwGlobals( [
7 'wgCanonicalServer' => 'https://example.org',
8 'wgServerName' => 'example.org',
9 'wgScriptPath' => '/w',
10 'wgDBname' => 'example',
11 'wgDBprefix' => '',
12 'wgRCFeeds' => [],
13 'wgRCEngines' => [],
14 ] );
15 }
16
17 /**
18 * @covers RecentChange::notifyRCFeeds
19 * @covers RecentChange::getEngine
20 * @covers RCFeedEngine
21 * @covers JSONRCFeedFormatter::formatArray
22 * @covers MachineReadableRCFeedFormatter::getLine
23 */
24 public function testNotify() {
25 $feed = $this->getMockBuilder( 'RCFeedEngine' )
26 ->setConstructorArgs( [ [ 'formatter' => 'JSONRCFeedFormatter' ] ] )
27 ->setMethods( [ 'send' ] )
28 ->getMock();
29
30 $feed->method( 'send' )
31 ->willReturn( true );
32
33 $feed->expects( $this->once() )
34 ->method( 'send' )
35 ->with( $this->anything(), $this->callback( function ( $line ) {
36 $this->assertJsonStringEqualsJsonString(
37 json_encode( [
38 'id' => null,
39 'type' => 'log',
40 'namespace' => 0,
41 'title' => 'Example',
42 'comment' => '',
43 'timestamp' => 1301644800,
44 'user' => 'UTSysop',
45 'bot' => false,
46 'log_id' => 0,
47 'log_type' => 'move',
48 'log_action' => 'move',
49 'log_params' => [
50 'color' => 'green',
51 'nr' => 42,
52 'pet' => 'cat',
53 ],
54 'log_action_comment' => '',
55 'server_url' => 'https://example.org',
56 'server_name' => 'example.org',
57 'server_script_path' => '/w',
58 'wiki' => 'example',
59 ] ),
60 $line
61 );
62 return true;
63 } ) );
64
65 $this->setMwGlobals( [
66 'wgRCFeeds' => [
67 'myfeed' => [
68 'uri' => 'test://localhost:1234',
69 'formatter' => 'JSONRCFeedFormatter',
70 ],
71 ],
72 'wgRCEngines' => [
73 'test' => $feed,
74 ],
75 ] );
76 $logpage = SpecialPage::getTitleFor( 'Log', 'move' );
77 $user = $this->getTestSysop()->getUser();
78 $rc = RecentChange::newLogEntry(
79 '20110401080000',
80 $logpage, // &$title
81 $user, // &$user
82 '', // $actionComment
83 '127.0.0.1', // $ip
84 'move', // $type
85 'move', // $action
86 Title::makeTitle( 0, 'Example' ), // $target
87 '', // $logComment
88 LogEntryBase::makeParamBlob( [
89 '4::color' => 'green',
90 '5:number:nr' => 42,
91 'pet' => 'cat',
92 ] )
93 );
94 $rc->notifyRCFeeds();
95 }
96 }