From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- .../includes/content/ContentHandlerTest.php | 15 ++- tests/phpunit/includes/content/JsonContentTest.php | 142 ++++++++++++++------- tests/phpunit/includes/content/TextContentTest.php | 21 +-- 3 files changed, 103 insertions(+), 75 deletions(-) (limited to 'tests/phpunit/includes/content') diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index f7449734..988a59ee 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -2,11 +2,6 @@ /** * @group ContentHandler - * @group Database - * - * @note Declare that we are using the database, because otherwise we'll fail in - * the "databaseless" test run. This is because the LinkHolderArray used by the - * parser needs database access. */ class ContentHandlerTest extends MediaWikiTestCase { @@ -36,6 +31,8 @@ class ContentHandlerTest extends MediaWikiTestCase { // Reset namespace cache MWNamespace::getCanonicalNamespaces( true ); $wgContLang->resetNamespaces(); + // And LinkCache + LinkCache::destroySingleton(); } protected function tearDown() { @@ -44,6 +41,8 @@ class ContentHandlerTest extends MediaWikiTestCase { // Reset namespace cache MWNamespace::getCanonicalNamespaces( true ); $wgContLang->resetNamespaces(); + // And LinkCache + LinkCache::destroySingleton(); parent::tearDown(); } @@ -83,6 +82,7 @@ class ContentHandlerTest extends MediaWikiTestCase { */ public function testGetForTitle( $title, $expectedContentModel ) { $title = Title::newFromText( $title ); + LinkCache::singleton()->addBadLinkObj( $title ); $handler = ContentHandler::getForTitle( $title ); $this->assertEquals( $expectedContentModel, $handler->getModelID() ); } @@ -139,6 +139,7 @@ class ContentHandlerTest extends MediaWikiTestCase { public function testGetPageLanguage( $title, $expected ) { if ( is_string( $title ) ) { $title = Title::newFromText( $title ); + LinkCache::singleton()->addBadLinkObj( $title ); } $expected = wfGetLangObj( $expected ); @@ -292,7 +293,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $expectedModelId, $expectedNativeData, $shouldFail ) { $title = Title::newFromText( $title ); - + LinkCache::singleton()->addBadLinkObj( $title ); try { $content = ContentHandler::makeContent( $data, $title, $modelId, $format ); @@ -317,6 +318,8 @@ class ContentHandlerTest extends MediaWikiTestCase { * page. */ public function testGetAutosummary() { + $this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) ); + $content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT ); $title = Title::newFromText( 'Help:Test' ); // Create a new content object with no content diff --git a/tests/phpunit/includes/content/JsonContentTest.php b/tests/phpunit/includes/content/JsonContentTest.php index 77b542f4..cccfe7b1 100644 --- a/tests/phpunit/includes/content/JsonContentTest.php +++ b/tests/phpunit/includes/content/JsonContentTest.php @@ -6,48 +6,85 @@ */ class JsonContentTest extends MediaWikiLangTestCase { - /** - * @dataProvider provideValidConstruction - */ - public function testValidConstruct( $text, $modelId, $isValid, $expected ) { - $obj = new JsonContent( $text, $modelId ); - $this->assertEquals( $isValid, $obj->isValid() ); - $this->assertEquals( $expected, $obj->getJsonData() ); + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgWellFormedXml', true ); } public static function provideValidConstruction() { return array( - array( 'foo', CONTENT_MODEL_JSON, false, null ), - array( FormatJson::encode( array() ), CONTENT_MODEL_JSON, true, array() ), - array( FormatJson::encode( array( 'foo' ) ), CONTENT_MODEL_JSON, true, array( 'foo' ) ), + array( 'foo', false, null ), + array( '[]', true, array() ), + array( '{}', true, (object)array() ), + array( '""', true, '' ), + array( '"0"', true, '0' ), + array( '"bar"', true, 'bar' ), + array( '0', true, '0' ), + array( '{ "0": "bar" }', true, (object)array( 'bar' ) ), ); } /** - * @dataProvider provideDataToEncode + * @dataProvider provideValidConstruction */ - public function testBeautifyUsesFormatJson( $data ) { - $obj = new JsonContent( FormatJson::encode( $data ) ); - $this->assertEquals( FormatJson::encode( $data, true ), $obj->beautifyJSON() ); + public function testIsValid( $text, $isValid, $expected ) { + $obj = new JsonContent( $text, CONTENT_MODEL_JSON ); + $this->assertEquals( $isValid, $obj->isValid() ); + $this->assertEquals( $expected, $obj->getData()->getValue() ); } public static function provideDataToEncode() { return array( - array( array() ), - array( array( 'foo' ) ), - array( array( 'foo', 'bar' ) ), - array( array( 'baz' => 'foo', 'bar' ) ), - array( array( 'baz' => 1000, 'bar' ) ), + array( + // Round-trip empty array + '[]', + '[]', + ), + array( + // Round-trip empty object + '{}', + '{}', + ), + array( + // Round-trip empty array/object (nested) + '{ "foo": {}, "bar": [] }', + "{\n \"foo\": {},\n \"bar\": []\n}", + ), + array( + '{ "foo": "bar" }', + "{\n \"foo\": \"bar\"\n}", + ), + array( + '{ "foo": 1000 }', + "{\n \"foo\": 1000\n}", + ), + array( + '{ "foo": 1000, "0": "bar" }', + "{\n \"foo\": 1000,\n \"0\": \"bar\"\n}", + ), ); } /** * @dataProvider provideDataToEncode */ - public function testPreSaveTransform( $data ) { - $obj = new JsonContent( FormatJson::encode( $data ) ); - $newObj = $obj->preSaveTransform( $this->getMockTitle(), $this->getMockUser(), $this->getMockParserOptions() ); - $this->assertTrue( $newObj->equals( new JsonContent( FormatJson::encode( $data, true ) ) ) ); + public function testBeautifyJson( $input, $beautified ) { + $obj = new JsonContent( $input ); + $this->assertEquals( $beautified, $obj->beautifyJSON() ); + } + + /** + * @dataProvider provideDataToEncode + */ + public function testPreSaveTransform( $input, $transformed ) { + $obj = new JsonContent( $input ); + $newObj = $obj->preSaveTransform( + $this->getMockTitle(), + $this->getMockUser(), + $this->getMockParserOptions() + ); + $this->assertTrue( $newObj->equals( new JsonContent( $transformed ) ) ); } private function getMockTitle() { @@ -67,48 +104,55 @@ class JsonContentTest extends MediaWikiLangTestCase { ->getMock(); } - /** - * @dataProvider provideDataAndParserText - */ - public function testFillParserOutput( $data, $expected ) { - $obj = new JsonContent( FormatJson::encode( $data ) ); - $parserOutput = $obj->getParserOutput( $this->getMockTitle(), null, null, true ); - $this->assertInstanceOf( 'ParserOutput', $parserOutput ); - $this->assertEquals( $expected, $parserOutput->getText() ); - } - public static function provideDataAndParserText() { return array( array( array(), - '
' + '
' . + '' + . '
Empty array
' ), array( - array( 'foo' ), - '
0"foo"
' + (object)array(), + '' . + '
Empty object
' ), array( - array( 'foo', 'bar' ), - '' . - "\n" . - '
0"foo"
1"bar"
' + (object)array( 'foo' ), + '' . + '
0"foo"
' ), array( - array( 'baz' => 'foo', 'bar' ), - '' . - "\n" . - '
baz"foo"
0"bar"
' + (object)array( 'foo', 'bar' ), + '' . + '
0"foo"
1"bar"
' ), array( - array( 'baz' => 1000, 'bar' ), + (object)array( 'baz' => 'foo', 'bar' ), + '' . + '
baz"foo"
0"bar"
' + ), + array( + (object)array( 'baz' => 1000, 'bar' ), '' . - "\n" . - '
baz1000
0"bar"
' + '0"bar"' ), array( - array( ''), - '
0"<script>alert("evil!")</script>"
', + (object)array( ''), + '
0"' . + '<script>alert("evil!")</script>"' . + '
', ), ); } + + /** + * @dataProvider provideDataAndParserText + */ + public function testFillParserOutput( $data, $expected ) { + $obj = new JsonContent( FormatJson::encode( $data ) ); + $parserOutput = $obj->getParserOutput( $this->getMockTitle(), null, null, true ); + $this->assertInstanceOf( 'ParserOutput', $parserOutput ); + $this->assertEquals( $expected, $parserOutput->getText() ); + } } diff --git a/tests/phpunit/includes/content/TextContentTest.php b/tests/phpunit/includes/content/TextContentTest.php index 2f811094..dd61f85b 100644 --- a/tests/phpunit/includes/content/TextContentTest.php +++ b/tests/phpunit/includes/content/TextContentTest.php @@ -7,11 +7,8 @@ */ class TextContentTest extends MediaWikiLangTestCase { protected $context; - protected $savedContentGetParserOutput; protected function setUp() { - global $wgHooks; - parent::setUp(); // Anon user @@ -32,24 +29,8 @@ class TextContentTest extends MediaWikiLangTestCase { 'wgUseTidy' => false, 'wgAlwaysUseTidy' => false, 'wgCapitalLinks' => true, + 'wgHooks' => array(), // bypass hook ContentGetParserOutput that force custom rendering ) ); - - // bypass hooks that force custom rendering - if ( isset( $wgHooks['ContentGetParserOutput'] ) ) { - $this->savedContentGetParserOutput = $wgHooks['ContentGetParserOutput']; - unset( $wgHooks['ContentGetParserOutput'] ); - } - } - - public function teardown() { - global $wgHooks; - - // restore hooks that force custom rendering - if ( $this->savedContentGetParserOutput !== null ) { - $wgHooks['ContentGetParserOutput'] = $this->savedContentGetParserOutput; - } - - parent::teardown(); } public function newContent( $text ) { -- cgit v1.2.3-54-g00ecf