2012-05-02 17:34:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2012-05-13 22:02:29 +00:00
|
|
|
* @group ContentHandler
|
2012-05-02 17:34:35 +00:00
|
|
|
* @group Database
|
2012-08-30 17:17:14 +00:00
|
|
|
*
|
|
|
|
|
* @group medium
|
2012-05-02 17:34:35 +00:00
|
|
|
*/
|
2017-10-12 12:23:33 +00:00
|
|
|
class RevisionIntegrationTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-07-24 15:58:02 +00:00
|
|
|
/**
|
2017-10-13 15:39:24 +00:00
|
|
|
* @var WikiPage $testPage
|
2012-07-24 15:58:02 +00:00
|
|
|
*/
|
2017-10-13 15:39:24 +00:00
|
|
|
private $testPage;
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-10 16:58:13 +00:00
|
|
|
public function __construct( $name = null, array $data = [], $dataName = '' ) {
|
2012-05-02 17:34:35 +00:00
|
|
|
parent::__construct( $name, $data, $dataName );
|
|
|
|
|
|
|
|
|
|
$this->tablesUsed = array_merge( $this->tablesUsed,
|
2017-10-12 12:23:33 +00:00
|
|
|
[
|
|
|
|
|
'page',
|
2013-02-14 11:36:35 +00:00
|
|
|
'revision',
|
2017-04-21 16:17:59 +00:00
|
|
|
'ip_changes',
|
2013-02-14 11:36:35 +00:00
|
|
|
'text',
|
2017-10-12 12:23:33 +00:00
|
|
|
'archive',
|
2013-02-14 11:36:35 +00:00
|
|
|
|
|
|
|
|
'recentchanges',
|
|
|
|
|
'logging',
|
|
|
|
|
|
|
|
|
|
'page_props',
|
|
|
|
|
'pagelinks',
|
|
|
|
|
'categorylinks',
|
|
|
|
|
'langlinks',
|
|
|
|
|
'externallinks',
|
|
|
|
|
'imagelinks',
|
|
|
|
|
'templatelinks',
|
2017-10-12 12:23:33 +00:00
|
|
|
'iwlinks'
|
|
|
|
|
]
|
|
|
|
|
);
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
protected function setUp() {
|
2017-10-11 14:02:38 +00:00
|
|
|
global $wgContLang;
|
2012-05-02 10:54:27 +00:00
|
|
|
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2017-10-11 14:02:38 +00:00
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
|
'wgExtraNamespaces',
|
|
|
|
|
[
|
|
|
|
|
12312 => 'Dummy',
|
|
|
|
|
12313 => 'Dummy_talk',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
|
'wgNamespaceContentModels',
|
|
|
|
|
[
|
2017-10-12 12:23:33 +00:00
|
|
|
12312 => DummyContentForTesting::MODEL_ID,
|
2017-10-11 14:02:38 +00:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
|
'wgContentHandlers',
|
|
|
|
|
[
|
2017-10-12 12:23:33 +00:00
|
|
|
DummyContentForTesting::MODEL_ID => 'DummyContentHandlerForTesting',
|
|
|
|
|
RevisionTestModifyableContent::MODEL_ID => 'RevisionTestModifyableContentHandler',
|
2017-10-11 14:02:38 +00:00
|
|
|
]
|
|
|
|
|
);
|
2012-05-02 10:54:27 +00:00
|
|
|
|
2017-09-11 20:37:18 +00:00
|
|
|
MWNamespace::clearCaches();
|
2017-10-10 16:58:13 +00:00
|
|
|
// Reset namespace cache
|
|
|
|
|
$wgContLang->resetNamespaces();
|
2017-10-13 15:39:24 +00:00
|
|
|
if ( !$this->testPage ) {
|
|
|
|
|
$this->testPage = WikiPage::factory( Title::newFromText( 'UTPage' ) );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-24 00:46:49 +00:00
|
|
|
protected function tearDown() {
|
2017-10-11 14:02:38 +00:00
|
|
|
global $wgContLang;
|
2012-05-02 10:54:27 +00:00
|
|
|
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::tearDown();
|
|
|
|
|
|
2017-09-11 20:37:18 +00:00
|
|
|
MWNamespace::clearCaches();
|
2017-10-10 16:58:13 +00:00
|
|
|
// Reset namespace cache
|
|
|
|
|
$wgContLang->resetNamespaces();
|
2012-05-02 10:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
private function makeRevisionWithProps( $props = null ) {
|
2013-02-14 11:36:35 +00:00
|
|
|
if ( $props === null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$props = [];
|
2013-02-14 11:36:35 +00:00
|
|
|
}
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2013-02-14 11:36:35 +00:00
|
|
|
if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) {
|
|
|
|
|
$props['text'] = 'Lorem Ipsum';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $props['comment'] ) ) {
|
|
|
|
|
$props['comment'] = 'just a test';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $props['page'] ) ) {
|
2017-10-13 15:39:24 +00:00
|
|
|
$props['page'] = $this->testPage->getId();
|
2013-02-14 11:36:35 +00:00
|
|
|
}
|
2012-05-02 17:34:35 +00:00
|
|
|
|
|
|
|
|
$rev = new Revision( $props );
|
|
|
|
|
|
2016-03-18 13:55:54 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2012-05-02 17:34:35 +00:00
|
|
|
$rev->insertOn( $dbw );
|
|
|
|
|
|
|
|
|
|
return $rev;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $titleString
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param string|null $model
|
|
|
|
|
*
|
|
|
|
|
* @return WikiPage
|
|
|
|
|
*/
|
2017-10-13 15:39:24 +00:00
|
|
|
private function createPage( $titleString, $text, $model = null ) {
|
2017-10-11 13:56:37 +00:00
|
|
|
if ( !preg_match( '/:/', $titleString ) &&
|
|
|
|
|
( $model === null || $model === CONTENT_MODEL_WIKITEXT )
|
|
|
|
|
) {
|
|
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
$titleString = MWNamespace::getCanonicalName( $ns ) . ':' . $titleString;
|
2012-10-12 16:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
$title = Title::newFromText( $titleString );
|
|
|
|
|
$wikipage = new WikiPage( $title );
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
// Delete the article if it already exists
|
|
|
|
|
if ( $wikipage->exists() ) {
|
|
|
|
|
$wikipage->doDeleteArticle( "done" );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
$content = ContentHandler::makeContent( $text, $title, $model );
|
|
|
|
|
$wikipage->doEditContent( $content, __METHOD__, EDIT_NEW );
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
return $wikipage;
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
private function assertRevEquals( Revision $orig, Revision $rev = null ) {
|
2012-05-02 17:34:35 +00:00
|
|
|
$this->assertNotNull( $rev, 'missing revision' );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $orig->getId(), $rev->getId() );
|
|
|
|
|
$this->assertEquals( $orig->getPage(), $rev->getPage() );
|
|
|
|
|
$this->assertEquals( $orig->getTimestamp(), $rev->getTimestamp() );
|
|
|
|
|
$this->assertEquals( $orig->getUser(), $rev->getUser() );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $orig->getContentModel(), $rev->getContentModel() );
|
2012-05-02 10:54:27 +00:00
|
|
|
$this->assertEquals( $orig->getContentFormat(), $rev->getContentFormat() );
|
2012-05-02 17:34:35 +00:00
|
|
|
$this->assertEquals( $orig->getSha1(), $rev->getSha1() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::__construct
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testConstructFromRow() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$latestRevisionId = $this->testPage->getLatest();
|
|
|
|
|
$latestRevision = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-10-13 15:39:24 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
|
'revision',
|
|
|
|
|
Revision::selectFields(),
|
|
|
|
|
[ 'rev_id' => $latestRevisionId ]
|
|
|
|
|
);
|
2012-05-02 17:34:35 +00:00
|
|
|
$this->assertTrue( is_object( $res ), 'query failed' );
|
|
|
|
|
|
|
|
|
|
$row = $res->fetchObject();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->assertRevEquals( $latestRevision, new Revision( $row ) );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-11 13:56:37 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromTitle
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromTitle_withoutId() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$latestRevId = $this->testPage->getLatest();
|
2017-10-11 13:56:37 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev = Revision::newFromTitle( $this->testPage->getTitle() );
|
2017-10-11 13:56:37 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->assertTrue( $this->testPage->getTitle()->equals( $rev->getTitle() ) );
|
2017-10-11 13:56:37 +00:00
|
|
|
$this->assertEquals( $latestRevId, $rev->getId() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromTitle
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromTitle_withId() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$latestRevId = $this->testPage->getLatest();
|
2017-10-11 13:56:37 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev = Revision::newFromTitle( $this->testPage->getTitle(), $latestRevId );
|
2017-10-11 13:56:37 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->assertTrue( $this->testPage->getTitle()->equals( $rev->getTitle() ) );
|
2017-10-11 13:56:37 +00:00
|
|
|
$this->assertEquals( $latestRevId, $rev->getId() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromTitle
|
|
|
|
|
*/
|
|
|
|
|
public function testNewFromTitle_withBadId() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$latestRevId = $this->testPage->getLatest();
|
2017-10-11 13:56:37 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev = Revision::newFromTitle( $this->testPage->getTitle(), $latestRevId + 1 );
|
2017-10-11 13:56:37 +00:00
|
|
|
|
|
|
|
|
$this->assertNull( $rev );
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 17:34:35 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromRow
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testNewFromRow() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$orig = $this->makeRevisionWithProps();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-06-06 17:39:14 +00:00
|
|
|
$res = $dbr->select( 'revision', Revision::selectFields(), [ 'rev_id' => $orig->getId() ] );
|
2012-05-02 17:34:35 +00:00
|
|
|
$this->assertTrue( is_object( $res ), 'query failed' );
|
|
|
|
|
|
|
|
|
|
$row = $res->fetchObject();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
|
|
|
|
$rev = Revision::newFromRow( $row );
|
|
|
|
|
|
|
|
|
|
$this->assertRevEquals( $orig, $rev );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromArchiveRow
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testNewFromArchiveRow() {
|
2014-04-24 12:35:05 +00:00
|
|
|
$page = $this->createPage(
|
|
|
|
|
'RevisionStorageTest_testNewFromArchiveRow',
|
|
|
|
|
'Lorem Ipsum',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
2012-05-02 17:34:35 +00:00
|
|
|
$orig = $page->getRevision();
|
|
|
|
|
$page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
|
|
|
|
|
|
2017-08-04 18:53:34 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-06-06 17:39:14 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
|
'archive', Revision::selectArchiveFields(), [ 'ar_rev_id' => $orig->getId() ]
|
|
|
|
|
);
|
2012-05-02 17:34:35 +00:00
|
|
|
$this->assertTrue( is_object( $res ), 'query failed' );
|
|
|
|
|
|
|
|
|
|
$row = $res->fetchObject();
|
|
|
|
|
$res->free();
|
|
|
|
|
|
|
|
|
|
$rev = Revision::newFromArchiveRow( $row );
|
|
|
|
|
|
|
|
|
|
$this->assertRevEquals( $orig, $rev );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::newFromId
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testNewFromId() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$orig = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
$rev = Revision::newFromId( $orig->getId() );
|
|
|
|
|
$this->assertRevEquals( $orig, $rev );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::fetchRevision
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testFetchRevision() {
|
2014-01-25 13:26:03 +00:00
|
|
|
// Hidden process cache assertion below
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->getRevision()->getId();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
|
|
|
|
|
$id = $this->testPage->getRevision()->getId();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$res = Revision::fetchRevision( $this->testPage->getTitle() );
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
# note: order is unspecified
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [];
|
2012-05-02 17:34:35 +00:00
|
|
|
while ( ( $row = $res->fetchObject() ) ) {
|
2013-02-14 11:36:35 +00:00
|
|
|
$rows[$row->rev_id] = $row;
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->assertEquals( 1, count( $rows ), 'expected exactly one revision' );
|
2014-01-25 13:26:03 +00:00
|
|
|
$this->assertArrayHasKey( $id, $rows, 'missing revision with id ' . $id );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::selectFields
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testSelectFields() {
|
2012-07-24 15:58:02 +00:00
|
|
|
global $wgContentHandlerUseDB;
|
|
|
|
|
|
2012-05-02 17:34:35 +00:00
|
|
|
$fields = Revision::selectFields();
|
|
|
|
|
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' );
|
|
|
|
|
$this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' );
|
2014-04-24 12:35:05 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
|
in_array( 'rev_timestamp', $fields ),
|
|
|
|
|
'missing rev_timestamp in list of fields'
|
|
|
|
|
);
|
2013-02-14 11:36:35 +00:00
|
|
|
$this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' );
|
2012-05-02 10:54:27 +00:00
|
|
|
|
2012-07-24 15:58:02 +00:00
|
|
|
if ( $wgContentHandlerUseDB ) {
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertTrue( in_array( 'rev_content_model', $fields ),
|
2013-02-14 11:36:35 +00:00
|
|
|
'missing rev_content_model in list of fields' );
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertTrue( in_array( 'rev_content_format', $fields ),
|
2013-02-14 11:36:35 +00:00
|
|
|
'missing rev_content_format in list of fields' );
|
2012-07-24 15:58:02 +00:00
|
|
|
}
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getPage
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testGetPage() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$page = $this->testPage;
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$orig = $this->makeRevisionWithProps( [ 'page' => $page->getId() ] );
|
2012-05-02 17:34:35 +00:00
|
|
|
$rev = Revision::newFromId( $orig->getId() );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $page->getId(), $rev->getPage() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::isCurrent
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testIsCurrent() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev1 = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2013-05-15 01:12:35 +00:00
|
|
|
# @todo find out if this should be true
|
2012-05-02 17:34:35 +00:00
|
|
|
# $this->assertTrue( $rev1->isCurrent() );
|
|
|
|
|
|
|
|
|
|
$rev1x = Revision::newFromId( $rev1->getId() );
|
|
|
|
|
$this->assertTrue( $rev1x->isCurrent() );
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
|
|
|
|
|
$rev2 = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2013-05-15 01:12:35 +00:00
|
|
|
# @todo find out if this should be true
|
2012-05-02 17:34:35 +00:00
|
|
|
# $this->assertTrue( $rev2->isCurrent() );
|
|
|
|
|
|
|
|
|
|
$rev1x = Revision::newFromId( $rev1->getId() );
|
|
|
|
|
$this->assertFalse( $rev1x->isCurrent() );
|
|
|
|
|
|
|
|
|
|
$rev2x = Revision::newFromId( $rev2->getId() );
|
|
|
|
|
$this->assertTrue( $rev2x->isCurrent() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getPrevious
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testGetPrevious() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$oldestRevision = $this->testPage->getOldestRevision();
|
|
|
|
|
$latestRevision = $this->testPage->getLatest();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->assertNull( $oldestRevision->getPrevious() );
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
|
|
|
|
|
$newRevision = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->assertNotNull( $newRevision->getPrevious() );
|
|
|
|
|
$this->assertEquals( $latestRevision, $newRevision->getPrevious()->getId() );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getNext
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testGetNext() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev1 = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
|
|
|
|
$this->assertNull( $rev1->getNext() );
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
|
|
|
|
|
$rev2 = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
|
|
|
|
$this->assertNotNull( $rev1->getNext() );
|
|
|
|
|
$this->assertEquals( $rev2->getId(), $rev1->getNext()->getId() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::newNullRevision
|
|
|
|
|
*/
|
2013-01-28 10:27:15 +00:00
|
|
|
public function testNewNullRevision() {
|
2017-10-13 15:39:24 +00:00
|
|
|
$this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
|
|
|
|
|
$orig = $this->testPage->getRevision();
|
2012-05-02 17:34:35 +00:00
|
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2017-10-13 15:39:24 +00:00
|
|
|
$rev = Revision::newNullRevision( $dbw, $this->testPage->getId(), 'a null revision', false );
|
2012-05-02 17:34:35 +00:00
|
|
|
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertNotEquals( $orig->getId(), $rev->getId(),
|
2017-10-13 15:39:24 +00:00
|
|
|
'new null revision should have a different id from the original revision' );
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertEquals( $orig->getTextId(), $rev->getTextId(),
|
2017-10-13 15:39:24 +00:00
|
|
|
'new null revision should have the same text id as the original revision' );
|
|
|
|
|
$this->assertEquals( __METHOD__, $rev->getContent()->getNativeData() );
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|
2012-08-30 17:17:14 +00:00
|
|
|
|
2017-04-21 16:17:59 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Revision::insertOn
|
|
|
|
|
*/
|
|
|
|
|
public function testInsertOn() {
|
|
|
|
|
$ip = '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
|
|
|
|
|
|
2017-10-13 15:39:24 +00:00
|
|
|
$orig = $this->makeRevisionWithProps( [
|
2017-04-21 16:17:59 +00:00
|
|
|
'user_text' => $ip
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// Make sure the revision was copied to ip_changes
|
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
|
$res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $orig->getId() ] );
|
|
|
|
|
$row = $res->fetchObject();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( IP::toHex( $ip ), $row->ipc_hex );
|
|
|
|
|
$this->assertEquals( $orig->getTimestamp(), $row->ipc_rev_timestamp );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideUserWasLastToEdit() {
|
2017-10-10 16:58:13 +00:00
|
|
|
yield 'actually the last edit' => [ 3, true ];
|
|
|
|
|
yield 'not the current edit, but still by this user' => [ 2, true ];
|
|
|
|
|
yield 'edit by another user' => [ 1, false ];
|
|
|
|
|
yield 'first edit, by this user, but another user edited in the mean time' => [ 0, false ];
|
2012-08-30 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideUserWasLastToEdit
|
2012-08-30 17:17:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testUserWasLastToEdit( $sinceIdx, $expectedLast ) {
|
2013-10-21 21:09:13 +00:00
|
|
|
$userA = User::newFromName( "RevisionStorageTest_userA" );
|
|
|
|
|
$userB = User::newFromName( "RevisionStorageTest_userB" );
|
2012-08-30 17:17:14 +00:00
|
|
|
|
|
|
|
|
if ( $userA->getId() === 0 ) {
|
2013-10-21 21:09:13 +00:00
|
|
|
$userA = User::createNew( $userA->getName() );
|
2012-08-30 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $userB->getId() === 0 ) {
|
2013-10-21 21:09:13 +00:00
|
|
|
$userB = User::createNew( $userB->getName() );
|
2012-08-30 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-12 16:30:38 +00:00
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
|
2012-08-30 17:17:14 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions = [];
|
2012-08-30 17:17:14 +00:00
|
|
|
|
|
|
|
|
// create revisions -----------------------------
|
2012-10-12 16:30:38 +00:00
|
|
|
$page = WikiPage::factory( Title::newFromText(
|
|
|
|
|
'RevisionStorageTest_testUserWasLastToEdit', $ns ) );
|
2013-12-07 15:40:58 +00:00
|
|
|
$page->insertOn( $dbw );
|
2012-08-30 17:17:14 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions[0] = new Revision( [
|
2012-08-30 17:17:14 +00:00
|
|
|
'page' => $page->getId(),
|
2014-04-24 12:35:05 +00:00
|
|
|
// we need the title to determine the page's default content model
|
|
|
|
|
'title' => $page->getTitle(),
|
2012-08-30 17:17:14 +00:00
|
|
|
'timestamp' => '20120101000000',
|
|
|
|
|
'user' => $userA->getId(),
|
|
|
|
|
'text' => 'zero',
|
2012-09-19 18:07:56 +00:00
|
|
|
'content_model' => CONTENT_MODEL_WIKITEXT,
|
2012-08-30 17:17:14 +00:00
|
|
|
'summary' => 'edit zero'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-08-30 17:17:14 +00:00
|
|
|
$revisions[0]->insertOn( $dbw );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions[1] = new Revision( [
|
2012-08-30 17:17:14 +00:00
|
|
|
'page' => $page->getId(),
|
2014-04-24 12:35:05 +00:00
|
|
|
// still need the title, because $page->getId() is 0 (there's no entry in the page table)
|
|
|
|
|
'title' => $page->getTitle(),
|
2012-08-30 17:17:14 +00:00
|
|
|
'timestamp' => '20120101000100',
|
|
|
|
|
'user' => $userA->getId(),
|
|
|
|
|
'text' => 'one',
|
2012-09-19 18:07:56 +00:00
|
|
|
'content_model' => CONTENT_MODEL_WIKITEXT,
|
2012-08-30 17:17:14 +00:00
|
|
|
'summary' => 'edit one'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-08-30 17:17:14 +00:00
|
|
|
$revisions[1]->insertOn( $dbw );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions[2] = new Revision( [
|
2012-08-30 17:17:14 +00:00
|
|
|
'page' => $page->getId(),
|
2012-09-18 15:43:20 +00:00
|
|
|
'title' => $page->getTitle(),
|
2012-08-30 17:17:14 +00:00
|
|
|
'timestamp' => '20120101000200',
|
|
|
|
|
'user' => $userB->getId(),
|
|
|
|
|
'text' => 'two',
|
2012-09-19 18:07:56 +00:00
|
|
|
'content_model' => CONTENT_MODEL_WIKITEXT,
|
2012-08-30 17:17:14 +00:00
|
|
|
'summary' => 'edit two'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-08-30 17:17:14 +00:00
|
|
|
$revisions[2]->insertOn( $dbw );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions[3] = new Revision( [
|
2012-08-30 17:17:14 +00:00
|
|
|
'page' => $page->getId(),
|
2012-09-18 15:43:20 +00:00
|
|
|
'title' => $page->getTitle(),
|
2012-08-30 17:17:14 +00:00
|
|
|
'timestamp' => '20120101000300',
|
|
|
|
|
'user' => $userA->getId(),
|
|
|
|
|
'text' => 'three',
|
2012-09-19 18:07:56 +00:00
|
|
|
'content_model' => CONTENT_MODEL_WIKITEXT,
|
2012-08-30 17:17:14 +00:00
|
|
|
'summary' => 'edit three'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-08-30 17:17:14 +00:00
|
|
|
$revisions[3]->insertOn( $dbw );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisions[4] = new Revision( [
|
2012-08-30 17:17:14 +00:00
|
|
|
'page' => $page->getId(),
|
2012-09-18 15:43:20 +00:00
|
|
|
'title' => $page->getTitle(),
|
2012-08-30 17:17:14 +00:00
|
|
|
'timestamp' => '20120101000200',
|
|
|
|
|
'user' => $userA->getId(),
|
|
|
|
|
'text' => 'zero',
|
2012-09-19 18:07:56 +00:00
|
|
|
'content_model' => CONTENT_MODEL_WIKITEXT,
|
2012-08-30 17:17:14 +00:00
|
|
|
'summary' => 'edit four'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-08-30 17:17:14 +00:00
|
|
|
$revisions[4]->insertOn( $dbw );
|
|
|
|
|
|
|
|
|
|
// test it ---------------------------------
|
2013-02-14 11:36:35 +00:00
|
|
|
$since = $revisions[$sinceIdx]->getTimestamp();
|
2012-08-30 17:17:14 +00:00
|
|
|
|
|
|
|
|
$wasLast = Revision::userWasLastToEdit( $dbw, $page->getId(), $userA->getId(), $since );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedLast, $wasLast );
|
|
|
|
|
}
|
2017-10-12 12:23:33 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param string $title
|
|
|
|
|
* @param string $model
|
|
|
|
|
* @param string $format
|
|
|
|
|
*
|
|
|
|
|
* @return Revision
|
|
|
|
|
*/
|
|
|
|
|
private function newTestRevision( $text, $title = "Test",
|
|
|
|
|
$model = CONTENT_MODEL_WIKITEXT, $format = null
|
|
|
|
|
) {
|
|
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent( $text, $title, $model, $format );
|
|
|
|
|
|
|
|
|
|
$rev = new Revision(
|
|
|
|
|
[
|
|
|
|
|
'id' => 42,
|
|
|
|
|
'page' => 23,
|
|
|
|
|
'title' => $title,
|
|
|
|
|
|
|
|
|
|
'content' => $content,
|
|
|
|
|
'length' => $content->getSize(),
|
|
|
|
|
'comment' => "testing",
|
|
|
|
|
'minor_edit' => false,
|
|
|
|
|
|
|
|
|
|
'content_format' => $format,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $rev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetContentModel() {
|
|
|
|
|
// NOTE: we expect the help namespace to always contain wikitext
|
|
|
|
|
return [
|
|
|
|
|
[ 'hello world', 'Help:Hello', null, null, CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'hello world', 'User:hello/there.css', null, null, CONTENT_MODEL_CSS ],
|
|
|
|
|
[ serialize( 'hello world' ), 'Dummy:Hello', null, null, DummyContentForTesting::MODEL_ID ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetContentModel
|
|
|
|
|
* @covers Revision::getContentModel
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentModel( $text, $title, $model, $format, $expectedModel ) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, $title, $model, $format );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedModel, $rev->getContentModel() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetContentFormat() {
|
|
|
|
|
// NOTE: we expect the help namespace to always contain wikitext
|
|
|
|
|
return [
|
|
|
|
|
[ 'hello world', 'Help:Hello', null, null, CONTENT_FORMAT_WIKITEXT ],
|
|
|
|
|
[ 'hello world', 'Help:Hello', CONTENT_MODEL_CSS, null, CONTENT_FORMAT_CSS ],
|
|
|
|
|
[ 'hello world', 'User:hello/there.css', null, null, CONTENT_FORMAT_CSS ],
|
|
|
|
|
[ serialize( 'hello world' ), 'Dummy:Hello', null, null, DummyContentForTesting::MODEL_ID ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetContentFormat
|
|
|
|
|
* @covers Revision::getContentFormat
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, $title, $model, $format );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedFormat, $rev->getContentFormat() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetContentHandler() {
|
|
|
|
|
// NOTE: we expect the help namespace to always contain wikitext
|
|
|
|
|
return [
|
|
|
|
|
[ 'hello world', 'Help:Hello', null, null, 'WikitextContentHandler' ],
|
|
|
|
|
[ 'hello world', 'User:hello/there.css', null, null, 'CssContentHandler' ],
|
|
|
|
|
[ serialize( 'hello world' ), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetContentHandler
|
|
|
|
|
* @covers Revision::getContentHandler
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, $title, $model, $format );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedClass, get_class( $rev->getContentHandler() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetContent() {
|
|
|
|
|
// NOTE: we expect the help namespace to always contain wikitext
|
|
|
|
|
return [
|
|
|
|
|
[ 'hello world', 'Help:Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ],
|
|
|
|
|
[
|
|
|
|
|
serialize( 'hello world' ),
|
|
|
|
|
'Hello',
|
|
|
|
|
DummyContentForTesting::MODEL_ID,
|
|
|
|
|
null,
|
|
|
|
|
Revision::FOR_PUBLIC,
|
|
|
|
|
serialize( 'hello world' )
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
serialize( 'hello world' ),
|
|
|
|
|
'Dummy:Hello',
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
Revision::FOR_PUBLIC,
|
|
|
|
|
serialize( 'hello world' )
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetContent
|
|
|
|
|
* @covers Revision::getContent
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContent( $text, $title, $model, $format,
|
|
|
|
|
$audience, $expectedSerialization
|
|
|
|
|
) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, $title, $model, $format );
|
|
|
|
|
$content = $rev->getContent( $audience );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedSerialization,
|
|
|
|
|
is_null( $content ) ? null : $content->serialize( $format )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getContent
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContent_failure() {
|
|
|
|
|
$rev = new Revision( [
|
2017-10-13 15:39:24 +00:00
|
|
|
'page' => $this->testPage->getId(),
|
|
|
|
|
'content_model' => $this->testPage->getContentModel(),
|
2017-10-12 12:23:33 +00:00
|
|
|
'text_id' => 123456789, // not in the test DB
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertNull( $rev->getContent(),
|
|
|
|
|
"getContent() should return null if the revision's text blob could not be loaded." );
|
|
|
|
|
|
|
|
|
|
// NOTE: check this twice, once for lazy initialization, and once with the cached value.
|
|
|
|
|
$this->assertNull( $rev->getContent(),
|
|
|
|
|
"getContent() should return null if the revision's text blob could not be loaded." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetSize() {
|
|
|
|
|
return [
|
|
|
|
|
[ "hello world.", CONTENT_MODEL_WIKITEXT, 12 ],
|
|
|
|
|
[ serialize( "hello world." ), DummyContentForTesting::MODEL_ID, 12 ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getSize
|
|
|
|
|
* @dataProvider provideGetSize
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSize( $text, $model, $expected_size ) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, 'RevisionTest_testGetSize', $model );
|
|
|
|
|
$this->assertEquals( $expected_size, $rev->getSize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetSha1() {
|
|
|
|
|
return [
|
|
|
|
|
[ "hello world.", CONTENT_MODEL_WIKITEXT, Revision::base36Sha1( "hello world." ) ],
|
|
|
|
|
[
|
|
|
|
|
serialize( "hello world." ),
|
|
|
|
|
DummyContentForTesting::MODEL_ID,
|
|
|
|
|
Revision::base36Sha1( serialize( "hello world." ) )
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Revision::getSha1
|
|
|
|
|
* @dataProvider provideGetSha1
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSha1( $text, $model, $expected_hash ) {
|
|
|
|
|
$rev = $this->newTestRevision( $text, 'RevisionTest_testGetSha1', $model );
|
|
|
|
|
$this->assertEquals( $expected_hash, $rev->getSha1() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests whether $rev->getContent() returns a clone when needed.
|
|
|
|
|
*
|
|
|
|
|
* @covers Revision::getContent
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentClone() {
|
|
|
|
|
$content = new RevisionTestModifyableContent( "foo" );
|
|
|
|
|
|
|
|
|
|
$rev = new Revision(
|
|
|
|
|
[
|
|
|
|
|
'id' => 42,
|
|
|
|
|
'page' => 23,
|
|
|
|
|
'title' => Title::newFromText( "testGetContentClone_dummy" ),
|
|
|
|
|
|
|
|
|
|
'content' => $content,
|
|
|
|
|
'length' => $content->getSize(),
|
|
|
|
|
'comment' => "testing",
|
|
|
|
|
'minor_edit' => false,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** @var RevisionTestModifyableContent $content */
|
|
|
|
|
$content = $rev->getContent( Revision::RAW );
|
|
|
|
|
$content->setText( "bar" );
|
|
|
|
|
|
|
|
|
|
/** @var RevisionTestModifyableContent $content2 */
|
|
|
|
|
$content2 = $rev->getContent( Revision::RAW );
|
|
|
|
|
// content is mutable, expect clone
|
|
|
|
|
$this->assertNotSame( $content, $content2, "expected a clone" );
|
|
|
|
|
// clone should contain the original text
|
|
|
|
|
$this->assertEquals( "foo", $content2->getText() );
|
|
|
|
|
|
|
|
|
|
$content2->setText( "bla bla" );
|
|
|
|
|
// clones should be independent
|
|
|
|
|
$this->assertEquals( "bar", $content->getText() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests whether $rev->getContent() returns the same object repeatedly if appropriate.
|
|
|
|
|
* @covers Revision::getContent
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentUncloned() {
|
|
|
|
|
$rev = $this->newTestRevision( "hello", "testGetContentUncloned_dummy", CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
$content = $rev->getContent( Revision::RAW );
|
|
|
|
|
$content2 = $rev->getContent( Revision::RAW );
|
|
|
|
|
|
|
|
|
|
// for immutable content like wikitext, this should be the same object
|
|
|
|
|
$this->assertSame( $content, $content2 );
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 17:34:35 +00:00
|
|
|
}
|