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