2012-11-14 11:17:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-02-16 19:35:21 +00:00
|
|
|
namespace MediaWiki\Tests\Api\Query;
|
|
|
|
|
|
2023-12-11 14:59:55 +00:00
|
|
|
use MediaWiki\CommentStore\CommentStoreComment;
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
2024-01-30 12:58:56 +00:00
|
|
|
use MediaWiki\Permissions\UltimateAuthority;
|
2022-04-14 20:54:04 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2024-02-16 19:35:21 +00:00
|
|
|
use MediaWiki\Tests\Api\ApiTestCase;
|
2024-01-30 12:58:56 +00:00
|
|
|
use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
|
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
2021-11-01 09:49:52 +00:00
|
|
|
|
2012-11-14 11:17:13 +00:00
|
|
|
/**
|
|
|
|
|
* @group API
|
|
|
|
|
* @group Database
|
2013-01-18 19:02:28 +00:00
|
|
|
* @group medium
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \ApiQueryRevisions
|
2012-11-14 11:17:13 +00:00
|
|
|
*/
|
|
|
|
|
class ApiQueryRevisionsTest extends ApiTestCase {
|
2024-01-30 12:58:56 +00:00
|
|
|
use TempUserTestTrait;
|
2012-11-14 11:17:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group medium
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testContentComesWithContentModelAndFormat() {
|
2013-02-14 13:10:38 +00:00
|
|
|
$pageName = 'Help:' . __METHOD__;
|
2021-11-01 09:49:52 +00:00
|
|
|
$page = $this->getExistingTestPage( $pageName );
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$page->newPageUpdater( $user )
|
|
|
|
|
->setContent( SlotRecord::MAIN, new WikitextContent( 'Some text' ) )
|
|
|
|
|
->saveRevision( CommentStoreComment::newUnsavedComment( 'inserting content' ) );
|
2012-11-14 11:17:13 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$apiResult = $this->doApiRequest( [
|
2012-11-14 11:17:13 +00:00
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
|
|
|
|
'titles' => $pageName,
|
|
|
|
|
'rvprop' => 'content',
|
2018-02-16 18:23:45 +00:00
|
|
|
'rvslots' => 'main',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-11-14 11:17:13 +00:00
|
|
|
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $apiResult[0]['query'] );
|
2013-02-14 13:10:38 +00:00
|
|
|
foreach ( $apiResult[0]['query']['pages'] as $page ) {
|
2012-11-14 11:17:13 +00:00
|
|
|
$this->assertArrayHasKey( 'revisions', $page );
|
2013-02-14 13:10:38 +00:00
|
|
|
foreach ( $page['revisions'] as $revision ) {
|
2018-02-16 18:23:45 +00:00
|
|
|
$this->assertArrayHasKey( 'slots', $revision );
|
|
|
|
|
$this->assertArrayHasKey( 'main', $revision['slots'] );
|
|
|
|
|
$this->assertArrayHasKey( 'contentformat', $revision['slots']['main'],
|
2013-02-08 06:45:19 +00:00
|
|
|
'contentformat should be included when asking content so client knows how to interpret it'
|
2012-11-14 11:17:13 +00:00
|
|
|
);
|
2018-02-16 18:23:45 +00:00
|
|
|
$this->assertArrayHasKey( 'contentmodel', $revision['slots']['main'],
|
2013-02-08 06:45:19 +00:00
|
|
|
'contentmodel should be included when asking content so client knows how to interpret it'
|
2012-11-14 11:17:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-03 14:44:06 +00:00
|
|
|
|
2024-01-30 12:58:56 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
* @group medium
|
|
|
|
|
*/
|
|
|
|
|
public function testRevisionMadeByTempUser() {
|
|
|
|
|
$this->enableAutoCreateTempUser();
|
2024-03-26 15:04:36 +00:00
|
|
|
$tempUser = new UserIdentityValue( 1236764321, '~1' );
|
2024-01-30 12:58:56 +00:00
|
|
|
|
|
|
|
|
$title = $this->getNonexistingTestPage( 'TestPage1' )->getTitle();
|
|
|
|
|
$this->editPage(
|
|
|
|
|
$title,
|
|
|
|
|
'Some Content',
|
|
|
|
|
'Create Page',
|
|
|
|
|
NS_MAIN,
|
|
|
|
|
new UltimateAuthority( $tempUser )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$apiResult = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
|
|
|
|
'titles' => 'TestPage1'
|
|
|
|
|
] );
|
|
|
|
|
$this->assertArrayHasKey( 'query', $apiResult[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $apiResult[0]['query'] );
|
|
|
|
|
$this->assertArrayHasKey( 'temp', $apiResult[0]['query']['pages'][1]['revisions'][0] );
|
|
|
|
|
$this->assertTrue( $apiResult[0]['query']['pages'][1]['revisions'][0]['temp'] );
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 14:44:06 +00:00
|
|
|
/**
|
|
|
|
|
* @group medium
|
|
|
|
|
*/
|
|
|
|
|
public function testResolvesPrevNextInDiffto() {
|
|
|
|
|
$pageName = 'Help:' . __METHOD__;
|
|
|
|
|
$page = $this->getExistingTestPage( $pageName );
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$revRecord = $page->newPageUpdater( $user )
|
|
|
|
|
->setContent( SlotRecord::MAIN, new WikitextContent( 'Some text' ) )
|
|
|
|
|
->saveRevision( CommentStoreComment::newUnsavedComment( 'inserting more content' ) );
|
|
|
|
|
|
|
|
|
|
[ $rvDiffToPrev ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
|
|
|
|
'titles' => $pageName,
|
|
|
|
|
'rvdiffto' => 'prev',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getId(),
|
|
|
|
|
$rvDiffToPrev['query']['pages'][$page->getId()]['revisions'][0]['revid']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getId(),
|
|
|
|
|
$rvDiffToPrev['query']['pages'][$page->getId()]['revisions'][0]['diff']['to']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getParentId(),
|
|
|
|
|
$rvDiffToPrev['query']['pages'][$page->getId()]['revisions'][0]['diff']['from']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
[ $rvDiffToNext ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
|
|
|
|
'titles' => $pageName,
|
|
|
|
|
'rvdiffto' => 'next',
|
|
|
|
|
'rvdir' => 'newer'
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getParentId(),
|
|
|
|
|
$rvDiffToNext['query']['pages'][$page->getId()]['revisions'][0]['revid']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getId(),
|
|
|
|
|
$rvDiffToNext['query']['pages'][$page->getId()]['revisions'][0]['diff']['to']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$revRecord->getParentId(),
|
|
|
|
|
$rvDiffToNext['query']['pages'][$page->getId()]['revisions'][0]['diff']['from']
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-11-18 14:19:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideSectionNewTestCases
|
|
|
|
|
* @param string $pageContent
|
|
|
|
|
* @param string $expectedSectionContent
|
|
|
|
|
* @group medium
|
|
|
|
|
*/
|
|
|
|
|
public function testSectionNewReturnsEmptyContentForPageWithSection(
|
|
|
|
|
$pageContent,
|
|
|
|
|
$expectedSectionContent
|
|
|
|
|
) {
|
|
|
|
|
$pageName = 'Help:' . __METHOD__;
|
|
|
|
|
$page = $this->getExistingTestPage( $pageName );
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$revRecord = $page->newPageUpdater( $user )
|
|
|
|
|
->setContent( SlotRecord::MAIN, new WikitextContent( $pageContent ) )
|
|
|
|
|
->saveRevision( CommentStoreComment::newUnsavedComment( 'inserting content' ) );
|
|
|
|
|
|
|
|
|
|
[ $response ] = $this->doApiRequest( [
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
|
|
|
|
'revids' => $revRecord->getId(),
|
|
|
|
|
'rvprop' => 'content|ids',
|
|
|
|
|
'rvslots' => 'main',
|
|
|
|
|
'rvsection' => 'new'
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$expectedSectionContent,
|
|
|
|
|
$response['query']['pages'][$page->getId()]['revisions'][0]['slots']['main']['content']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideSectionNewTestCases() {
|
2022-11-18 14:19:54 +00:00
|
|
|
yield 'page with existing section' => [
|
|
|
|
|
"==A section==\ntext",
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
yield 'page with no sections' => [
|
|
|
|
|
'This page has no sections',
|
|
|
|
|
'This page has no sections'
|
|
|
|
|
];
|
|
|
|
|
}
|
2012-11-14 11:17:13 +00:00
|
|
|
}
|