RCFeedIntegrationTest.php 2.3 KB

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