parent::__construct( $name, $data, $dataName );
$this->tablesUsed = array_merge( $this->tablesUsed,
- array( 'page',
- 'revision',
- 'text',
-
- 'recentchanges',
- 'logging',
-
- 'page_props',
- 'pagelinks',
- 'categorylinks',
- 'langlinks',
- 'externallinks',
- 'imagelinks',
- 'templatelinks',
- 'iwlinks' ) );
+ array( 'page',
+ 'revision',
+ 'text',
+
+ 'recentchanges',
+ 'logging',
+
+ 'page_props',
+ 'pagelinks',
+ 'categorylinks',
+ 'langlinks',
+ 'externallinks',
+ 'imagelinks',
+ 'templatelinks',
+ 'iwlinks' ) );
}
public function setUp() {
parent::setUp();
- $wgExtraNamespaces[ 12312 ] = 'Dummy';
- $wgExtraNamespaces[ 12313 ] = 'Dummy_talk';
+ $wgExtraNamespaces[12312] = 'Dummy';
+ $wgExtraNamespaces[12313] = 'Dummy_talk';
- $wgNamespaceContentModels[ 12312 ] = 'DUMMY';
- $wgContentHandlers[ 'DUMMY' ] = 'DummyContentHandlerForTesting';
+ $wgNamespaceContentModels[12312] = 'DUMMY';
+ $wgContentHandlers['DUMMY'] = 'DummyContentHandlerForTesting';
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
parent::tearDown();
- unset( $wgExtraNamespaces[ 12312 ] );
- unset( $wgExtraNamespaces[ 12313 ] );
+ unset( $wgExtraNamespaces[12312] );
+ unset( $wgExtraNamespaces[12313] );
- unset( $wgNamespaceContentModels[ 12312 ] );
- unset( $wgContentHandlers[ 'DUMMY' ] );
+ unset( $wgNamespaceContentModels[12312] );
+ unset( $wgContentHandlers['DUMMY'] );
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
}
protected function makeRevision( $props = null ) {
- if ( $props === null ) $props = array();
+ if ( $props === null ) {
+ $props = array();
+ }
- if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) $props['text'] = 'Lorem Ipsum';
- if ( !isset( $props['comment'] ) ) $props['comment'] = 'just a test';
- if ( !isset( $props['page'] ) ) $props['page'] = $this->the_page->getId();
+ if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) {
+ $props['text'] = 'Lorem Ipsum';
+ }
+
+ if ( !isset( $props['comment'] ) ) {
+ $props['comment'] = 'just a test';
+ }
+
+ if ( !isset( $props['page'] ) ) {
+ $props['page'] = $this->the_page->getId();
+ }
$rev = new Revision( $props );
protected function createPage( $page, $text, $model = null ) {
if ( is_string( $page ) ) {
if ( !preg_match( '/:/', $page ) &&
- ( $model === null || $model === CONTENT_MODEL_WIKITEXT ) ) {
-
+ ( $model === null || $model === CONTENT_MODEL_WIKITEXT )
+ ) {
$ns = $this->getDefaultWikitextNS();
$page = MWNamespace::getCanonicalName( $ns ) . ':' . $page;
}
/**
* @covers Revision::__construct
*/
- public function testConstructFromRow()
- {
+ public function testConstructFromRow() {
$orig = $this->makeRevision();
$dbr = wfgetDB( DB_SLAVE );
/**
* @covers Revision::newFromRow
*/
- public function testNewFromRow()
- {
+ public function testNewFromRow() {
$orig = $this->makeRevision();
$dbr = wfgetDB( DB_SLAVE );
/**
* @covers Revision::newFromArchiveRow
*/
- public function testNewFromArchiveRow()
- {
+ public function testNewFromArchiveRow() {
$page = $this->createPage( 'RevisionStorageTest_testNewFromArchiveRow', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
$orig = $page->getRevision();
$page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
/**
* @covers Revision::newFromId
*/
- public function testNewFromId()
- {
+ public function testNewFromId() {
$orig = $this->makeRevision();
$rev = Revision::newFromId( $orig->getId() );
/**
* @covers Revision::fetchRevision
*/
- public function testFetchRevision()
- {
+ public function testFetchRevision() {
$page = $this->createPage( 'RevisionStorageTest_testFetchRevision', 'one', CONTENT_MODEL_WIKITEXT );
$id1 = $page->getRevision()->getId();
#note: order is unspecified
$rows = array();
while ( ( $row = $res->fetchObject() ) ) {
- $rows[ $row->rev_id ]= $row;
+ $rows[$row->rev_id] = $row;
}
$row = $res->fetchObject();
- $this->assertEquals( 1, count($rows), 'expected exactly one revision' );
+ $this->assertEquals( 1, count( $rows ), 'expected exactly one revision' );
$this->assertArrayHasKey( $id2, $rows, 'missing revision with id ' . $id2 );
}
/**
* @covers Revision::selectFields
*/
- public function testSelectFields()
- {
+ 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');
+ $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');
+ 'missing rev_content_model in list of fields' );
$this->assertTrue( in_array( 'rev_content_format', $fields ),
- 'missing rev_content_format in list of fields');
+ 'missing rev_content_format in list of fields' );
}
}
/**
* @covers Revision::getPage
*/
- public function testGetPage()
- {
+ public function testGetPage() {
$page = $this->the_page;
$orig = $this->makeRevision( array( 'page' => $page->getId() ) );
/**
* @covers Revision::getText
*/
- public function testGetText()
- {
+ public function testGetText() {
$this->hideDeprecated( 'Revision::getText' );
$orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
/**
* @covers Revision::getContent
*/
- public function testGetContent()
- {
+ public function testGetContent_failure() {
+ $rev = new Revision( array(
+ 'page' => $this->the_page->getId(),
+ 'content_model' => $this->the_page->getContentModel(),
+ '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." );
+ }
+
+ /**
+ * @covers Revision::getContent
+ */
+ public function testGetContent() {
$orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
$rev = Revision::newFromId( $orig->getId() );
/**
* @covers Revision::revText
*/
- public function testRevText()
- {
+ public function testRevText() {
$this->hideDeprecated( 'Revision::revText' );
$orig = $this->makeRevision( array( 'text' => 'hello hello rev.' ) );
$rev = Revision::newFromId( $orig->getId() );
/**
* @covers Revision::getRawText
*/
- public function testGetRawText()
- {
+ public function testGetRawText() {
$this->hideDeprecated( 'Revision::getRawText' );
$orig = $this->makeRevision( array( 'text' => 'hello hello raw.' ) );
/**
* @covers Revision::getContentModel
*/
- public function testGetContentModel()
- {
+ public function testGetContentModel() {
global $wgContentHandlerUseDB;
if ( !$wgContentHandlerUseDB ) {
}
$orig = $this->makeRevision( array( 'text' => 'hello hello.',
- 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
+ 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
/**
* @covers Revision::getContentFormat
*/
- public function testGetContentFormat()
- {
+ public function testGetContentFormat() {
global $wgContentHandlerUseDB;
if ( !$wgContentHandlerUseDB ) {
$this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
}
- $orig = $this->makeRevision( array( 'text' => 'hello hello.',
- 'content_model' => CONTENT_MODEL_JAVASCRIPT,
- 'content_format' => CONTENT_FORMAT_JAVASCRIPT ) );
+ $orig = $this->makeRevision( array(
+ 'text' => 'hello hello.',
+ 'content_model' => CONTENT_MODEL_JAVASCRIPT,
+ 'content_format' => CONTENT_FORMAT_JAVASCRIPT
+ ) );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( CONTENT_FORMAT_JAVASCRIPT, $rev->getContentFormat() );
/**
* @covers Revision::isCurrent
*/
- public function testIsCurrent()
- {
+ public function testIsCurrent() {
$page = $this->createPage( 'RevisionStorageTest_testIsCurrent', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
$rev1 = $page->getRevision();
/**
* @covers Revision::getPrevious
*/
- public function testGetPrevious()
- {
+ public function testGetPrevious() {
$page = $this->createPage( 'RevisionStorageTest_testGetPrevious', 'Lorem Ipsum testGetPrevious', CONTENT_MODEL_WIKITEXT );
$rev1 = $page->getRevision();
$this->assertNull( $rev1->getPrevious() );
$page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- 'second rev testGetPrevious' );
+ 'second rev testGetPrevious' );
$rev2 = $page->getRevision();
$this->assertNotNull( $rev2->getPrevious() );
/**
* @covers Revision::getNext
*/
- public function testGetNext()
- {
+ public function testGetNext() {
$page = $this->createPage( 'RevisionStorageTest_testGetNext', 'Lorem Ipsum testGetNext', CONTENT_MODEL_WIKITEXT );
$rev1 = $page->getRevision();
$this->assertNull( $rev1->getNext() );
$page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
- 'second rev testGetNext' );
+ 'second rev testGetNext' );
$rev2 = $page->getRevision();
$this->assertNotNull( $rev1->getNext() );
/**
* @covers Revision::newNullRevision
*/
- public function testNewNullRevision()
- {
+ public function testNewNullRevision() {
$page = $this->createPage( 'RevisionStorageTest_testNewNullRevision', 'some testing text', CONTENT_MODEL_WIKITEXT );
$orig = $page->getRevision();
$rev = Revision::newNullRevision( $dbw, $page->getId(), 'a null revision', false );
$this->assertNotEquals( $orig->getId(), $rev->getId(),
- 'new null revision shold have a different id from the original revision' );
+ 'new null revision shold have a different id from the original revision' );
$this->assertEquals( $orig->getTextId(), $rev->getTextId(),
- 'new null revision shold have the same text id as the original revision' );
+ 'new null revision shold have the same text id as the original revision' );
$this->assertEquals( 'some testing text', $rev->getContent()->getNativeData() );
}
$revisions[4]->insertOn( $dbw );
// test it ---------------------------------
- $since = $revisions[ $sinceIdx ]->getTimestamp();
+ $since = $revisions[$sinceIdx]->getTimestamp();
$wasLast = Revision::userWasLastToEdit( $dbw, $page->getId(), $userA->getId(), $since );