2010-12-14 16:26:35 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2014-07-18 19:35:43 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @group GlobalFunctions
|
|
|
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
|
class GlobalTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
|
protected function setUp() {
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
2015-02-11 01:42:33 +00:00
|
|
|
|
$readOnlyFile = $this->getNewTempFile();
|
2012-10-08 10:56:20 +00:00
|
|
|
|
unlink( $readOnlyFile );
|
|
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
|
'wgReadOnlyFile' => $readOnlyFile,
|
|
|
|
|
|
'wgUrlProtocols' => array(
|
|
|
|
|
|
'http://',
|
|
|
|
|
|
'https://',
|
|
|
|
|
|
'mailto:',
|
|
|
|
|
|
'//',
|
|
|
|
|
|
'file://', # Non-default
|
|
|
|
|
|
),
|
|
|
|
|
|
) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideForWfArrayDiff2
|
|
|
|
|
|
* @covers ::wfArrayDiff2
|
|
|
|
|
|
*/
|
2011-02-06 13:59:06 +00:00
|
|
|
|
public function testWfArrayDiff2( $a, $b, $expected ) {
|
|
|
|
|
|
$this->assertEquals(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
wfArrayDiff2( $a, $b ), $expected
|
2011-02-06 13:59:06 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @todo Provide more tests
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideForWfArrayDiff2() {
|
2011-02-06 13:59:06 +00:00
|
|
|
|
// $a $b $expected
|
|
|
|
|
|
return array(
|
|
|
|
|
|
array(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'a', 'b' ),
|
|
|
|
|
|
array( 'a', 'b' ),
|
2011-02-06 13:59:06 +00:00
|
|
|
|
array(),
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( array( 'a' ), array( 'a', 'b', 'c' ) ),
|
|
|
|
|
|
array( array( 'a' ), array( 'a', 'b' ) ),
|
2011-02-06 13:59:06 +00:00
|
|
|
|
array( 1 => array( 'a', 'b', 'c' ) ),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-23 15:28:50 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* Test cases for random functions could hypothetically fail,
|
|
|
|
|
|
* even though they shouldn't.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfRandom
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testRandom() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertFalse(
|
2014-07-23 15:28:50 +00:00
|
|
|
|
wfRandom() == wfRandom()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfRandomString
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testRandomString() {
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
|
wfRandomString() == wfRandomString()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
strlen( wfRandomString( 10 ) ), 10
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
|
preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
|
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfUrlencode
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testUrlencode() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
"%E7%89%B9%E5%88%A5:Contributions/Foobar",
|
|
|
|
|
|
wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfExpandIRI
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testExpandIRI() {
|
2012-03-29 05:55:27 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
"https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
|
2014-04-24 09:47:06 +00:00
|
|
|
|
wfExpandIRI( "https://te.wikibooks.org/wiki/"
|
|
|
|
|
|
. "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
|
|
|
|
|
|
. "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
|
|
|
|
|
|
. "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
|
|
|
|
|
|
. "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
|
2012-03-29 05:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfReadOnly
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testReadOnlyEmpty() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
global $wgReadOnly;
|
|
|
|
|
|
$wgReadOnly = null;
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( wfReadOnly() );
|
|
|
|
|
|
$this->assertFalse( wfReadOnly() );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfReadOnly
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testReadOnlySet() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
global $wgReadOnly, $wgReadOnlyFile;
|
|
|
|
|
|
|
|
|
|
|
|
$f = fopen( $wgReadOnlyFile, "wt" );
|
|
|
|
|
|
fwrite( $f, 'Message' );
|
|
|
|
|
|
fclose( $f );
|
2010-12-24 12:08:47 +00:00
|
|
|
|
$wgReadOnly = null; # Check on $wgReadOnlyFile
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( wfReadOnly() );
|
2010-12-24 12:08:47 +00:00
|
|
|
|
$this->assertTrue( wfReadOnly() ); # Check cached
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
unlink( $wgReadOnlyFile );
|
2010-12-24 12:08:47 +00:00
|
|
|
|
$wgReadOnly = null; # Clean cache
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( wfReadOnly() );
|
|
|
|
|
|
$this->assertFalse( wfReadOnly() );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideArrayToCGI() {
|
2012-01-05 00:26:13 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
array( array(), '' ), // empty
|
|
|
|
|
|
array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test
|
|
|
|
|
|
array( array( 'foo' => '' ), 'foo=' ), // empty string test
|
|
|
|
|
|
array( array( 'foo' => 1 ), 'foo=1' ), // number test
|
|
|
|
|
|
array( array( 'foo' => true ), 'foo=1' ), // true test
|
|
|
|
|
|
array( array( 'foo' => false ), '' ), // false test
|
2012-08-28 00:51:38 +00:00
|
|
|
|
array( array( 'foo' => null ), '' ), // null test
|
2012-01-05 00:26:13 +00:00
|
|
|
|
array( array( 'foo' => 'A&B=5+6@!"\'' ), 'foo=A%26B%3D5%2B6%40%21%22%27' ), // urlencoding test
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
array( 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ),
|
|
|
|
|
|
'foo=bar&baz=is&asdf=qwerty'
|
|
|
|
|
|
), // multi-item test
|
2012-01-05 00:26:13 +00:00
|
|
|
|
array( array( 'foo' => array( 'bar' => 'baz' ) ), 'foo%5Bbar%5D=baz' ),
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ),
|
|
|
|
|
|
'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
|
|
|
|
|
|
),
|
2012-01-05 00:26:13 +00:00
|
|
|
|
array( array( 'foo' => array( 'bar', 'baz' ) ), 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ),
|
|
|
|
|
|
'foo%5Bbar%5D%5Bbar%5D=baz'
|
|
|
|
|
|
),
|
2012-01-05 00:26:13 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
|
* @dataProvider provideArrayToCGI
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfArrayToCgi
|
2012-01-05 00:26:13 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testArrayToCGI( $array, $result ) {
|
2013-01-28 18:04:20 +00:00
|
|
|
|
$this->assertEquals( $result, wfArrayToCgi( $array ) );
|
2012-01-05 00:26:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
2013-11-16 15:01:24 +00:00
|
|
|
|
* @covers ::wfArrayToCgi
|
2013-10-24 09:53:24 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testArrayToCGI2() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
2012-01-05 00:26:13 +00:00
|
|
|
|
"baz=bar&foo=bar",
|
2013-01-28 18:04:20 +00:00
|
|
|
|
wfArrayToCgi(
|
2012-01-05 00:26:13 +00:00
|
|
|
|
array( 'baz' => 'bar' ),
|
2010-12-14 16:26:35 +00:00
|
|
|
|
array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
|
2011-06-23 15:25:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideCgiToArray() {
|
2012-01-05 00:26:13 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
array( '', array() ), // empty
|
|
|
|
|
|
array( 'foo=bar', array( 'foo' => 'bar' ) ), // string
|
|
|
|
|
|
array( 'foo=', array( 'foo' => '' ) ), // empty string
|
|
|
|
|
|
array( 'foo', array( 'foo' => '' ) ), // missing =
|
|
|
|
|
|
array( 'foo=bar&qwerty=asdf', array( 'foo' => 'bar', 'qwerty' => 'asdf' ) ), // multiple value
|
|
|
|
|
|
array( 'foo=A%26B%3D5%2B6%40%21%22%27', array( 'foo' => 'A&B=5+6@!"\'' ) ), // urldecoding test
|
|
|
|
|
|
array( 'foo%5Bbar%5D=baz', array( 'foo' => array( 'bar' => 'baz' ) ) ),
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
|
|
|
|
|
|
array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) )
|
|
|
|
|
|
),
|
2012-01-05 00:26:13 +00:00
|
|
|
|
array( 'foo%5B0%5D=bar&foo%5B1%5D=baz', array( 'foo' => array( 0 => 'bar', 1 => 'baz' ) ) ),
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
'foo%5Bbar%5D%5Bbar%5D=baz',
|
|
|
|
|
|
array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) )
|
|
|
|
|
|
),
|
2012-01-05 00:26:13 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
|
* @dataProvider provideCgiToArray
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfCgiToArray
|
2012-01-05 00:26:13 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testCgiToArray( $cgi, $result ) {
|
2012-01-05 00:26:13 +00:00
|
|
|
|
$this->assertEquals( $result, wfCgiToArray( $cgi ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideCgiRoundTrip() {
|
2012-01-05 00:26:13 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
array( '' ),
|
|
|
|
|
|
array( 'foo=bar' ),
|
|
|
|
|
|
array( 'foo=' ),
|
|
|
|
|
|
array( 'foo=bar&baz=biz' ),
|
|
|
|
|
|
array( 'foo=A%26B%3D5%2B6%40%21%22%27' ),
|
|
|
|
|
|
array( 'foo%5Bbar%5D=baz' ),
|
|
|
|
|
|
array( 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
|
|
|
|
|
|
array( 'foo%5Bbar%5D%5Bbar%5D=baz' ),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
|
* @dataProvider provideCgiRoundTrip
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfArrayToCgi
|
2012-01-05 00:26:13 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testCgiRoundTrip( $cgi ) {
|
2013-01-28 18:04:20 +00:00
|
|
|
|
$this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::mimeTypeMatch
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testMimeTypeMatch() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'text/html',
|
|
|
|
|
|
mimeTypeMatch( 'text/html',
|
|
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.7,
|
|
|
|
|
|
'text/plain' => 0.3 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'text/*',
|
|
|
|
|
|
mimeTypeMatch( 'text/html',
|
|
|
|
|
|
array( 'image/*' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/*' => 0.5 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'*/*',
|
|
|
|
|
|
mimeTypeMatch( 'text/html',
|
|
|
|
|
|
array( '*/*' => 1.0 ) ) );
|
|
|
|
|
|
$this->assertNull(
|
|
|
|
|
|
mimeTypeMatch( 'text/html',
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'image/png' => 1.0,
|
|
|
|
|
|
'image/svg+xml' => 0.5 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfNegotiateType
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testNegotiateType() {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'text/html',
|
|
|
|
|
|
wfNegotiateType(
|
|
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.7,
|
|
|
|
|
|
'text/plain' => 0.5,
|
|
|
|
|
|
'text/*' => 0.2 ),
|
|
|
|
|
|
array( 'text/html' => 1.0 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'application/xhtml+xml',
|
|
|
|
|
|
wfNegotiateType(
|
|
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.7,
|
|
|
|
|
|
'text/plain' => 0.5,
|
|
|
|
|
|
'text/*' => 0.2 ),
|
2010-12-14 16:26:35 +00:00
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.5 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'text/html',
|
|
|
|
|
|
wfNegotiateType(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'text/html' => 1.0,
|
|
|
|
|
|
'text/plain' => 0.5,
|
|
|
|
|
|
'text/*' => 0.5,
|
|
|
|
|
|
'application/xhtml+xml' => 0.2 ),
|
2010-12-14 16:26:35 +00:00
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.5 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
'text/html',
|
|
|
|
|
|
wfNegotiateType(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'text/*' => 1.0,
|
|
|
|
|
|
'image/*' => 0.7,
|
|
|
|
|
|
'*/*' => 0.3 ),
|
2010-12-14 16:26:35 +00:00
|
|
|
|
array( 'application/xhtml+xml' => 1.0,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
'text/html' => 0.5 ) ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
$this->assertNull(
|
|
|
|
|
|
wfNegotiateType(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'text/*' => 1.0 ),
|
2010-12-14 16:26:35 +00:00
|
|
|
|
array( 'application/xhtml+xml' => 1.0 ) ) );
|
|
|
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfDebug
|
|
|
|
|
|
* @covers ::wfDebugMem
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testDebugFunctionTest() {
|
2015-02-11 01:42:33 +00:00
|
|
|
|
$debugLogFile = $this->getNewTempFile();
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2015-02-11 01:42:33 +00:00
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
|
'wgDebugLogFile' => $debugLogFile,
|
|
|
|
|
|
# @todo FIXME: $wgDebugTimestamps should be tested
|
|
|
|
|
|
'wgDebugTimestamps' => false
|
|
|
|
|
|
) );
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2011-01-02 01:59:52 +00:00
|
|
|
|
wfDebug( "This is a normal string" );
|
2015-02-11 01:42:33 +00:00
|
|
|
|
$this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
|
|
|
|
|
|
unlink( $debugLogFile );
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2011-01-02 01:59:52 +00:00
|
|
|
|
wfDebug( "This is nöt an ASCII string" );
|
2015-02-11 01:42:33 +00:00
|
|
|
|
$this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
|
|
|
|
|
|
unlink( $debugLogFile );
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2011-01-02 01:59:52 +00:00
|
|
|
|
wfDebug( "\00305This has böth UTF and control chars\003" );
|
2014-04-24 09:47:06 +00:00
|
|
|
|
$this->assertEquals(
|
2014-03-21 05:01:24 +00:00
|
|
|
|
" 05This has böth UTF and control chars \n",
|
2015-02-11 01:42:33 +00:00
|
|
|
|
file_get_contents( $debugLogFile )
|
2014-04-24 09:47:06 +00:00
|
|
|
|
);
|
2015-02-11 01:42:33 +00:00
|
|
|
|
unlink( $debugLogFile );
|
2012-08-27 20:57:15 +00:00
|
|
|
|
|
2011-01-02 02:33:07 +00:00
|
|
|
|
wfDebugMem();
|
2014-04-24 09:47:06 +00:00
|
|
|
|
$this->assertGreaterThan(
|
|
|
|
|
|
1000,
|
2015-02-11 01:42:33 +00:00
|
|
|
|
preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
|
2014-04-24 09:47:06 +00:00
|
|
|
|
);
|
2015-02-11 01:42:33 +00:00
|
|
|
|
unlink( $debugLogFile );
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
|
wfDebugMem( true );
|
2014-04-24 09:47:06 +00:00
|
|
|
|
$this->assertGreaterThan(
|
|
|
|
|
|
1000000,
|
2015-02-11 01:42:33 +00:00
|
|
|
|
preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
|
2014-04-24 09:47:06 +00:00
|
|
|
|
);
|
2015-02-11 01:42:33 +00:00
|
|
|
|
unlink( $debugLogFile );
|
2011-01-02 01:59:52 +00:00
|
|
|
|
}
|
2012-10-15 13:40:21 +00:00
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfClientAcceptsGzip
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testClientAcceptsGzipTest() {
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
2011-01-02 04:38:04 +00:00
|
|
|
|
$settings = array(
|
|
|
|
|
|
'gzip' => true,
|
|
|
|
|
|
'bzip' => false,
|
|
|
|
|
|
'*' => false,
|
|
|
|
|
|
'compress, gzip' => true,
|
|
|
|
|
|
'gzip;q=1.0' => true,
|
|
|
|
|
|
'foozip' => false,
|
|
|
|
|
|
'foo*zip' => false,
|
|
|
|
|
|
'gzip;q=abcde' => true, //is this REALLY valid?
|
|
|
|
|
|
'gzip;q=12345678.9' => true,
|
|
|
|
|
|
' gzip' => true,
|
|
|
|
|
|
);
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
|
|
|
|
|
if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
|
|
|
|
|
|
$old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-01-02 04:38:04 +00:00
|
|
|
|
foreach ( $settings as $encoding => $expect ) {
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
2011-01-02 04:38:04 +00:00
|
|
|
|
$this->assertEquals( $expect, wfClientAcceptsGzip( true ),
|
|
|
|
|
|
"'$encoding' => " . wfBoolToStr( $expect ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
|
if ( isset( $old_server_setting ) ) {
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
|
|
|
|
|
|
}
|
2011-01-02 04:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::swap
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testSwapVarsTest() {
|
2014-06-18 01:40:03 +00:00
|
|
|
|
$this->hideDeprecated( 'swap' );
|
|
|
|
|
|
|
2011-01-02 04:38:04 +00:00
|
|
|
|
$var1 = 1;
|
|
|
|
|
|
$var2 = 2;
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $var1, 1, 'var1 is set originally' );
|
|
|
|
|
|
$this->assertEquals( $var2, 2, 'var1 is set originally' );
|
|
|
|
|
|
|
|
|
|
|
|
swap( $var1, $var2 );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $var1, 2, 'var1 is swapped' );
|
|
|
|
|
|
$this->assertEquals( $var2, 1, 'var2 is swapped' );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfPercent
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testWfPercentTest() {
|
2011-01-02 04:38:04 +00:00
|
|
|
|
|
|
|
|
|
|
$pcts = array(
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 6 / 7, '0.86%', 2, false ),
|
|
|
|
|
|
array( 3 / 3, '1%' ),
|
|
|
|
|
|
array( 22 / 7, '3.14286%', 5 ),
|
|
|
|
|
|
array( 3 / 6, '0.5%' ),
|
|
|
|
|
|
array( 1 / 3, '0%', 0 ),
|
|
|
|
|
|
array( 10 / 3, '0%', -1 ),
|
|
|
|
|
|
array( 3 / 4 / 5, '0.1%', 1 ),
|
|
|
|
|
|
array( 6 / 7 * 8, '6.8571428571%', 10 ),
|
2011-01-02 04:38:04 +00:00
|
|
|
|
);
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
|
|
|
|
|
foreach ( $pcts as $pct ) {
|
|
|
|
|
|
if ( !isset( $pct[2] ) ) {
|
|
|
|
|
|
$pct[2] = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( !isset( $pct[3] ) ) {
|
|
|
|
|
|
$pct[3] = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-01-02 04:38:04 +00:00
|
|
|
|
$this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-06 18:02:47 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* test @see wfShorthandToInteger()
|
|
|
|
|
|
* @dataProvider provideShorthand
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfShorthandToInteger
|
2011-02-06 18:02:47 +00:00
|
|
|
|
*/
|
|
|
|
|
|
public function testWfShorthandToInteger( $shorthand, $expected ) {
|
|
|
|
|
|
$this->assertEquals( $expected,
|
|
|
|
|
|
wfShorthandToInteger( $shorthand )
|
2013-02-14 11:22:13 +00:00
|
|
|
|
);
|
2011-02-06 18:02:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** array( shorthand, expected integer ) */
|
2012-10-08 10:56:20 +00:00
|
|
|
|
public static function provideShorthand() {
|
2011-02-06 18:02:47 +00:00
|
|
|
|
return array(
|
2013-08-24 15:06:25 +00:00
|
|
|
|
# Null, empty ...
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( '', -1 ),
|
|
|
|
|
|
array( ' ', -1 ),
|
|
|
|
|
|
array( null, -1 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Failures returns 0 :(
|
|
|
|
|
|
array( 'ABCDEFG', 0 ),
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'Ak', 0 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Int, strings with spaces
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 1, 1 ),
|
|
|
|
|
|
array( ' 1 ', 1 ),
|
|
|
|
|
|
array( 1023, 1023 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
array( ' 1023 ', 1023 ),
|
|
|
|
|
|
|
|
|
|
|
|
# kilo, Mega, Giga
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( '1k', 1024 ),
|
|
|
|
|
|
array( '1K', 1024 ),
|
|
|
|
|
|
array( '1m', 1024 * 1024 ),
|
|
|
|
|
|
array( '1M', 1024 * 1024 ),
|
|
|
|
|
|
array( '1g', 1024 * 1024 * 1024 ),
|
|
|
|
|
|
array( '1G', 1024 * 1024 * 1024 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Negatives
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( -1, -1 ),
|
|
|
|
|
|
array( -500, -500 ),
|
|
|
|
|
|
array( '-500', -500 ),
|
|
|
|
|
|
array( '-1k', -1024 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
# Zeroes
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( '0', 0 ),
|
|
|
|
|
|
array( '0k', 0 ),
|
|
|
|
|
|
array( '0M', 0 ),
|
|
|
|
|
|
array( '0G', 0 ),
|
|
|
|
|
|
array( '-0', 0 ),
|
2011-02-06 18:02:47 +00:00
|
|
|
|
array( '-0k', 0 ),
|
|
|
|
|
|
array( '-0M', 0 ),
|
|
|
|
|
|
array( '-0G', 0 ),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-10 16:18:12 +00:00
|
|
|
|
/**
|
2014-04-08 15:29:17 +00:00
|
|
|
|
* @param string $old Text as it was in the database
|
|
|
|
|
|
* @param string $mine Text submitted while user was editing
|
|
|
|
|
|
* @param string $yours Text submitted by the user
|
|
|
|
|
|
* @param bool $expectedMergeResult Whether the merge should be a success
|
|
|
|
|
|
* @param string $expectedText Text after merge has been completed
|
2012-11-10 16:18:12 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @dataProvider provideMerge()
|
2013-01-18 19:02:28 +00:00
|
|
|
|
* @group medium
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfMerge
|
2012-11-10 16:18:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
|
2012-11-22 16:45:50 +00:00
|
|
|
|
$this->checkHasDiff3();
|
|
|
|
|
|
|
2012-11-10 16:18:12 +00:00
|
|
|
|
$mergedText = null;
|
|
|
|
|
|
$isMerged = wfMerge( $old, $mine, $yours, $mergedText );
|
|
|
|
|
|
|
|
|
|
|
|
$msg = 'Merge should be a ';
|
|
|
|
|
|
$msg .= $expectedMergeResult ? 'success' : 'failure';
|
|
|
|
|
|
$this->assertEquals( $expectedMergeResult, $isMerged, $msg );
|
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
|
if ( $isMerged ) {
|
2012-11-10 16:18:12 +00:00
|
|
|
|
// Verify the merged text
|
|
|
|
|
|
$this->assertEquals( $expectedText, $mergedText,
|
|
|
|
|
|
'is merged text as expected?' );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function provideMerge() {
|
|
|
|
|
|
$EXPECT_MERGE_SUCCESS = true;
|
|
|
|
|
|
$EXPECT_MERGE_FAILURE = false;
|
|
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
|
// #0: clean merge
|
|
|
|
|
|
array(
|
|
|
|
|
|
// old:
|
|
|
|
|
|
"one one one\n" . // trimmed
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"two two two",
|
2012-11-10 16:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
// mine:
|
|
|
|
|
|
"one one one ONE ONE\n" .
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"two two two\n", // with tailing whitespace
|
2012-11-10 16:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
// yours:
|
|
|
|
|
|
"one one one\n" .
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"two two TWO TWO", // trimmed
|
2012-11-10 16:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
// ok:
|
|
|
|
|
|
$EXPECT_MERGE_SUCCESS,
|
|
|
|
|
|
|
|
|
|
|
|
// result:
|
|
|
|
|
|
"one one one ONE ONE\n" .
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"two two TWO TWO\n", // note: will always end in a newline
|
2012-11-10 16:18:12 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
// #1: conflict, fail
|
|
|
|
|
|
array(
|
|
|
|
|
|
// old:
|
|
|
|
|
|
"one one one", // trimmed
|
|
|
|
|
|
|
|
|
|
|
|
// mine:
|
|
|
|
|
|
"one one one ONE ONE\n" .
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"bla bla\n" .
|
|
|
|
|
|
"\n", // with tailing whitespace
|
2012-11-10 16:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
// yours:
|
|
|
|
|
|
"one one one\n" .
|
2013-02-14 11:22:13 +00:00
|
|
|
|
"\n" .
|
|
|
|
|
|
"two two", // trimmed
|
2012-11-10 16:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
$EXPECT_MERGE_FAILURE,
|
|
|
|
|
|
|
|
|
|
|
|
// result:
|
|
|
|
|
|
null,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-25 21:00:49 +00:00
|
|
|
|
/**
|
2011-11-14 09:13:58 +00:00
|
|
|
|
* @dataProvider provideMakeUrlIndexes()
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfMakeUrlIndexes
|
2011-04-25 21:00:49 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testMakeUrlIndexes( $url, $expected ) {
|
2011-11-14 09:13:58 +00:00
|
|
|
|
$index = wfMakeUrlIndexes( $url );
|
|
|
|
|
|
$this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
|
2011-04-25 21:00:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function provideMakeUrlIndexes() {
|
2011-04-25 21:00:49 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
array(
|
|
|
|
|
|
// just a regular :)
|
|
|
|
|
|
'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
|
2011-11-14 09:13:58 +00:00
|
|
|
|
array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
|
2011-04-25 21:00:49 +00:00
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
// mailtos are handled special
|
|
|
|
|
|
// is this really right though? that final . probably belongs earlier?
|
|
|
|
|
|
'mailto:wiki@wikimedia.org',
|
2011-11-14 09:13:58 +00:00
|
|
|
|
array( 'mailto:org.wikimedia@wiki.' )
|
2011-04-25 21:00:49 +00:00
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
// file URL cases per bug 28627...
|
|
|
|
|
|
array(
|
|
|
|
|
|
// three slashes: local filesystem path Unix-style
|
|
|
|
|
|
'file:///whatever/you/like.txt',
|
2011-11-14 09:13:58 +00:00
|
|
|
|
array( 'file://./whatever/you/like.txt' )
|
2011-04-25 21:00:49 +00:00
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
// three slashes: local filesystem path Windows-style
|
|
|
|
|
|
'file:///c:/whatever/you/like.txt',
|
2011-11-14 09:13:58 +00:00
|
|
|
|
array( 'file://./c:/whatever/you/like.txt' )
|
2011-04-25 21:00:49 +00:00
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
// two slashes: UNC filesystem path Windows-style
|
|
|
|
|
|
'file://intranet/whatever/you/like.txt',
|
2011-11-14 09:13:58 +00:00
|
|
|
|
array( 'file://intranet./whatever/you/like.txt' )
|
2011-04-25 21:00:49 +00:00
|
|
|
|
),
|
|
|
|
|
|
// Multiple-slash cases that can sorta work on Mozilla
|
|
|
|
|
|
// if you hack it just right are kinda pathological,
|
|
|
|
|
|
// and unreliable cross-platform or on IE which means they're
|
|
|
|
|
|
// unlikely to appear on intranets.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Those will survive the algorithm but with results that
|
|
|
|
|
|
// are less consistent.
|
2011-11-14 09:13:58 +00:00
|
|
|
|
|
|
|
|
|
|
// protocol-relative URL cases per bug 29854...
|
|
|
|
|
|
array(
|
|
|
|
|
|
'//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
|
|
|
|
|
|
array(
|
|
|
|
|
|
'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
|
|
|
|
|
|
'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
|
|
|
|
|
|
)
|
|
|
|
|
|
),
|
2011-04-25 21:00:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
2011-08-20 10:41:44 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideWfMatchesDomainList
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfMatchesDomainList
|
2011-08-20 10:41:44 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
|
2011-08-20 10:41:44 +00:00
|
|
|
|
$actual = wfMatchesDomainList( $url, $domains );
|
|
|
|
|
|
$this->assertEquals( $expected, $actual, $description );
|
|
|
|
|
|
}
|
2013-02-14 11:22:13 +00:00
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function provideWfMatchesDomainList() {
|
2011-08-20 10:41:44 +00:00
|
|
|
|
$a = array();
|
|
|
|
|
|
$protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
|
|
|
|
|
|
foreach ( $protocols as $pDesc => $p ) {
|
|
|
|
|
|
$a = array_merge( $a, array(
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example.com",
|
|
|
|
|
|
array(),
|
|
|
|
|
|
false,
|
|
|
|
|
|
"No matches for empty domains array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example.com",
|
|
|
|
|
|
array( 'www.example.com' ),
|
|
|
|
|
|
true,
|
|
|
|
|
|
"Exact match in domains array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example.com",
|
|
|
|
|
|
array( 'example.com' ),
|
|
|
|
|
|
true,
|
|
|
|
|
|
"Match without subdomain in domains array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example2.com",
|
|
|
|
|
|
array( 'www.example.com', 'www.example2.com', 'www.example3.com' ),
|
|
|
|
|
|
true,
|
|
|
|
|
|
"Exact match with other domains in array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example2.com",
|
|
|
|
|
|
array( 'example.com', 'example2.com', 'example3,com' ),
|
|
|
|
|
|
true,
|
|
|
|
|
|
"Match without subdomain with other domains in array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//www.example4.com",
|
|
|
|
|
|
array( 'example.com', 'example2.com', 'example3,com' ),
|
|
|
|
|
|
false,
|
|
|
|
|
|
"Domain not in array, $pDesc URL"
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"$p//nds-nl.wikipedia.org",
|
|
|
|
|
|
array( 'nl.wikipedia.org' ),
|
|
|
|
|
|
false,
|
|
|
|
|
|
"Non-matching substring of domain, $pDesc URL"
|
|
|
|
|
|
),
|
2011-08-20 10:41:44 +00:00
|
|
|
|
) );
|
|
|
|
|
|
}
|
2013-04-26 12:00:22 +00:00
|
|
|
|
|
2011-08-20 10:41:44 +00:00
|
|
|
|
return $a;
|
|
|
|
|
|
}
|
2011-04-25 21:00:49 +00:00
|
|
|
|
|
2013-10-24 09:53:24 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers ::wfMkdirParents
|
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testWfMkdirParents() {
|
2013-09-12 22:55:45 +00:00
|
|
|
|
// Should not return true if file exists instead of directory
|
|
|
|
|
|
$fname = $this->getNewTempFile();
|
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
|
$ok = wfMkdirParents( $fname );
|
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
|
$this->assertFalse( $ok );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-09-23 20:42:22 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideWfShellMaintenanceCmdList
|
2013-10-24 09:53:24 +00:00
|
|
|
|
* @covers ::wfShellMaintenanceCmd
|
2011-09-23 20:42:22 +00:00
|
|
|
|
*/
|
2014-04-24 09:47:06 +00:00
|
|
|
|
public function testWfShellMaintenanceCmd( $script, $parameters, $options,
|
|
|
|
|
|
$expected, $description
|
|
|
|
|
|
) {
|
2013-02-14 11:22:13 +00:00
|
|
|
|
if ( wfIsWindows() ) {
|
2011-09-23 22:17:41 +00:00
|
|
|
|
// Approximation that's good enough for our purposes just now
|
|
|
|
|
|
$expected = str_replace( "'", '"', $expected );
|
|
|
|
|
|
}
|
2011-09-23 20:42:22 +00:00
|
|
|
|
$actual = wfShellMaintenanceCmd( $script, $parameters, $options );
|
|
|
|
|
|
$this->assertEquals( $expected, $actual, $description );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function provideWfShellMaintenanceCmdList() {
|
2011-09-23 20:42:22 +00:00
|
|
|
|
global $wgPhpCli;
|
2013-04-26 12:00:22 +00:00
|
|
|
|
|
2011-09-23 20:42:22 +00:00
|
|
|
|
return array(
|
|
|
|
|
|
array( 'eval.php', array( '--help', '--test' ), array(),
|
2012-03-19 18:28:47 +00:00
|
|
|
|
"'$wgPhpCli' 'eval.php' '--help' '--test'",
|
2011-09-23 20:42:22 +00:00
|
|
|
|
"Called eval.php --help --test" ),
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'eval.php', array( '--help', '--test space' ), array( 'php' => 'php5' ),
|
2012-03-19 18:28:47 +00:00
|
|
|
|
"'php5' 'eval.php' '--help' '--test space'",
|
2011-09-23 20:42:22 +00:00
|
|
|
|
"Called eval.php --help --test with php option" ),
|
2013-02-14 11:22:13 +00:00
|
|
|
|
array( 'eval.php', array( '--help', '--test', 'X' ), array( 'wrapper' => 'MWScript.php' ),
|
2012-03-19 18:28:47 +00:00
|
|
|
|
"'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
|
2011-09-23 20:42:22 +00:00
|
|
|
|
"Called eval.php --help --test with wrapper option" ),
|
2014-04-24 09:47:06 +00:00
|
|
|
|
array(
|
|
|
|
|
|
'eval.php',
|
|
|
|
|
|
array( '--help', '--test', 'y' ),
|
|
|
|
|
|
array( 'php' => 'php5', 'wrapper' => 'MWScript.php' ),
|
2012-03-19 18:28:47 +00:00
|
|
|
|
"'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
|
2014-04-24 09:47:06 +00:00
|
|
|
|
"Called eval.php --help --test with wrapper and php option"
|
|
|
|
|
|
),
|
2011-09-23 20:42:22 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2014-07-23 20:04:48 +00:00
|
|
|
|
/* @todo many more! */
|
2010-12-14 16:26:35 +00:00
|
|
|
|
}
|