* ^--- important, causes tests not to fail with timeout
*/
class RevisionStorageTest extends MediaWikiTestCase {
-
/**
* @var WikiPage $the_page
*/
- var $the_page;
+ private $the_page;
- function __construct( $name = null, array $data = array(), $dataName = '' ) {
+ function __construct( $name = null, array $data = [], $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
$this->tablesUsed = array_merge( $this->tablesUsed,
- array( 'page',
+ [ 'page',
'revision',
'text',
'externallinks',
'imagelinks',
'templatelinks',
- 'iwlinks' ) );
+ 'iwlinks' ] );
}
protected function setUp() {
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
if ( !$this->the_page ) {
- $this->the_page = $this->createPage( 'RevisionStorageTest_the_page', "just a dummy page", CONTENT_MODEL_WIKITEXT );
+ $this->the_page = $this->createPage(
+ 'RevisionStorageTest_the_page',
+ "just a dummy page",
+ CONTENT_MODEL_WIKITEXT
+ );
}
+
+ $this->tablesUsed[] = 'archive';
}
protected function tearDown() {
protected function makeRevision( $props = null ) {
if ( $props === null ) {
- $props = array();
+ $props = [];
}
if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) {
$rev = new Revision( $props );
- $dbw = wfgetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER );
$rev->insertOn( $dbw );
return $rev;
public function testConstructFromRow() {
$orig = $this->makeRevision();
- $dbr = wfgetDB( DB_SLAVE );
- $res = $dbr->select( 'revision', '*', array( 'rev_id' => $orig->getId() ) );
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'revision', '*', [ 'rev_id' => $orig->getId() ] );
$this->assertTrue( is_object( $res ), 'query failed' );
$row = $res->fetchObject();
public function testNewFromRow() {
$orig = $this->makeRevision();
- $dbr = wfgetDB( DB_SLAVE );
- $res = $dbr->select( 'revision', '*', array( 'rev_id' => $orig->getId() ) );
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'revision', '*', [ 'rev_id' => $orig->getId() ] );
$this->assertTrue( is_object( $res ), 'query failed' );
$row = $res->fetchObject();
* @covers Revision::newFromArchiveRow
*/
public function testNewFromArchiveRow() {
- $page = $this->createPage( 'RevisionStorageTest_testNewFromArchiveRow', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
+ $page = $this->createPage(
+ 'RevisionStorageTest_testNewFromArchiveRow',
+ 'Lorem Ipsum',
+ CONTENT_MODEL_WIKITEXT
+ );
$orig = $page->getRevision();
$page->doDeleteArticle( 'test Revision::newFromArchiveRow' );
- $dbr = wfgetDB( DB_SLAVE );
- $res = $dbr->select( 'archive', '*', array( 'ar_rev_id' => $orig->getId() ) );
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $orig->getId() ] );
$this->assertTrue( is_object( $res ), 'query failed' );
$row = $res->fetchObject();
* @covers Revision::fetchRevision
*/
public function testFetchRevision() {
- $page = $this->createPage( 'RevisionStorageTest_testFetchRevision', 'one', CONTENT_MODEL_WIKITEXT );
+ $page = $this->createPage(
+ 'RevisionStorageTest_testFetchRevision',
+ 'one',
+ CONTENT_MODEL_WIKITEXT
+ );
// Hidden process cache assertion below
$page->getRevision()->getId();
$res = Revision::fetchRevision( $page->getTitle() );
- #note: order is unspecified
- $rows = array();
+ # note: order is unspecified
+ $rows = [];
while ( ( $row = $res->fetchObject() ) ) {
$rows[$row->rev_id] = $row;
}
$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_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 ) {
public function testGetPage() {
$page = $this->the_page;
- $orig = $this->makeRevision( array( 'page' => $page->getId() ) );
+ $orig = $this->makeRevision( [ 'page' => $page->getId() ] );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( $page->getId(), $rev->getPage() );
public function testGetText() {
$this->hideDeprecated( 'Revision::getText' );
- $orig = $this->makeRevision( array( 'text' => 'hello hello.' ) );
+ $orig = $this->makeRevision( [ 'text' => 'hello hello.' ] );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( 'hello hello.', $rev->getText() );
* @covers Revision::getContent
*/
public function testGetContent_failure() {
- $rev = new Revision( array(
+ $rev = new Revision( [
'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.
+ // 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.' ) );
+ $orig = $this->makeRevision( [ 'text' => 'hello hello.' ] );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( 'hello hello.', $rev->getContent()->getNativeData() );
}
- /**
- * @covers Revision::getRawText
- */
- public function testGetRawText() {
- $this->hideDeprecated( 'Revision::getRawText' );
-
- $orig = $this->makeRevision( array( 'text' => 'hello hello raw.' ) );
- $rev = Revision::newFromId( $orig->getId() );
-
- $this->assertEquals( 'hello hello raw.', $rev->getRawText() );
- }
-
/**
* @covers Revision::getContentModel
*/
$this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
}
- $orig = $this->makeRevision( array( 'text' => 'hello hello.',
- 'content_model' => CONTENT_MODEL_JAVASCRIPT ) );
+ $orig = $this->makeRevision( [ 'text' => 'hello hello.',
+ 'content_model' => CONTENT_MODEL_JAVASCRIPT ] );
$rev = Revision::newFromId( $orig->getId() );
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
$this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
}
- $orig = $this->makeRevision( array(
+ $orig = $this->makeRevision( [
'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() {
- $page = $this->createPage( 'RevisionStorageTest_testIsCurrent', 'Lorem Ipsum', CONTENT_MODEL_WIKITEXT );
+ $page = $this->createPage(
+ 'RevisionStorageTest_testIsCurrent',
+ 'Lorem Ipsum',
+ CONTENT_MODEL_WIKITEXT
+ );
$rev1 = $page->getRevision();
# @todo find out if this should be true
$rev1x = Revision::newFromId( $rev1->getId() );
$this->assertTrue( $rev1x->isCurrent() );
- $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ), 'second rev' );
+ $page->doEditContent(
+ ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ 'second rev'
+ );
$rev2 = $page->getRevision();
# @todo find out if this should be true
* @covers Revision::getPrevious
*/
public function testGetPrevious() {
- $page = $this->createPage( 'RevisionStorageTest_testGetPrevious', 'Lorem Ipsum testGetPrevious', CONTENT_MODEL_WIKITEXT );
+ $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 ),
+ $page->doEditContent(
+ ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
'second rev testGetPrevious' );
$rev2 = $page->getRevision();
* @covers Revision::getNext
*/
public function testGetNext() {
- $page = $this->createPage( 'RevisionStorageTest_testGetNext', 'Lorem Ipsum testGetNext', CONTENT_MODEL_WIKITEXT );
+ $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' );
+ $page->doEditContent(
+ ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ),
+ 'second rev testGetNext'
+ );
$rev2 = $page->getRevision();
$this->assertNotNull( $rev1->getNext() );
* @covers Revision::newNullRevision
*/
public function testNewNullRevision() {
- $page = $this->createPage( 'RevisionStorageTest_testNewNullRevision', 'some testing text', CONTENT_MODEL_WIKITEXT );
+ $page = $this->createPage(
+ 'RevisionStorageTest_testNewNullRevision',
+ 'some testing text',
+ CONTENT_MODEL_WIKITEXT
+ );
$orig = $page->getRevision();
$dbw = wfGetDB( DB_MASTER );
}
public static function provideUserWasLastToEdit() {
- return array(
- array( #0
+ return [
+ [ # 0
3, true, # actually the last edit
- ),
- array( #1
+ ],
+ [ # 1
2, true, # not the current edit, but still by this user
- ),
- array( #2
+ ],
+ [ # 2
1, false, # edit by another user
- ),
- array( #3
+ ],
+ [ # 3
0, false, # first edit, by this user, but another user edited in the mean time
- ),
- );
+ ],
+ ];
}
/**
$ns = $this->getDefaultWikitextNS();
$dbw = wfGetDB( DB_MASTER );
- $revisions = array();
+ $revisions = [];
// create revisions -----------------------------
$page = WikiPage::factory( Title::newFromText(
$page->insertOn( $dbw );
# zero
- $revisions[0] = new Revision( array(
+ $revisions[0] = new Revision( [
'page' => $page->getId(),
- 'title' => $page->getTitle(), // we need the title to determine the page's default content model
+ // we need the title to determine the page's default content model
+ 'title' => $page->getTitle(),
'timestamp' => '20120101000000',
'user' => $userA->getId(),
'text' => 'zero',
'content_model' => CONTENT_MODEL_WIKITEXT,
'summary' => 'edit zero'
- ) );
+ ] );
$revisions[0]->insertOn( $dbw );
# one
- $revisions[1] = new Revision( array(
+ $revisions[1] = new Revision( [
'page' => $page->getId(),
- 'title' => $page->getTitle(), // still need the title, because $page->getId() is 0 (there's no entry in the page table)
+ // still need the title, because $page->getId() is 0 (there's no entry in the page table)
+ 'title' => $page->getTitle(),
'timestamp' => '20120101000100',
'user' => $userA->getId(),
'text' => 'one',
'content_model' => CONTENT_MODEL_WIKITEXT,
'summary' => 'edit one'
- ) );
+ ] );
$revisions[1]->insertOn( $dbw );
# two
- $revisions[2] = new Revision( array(
+ $revisions[2] = new Revision( [
'page' => $page->getId(),
'title' => $page->getTitle(),
'timestamp' => '20120101000200',
'text' => 'two',
'content_model' => CONTENT_MODEL_WIKITEXT,
'summary' => 'edit two'
- ) );
+ ] );
$revisions[2]->insertOn( $dbw );
# three
- $revisions[3] = new Revision( array(
+ $revisions[3] = new Revision( [
'page' => $page->getId(),
'title' => $page->getTitle(),
'timestamp' => '20120101000300',
'text' => 'three',
'content_model' => CONTENT_MODEL_WIKITEXT,
'summary' => 'edit three'
- ) );
+ ] );
$revisions[3]->insertOn( $dbw );
# four
- $revisions[4] = new Revision( array(
+ $revisions[4] = new Revision( [
'page' => $page->getId(),
'title' => $page->getTitle(),
'timestamp' => '20120101000200',
'text' => 'zero',
'content_model' => CONTENT_MODEL_WIKITEXT,
'summary' => 'edit four'
- ) );
+ ] );
$revisions[4]->insertOn( $dbw );
// test it ---------------------------------