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