$wgExtraNamespaces[ 12312 ] = 'Dummy';
$wgExtraNamespaces[ 12313 ] = 'Dummy_talk';
- $wgNamespaceContentModels[ 12312 ] = 999999;
- $wgContentHandlers[ 999999 ] = 'DummyContentHandlerForTesting';
+ $wgNamespaceContentModels[ 12312 ] = "testing";
+ $wgContentHandlers[ "testing" ] = 'DummyContentHandlerForTesting';
+ $wgContentHandlers[ "RevisionTestModifyableContent" ] = 'RevisionTestModifyableContentHandler';
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
$wgContLang->resetNamespaces(); # reset namespace cache
return array(
array( 'hello world', 'Hello', null, null, CONTENT_MODEL_WIKITEXT ),
array( 'hello world', 'User:hello/there.css', null, null, CONTENT_MODEL_CSS ),
- array( serialize('hello world'), 'Dummy:Hello', null, null, 999999 ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, "testing" ),
);
}
/**
+ * @group Database
* @dataProvider dataGetContentModel
*/
function testGetContentModel( $text, $title, $model, $format, $expectedModel ) {
array( 'hello world', 'Hello', null, null, CONTENT_FORMAT_WIKITEXT ),
array( 'hello world', 'Hello', CONTENT_MODEL_CSS, null, CONTENT_FORMAT_CSS ),
array( 'hello world', 'User:hello/there.css', null, null, CONTENT_FORMAT_CSS ),
- array( serialize('hello world'), 'Dummy:Hello', null, null, 999999 ),
+ array( serialize('hello world'), 'Dummy:Hello', null, null, "testing" ),
);
}
/**
+ * @group Database
* @dataProvider dataGetContentFormat
*/
function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) {
}
/**
+ * @group Database
* @dataProvider dataGetContentHandler
*/
function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) {
function dataGetContent() {
return array(
array( 'hello world', 'Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ),
- array( serialize('hello world'), 'Hello', 999999, null, Revision::FOR_PUBLIC, serialize('hello world') ),
+ array( serialize('hello world'), 'Hello', "testing", null, Revision::FOR_PUBLIC, serialize('hello world') ),
array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, serialize('hello world') ),
);
}
/**
+ * @group Database
* @dataProvider dataGetContent
*/
function testGetContent( $text, $title, $model, $format, $audience, $expectedSerialization ) {
function dataGetText() {
return array(
array( 'hello world', 'Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ),
- array( serialize('hello world'), 'Hello', 999999, null, Revision::FOR_PUBLIC, null ),
+ array( serialize('hello world'), 'Hello', "testing", null, Revision::FOR_PUBLIC, null ),
array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, null ),
);
}
/**
+ * @group Database
* @dataProvider dataGetText
*/
function testGetText( $text, $title, $model, $format, $audience, $expectedText ) {
+ $this->hideDeprecated( 'Revision::getText' );
+
$rev = $this->newTestRevision( $text, $title, $model, $format );
$this->assertEquals( $expectedText, $rev->getText( $audience ) );
}
/**
+ * @group Database
* @dataProvider dataGetText
*/
function testGetRawText( $text, $title, $model, $format, $audience, $expectedText ) {
+ $this->hideDeprecated( 'Revision::getRawText' );
+
$rev = $this->newTestRevision( $text, $title, $model, $format );
$this->assertEquals( $expectedText, $rev->getRawText( $audience ) );
public function dataGetSize( ) {
return array(
array( "hello world.", null, 12 ),
- array( serialize( "hello world." ), 999999, 12 ),
+ array( serialize( "hello world." ), "testing", 12 ),
);
}
/**
* @covers Revision::getSize
+ * @group Database
* @dataProvider dataGetSize
*/
public function testGetSize( $text, $model, $expected_size )
public function dataGetSha1( ) {
return array(
array( "hello world.", null, Revision::base36Sha1( "hello world." ) ),
- array( serialize( "hello world." ), 999999, Revision::base36Sha1( serialize( "hello world." ) ) ),
+ array( serialize( "hello world." ), "testing", Revision::base36Sha1( serialize( "hello world." ) ) ),
);
}
/**
* @covers Revision::getSha1
+ * @group Database
* @dataProvider dataGetSha1
*/
public function testGetSha1( $text, $model, $expected_hash )
}
public function testConstructWithText() {
+ $this->hideDeprecated( "Revision::getText" );
+
$rev = new Revision( array(
'text' => 'hello world.',
'content_model' => CONTENT_MODEL_JAVASCRIPT
}
public function testConstructWithContent() {
+ $this->hideDeprecated( "Revision::getText" );
+
$title = Title::newFromText( 'RevisionTest_testConstructWithContent' );
$rev = new Revision( array(
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
}
+ /**
+ * Tests whether $rev->getContent() returns a clone when needed.
+ *
+ * @group Database
+ */
+ function testGetContentClone( ) {
+ $content = new RevisionTestModifyableContent( "foo" );
+
+ $rev = new Revision(
+ array(
+ 'id' => 42,
+ 'page' => 23,
+ 'title' => Title::newFromText( "testGetContentClone_dummy" ),
+
+ 'content' => $content,
+ 'length' => $content->getSize(),
+ 'comment' => "testing",
+ 'minor_edit' => false,
+ )
+ );
+
+ $content = $rev->getContent( Revision::RAW );
+ $content->setText( "bar" );
+
+ $content2 = $rev->getContent( Revision::RAW );
+ $this->assertNotSame( $content, $content2, "expected a clone" ); // content is mutable, expect clone
+ $this->assertEquals( "foo", $content2->getText() ); // clone should contain the original text
+
+ $content2->setText( "bla bla" );
+ $this->assertEquals( "bar", $content->getText() ); // clones should be independent
+ }
+
+
+ /**
+ * Tests whether $rev->getContent() returns the same object repeatedly if appropriate.
+ *
+ * @group Database
+ */
+ 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 );
+ }
+
}
+class RevisionTestModifyableContent extends TextContent {
+ public function __construct( $text ) {
+ parent::__construct( $text, "RevisionTestModifyableContent" );
+ }
+
+ public function copy( ) {
+ return new RevisionTestModifyableContent( $this->mText );
+ }
+ public function getText() {
+ return $this->mText;
+ }
+
+ public function setText( $text ) {
+ $this->mText = $text;
+ }
+
+}
+
+class RevisionTestModifyableContentHandler extends TextContentHandler {
+
+ public function __construct( ) {
+ parent::__construct( "RevisionTestModifyableContent", array( CONTENT_FORMAT_TEXT ) );
+ }
+
+ public function unserializeContent( $text, $format = null ) {
+ $this->checkFormat( $format );
+
+ return new RevisionTestModifyableContent( $text );
+ }
+
+ public function makeEmptyContent() {
+ return new RevisionTestModifyableContent( '' );
+ }
+}