summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/parser
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/parser')
-rw-r--r--tests/phpunit/includes/parser/MediaWikiParserTest.php2
-rw-r--r--tests/phpunit/includes/parser/NewParserTest.php18
-rw-r--r--tests/phpunit/includes/parser/ParserMethodsTest.php33
-rw-r--r--tests/phpunit/includes/parser/PreprocessorTest.php4
4 files changed, 46 insertions, 11 deletions
diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php b/tests/phpunit/includes/parser/MediaWikiParserTest.php
index 816c017a..6a6fded1 100644
--- a/tests/phpunit/includes/parser/MediaWikiParserTest.php
+++ b/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -1,5 +1,5 @@
<?php
-require_once( dirname( __FILE__ ) . '/NewParserTest.php' );
+require_once( __DIR__ . '/NewParserTest.php' );
/**
* The UnitTest must be either a class that inherits from MediaWikiTestCase
diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php
index d9b16710..69a96e66 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -186,7 +186,7 @@ class NewParserTest extends MediaWikiTestCase {
if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
$image->recordUpload2(
'', // archive name
- 'Upload of some lame file',
+ 'Upload of some lame file',
'Some lame file',
array(
'size' => 12345,
@@ -197,7 +197,7 @@ class NewParserTest extends MediaWikiTestCase {
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
+ 'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
}
@@ -207,8 +207,8 @@ class NewParserTest extends MediaWikiTestCase {
if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
$image->recordUpload2(
'', // archive name
- 'zomgnotcensored',
- 'Borderline image',
+ 'zomgnotcensored',
+ 'Borderline image',
array(
'size' => 12345,
'width' => 320,
@@ -218,7 +218,7 @@ class NewParserTest extends MediaWikiTestCase {
'mime' => 'image/jpeg',
'metadata' => serialize( array() ),
'sha1' => wfBaseConvert( '', 16, 36, 31 ),
- 'fileExists' => true ),
+ 'fileExists' => true ),
$this->db->timestamp( '20010115123500' ), $user
);
}
@@ -326,7 +326,6 @@ class NewParserTest extends MediaWikiTestCase {
'wgExternalLinkTarget' => false,
'wgAlwaysUseTidy' => false,
'wgHtml5' => true,
- 'wgCleanupPresentationalAttributes' => true,
'wgWellFormedXml' => true,
'wgAllowMicrodataAttributes' => true,
'wgAdaptiveMessageCache' => true,
@@ -345,6 +344,9 @@ class NewParserTest extends MediaWikiTestCase {
$this->savedGlobals = array();
+ /** @since 1.20 */
+ wfRunHooks( 'ParserTestGlobals', array( &$settings ) );
+
foreach ( $settings as $var => $val ) {
if ( array_key_exists( $var, $GLOBALS ) ) {
$this->savedGlobals[$var] = $GLOBALS[$var];
@@ -380,7 +382,7 @@ class NewParserTest extends MediaWikiTestCase {
# The entries saved into RepoGroup cache with previous globals will be wrong.
RepoGroup::destroySingleton();
FileBackendGroup::destroySingleton();
- MessageCache::singleton()->destroyInstance();
+ MessageCache::destroyInstance();
return $context;
}
@@ -596,7 +598,7 @@ class NewParserTest extends MediaWikiTestCase {
* Run a fuzz test series
* Draw input from a set of test files
*
- * @todo @fixme Needs some work to not eat memory until the world explodes
+ * @todo fixme Needs some work to not eat memory until the world explodes
*
* @group ParserFuzz
*/
diff --git a/tests/phpunit/includes/parser/ParserMethodsTest.php b/tests/phpunit/includes/parser/ParserMethodsTest.php
new file mode 100644
index 00000000..dea406c3
--- /dev/null
+++ b/tests/phpunit/includes/parser/ParserMethodsTest.php
@@ -0,0 +1,33 @@
+<?php
+
+class ParserMethodsTest extends MediaWikiLangTestCase {
+
+ public function dataPreSaveTransform() {
+ return array(
+ array( 'hello this is ~~~',
+ "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
+ ),
+ array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider dataPreSaveTransform
+ */
+ public function testPreSaveTransform( $text, $expected ) {
+ global $wgParser;
+
+ $title = Title::newFromText( str_replace( '::', '__', __METHOD__ ) );
+ $user = new User();
+ $user->setName( "127.0.0.1" );
+ $popts = ParserOptions::newFromUser( $user );
+ $text = $wgParser->preSaveTransform( $text, $title, $user, $popts );
+
+ $this->assertEquals( $expected, $text );
+ }
+
+ // TODO: Add tests for cleanSig() / cleanSigInSig(), getSection(), replaceSection(), getPreloadText()
+}
+
diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php
index 9d3499a0..fee56748 100644
--- a/tests/phpunit/includes/parser/PreprocessorTest.php
+++ b/tests/phpunit/includes/parser/PreprocessorTest.php
@@ -103,7 +103,7 @@ class PreprocessorTest extends MediaWikiTestCase {
array( "{{foo|bar=|}", "<root>{{foo|bar=|}</root>"),
array( "{{Foo|} Bar=", "<root>{{Foo|} Bar=</root>"),
array( "{{Foo|} Bar=}}", "<root><template><title>Foo</title><part><name>} Bar</name>=<value></value></part></template></root>"),
- /* array( file_get_contents( dirname( __FILE__ ) . '/QuoteQuran.txt' ), file_get_contents( dirname( __FILE__ ) . '/QuoteQuranExpanded.txt' ) ), */
+ /* array( file_get_contents( __DIR__ . '/QuoteQuran.txt' ), file_get_contents( __DIR__ . '/QuoteQuranExpanded.txt' ) ), */
);
}
@@ -165,7 +165,7 @@ class PreprocessorTest extends MediaWikiTestCase {
* @dataProvider provideFiles
*/
function testPreprocessorOutputFiles( $filename ) {
- $folder = dirname( __FILE__ ) . "/../../../parser/preprocess";
+ $folder = __DIR__ . "/../../../parser/preprocess";
$wikiText = file_get_contents( "$folder/$filename.txt" );
$output = $this->preprocessToXml( $wikiText );