*/
/** */
-$options = array( 'quick', 'color' );
+$options = array( 'quick', 'color', 'quiet', 'help' );
$optionsWithArgs = array( 'regex' );
require_once( 'commandLine.inc' );
}
$this->showDiffs = !isset( $options['quick'] );
+
+ $this->quiet = isset( $options['quiet'] );
if (isset($options['regex'])) {
$this->regex = $options['regex'];
* @return bool
*/
function runTest( $desc, $input, $result, $opts ) {
- print "Running test $desc... ";
+ if( !$this->quiet ) {
+ $this->showTesting( $desc );
+ }
$this->setupGlobals($opts);
if (preg_match('/\\bpst\\b/i', $opts)) {
$out = $parser->preSaveTransform( $input, $title, $user, $options );
- }
- else if (preg_match('/\\bmsg\\b/i', $opts)) {
+ } elseif (preg_match('/\\bmsg\\b/i', $opts)) {
$out = $parser->transformMsg( $input, $options );
- }
- else {
+ } else {
$output =& $parser->parse( $input, $title, $options );
$out = $output->getText();
if (preg_match('/\\bill\\b/i', $opts)) {
$out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
- }
- else if (preg_match('/\\bcat\\b/i', $opts)) {
+ } else if (preg_match('/\\bcat\\b/i', $opts)) {
$out = $this->tidy ( implode( ' ', $output->getCategoryLinks() ) );
}
foreach( $this->listTables() as $table ) {
$this->oldTableNames[$table] = $db->tableName( $table );
}
+ if( !isset( $this->uploadDir ) ) {
+ $this->uploadDir = $this->setupUploadDir();
+ }
$settings = array(
'wgServer' => 'http://localhost',
'wgScriptPath' => '/',
'wgArticlePath' => '/wiki/$1',
'wgUploadPath' => '/images',
+ 'wgUploadDirectory' => $this->uploadDir,
+ 'wgStyleSheetPath' => '/skins',
'wgSitename' => 'MediaWiki',
'wgLanguageCode' => 'en',
'wgUseLatin1' => false,
}
}
+ /**
+ * Create a dummy uploads directory which will contain a couple
+ * of files in order to pass existence tests.
+ * @return string The directory
+ * @access private
+ */
+ function setupUploadDir() {
+ $dir = "/tmp/mwParser-" . mt_rand() . "-images";
+ mkdir( $dir );
+ mkdir( $dir . '/3' );
+ mkdir( $dir . '/3/3a' );
+ $f = fopen( $dir . '/3/3a/Foobar.jpg', 'wb' );
+ fwrite( $f, 'Dummy file' );
+ fclose( $f );
+ return $dir;
+ }
+
/**
* Restore default values and perform any necessary clean-up
* after each test runs.
foreach( $this->savedGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
+ if( isset( $this->uploadDir ) ) {
+ $this->teardownUploadDir( $this->uploadDir );
+ unset( $this->uploadDir );
+ }
+ }
+
+ /**
+ * Remove the dummy uploads directory
+ * @access private
+ */
+ function teardownUploadDir( $dir ) {
+ unlink( "$dir/3/3a/Foobar.jpg" );
+ rmdir( "$dir/3/3a" );
+ rmdir( "$dir/3" );
+ @rmdir( "$dir/thumb/3/39" );
+ @rmdir( "$dir/thumb/3" );
+ @rmdir( "$dir/thumb" );
+ rmdir( "$dir" );
+ }
+
+ /**
+ * "Running test $desc..."
+ * @access private
+ */
+ function showTesting( $desc ) {
+ print "Running test $desc... ";
}
/**
* @access private
*/
function showSuccess( $desc ) {
- print $this->termColor( '1;32' ) . 'PASSED' . $this->termReset() . "\n";
+ if( !$this->quiet ) {
+ print $this->termColor( '1;32' ) . 'PASSED' . $this->termReset() . "\n";
+ }
return true;
}
* @access private
*/
function showFailure( $desc, $result, $html ) {
+ if( $this->quiet ) {
+ # In quiet mode we didn't show the 'Testing' message before the
+ # test, in case it succeeded. Show it now:
+ $this->showTesting( $desc );
+ }
print $this->termColor( '1;31' ) . 'FAILED!' . $this->termReset() . "\n";
if( $this->showDiffs ) {
print $this->quickDiff( $result, $html );
}
}
+if( isset( $options['help'] ) ) {
+ echo <<<END
+MediaWiki $wgVersion parser test suite
+Usage: php parserTests.php [--quick] [--quiet] [--color[=(yes|no)]]
+ [--regex <expression>] [--help]
+Options:
+ --quick Suppress diff output of failed tests
+ --quiet Suppress notification of passed tests (shows only failed tests)
+ --color Override terminal detection and force color output on or off
+ --regex Only run tests whose descriptions which match given regex
+ --help Show this help message
+
+
+END;
+ exit( 0 );
+}
+
# There is a convention that the parser should never
# refer to $wgTitle directly, but instead use the title
# passed to it.
!! test
Simple image
!! input
-[[Image: test]]
+[[Image:foobar.jpg]]
!! result
-<p><a href="/wiki/Image:Test" class="image" title="Image: test"><img src="/images/0/0c/Test" alt="Image: test" longdesc="http://localhost/wiki/Image:Test" /></a>
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="Image:foobar.jpg"><img src="/images/3/3a/Foobar.jpg" alt="Image:foobar.jpg" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a>
</p>
!! end
!! test
Right-aligned image
!! input
-[[Image:test|right]]
+[[Image:foobar.jpg|right]]
!! result
-<div class="floatright"><span><a href="/wiki/Image:Test" class="image" title=""><img src="/images/0/0c/Test" alt="" longdesc="http://localhost/wiki/Image:Test" /></a></span></div>
+<div class="floatright"><span><a href="/wiki/Image:Foobar.jpg" class="image" title=""><img src="/images/3/3a/Foobar.jpg" alt="" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a></span></div>
!! end
!! test
Image with caption
!! input
-[[Image:test|right|Caption text]]
+[[Image:foobar.jpg|right|Caption text]]
!! result
-<div class="floatright"><span><a href="/wiki/Image:Test" class="image" title="Caption text"><img src="/images/0/0c/Test" alt="Caption text" longdesc="http://localhost/wiki/Image:Test" /></a></span></div>
+<div class="floatright"><span><a href="/wiki/Image:Foobar.jpg" class="image" title="Caption text"><img src="/images/3/3a/Foobar.jpg" alt="Caption text" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a></span></div>
!! end
!! test
Frameless image caption with a free URL
!! input
-[[Image:foo|http://example.com]]
+[[Image:foobar.jpg|http://example.com]]
!! result
-<p><a href="/wiki/Image:Foo" class="image" title="http://example.com"><img src="/images/1/13/Foo" alt="http://example.com" longdesc="http://localhost/wiki/Image:Foo" /></a>
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="http://example.com"><img src="/images/3/3a/Foobar.jpg" alt="http://example.com" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a>
</p>
!! end
!! test
Thumbnail image caption with a free URL
!! input
-[[Image:foo|thumb|http://example.com]]
+[[Image:foobar.jpg|thumb|http://example.com]]
!! result
-<div class="thumb tright"><div style="width:182px;"><b>Missing image</b><br /><i>Foo</i> <div class="thumbcaption" ><a href="http://example.com" class='external'>http://example.com</a></div></div></div>
+<div class="thumb tright"><div style="width:182px;"><a href="/wiki/Image:Foobar.jpg" class="internal" title="http://example.com"><img src="/images/3/3a/Foobar.jpg" alt="http://example.com" width="180" height="180" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a> <div class="thumbcaption" ><div class="magnify" style="float:right"><a href="/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div><a href="http://example.com" class='external'>http://example.com</a></div></div></div>
!! end
!! test
BUG 648: Frameless image caption with a link
!! input
-[[Image:foo|text with a [[link]] in it]]
+[[Image:foobar.jpg|text with a [[link]] in it]]
!! result
-<p><a href="/wiki/Image:Foo" class="image" title="text with a link in it"><img src="/images/1/13/Foo" alt="text with a link in it" longdesc="http://localhost/wiki/Image:Foo" /></a>
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="text with a link in it"><img src="/images/3/3a/Foobar.jpg" alt="text with a link in it" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a>
</p>
!! end
!! test
Escape HTML special chars in image alt text
!! input
-[[Image:example.jpg|& < > "]]
+[[Image:foobar.jpg|& < > "]]
!! result
-<p><a href="/wiki/Image:Example.jpg" class="image" title="& < > ""><img src="/images/a/a9/Example.jpg" alt="& < > "" longdesc="http://localhost/wiki/Image:Example.jpg" /></a>
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="& < > ""><img src="/images/3/3a/Foobar.jpg" alt="& < > "" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a>
</p>
!! end
!! test
BUG 499: Alt text should have Ӓ, not &1234;
!! input
-[[Image:image.jpg|♀]]
+[[Image:foobar.jpg|♀]]
!! result
-<p><a href="/wiki/Image:Image.jpg" class="image" title="♀"><img src="/images/7/78/Image.jpg" alt="♀" longdesc="http://localhost/wiki/Image:Image.jpg" /></a>
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="♀"><img src="/images/3/3a/Foobar.jpg" alt="♀" longdesc="http://localhost/wiki/Image:Foobar.jpg" /></a>
</p>
!! end
!! test
Broken image caption with link
!! input
-[[Image:Rowan.jpeg|thumb|This is a broken caption. But [[Main Page|this]] is just an ordinary link.
+[[Image:Foobar.jpg|thumb|This is a broken caption. But [[Main Page|this]] is just an ordinary link.
!! result
-<p>[[Image:Rowan.jpeg|thumb|This is a broken caption. But <a href="/wiki/Main_Page" title="Main Page">this</a> is just an ordinary link.
+<p>[[Image:Foobar.jpg|thumb|This is a broken caption. But <a href="/wiki/Main_Page" title="Main Page">this</a> is just an ordinary link.
</p>
!! end
!! test
Image caption containing another image
!! input
-[[Image:Bar.jpeg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]]
+[[Image:Foobar.jpg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]]
!! result
-<div class="thumb tright"><div style="width:182px;"><b>Missing image</b><br /><i>Bar.jpeg</i> <div class="thumbcaption" >This is a caption with another <a href="/wiki/Image:Icon.png" class="image" title="image"><img src="/images/9/96/Icon.png" alt="image" longdesc="http://localhost/wiki/Image:Icon.png" /></a> inside it!</div></div></div>
+<div class="thumb tright"><div style="width:182px;"><b>Missing image</b><br /><i>Foobar.jpg</i> <div class="thumbcaption" >This is a caption with another <a href="/wiki/Image:Icon.png" class="image" title="image"><img src="/images/9/96/Icon.png" alt="image" longdesc="http://localhost/wiki/Image:Icon.png" /></a> inside it!</div></div></div>
!! end