2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These tests should work regardless of $wgCapitalLinks
|
2013-10-24 16:45:52 +00:00
|
|
|
* @todo Split tests into providers and test methods
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
|
|
|
|
|
2020-06-30 15:09:24 +00:00
|
|
|
class LocalFileTest extends MediaWikiIntegrationTestCase {
|
2019-10-23 14:38:24 +00:00
|
|
|
private static function getDefaultInfo() {
|
|
|
|
|
return [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'test',
|
|
|
|
|
'directory' => '/testdir',
|
|
|
|
|
'url' => '/testurl',
|
|
|
|
|
'hashLevels' => 2,
|
2010-12-14 16:26:35 +00:00
|
|
|
'transformVia404' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'backend' => new FSFileBackend( [
|
2013-02-14 11:22:13 +00:00
|
|
|
'name' => 'local-backend',
|
2016-03-18 13:55:54 +00:00
|
|
|
'wikiId' => wfWikiID(),
|
2016-02-17 09:09:32 +00:00
|
|
|
'containerPaths' => [
|
2012-01-07 01:33:23 +00:00
|
|
|
'cont1' => "/testdir/local-backend/tempimages/cont1",
|
|
|
|
|
'cont2' => "/testdir/local-backend/tempimages/cont2"
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
] )
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getHashPath
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetHashPath
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetHashPath( $expected, $capitalLinks, array $info ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getHashPath() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetHashPath() {
|
|
|
|
|
return [
|
|
|
|
|
[ '', true, [ 'hashLevels' => 0 ] ],
|
|
|
|
|
[ 'a/a2/', true, [ 'hashLevels' => 2 ] ],
|
|
|
|
|
[ 'c/c4/', false, [ 'initialCapital' => false ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getRel
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetRel
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetRel( $expected, $capitalLinks, array $info ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getRel() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetRel() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'Test!', true, [ 'hashLevels' => 0 ] ],
|
|
|
|
|
[ 'a/a2/Test!', true, [ 'hashLevels' => 2 ] ],
|
|
|
|
|
[ 'c/c4/test!', false, [ 'initialCapital' => false ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getUrlRel
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetUrlRel
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetUrlRel( $expected, $capitalLinks, array $info ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getUrlRel() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetUrlRel() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'Test%21', true, [ 'hashLevels' => 0 ] ],
|
|
|
|
|
[ 'a/a2/Test%21', true, [ 'hashLevels' => 2 ] ],
|
|
|
|
|
[ 'c/c4/test%21', false, [ 'initialCapital' => false ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchivePath
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetArchivePath
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetArchivePath( $expected, $capitalLinks, array $info, array $args ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getArchivePath( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetArchivePath() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'mwstore://local-backend/test-public/archive', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ 'mwstore://local-backend/test-public/archive/a/a2', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[
|
|
|
|
|
'mwstore://local-backend/test-public/archive/!',
|
|
|
|
|
true, [ 'hashLevels' => 0 ], [ '!' ]
|
|
|
|
|
], [
|
|
|
|
|
'mwstore://local-backend/test-public/archive/a/a2/!',
|
|
|
|
|
true, [ 'hashLevels' => 2 ], [ '!' ]
|
|
|
|
|
],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbPath
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetThumbPath
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetThumbPath( $expected, $capitalLinks, array $info, array $args ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getThumbPath( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetThumbPath() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'mwstore://local-backend/test-thumb/Test!', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ 'mwstore://local-backend/test-thumb/a/a2/Test!', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[
|
|
|
|
|
'mwstore://local-backend/test-thumb/Test!/x',
|
|
|
|
|
true, [ 'hashLevels' => 0 ], [ 'x' ]
|
|
|
|
|
], [
|
|
|
|
|
'mwstore://local-backend/test-thumb/a/a2/Test!/x',
|
|
|
|
|
true, [ 'hashLevels' => 2 ], [ 'x' ]
|
|
|
|
|
],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchiveUrl
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetArchiveUrl
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetArchiveUrl( $expected, $capitalLinks, array $info, array $args ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getArchiveUrl( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetArchiveUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ '/testurl/archive', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ '/testurl/archive/a/a2', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[ '/testurl/archive/%21', true, [ 'hashLevels' => 0 ], [ '!' ] ],
|
|
|
|
|
[ '/testurl/archive/a/a2/%21', true, [ 'hashLevels' => 2 ], [ '!' ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbUrl
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetThumbUrl
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetThumbUrl( $expected, $capitalLinks, array $info, array $args ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getThumbUrl( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetThumbUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ '/testurl/thumb/Test%21', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ '/testurl/thumb/a/a2/Test%21', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[ '/testurl/thumb/Test%21/x', true, [ 'hashLevels' => 0 ], [ 'x' ] ],
|
|
|
|
|
[ '/testurl/thumb/a/a2/Test%21/x', true, [ 'hashLevels' => 2 ], [ 'x' ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getArchiveVirtualUrl
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetArchiveVirtualUrl
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetArchiveVirtualUrl(
|
|
|
|
|
$expected, $capitalLinks, array $info, array $args
|
|
|
|
|
) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getArchiveVirtualUrl( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetArchiveVirtualUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'mwrepo://test/public/archive', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ 'mwrepo://test/public/archive/a/a2', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[ 'mwrepo://test/public/archive/%21', true, [ 'hashLevels' => 0 ], [ '!' ] ],
|
|
|
|
|
[ 'mwrepo://test/public/archive/a/a2/%21', true, [ 'hashLevels' => 2 ], [ '!' ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getThumbVirtualUrl
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetThumbVirtualUrl
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
|
|
|
|
* @param array $args
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetThumbVirtualUrl( $expected, $capitalLinks, array $info, array $args ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getThumbVirtualUrl( ...$args ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetThumbVirtualUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ 'mwrepo://test/thumb/Test%21', true, [ 'hashLevels' => 0 ], [] ],
|
|
|
|
|
[ 'mwrepo://test/thumb/a/a2/Test%21', true, [ 'hashLevels' => 2 ], [] ],
|
|
|
|
|
[ 'mwrepo://test/thumb/Test%21/%21', true, [ 'hashLevels' => 0 ], [ '!' ] ],
|
|
|
|
|
[ 'mwrepo://test/thumb/a/a2/Test%21/%21', true, [ 'hashLevels' => 2 ], [ '!' ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers File::getUrl
|
2019-10-23 14:38:24 +00:00
|
|
|
* @dataProvider provideGetUrl
|
|
|
|
|
* @param string $expected
|
|
|
|
|
* @param bool $capitalLinks
|
|
|
|
|
* @param array $info
|
2013-10-24 16:45:52 +00:00
|
|
|
*/
|
2019-10-23 14:38:24 +00:00
|
|
|
public function testGetUrl( $expected, $capitalLinks, array $info ) {
|
|
|
|
|
$this->setMwGlobals( 'wgCapitalLinks', $capitalLinks );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected, ( new LocalRepo( $info + self::getDefaultInfo() ) )
|
|
|
|
|
->newFile( 'test!' )->getUrl() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideGetUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ '/testurl/Test%21', true, [ 'hashLevels' => 0 ] ],
|
|
|
|
|
[ '/testurl/a/a2/Test%21', true, [ 'hashLevels' => 2 ] ],
|
|
|
|
|
];
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ::wfLocalFile
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testWfLocalFile() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
|
2021-03-12 16:55:16 +00:00
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
LocalFile::class,
|
2014-04-24 12:35:05 +00:00
|
|
|
$file,
|
|
|
|
|
'wfLocalFile() returns LocalFile for valid Titles'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2019-08-30 08:55:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers File::getUser
|
|
|
|
|
*/
|
|
|
|
|
public function testGetUserForNonExistingFile() {
|
2019-10-23 14:38:24 +00:00
|
|
|
$file = ( new LocalRepo( self::getDefaultInfo() ) )->newFile( 'test!' );
|
|
|
|
|
$this->assertSame( 'Unknown user', $file->getUser() );
|
|
|
|
|
$this->assertSame( 0, $file->getUser( 'id' ) );
|
2019-08-30 08:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers File::getUser
|
|
|
|
|
*/
|
|
|
|
|
public function testDescriptionShortUrlForNonExistingFile() {
|
2019-10-23 14:38:24 +00:00
|
|
|
$file = ( new LocalRepo( self::getDefaultInfo() ) )->newFile( 'test!' );
|
|
|
|
|
$this->assertNull( $file->getDescriptionShortUrl() );
|
2019-08-30 08:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers File::getUser
|
|
|
|
|
*/
|
|
|
|
|
public function testDescriptionTextForNonExistingFile() {
|
2019-10-23 14:38:24 +00:00
|
|
|
$file = ( new LocalRepo( self::getDefaultInfo() ) )->newFile( 'test!' );
|
|
|
|
|
$this->assertFalse( $file->getDescriptionText() );
|
2019-08-30 08:55:01 +00:00
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|