2017-11-15 12:02:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-20 17:29:04 +00:00
|
|
|
namespace MediaWiki\Tests\Revision;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
2021-01-11 22:36:33 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
|
|
|
|
use MediaWiki\Page\PageIdentityValue;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2021-01-25 14:22:41 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-06-30 15:09:24 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2021-01-11 22:36:33 +00:00
|
|
|
use MockTitleTrait;
|
2017-11-15 12:02:40 +00:00
|
|
|
use Title;
|
2021-01-11 22:36:33 +00:00
|
|
|
use TitleValue;
|
|
|
|
|
use Wikimedia\Assert\PreconditionException;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\MutableRevisionRecord
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionRecord
|
2017-11-15 12:02:40 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class MutableRevisionRecordTest extends MediaWikiIntegrationTestCase {
|
2021-01-11 22:36:33 +00:00
|
|
|
use MockTitleTrait;
|
2018-04-17 16:51:38 +00:00
|
|
|
|
|
|
|
|
public function provideConstructor() {
|
|
|
|
|
$title = Title::newFromText( 'Dummy' );
|
|
|
|
|
$title->resetArticleID( 17 );
|
2021-01-11 22:36:33 +00:00
|
|
|
yield 'local wiki, with title' => [ $title, PageIdentity::LOCAL ];
|
|
|
|
|
yield 'local wiki' => [
|
|
|
|
|
new PageIdentityValue( 17, NS_MAIN, 'Dummy', PageIdentity::LOCAL ),
|
|
|
|
|
PageIdentity::LOCAL,
|
2018-04-17 16:51:38 +00:00
|
|
|
];
|
2021-01-11 22:36:33 +00:00
|
|
|
yield 'foreign wiki' => [
|
|
|
|
|
new PageIdentityValue( 17, NS_MAIN, 'Dummy', 'acmewiki' ),
|
|
|
|
|
'acmewiki',
|
|
|
|
|
PreconditionException::class
|
|
|
|
|
];
|
2018-04-17 16:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideConstructor
|
|
|
|
|
*
|
2021-01-11 22:36:33 +00:00
|
|
|
* @param PageIdentity $page
|
2018-04-17 16:51:38 +00:00
|
|
|
* @param bool $wikiId
|
2021-01-11 22:36:33 +00:00
|
|
|
* @param string|null $expectedException
|
2018-04-17 16:51:38 +00:00
|
|
|
*/
|
|
|
|
|
public function testConstructorAndGetters(
|
2021-01-11 22:36:33 +00:00
|
|
|
PageIdentity $page,
|
2021-01-25 14:22:41 +00:00
|
|
|
$wikiId = RevisionRecord::LOCAL,
|
2021-01-11 22:36:33 +00:00
|
|
|
string $expectedException = null
|
2018-04-17 16:51:38 +00:00
|
|
|
) {
|
2021-01-11 22:36:33 +00:00
|
|
|
$rec = new MutableRevisionRecord( $page, $wikiId );
|
2018-04-17 16:51:38 +00:00
|
|
|
|
2021-01-11 22:36:33 +00:00
|
|
|
$this->assertTrue( $page->isSamePageAs( $rec->getPage() ), 'getPage' );
|
2018-04-17 16:51:38 +00:00
|
|
|
$this->assertSame( $wikiId, $rec->getWikiId(), 'getWikiId' );
|
2021-01-11 22:36:33 +00:00
|
|
|
|
|
|
|
|
if ( $expectedException ) {
|
|
|
|
|
$this->expectException( $expectedException );
|
|
|
|
|
$rec->getPageAsLinkTarget();
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
TitleValue::newFromPage( $page )->isSameLinkAs( $rec->getPageAsLinkTarget() ),
|
|
|
|
|
'getPageAsLinkTarget'
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-04-17 16:51:38 +00:00
|
|
|
}
|
2017-11-15 12:02:40 +00:00
|
|
|
}
|