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