1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
<?php
namespace MediaWiki\Tests\Revision;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleValue;
use MediaWikiIntegrationTestCase;
use MockTitleTrait;
use Wikimedia\Assert\PreconditionException;
/**
* @covers \MediaWiki\Revision\MutableRevisionRecord
* @covers \MediaWiki\Revision\RevisionRecord
*/
class MutableRevisionRecordTest extends MediaWikiIntegrationTestCase {
use MockTitleTrait;
public static function provideConstructor() {
$title = Title::makeTitle( NS_MAIN, 'Dummy' );
$title->resetArticleID( 17 );
yield 'local wiki, with title' => [ $title, PageIdentity::LOCAL ];
yield 'local wiki' => [
new PageIdentityValue( 17, NS_MAIN, 'Dummy', PageIdentity::LOCAL ),
PageIdentity::LOCAL,
];
yield 'foreign wiki' => [
new PageIdentityValue( 17, NS_MAIN, 'Dummy', 'acmewiki' ),
'acmewiki',
PreconditionException::class
];
}
/**
* @dataProvider provideConstructor
*
* @param PageIdentity $page
* @param string|false $wikiId
* @param string|null $expectedException
*/
public function testConstructorAndGetters(
PageIdentity $page,
$wikiId = RevisionRecord::LOCAL,
?string $expectedException = null
) {
$rec = new MutableRevisionRecord( $page, $wikiId );
$this->assertTrue( $page->isSamePageAs( $rec->getPage() ), 'getPage' );
$this->assertSame( $wikiId, $rec->getWikiId(), 'getWikiId' );
if ( $expectedException ) {
$this->expectException( $expectedException );
$rec->getPageAsLinkTarget();
} else {
$this->assertTrue(
TitleValue::newFromPage( $page )->isSameLinkAs( $rec->getPageAsLinkTarget() ),
'getPageAsLinkTarget'
);
}
}
}
|