summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/content
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /tests/phpunit/includes/content
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'tests/phpunit/includes/content')
-rw-r--r--tests/phpunit/includes/content/ContentHandlerTest.php15
-rw-r--r--tests/phpunit/includes/content/JsonContentTest.php142
-rw-r--r--tests/phpunit/includes/content/TextContentTest.php21
3 files changed, 103 insertions, 75 deletions
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(),
- '<table class="mw-json"><tbody></tbody></table>'
+ '<table class="mw-json"><tbody><tr><td>' .
+ '<table class="mw-json"><tbody><tr><td class="mw-json-empty">Empty array</td></tr>'
+ . '</tbody></table></td></tr></tbody></table>'
),
array(
- array( 'foo' ),
- '<table class="mw-json"><tbody><tr><th>0</th><td class="value">&quot;foo&quot;</td></tr></tbody></table>'
+ (object)array(),
+ '<table class="mw-json"><tbody><tr><td class="mw-json-empty">Empty object</td></tr>' .
+ '</tbody></table>'
),
array(
- array( 'foo', 'bar' ),
- '<table class="mw-json"><tbody><tr><th>0</th><td class="value">&quot;foo&quot;</td></tr>' .
- "\n" .
- '<tr><th>1</th><td class="value">&quot;bar&quot;</td></tr></tbody></table>'
+ (object)array( 'foo' ),
+ '<table class="mw-json"><tbody><tr><th>0</th><td class="value">"foo"</td></tr>' .
+ '</tbody></table>'
),
array(
- array( 'baz' => 'foo', 'bar' ),
- '<table class="mw-json"><tbody><tr><th>baz</th><td class="value">&quot;foo&quot;</td></tr>' .
- "\n" .
- '<tr><th>0</th><td class="value">&quot;bar&quot;</td></tr></tbody></table>'
+ (object)array( 'foo', 'bar' ),
+ '<table class="mw-json"><tbody><tr><th>0</th><td class="value">"foo"</td></tr>' .
+ '<tr><th>1</th><td class="value">"bar"</td></tr></tbody></table>'
),
array(
- array( 'baz' => 1000, 'bar' ),
+ (object)array( 'baz' => 'foo', 'bar' ),
+ '<table class="mw-json"><tbody><tr><th>baz</th><td class="value">"foo"</td></tr>' .
+ '<tr><th>0</th><td class="value">"bar"</td></tr></tbody></table>'
+ ),
+ array(
+ (object)array( 'baz' => 1000, 'bar' ),
'<table class="mw-json"><tbody><tr><th>baz</th><td class="value">1000</td></tr>' .
- "\n" .
- '<tr><th>0</th><td class="value">&quot;bar&quot;</td></tr></tbody></table>'
+ '<tr><th>0</th><td class="value">"bar"</td></tr></tbody></table>'
),
array(
- array( '<script>alert("evil!")</script>'),
- '<table class="mw-json"><tbody><tr><th>0</th><td class="value">&quot;&lt;script&gt;alert(&quot;evil!&quot;)&lt;/script&gt;&quot;</td></tr></tbody></table>',
+ (object)array( '<script>alert("evil!")</script>'),
+ '<table class="mw-json"><tbody><tr><th>0</th><td class="value">"' .
+ '&lt;script>alert("evil!")&lt;/script>"' .
+ '</td></tr></tbody></table>',
),
);
}
+
+ /**
+ * @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 ) {