summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/filerepo
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-04-25 06:26:49 +0200
committerPierre Schmitz <pierre@archlinux.de>2014-04-25 06:26:49 +0200
commit2e44b49a2db3026050b136de9b00f749dd3ff939 (patch)
treeef048f4db79a93c25cfc86319264aa7ae2a4ae0b /tests/phpunit/includes/filerepo
parent9441dde8bfb95277df073717ed7817dced40f948 (diff)
Update to MediaWiki 1.22.6
Diffstat (limited to 'tests/phpunit/includes/filerepo')
-rw-r--r--tests/phpunit/includes/filerepo/FileRepoTest.php55
-rw-r--r--tests/phpunit/includes/filerepo/StoreBatchTest.php134
2 files changed, 0 insertions, 189 deletions
diff --git a/tests/phpunit/includes/filerepo/FileRepoTest.php b/tests/phpunit/includes/filerepo/FileRepoTest.php
deleted file mode 100644
index e3a75567..00000000
--- a/tests/phpunit/includes/filerepo/FileRepoTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-class FileRepoTest extends MediaWikiTestCase {
-
- /**
- * @expectedException MWException
- * @covers FileRepo::__construct
- */
- public function testFileRepoConstructionOptionCanNotBeNull() {
- new FileRepo();
- }
-
- /**
- * @expectedException MWException
- * @covers FileRepo::__construct
- */
- public function testFileRepoConstructionOptionCanNotBeAnEmptyArray() {
- new FileRepo( array() );
- }
-
- /**
- * @expectedException MWException
- * @covers FileRepo::__construct
- */
- public function testFileRepoConstructionOptionNeedNameKey() {
- new FileRepo( array(
- 'backend' => 'foobar'
- ) );
- }
-
- /**
- * @expectedException MWException
- * @covers FileRepo::__construct
- */
- public function testFileRepoConstructionOptionNeedBackendKey() {
- new FileRepo( array(
- 'name' => 'foobar'
- ) );
- }
-
- /**
- * @covers FileRepo::__construct
- */
- public function testFileRepoConstructionWithRequiredOptions() {
- $f = new FileRepo( array(
- 'name' => 'FileRepoTestRepository',
- 'backend' => new FSFileBackend( array(
- 'name' => 'local-testing',
- 'lockManager' => 'nullLockManager',
- 'containerPaths' => array()
- ) )
- ) );
- $this->assertInstanceOf( 'FileRepo', $f );
- }
-}
diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php
deleted file mode 100644
index b33c1bbb..00000000
--- a/tests/phpunit/includes/filerepo/StoreBatchTest.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-
-/**
- * @group FileRepo
- * @group medium
- */
-class StoreBatchTest extends MediaWikiTestCase {
-
- protected $createdFiles;
- protected $date;
- /** @var FileRepo */
- protected $repo;
-
- protected function setUp() {
- global $wgFileBackends;
- parent::setUp();
-
- # Forge a FSRepo object to not have to rely on local wiki settings
- $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand();
- if ( $this->getCliArg( 'use-filebackend=' ) ) {
- $name = $this->getCliArg( 'use-filebackend=' );
- $useConfig = array();
- foreach ( $wgFileBackends as $conf ) {
- if ( $conf['name'] == $name ) {
- $useConfig = $conf;
- }
- }
- $useConfig['name'] = 'local-testing'; // swap name
- $class = $useConfig['class'];
- $backend = new $class( $useConfig );
- } else {
- $backend = new FSFileBackend( array(
- 'name' => 'local-testing',
- 'lockManager' => 'nullLockManager',
- 'containerPaths' => array(
- 'unittests-public' => "{$tmpPrefix}-public",
- 'unittests-thumb' => "{$tmpPrefix}-thumb",
- 'unittests-temp' => "{$tmpPrefix}-temp",
- 'unittests-deleted' => "{$tmpPrefix}-deleted",
- )
- ) );
- }
- $this->repo = new FileRepo( array(
- 'name' => 'unittests',
- 'backend' => $backend
- ) );
-
- $this->date = gmdate( "YmdHis" );
- $this->createdFiles = array();
- }
-
- 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 ) );
- }
- }
- parent::tearDown();
- }
-
- /**
- * Store a file or virtual URL source into a media file name.
- *
- * @param $originalName string The title of the image
- * @param $srcPath string The filepath or virtual URL
- * @param $flags integer Flags to pass into repo::store().
- * @return FileRepoStatus
- */
- private function storeit( $originalName, $srcPath, $flags ) {
- $hashPath = $this->repo->getHashPath( $originalName );
- $dstRel = "$hashPath{$this->date}!$originalName";
- $dstUrlRel = $hashPath . $this->date . '!' . rawurlencode( $originalName );
-
- $result = $this->repo->store( $srcPath, 'temp', $dstRel, $flags );
- $result->value = $this->repo->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
- $this->createdFiles[] = $result->value;
-
- return $result;
- }
-
- /**
- * Test storing a file using different flags.
- *
- * @param $fn string The title of the image
- * @param $infn string The name of the file (in the filesystem)
- * @param $otherfn string The name of the different file (in the filesystem)
- * @param $fromrepo bool 'true' if we want to copy from a virtual URL out of the Repo.
- */
- private function storecohort( $fn, $infn, $otherfn, $fromrepo ) {
- $f = $this->storeit( $fn, $infn, 0 );
- $this->assertTrue( $f->isOK(), 'failed to store a new file' );
- $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
- $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
- if ( $fromrepo ) {
- $f = $this->storeit( "Other-$fn", $infn, FileRepo::OVERWRITE );
- $infn = $f->value;
- }
- // This should work because we're allowed to overwrite
- $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE );
- $this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' );
- $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
- $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
- // This should fail because we're overwriting.
- $f = $this->storeit( $fn, $infn, 0 );
- $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' );
- $this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
- $this->assertEquals( $f->successCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
- // This should succeed because we're overwriting the same content.
- $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE_SAME );
- $this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' );
- $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
- $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
- // This should fail because we're overwriting different content.
- if ( $fromrepo ) {
- $f = $this->storeit( "Other-$fn", $otherfn, FileRepo::OVERWRITE );
- $otherfn = $f->value;
- }
- $f = $this->storeit( $fn, $otherfn, FileRepo::OVERWRITE_SAME );
- $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' );
- $this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
- $this->assertEquals( $f->successCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
- }
-
- /**
- * @covers FileRepo::store
- */
- public function teststore() {
- global $IP;
- $this->storecohort( "Test1.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", false );
- $this->storecohort( "Test2.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", true );
- }
-}