http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99546
Revision: 99546
Author: nelson
Date: 2011-10-11 19:49:29 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
Some docs and a test for FileRepo::storeBatch()
Modified Paths:
--------------
trunk/phase3/includes/filerepo/README
trunk/phase3/includes/filerepo/RepoGroup.php
Added Paths:
-----------
trunk/phase3/tests/phpunit/includes/filerepo/
trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
Modified: trunk/phase3/includes/filerepo/README
===================================================================
--- trunk/phase3/includes/filerepo/README 2011-10-11 19:45:44 UTC (rev
99545)
+++ trunk/phase3/includes/filerepo/README 2011-10-11 19:49:29 UTC (rev
99546)
@@ -42,18 +42,21 @@
Structure:
-File.php defines an abstract class File.
- ForeignAPIFile.php extends File.
- LocalFile.php extends File.
- ForeignDBFile.php extends LocalFile
- Image.php extends LocalFile
- UnregisteredLocalFile.php extends File.
-FileRepo.php defines an abstract class FileRepo.
- ForeignAPIRepo.php extends FileRepo
+File defines an abstract class File.
+ ForeignAPIFile extends File.
+ LocalFile extends File.
+ ForeignDBFile extends LocalFile
+ Image extends LocalFile
+ SwiftFile extends LocalFile
+ UnregisteredLocalFile extends File.
+ UploadStashFile extends UnregisteredLocalFile.
+FileRepo defines an abstract class FileRepo.
+ ForeignAPIRepo extends FileRepo
FSRepo extends FileRepo
- LocalRepo.php extends FSRepo
- ForeignDBRepo.php extends LocalRepo
- ForeignDBViaLBRepo.php extends LocalRepo
+ LocalRepo extends FSRepo
+ ForeignDBRepo extends LocalRepo
+ ForeignDBViaLBRepo extends LocalRepo
+ SwiftRepo extends LocalRepo
NullRepo extends FileRepo
Russ Nelson, March 2011
Modified: trunk/phase3/includes/filerepo/RepoGroup.php
===================================================================
--- trunk/phase3/includes/filerepo/RepoGroup.php 2011-10-11 19:45:44 UTC
(rev 99545)
+++ trunk/phase3/includes/filerepo/RepoGroup.php 2011-10-11 19:49:29 UTC
(rev 99546)
@@ -56,6 +56,9 @@
/**
* Set the singleton instance to a given object
+ * Used by extensions which hook into the Repo chain.
+ * It's not enough to just create a superclass ... you have
+ * to get people to call into it even though all they know is
RepoGroup::singleton()
*
* @param $instance RepoGroup
*/
Added: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
(rev 0)
+++ trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
2011-10-11 19:49:29 UTC (rev 99546)
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @group Filerepo
+ */
+class StoreBatchTest extends MediaWikiTestCase {
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->repo = RepoGroup::singleton()->getLocalRepo();
+ $this->date = gmdate( "YmdHis" );
+ $this->users = array(
+ 'sysop' => new ApiTestUser(
+ 'Uploadstashtestsysop',
+ 'Upload Stash Test Sysop',
+ '[email protected]',
+ array( 'sysop' )
+ ),
+ 'uploader' => new ApiTestUser(
+ 'Uploadstashtestuser',
+ 'Upload Stash Test User',
+ '[email protected]',
+ array()
+ )
+ );
+ }
+
+ /**
+ * 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().
+ */
+ 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;
+ 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 logical '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->assertTrue( $f->failCount == 0, "counts wrong
{$f->successCount} {$f->failCount}" );
+ $this->assertTrue( $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->assertTrue( $f->failCount == 0, "counts wrong
{$f->successCount} {$f->failCount}" );
+ $this->assertTrue( $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->assertTrue( $f->failCount == 0, "counts wrong
{$f->successCount} {$f->failCount}" );
+ #$this->assertTrue( $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->assertTrue( $f->failCount == 0, "counts wrong
{$f->successCount} {$f->failCount}" );
+ $this->assertTrue( $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->assertTrue( $f->failCount == 0, "counts wrong
{$f->successCount} {$f->failCount}" );
+ #$this->assertTrue( $f->successCount == 0 , "counts wrong
{$f->successCount} {$f->failCount}" );
+ }
+
+ 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 );
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+
+ }
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs