Merge "Remove use of BagOStuff TTL constants from unrelated code"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryRecentChangesIntegrationTest.php
blobcd477610a64f137046f2abd1380971a49fec6ce5
1 <?php
3 namespace MediaWiki\Tests\Api\Query;
5 use MediaWiki\Linker\LinkTarget;
6 use MediaWiki\Permissions\Authority;
7 use MediaWiki\Tests\Api\ApiTestCase;
8 use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
9 use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
10 use MediaWiki\Title\TitleValue;
11 use MediaWiki\User\User;
12 use MediaWiki\Watchlist\WatchedItemQueryService;
13 use RecentChange;
15 /**
16 * @group API
17 * @group Database
18 * @group medium
20 * @covers \MediaWiki\Api\ApiQueryRecentChanges
22 class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
23 use MockAuthorityTrait;
24 use TempUserTestTrait;
26 private function getLoggedInTestUser() {
27 return $this->getTestUser()->getUser();
30 private function doPageEdit( Authority $performer, $target, $summary ) {
31 static $i = 0;
33 $this->editPage(
34 $target,
35 __CLASS__ . $i++,
36 $summary,
37 NS_MAIN,
38 $performer
42 private function doMinorPageEdit( User $user, LinkTarget $target, $summary ) {
43 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
44 $page->doUserEditContent(
45 $page->getContentHandler()->unserializeContent( __CLASS__ ),
46 $user,
47 $summary,
48 EDIT_MINOR
52 private function doBotPageEdit( User $user, LinkTarget $target, $summary ) {
53 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
54 $page->doUserEditContent(
55 $page->getContentHandler()->unserializeContent( __CLASS__ ),
56 $user,
57 $summary,
58 EDIT_FORCE_BOT
62 private function doAnonPageEdit( LinkTarget $target, $summary ) {
63 $this->disableAutoCreateTempUser();
64 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
65 $page->doUserEditContent(
66 $page->getContentHandler()->unserializeContent( __CLASS__ ),
67 $this->getServiceContainer()->getUserFactory()->newAnonymous(),
68 $summary
72 private function doTempPageEdit( LinkTarget $target, $summary ) {
73 // Set up temp user config
74 $this->enableAutoCreateTempUser();
75 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
76 $page->doUserEditContent(
77 $page->getContentHandler()->unserializeContent( __CLASS__ ),
78 $this->mockTempUltimateAuthority(),
79 $summary
83 /**
84 * Performs a batch of page edits as a specified user
85 * @param User $user
86 * @param array $editData associative array, keys:
87 * - target => LinkTarget page to edit
88 * - summary => string edit summary
89 * - minorEdit => bool mark as minor edit if true (defaults to false)
90 * - botEdit => bool mark as bot edit if true (defaults to false)
92 private function doPageEdits( User $user, array $editData ) {
93 foreach ( $editData as $singleEditData ) {
94 if ( array_key_exists( 'minorEdit', $singleEditData ) && $singleEditData['minorEdit'] ) {
95 $this->doMinorPageEdit(
96 $user,
97 $singleEditData['target'],
98 $singleEditData['summary']
100 continue;
102 if ( array_key_exists( 'botEdit', $singleEditData ) && $singleEditData['botEdit'] ) {
103 $this->doBotPageEdit(
104 $user,
105 $singleEditData['target'],
106 $singleEditData['summary']
108 continue;
110 $this->doPageEdit(
111 $user,
112 $singleEditData['target'],
113 $singleEditData['summary']
118 private function doListRecentChangesRequest( array $params = [] ) {
119 return $this->doApiRequest(
120 array_merge(
121 [ 'action' => 'query', 'list' => 'recentchanges' ],
122 $params
124 null,
125 false,
126 $this->getLoggedInTestUser()
130 private function doGeneratorRecentChangesRequest( array $params = [] ) {
131 return $this->doApiRequest(
132 array_merge(
133 [ 'action' => 'query', 'generator' => 'recentchanges' ],
134 $params
136 null,
137 false,
138 $this->getLoggedInTestUser()
142 private function getItemsFromRecentChangesResult( array $result ) {
143 return $result[0]['query']['recentchanges'];
146 public function testListRecentChanges_returnsRCInfo() {
147 $target = new TitleValue( NS_MAIN, 'ApiQueryRecentChangesIntegrationTestPage' );
148 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
150 $result = $this->doListRecentChangesRequest();
151 $items = $this->getItemsFromRecentChangesResult( $result );
153 // Default contains at least props for 'title', 'timestamp', and 'ids'.
154 $this->assertCount( 1, $items );
155 $item = $items[0];
156 foreach ( [
157 'pageid',
158 'revid',
159 'old_revid',
160 'rcid',
161 'timestamp',
162 ] as $key ) {
163 // Assert key but ignore value
164 $this->assertArrayHasKey( $key, $item );
165 unset( $item[ $key ] );
168 // The rest must equal exactly, with no additional keys (e.g. 'minor' or 'bot').
169 $this->assertEquals(
171 'type' => 'new',
172 'ns' => NS_MAIN,
173 'title' => 'ApiQueryRecentChangesIntegrationTestPage',
175 $item
179 public function testIdsPropParameter() {
180 $target = new TitleValue( NS_MAIN, 'ApiQueryRecentChangesIntegrationTestPage' );
181 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
182 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'ids' ] );
183 $items = $this->getItemsFromRecentChangesResult( $result );
185 $this->assertCount( 1, $items );
186 $item = $items[0];
187 foreach ( [
188 'pageid',
189 'revid',
190 'old_revid',
191 'rcid',
192 ] as $key ) {
193 // Assert key but ignore value
194 $this->assertArrayHasKey( $key, $item );
195 unset( $item[ $key ] );
198 $this->assertEquals(
200 'type' => 'new',
202 $item
206 public function testTitlePropParameter() {
207 $this->doPageEdits(
208 $this->getLoggedInTestUser(),
211 'target' => new TitleValue( NS_MAIN, 'Thing' ),
212 'summary' => 'Create the page',
215 'target' => new TitleValue( NS_TALK, 'Thing' ),
216 'summary' => 'Create Talk page',
221 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] );
223 $this->assertEquals(
226 'type' => 'new',
227 'ns' => NS_TALK,
228 'title' => 'Talk:Thing',
231 'type' => 'new',
232 'ns' => NS_MAIN,
233 'title' => 'Thing',
236 $this->getItemsFromRecentChangesResult( $result )
240 public function testFlagsPropParameter() {
241 $this->doPageEdits(
242 $this->getLoggedInTestUser(),
245 'summary' => 'Create the page',
246 'target' => new TitleValue( NS_MAIN, 'Regularpage' ),
249 'summary' => 'Create the page for minor change',
250 'target' => new TitleValue( NS_MAIN, 'Minorpage' ),
253 'summary' => 'Make minor content',
254 'target' => new TitleValue( NS_MAIN, 'Minorpage' ),
255 'minorEdit' => true,
258 'summary' => 'Create the page as a bot',
259 'target' => new TitleValue( NS_MAIN, 'Botpage' ),
260 'botEdit' => true,
265 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'flags' ] );
267 $this->assertEquals(
270 'type' => 'new',
271 'new' => true,
272 'minor' => false,
273 'bot' => true,
276 'type' => 'edit',
277 'new' => false,
278 'minor' => true,
279 'bot' => false,
282 'type' => 'new',
283 'new' => true,
284 'minor' => false,
285 'bot' => false,
288 'type' => 'new',
289 'new' => true,
290 'minor' => false,
291 'bot' => false,
294 $this->getItemsFromRecentChangesResult( $result )
298 public function testUserPropParameter() {
299 $userEditTarget = new TitleValue( NS_MAIN, 'Foo' );
300 $anonEditTarget = new TitleValue( NS_MAIN, 'Bar' );
301 $tempEditTarget = new TitleValue( NS_MAIN, 'Baz' );
302 $this->doPageEdit( $this->getLoggedInTestUser(), $userEditTarget, 'Create the page' );
303 $this->doAnonPageEdit( $anonEditTarget, 'Create the page' );
305 // Test that querying for anonymous edits works even if temporary accounts are disabled
306 $this->disableAutoCreateTempUser();
307 $result = $this->doListRecentChangesRequest( [
308 'rcprop' => 'user',
309 'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON,
310 ] );
311 $this->assertEquals(
314 'type' => 'new',
315 'user' => $this->getLoggedInTestUser()->getName(),
318 $this->getItemsFromRecentChangesResult( $result )
321 // Test that temporary accounts are treated as anonymous
322 $this->doTempPageEdit( $tempEditTarget, 'Create the page' );
323 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'user' ] );
324 $this->assertEquals(
327 'type' => 'new',
328 'temp' => true,
329 'user' => '~2024-1',
332 'type' => 'new',
333 'anon' => true,
334 'user' => '127.0.0.1',
337 'type' => 'new',
338 'user' => $this->getLoggedInTestUser()->getName(),
341 $this->getItemsFromRecentChangesResult( $result )
345 public function testUserIdPropParameter() {
346 $user = $this->getLoggedInTestUser();
347 $userEditTarget = new TitleValue( NS_MAIN, 'Foo' );
348 $anonEditTarget = new TitleValue( NS_MAIN, 'Bar' );
349 $this->doPageEdit( $user, $userEditTarget, 'Create the page' );
350 $this->doAnonPageEdit( $anonEditTarget, 'Create the page' );
352 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'userid' ] );
354 $this->assertEquals(
357 'type' => 'new',
358 'anon' => true,
359 'userid' => 0,
362 'type' => 'new',
363 'userid' => $user->getId(),
366 $this->getItemsFromRecentChangesResult( $result )
370 public function testCommentPropParameter() {
371 $target = new TitleValue( NS_MAIN, 'Thing' );
372 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' );
374 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'comment' ] );
376 $this->assertEquals(
379 'type' => 'new',
380 'comment' => 'Create the <b>page</b>',
383 $this->getItemsFromRecentChangesResult( $result )
387 public function testParsedCommentPropParameter() {
388 $target = new TitleValue( NS_MAIN, 'Thing' );
389 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the <b>page</b>' );
391 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'parsedcomment' ] );
393 $this->assertEquals(
396 'type' => 'new',
397 'parsedcomment' => 'Create the &lt;b&gt;page&lt;/b&gt;',
400 $this->getItemsFromRecentChangesResult( $result )
404 public function testTimestampPropParameter() {
405 $target = new TitleValue( NS_MAIN, 'Thing' );
406 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
408 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'timestamp' ] );
409 $items = $this->getItemsFromRecentChangesResult( $result );
411 $this->assertCount( 1, $items );
412 $this->assertIsString( $items[0]['timestamp'] );
415 public function testSizesPropParameter() {
416 $target = new TitleValue( NS_MAIN, 'Thing' );
417 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
419 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'sizes' ] );
421 $this->assertEquals(
424 'type' => 'new',
425 'oldlen' => 0,
426 // strlen( __CLASS__ ) - 2 = 64
427 'newlen' => 64,
430 $this->getItemsFromRecentChangesResult( $result )
434 private function createPageAndDeleteIt( LinkTarget $target ) {
435 $wikiPage = $this->getServiceContainer()->getWikiPageFactory()->newFromLinkTarget( $target );
436 $this->doPageEdit( $this->getLoggedInTestUser(),
437 $wikiPage,
438 'Create the page that will be deleted'
440 $this->deletePage( $wikiPage, 'Important Reason' );
443 public function testLoginfoPropParameter() {
444 $target = new TitleValue( NS_MAIN, 'Thing' );
445 $this->createPageAndDeleteIt( $target );
447 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'loginfo' ] );
448 $items = $this->getItemsFromRecentChangesResult( $result );
450 $this->assertCount( 1, $items );
451 foreach ( [
452 'logid',
453 ] as $key ) {
454 // Assert key but ignore value
455 $this->assertArrayHasKey( $key, $items[0] );
456 unset( $items[0][ $key ] );
458 $this->assertEquals(
460 'type' => 'log',
461 'logtype' => 'delete',
462 'logaction' => 'delete',
463 'logparams' => [],
465 $items[0]
469 public function testEmptyPropParameter() {
470 $user = $this->getLoggedInTestUser();
471 $target = new TitleValue( NS_MAIN, 'Thing' );
472 $this->doPageEdit( $user, $target, 'Create the page' );
474 $result = $this->doListRecentChangesRequest( [ 'rcprop' => '' ] );
476 $this->assertEquals(
479 'type' => 'new',
482 $this->getItemsFromRecentChangesResult( $result )
486 public function testNamespaceParam() {
487 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
488 $talkTarget = new TitleValue( NS_TALK, 'Foo' );
489 $this->doPageEdits(
490 $this->getLoggedInTestUser(),
493 'target' => $subjectTarget,
494 'summary' => 'Create the page',
497 'target' => $talkTarget,
498 'summary' => 'Create the talk page',
503 $result = $this->doListRecentChangesRequest( [ 'rcnamespace' => '0', 'rcprop' => 'title' ] );
504 $items = $this->getItemsFromRecentChangesResult( $result );
506 $this->assertCount( 1, $items );
507 $this->assertEquals(
509 'type' => 'new',
510 'ns' => NS_MAIN,
511 'title' => 'Foo',
513 $items[0]
517 public function testShowAnonParams() {
518 $target = new TitleValue( NS_MAIN, 'Thing' );
519 $this->doAnonPageEdit( $target, 'Create the page' );
521 $tempEditTarget = new TitleValue( NS_MAIN, 'Baz' );
522 $this->doTempPageEdit( $tempEditTarget, 'Create the page' );
524 $resultAnon = $this->doListRecentChangesRequest( [
525 'rcprop' => 'user',
526 'rcshow' => WatchedItemQueryService::FILTER_ANON
527 ] );
528 $resultNotAnon = $this->doListRecentChangesRequest( [
529 'rcprop' => 'user',
530 'rcshow' => WatchedItemQueryService::FILTER_NOT_ANON
531 ] );
533 $items = $this->getItemsFromRecentChangesResult( $resultAnon );
534 $this->assertCount( 2, $items );
535 $this->assertEquals(
538 'type' => 'new',
539 'temp' => true,
540 'user' => '~2024-1',
543 'type' => 'new',
544 'anon' => true,
545 'user' => '127.0.0.1',
548 $items
550 $this->assertSame( [], $this->getItemsFromRecentChangesResult( $resultNotAnon ) );
553 public function testNewAndEditTypeParameters() {
554 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
555 $talkTarget = new TitleValue( NS_TALK, 'Foo' );
556 $this->doPageEdits(
557 $this->getLoggedInTestUser(),
560 'target' => $subjectTarget,
561 'summary' => 'Create the page',
564 'target' => $subjectTarget,
565 'summary' => 'Change the content',
568 'target' => $talkTarget,
569 'summary' => 'Create Talk page',
574 $resultNew = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'new' ] );
575 $resultEdit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'edit' ] );
577 $this->assertEquals(
580 'type' => 'new',
581 'ns' => NS_TALK,
582 'title' => 'Talk:Foo',
585 'type' => 'new',
586 'ns' => NS_MAIN,
587 'title' => 'Foo',
590 $this->getItemsFromRecentChangesResult( $resultNew )
592 $this->assertEquals(
595 'type' => 'edit',
596 'ns' => NS_MAIN,
597 'title' => 'Foo',
600 $this->getItemsFromRecentChangesResult( $resultEdit )
604 public function testLogTypeParameters() {
605 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
606 $talkTarget = new TitleValue( NS_TALK, 'Foo' );
607 $this->createPageAndDeleteIt( $subjectTarget );
608 $this->doPageEdit( $this->getLoggedInTestUser(), $talkTarget, 'Create Talk page' );
610 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'log' ] );
612 $this->assertEquals(
615 'type' => 'log',
616 'ns' => NS_MAIN,
617 'title' => 'Foo',
620 $this->getItemsFromRecentChangesResult( $result )
624 private function getExternalRC( LinkTarget $target ) {
625 $title = $this->getServiceContainer()->getTitleFactory()->newFromLinkTarget( $target );
627 $rc = new RecentChange;
628 $rc->mAttribs = [
629 'rc_timestamp' => wfTimestamp( TS_MW ),
630 'rc_namespace' => $title->getNamespace(),
631 'rc_title' => $title->getDBkey(),
632 'rc_type' => RC_EXTERNAL,
633 'rc_source' => 'foo',
634 'rc_minor' => 0,
635 'rc_cur_id' => $title->getArticleID(),
636 'rc_user' => 0,
637 'rc_user_text' => 'm>External User',
638 'rc_comment' => '',
639 'rc_comment_text' => '',
640 'rc_comment_data' => null,
641 'rc_this_oldid' => $title->getLatestRevID(),
642 'rc_last_oldid' => $title->getLatestRevID(),
643 'rc_bot' => 0,
644 'rc_ip' => '',
645 'rc_patrolled' => 0,
646 'rc_new' => 0,
647 'rc_old_len' => $title->getLength(),
648 'rc_new_len' => $title->getLength(),
649 'rc_deleted' => 0,
650 'rc_logid' => 0,
651 'rc_log_type' => null,
652 'rc_log_action' => '',
653 'rc_params' => '',
655 $rc->mExtra = [
656 'prefixedDBkey' => $title->getPrefixedDBkey(),
657 'lastTimestamp' => 0,
658 'oldSize' => $title->getLength(),
659 'newSize' => $title->getLength(),
660 'pageStatus' => 'changed'
663 return $rc;
666 public function testExternalTypeParameters() {
667 $user = $this->getLoggedInTestUser();
668 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
669 $talkTarget = new TitleValue( NS_TALK, 'Foo' );
670 $this->doPageEdit( $user, $subjectTarget, 'Create the page' );
671 $this->doPageEdit( $user, $talkTarget, 'Create Talk page' );
672 $rc = $this->getExternalRC( $subjectTarget );
673 $rc->save();
675 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'external' ] );
677 $this->assertEquals(
680 'type' => 'external',
681 'ns' => NS_MAIN,
682 'title' => 'Foo',
685 $this->getItemsFromRecentChangesResult( $result )
689 public function testCategorizeTypeParameter() {
690 $user = $this->getLoggedInTestUser();
691 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
692 $categoryTarget = new TitleValue( NS_CATEGORY, 'Bar' );
693 $this->doPageEdits(
694 $user,
697 'target' => $categoryTarget,
698 'summary' => 'Create the category',
701 'target' => $subjectTarget,
702 'summary' => 'Create the page and add it to the category',
706 $titleFactory = $this->getServiceContainer()->getTitleFactory();
707 $title = $titleFactory->newFromLinkTarget( $subjectTarget );
708 $revision = $this->getServiceContainer()
709 ->getRevisionLookup()
710 ->getRevisionByTitle( $title );
712 $comment = $revision->getComment();
713 $rc = RecentChange::newForCategorization(
714 $revision->getTimestamp(),
715 $titleFactory->newFromLinkTarget( $categoryTarget ),
716 $user,
717 $comment ? $comment->text : '',
718 $title,
720 $revision->getId(),
721 null,
722 false
724 $rc->save();
726 $result = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rctype' => 'categorize' ] );
728 $this->assertEquals(
731 'type' => 'categorize',
732 'ns' => NS_CATEGORY,
733 'title' => 'Category:Bar',
736 $this->getItemsFromRecentChangesResult( $result )
740 public function testLimitParam() {
741 $this->doPageEdits(
742 $this->getLoggedInTestUser(),
745 'target' => new TitleValue( NS_MAIN, 'Foo' ),
746 'summary' => 'Create the page',
749 'target' => new TitleValue( NS_TALK, 'Foo' ),
750 'summary' => 'Create Talk page',
753 'target' => new TitleValue( NS_MAIN, 'Bar' ),
754 'summary' => 'Create another page',
759 $resultWithoutLimit = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] );
760 $resultWithLimit = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] );
762 $this->assertEquals(
765 'type' => 'new',
766 'ns' => NS_MAIN,
767 'title' => 'Bar'
770 'type' => 'new',
771 'ns' => NS_TALK,
772 'title' => 'Talk:Foo'
775 'type' => 'new',
776 'ns' => NS_MAIN,
777 'title' => 'Foo'
780 $this->getItemsFromRecentChangesResult( $resultWithoutLimit )
782 $this->assertEquals(
785 'type' => 'new',
786 'ns' => NS_MAIN,
787 'title' => 'Bar'
790 'type' => 'new',
791 'ns' => NS_TALK,
792 'title' => 'Talk:Foo'
795 $this->getItemsFromRecentChangesResult( $resultWithLimit )
797 $this->assertArrayHasKey( 'rccontinue', $resultWithLimit[0]['continue'] );
800 public function testAllRevParam() {
801 $target = new TitleValue( NS_MAIN, 'Thing' );
802 $this->doPageEdits(
803 $this->getLoggedInTestUser(),
806 'target' => $target,
807 'summary' => 'Create the page',
810 'target' => $target,
811 'summary' => 'Change the content',
816 $resultAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title', 'rcallrev' => '' ] );
817 $resultNoAllRev = $this->doListRecentChangesRequest( [ 'rcprop' => 'title' ] );
819 $this->assertEquals(
822 'type' => 'edit',
823 'ns' => NS_MAIN,
824 'title' => 'Thing',
827 'type' => 'new',
828 'ns' => NS_MAIN,
829 'title' => 'Thing',
832 $this->getItemsFromRecentChangesResult( $resultNoAllRev )
834 $this->assertEquals(
837 'type' => 'edit',
838 'ns' => NS_MAIN,
839 'title' => 'Thing',
842 'type' => 'new',
843 'ns' => NS_MAIN,
844 'title' => 'Thing',
847 $this->getItemsFromRecentChangesResult( $resultAllRev )
851 public function testDirParams() {
852 $subjectTarget = new TitleValue( NS_MAIN, 'Foo' );
853 $talkTarget = new TitleValue( NS_TALK, 'Foo' );
854 $this->doPageEdits(
855 $this->getLoggedInTestUser(),
858 'target' => $subjectTarget,
859 'summary' => 'Create the page',
862 'target' => $talkTarget,
863 'summary' => 'Create Talk page',
868 $resultDirOlder = $this->doListRecentChangesRequest(
869 [ 'rcdir' => 'older', 'rcprop' => 'title' ]
871 $resultDirNewer = $this->doListRecentChangesRequest(
872 [ 'rcdir' => 'newer', 'rcprop' => 'title' ]
875 $this->assertEquals(
878 'type' => 'new',
879 'ns' => NS_TALK,
880 'title' => 'Talk:Foo'
883 'type' => 'new',
884 'ns' => NS_MAIN,
885 'title' => 'Foo'
888 $this->getItemsFromRecentChangesResult( $resultDirOlder )
890 $this->assertEquals(
893 'type' => 'new',
894 'ns' => NS_MAIN,
895 'title' => 'Foo'
898 'type' => 'new',
899 'ns' => NS_TALK,
900 'title' => 'Talk:Foo'
903 $this->getItemsFromRecentChangesResult( $resultDirNewer )
907 public function testTitleParams() {
908 $this->doPageEdits(
909 $this->getLoggedInTestUser(),
912 'target' => new TitleValue( NS_MAIN, 'Foo' ),
913 'summary' => 'Create the page',
916 'target' => new TitleValue( NS_TALK, 'Bar' ),
917 'summary' => 'Create the page',
920 'target' => new TitleValue( NS_MAIN, 'Quux' ),
921 'summary' => 'Create the page',
926 $result1 = $this->doListRecentChangesRequest(
928 'rctitle' => 'Foo',
929 'rcprop' => 'title'
932 $result2 = $this->doListRecentChangesRequest(
934 'rctitle' => 'Talk:Bar',
935 'rcprop' => 'title'
939 $this->assertEquals(
942 'type' => 'new',
943 'ns' => NS_MAIN,
944 'title' => 'Foo'
947 $this->getItemsFromRecentChangesResult( $result1 )
949 $this->assertEquals(
952 'type' => 'new',
953 'ns' => NS_TALK,
954 'title' => 'Talk:Bar'
957 $this->getItemsFromRecentChangesResult( $result2 )
961 public function testStartEndParams() {
962 $target = new TitleValue( NS_MAIN, 'Thing' );
963 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
965 $resultStart = $this->doListRecentChangesRequest( [
966 'rcstart' => '20010115000000',
967 'rcdir' => 'newer',
968 'rcprop' => 'title',
969 ] );
970 $resultEnd = $this->doListRecentChangesRequest( [
971 'rcend' => '20010115000000',
972 'rcdir' => 'newer',
973 'rcprop' => 'title',
974 ] );
976 $this->assertEquals(
979 'type' => 'new',
980 'ns' => NS_MAIN,
981 'title' => 'Thing',
984 $this->getItemsFromRecentChangesResult( $resultStart )
986 $this->assertSame( [], $this->getItemsFromRecentChangesResult( $resultEnd ) );
989 public function testContinueParam() {
990 $this->doPageEdits(
991 $this->getLoggedInTestUser(),
994 'target' => new TitleValue( NS_MAIN, 'Foo' ),
995 'summary' => 'Create the page',
998 'target' => new TitleValue( NS_TALK, 'Foo' ),
999 'summary' => 'Create Talk page',
1002 'target' => new TitleValue( NS_MAIN, 'Bar' ),
1003 'summary' => 'Create the page',
1008 $firstResult = $this->doListRecentChangesRequest( [ 'rclimit' => 2, 'rcprop' => 'title' ] );
1010 $continuationParam = $firstResult[0]['continue']['rccontinue'];
1012 $continuedResult = $this->doListRecentChangesRequest(
1013 [ 'rccontinue' => $continuationParam, 'rcprop' => 'title' ]
1016 $this->assertEquals(
1019 'type' => 'new',
1020 'ns' => NS_MAIN,
1021 'title' => 'Bar',
1024 'type' => 'new',
1025 'ns' => NS_TALK,
1026 'title' => 'Talk:Foo',
1029 $this->getItemsFromRecentChangesResult( $firstResult )
1031 $this->assertEquals(
1034 'type' => 'new',
1035 'ns' => NS_MAIN,
1036 'title' => 'Foo',
1039 $this->getItemsFromRecentChangesResult( $continuedResult )
1043 public function testGeneratorRecentChangesPropInfo_returnsRCPages() {
1044 $target = new TitleValue( NS_MAIN, 'Thing' );
1045 $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );
1047 $result = $this->doGeneratorRecentChangesRequest( [ 'prop' => 'info' ] );
1049 // $result[0]['query']['pages'] uses page ids as keys. Page ids don't matter here, so drop them
1050 $pages = array_values( $result[0]['query']['pages'] );
1051 $this->assertCount( 1, $pages );
1053 $page = $pages[0];
1054 foreach ( [
1055 'pageid',
1056 'touched',
1057 'lastrevid',
1058 'length',
1059 ] as $key ) {
1060 // Assert key but ignore value
1061 $this->assertArrayHasKey( $key, $page );
1062 unset( $page[ $key ] );
1065 $this->assertEquals(
1067 'ns' => NS_MAIN,
1068 'title' => 'Thing',
1069 'new' => true,
1070 'contentmodel' => 'wikitext',
1071 'pagelanguage' => 'en',
1072 'pagelanguagehtmlcode' => 'en',
1073 'pagelanguagedir' => 'ltr',
1075 $page