$this->assertRevEquals( $orig, $rev );
}
- public function provideTrueFalse() {
- yield [ true ];
- yield [ false ];
+ public function provideNewFromArchiveRow() {
+ yield [
+ true,
+ function ( $f ) {
+ return $f;
+ },
+ ];
+ yield [
+ false,
+ function ( $f ) {
+ return $f;
+ },
+ ];
+ yield [
+ true,
+ function ( $f ) {
+ return $f + [ 'ar_namespace', 'ar_title' ];
+ },
+ ];
+ yield [
+ false,
+ function ( $f ) {
+ return $f + [ 'ar_namespace', 'ar_title' ];
+ },
+ ];
+ yield [
+ true,
+ function ( $f ) {
+ unset( $f['ar_text_id'] );
+ return $f;
+ },
+ ];
+ yield [
+ false,
+ function ( $f ) {
+ unset( $f['ar_text_id'] );
+ return $f;
+ },
+ ];
}
/**
- * @dataProvider provideTrueFalse
+ * @dataProvider provideNewFromArchiveRow
* @covers Revision::newFromArchiveRow
*/
- public function testNewFromArchiveRow( $contentHandlerUseDB ) {
+ public function testNewFromArchiveRow( $contentHandlerUseDB, $selectModifier ) {
$this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
$page = $this->createPage(
$page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
$dbr = wfGetDB( DB_REPLICA );
+ $selectFields = $selectModifier( Revision::selectArchiveFields() );
$res = $dbr->select(
- 'archive', Revision::selectArchiveFields(), [ 'ar_rev_id' => $orig->getId() ]
+ 'archive', $selectFields, [ 'ar_rev_id' => $orig->getId() ]
);
$this->assertTrue( is_object( $res ), 'query failed' );
$this->assertRevEquals( $orig, $rev );
}
+ /**
+ * @covers Revision::newFromArchiveRow
+ */
+ public function testNewFromArchiveRowOverrides() {
+ $page = $this->createPage(
+ 'RevisionStorageTest_testNewFromArchiveRow',
+ 'Lorem Ipsum',
+ CONTENT_MODEL_WIKITEXT
+ );
+ $orig = $page->getRevision();
+ $page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
+
+ $dbr = wfGetDB( DB_REPLICA );
+ $res = $dbr->select(
+ 'archive', Revision::selectArchiveFields(), [ 'ar_rev_id' => $orig->getId() ]
+ );
+ $this->assertTrue( is_object( $res ), 'query failed' );
+
+ $row = $res->fetchObject();
+ $res->free();
+
+ $rev = Revision::newFromArchiveRow( $row, [ 'comment' => 'SOMEOVERRIDE' ] );
+
+ $this->assertNotEquals( $orig->getComment(), $rev->getComment() );
+ $this->assertEquals( 'SOMEOVERRIDE', $rev->getComment() );
+ }
+
/**
* @covers Revision::newFromId
*/
$this->assertArrayHasKey( $id, $rows, 'missing revision with id ' . $id );
}
- /**
- * @covers Revision::selectFields
- */
- public function testSelectFields() {
- global $wgContentHandlerUseDB;
-
- $fields = Revision::selectFields();
-
- $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' );
- $this->assertTrue(
- in_array( 'rev_timestamp', $fields ),
- 'missing rev_timestamp in list of fields'
- );
- $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' );
-
- if ( $wgContentHandlerUseDB ) {
- $this->assertTrue( in_array( 'rev_content_model', $fields ),
- 'missing rev_content_model in list of fields' );
- $this->assertTrue( in_array( 'rev_content_format', $fields ),
- 'missing rev_content_format in list of fields' );
- }
- }
-
/**
* @covers Revision::getPage
*/
$this->assertSame( $content, $content2 );
}
+ /**
+ * @covers Revision::loadFromId
+ */
+ public function testLoadFromId() {
+ $rev = $this->testPage->getRevision();
+ $this->assertRevEquals(
+ $rev,
+ Revision::loadFromId( wfGetDB( DB_MASTER ), $rev->getId() )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromPageId
+ */
+ public function testLoadFromPageId() {
+ $this->assertRevEquals(
+ $this->testPage->getRevision(),
+ Revision::loadFromPageId( wfGetDB( DB_MASTER ), $this->testPage->getId() )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromPageId
+ */
+ public function testLoadFromPageIdWithLatestRevId() {
+ $this->assertRevEquals(
+ $this->testPage->getRevision(),
+ Revision::loadFromPageId(
+ wfGetDB( DB_MASTER ),
+ $this->testPage->getId(),
+ $this->testPage->getLatest()
+ )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromPageId
+ */
+ public function testLoadFromPageIdWithNotLatestRevId() {
+ $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+ $this->assertRevEquals(
+ $this->testPage->getRevision()->getPrevious(),
+ Revision::loadFromPageId(
+ wfGetDB( DB_MASTER ),
+ $this->testPage->getId(),
+ $this->testPage->getRevision()->getPrevious()->getId()
+ )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromTitle
+ */
+ public function testLoadFromTitle() {
+ $this->assertRevEquals(
+ $this->testPage->getRevision(),
+ Revision::loadFromTitle( wfGetDB( DB_MASTER ), $this->testPage->getTitle() )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromTitle
+ */
+ public function testLoadFromTitleWithLatestRevId() {
+ $this->assertRevEquals(
+ $this->testPage->getRevision(),
+ Revision::loadFromTitle(
+ wfGetDB( DB_MASTER ),
+ $this->testPage->getTitle(),
+ $this->testPage->getLatest()
+ )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromTitle
+ */
+ public function testLoadFromTitleWithNotLatestRevId() {
+ $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ );
+ $this->assertRevEquals(
+ $this->testPage->getRevision()->getPrevious(),
+ Revision::loadFromTitle(
+ wfGetDB( DB_MASTER ),
+ $this->testPage->getTitle(),
+ $this->testPage->getRevision()->getPrevious()->getId()
+ )
+ );
+ }
+
+ /**
+ * @covers Revision::loadFromTimestamp()
+ */
+ public function testLoadFromTimestamp() {
+ $this->assertRevEquals(
+ $this->testPage->getRevision(),
+ Revision::loadFromTimestamp(
+ wfGetDB( DB_MASTER ),
+ $this->testPage->getTitle(),
+ $this->testPage->getRevision()->getTimestamp()
+ )
+ );
+ }
+
}