diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:02 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:02 -0400 |
commit | 1de335ad3f395ca6861085393ba366a9e3fb4a0d (patch) | |
tree | f1fdd326034e05177596851be6a7127615d81498 /tests/phpunit/includes/filerepo | |
parent | 9c75fa8ff6d4d38ef552c00fef5969fb154765e8 (diff) | |
parent | f6d65e533c62f6deb21342d4901ece24497b433e (diff) |
Merge commit 'f6d65'
# Conflicts:
# skins/ArchLinux/ArchLinux.php
Diffstat (limited to 'tests/phpunit/includes/filerepo')
-rw-r--r-- | tests/phpunit/includes/filerepo/StoreBatchTest.php | 19 | ||||
-rw-r--r-- | tests/phpunit/includes/filerepo/file/LocalFileTest.php | 183 |
2 files changed, 190 insertions, 12 deletions
diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php index 9cc2efbf..86bfe123 100644 --- a/tests/phpunit/includes/filerepo/StoreBatchTest.php +++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php @@ -16,7 +16,7 @@ class StoreBatchTest extends MediaWikiTestCase { parent::setUp(); # Forge a FSRepo object to not have to rely on local wiki settings - $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand(); + $tmpPrefix = $this->getNewTempDirectory(); if ( $this->getCliArg( 'use-filebackend' ) ) { $name = $this->getCliArg( 'use-filebackend' ); $useConfig = array(); @@ -35,10 +35,10 @@ class StoreBatchTest extends MediaWikiTestCase { 'name' => 'local-testing', 'wikiId' => wfWikiID(), 'containerPaths' => array( - 'unittests-public' => "{$tmpPrefix}-public", - 'unittests-thumb' => "{$tmpPrefix}-thumb", - 'unittests-temp' => "{$tmpPrefix}-temp", - 'unittests-deleted' => "{$tmpPrefix}-deleted", + 'unittests-public' => "{$tmpPrefix}/public", + 'unittests-thumb' => "{$tmpPrefix}/thumb", + 'unittests-temp' => "{$tmpPrefix}/temp", + 'unittests-deleted' => "{$tmpPrefix}/deleted", ) ) ); } @@ -52,13 +52,8 @@ class StoreBatchTest extends MediaWikiTestCase { } protected function tearDown() { - $this->repo->cleanupBatch( $this->createdFiles ); // delete files - foreach ( $this->createdFiles as $tmp ) { // delete dirs - $tmp = $this->repo->resolveVirtualUrl( $tmp ); - while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { - $this->repo->getBackend()->clean( array( 'dir' => $tmp ) ); - } - } + // Delete files + $this->repo->cleanupBatch( $this->createdFiles ); parent::tearDown(); } diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php new file mode 100644 index 00000000..3c5754bf --- /dev/null +++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php @@ -0,0 +1,183 @@ +<?php + +/** + * These tests should work regardless of $wgCapitalLinks + * @todo Split tests into providers and test methods + */ + +class LocalFileTest extends MediaWikiTestCase { + + protected function setUp() { + parent::setUp(); + + $this->setMwGlobals( 'wgCapitalLinks', true ); + + $info = array( + 'name' => 'test', + 'directory' => '/testdir', + 'url' => '/testurl', + 'hashLevels' => 2, + 'transformVia404' => false, + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', + 'wikiId' => wfWikiId(), + 'containerPaths' => array( + 'cont1' => "/testdir/local-backend/tempimages/cont1", + 'cont2' => "/testdir/local-backend/tempimages/cont2" + ) + ) ) + ); + $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info ); + $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info ); + $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info ); + $this->file_hl0 = $this->repo_hl0->newFile( 'test!' ); + $this->file_hl2 = $this->repo_hl2->newFile( 'test!' ); + $this->file_lc = $this->repo_lc->newFile( 'test!' ); + } + + /** + * @covers File::getHashPath + */ + public function testGetHashPath() { + $this->assertEquals( '', $this->file_hl0->getHashPath() ); + $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() ); + $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() ); + } + + /** + * @covers File::getRel + */ + public function testGetRel() { + $this->assertEquals( 'Test!', $this->file_hl0->getRel() ); + $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() ); + $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() ); + } + + /** + * @covers File::getUrlRel + */ + public function testGetUrlRel() { + $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() ); + $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() ); + $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() ); + } + + /** + * @covers File::getArchivePath + */ + public function testGetArchivePath() { + $this->assertEquals( + 'mwstore://local-backend/test-public/archive', + $this->file_hl0->getArchivePath() + ); + $this->assertEquals( + 'mwstore://local-backend/test-public/archive/a/a2', + $this->file_hl2->getArchivePath() + ); + $this->assertEquals( + 'mwstore://local-backend/test-public/archive/!', + $this->file_hl0->getArchivePath( '!' ) + ); + $this->assertEquals( + 'mwstore://local-backend/test-public/archive/a/a2/!', + $this->file_hl2->getArchivePath( '!' ) + ); + } + + /** + * @covers File::getThumbPath + */ + public function testGetThumbPath() { + $this->assertEquals( + 'mwstore://local-backend/test-thumb/Test!', + $this->file_hl0->getThumbPath() + ); + $this->assertEquals( + 'mwstore://local-backend/test-thumb/a/a2/Test!', + $this->file_hl2->getThumbPath() + ); + $this->assertEquals( + 'mwstore://local-backend/test-thumb/Test!/x', + $this->file_hl0->getThumbPath( 'x' ) + ); + $this->assertEquals( + 'mwstore://local-backend/test-thumb/a/a2/Test!/x', + $this->file_hl2->getThumbPath( 'x' ) + ); + } + + /** + * @covers File::getArchiveUrl + */ + public function testGetArchiveUrl() { + $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() ); + $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() ); + $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) ); + $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) ); + } + + /** + * @covers File::getThumbUrl + */ + public function testGetThumbUrl() { + $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() ); + $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() ); + $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) ); + $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) ); + } + + /** + * @covers File::getArchiveVirtualUrl + */ + public function testGetArchiveVirtualUrl() { + $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() ); + $this->assertEquals( + 'mwrepo://test/public/archive/a/a2', + $this->file_hl2->getArchiveVirtualUrl() + ); + $this->assertEquals( + 'mwrepo://test/public/archive/%21', + $this->file_hl0->getArchiveVirtualUrl( '!' ) + ); + $this->assertEquals( + 'mwrepo://test/public/archive/a/a2/%21', + $this->file_hl2->getArchiveVirtualUrl( '!' ) + ); + } + + /** + * @covers File::getThumbVirtualUrl + */ + public function testGetThumbVirtualUrl() { + $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() ); + $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() ); + $this->assertEquals( + 'mwrepo://test/thumb/Test%21/%21', + $this->file_hl0->getThumbVirtualUrl( '!' ) + ); + $this->assertEquals( + 'mwrepo://test/thumb/a/a2/Test%21/%21', + $this->file_hl2->getThumbVirtualUrl( '!' ) + ); + } + + /** + * @covers File::getUrl + */ + public function testGetUrl() { + $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() ); + $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() ); + } + + /** + * @covers ::wfLocalFile + */ + public function testWfLocalFile() { + $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" ); + $this->assertThat( + $file, + $this->isInstanceOf( 'LocalFile' ), + 'wfLocalFile() returns LocalFile for valid Titles' + ); + } +} |