r22908 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22907‎ | r22908 | r22909 >
Date:14:46, 11 June 2007
Author:tstarling
Status:old
Tags:
Comment:
Fixed some errant double-slashes appearing in file paths. Added unit tests for the path and URL functions.
Modified paths:
  • /trunk/phase3/includes/filerepo/FSRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/tests/LocalFileTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/LocalFileTest.php
@@ -0,0 +1,90 @@
 2+<?php
 3+
 4+/**
 5+ * These tests should work regardless of $wgCapitalLinks
 6+ */
 7+
 8+class LocalFileTest extends PHPUnit_Framework_TestCase {
 9+ function setUp() {
 10+ $info = array(
 11+ 'name' => 'test',
 12+ 'directory' => '/testdir',
 13+ 'url' => '/testurl',
 14+ 'hashLevels' => 2,
 15+ 'transformVia404' => false,
 16+ );
 17+ $this->repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
 18+ $this->repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
 19+ $this->repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
 20+ $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
 21+ $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
 22+ $this->file_lc = $this->repo_lc->newFile( 'test!' );
 23+ }
 24+
 25+ function testGetHashPath() {
 26+ $this->assertEquals( '', $this->file_hl0->getHashPath() );
 27+ $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
 28+ $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
 29+ }
 30+
 31+ function testGetRel() {
 32+ $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
 33+ $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
 34+ $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
 35+ }
 36+
 37+ function testGetUrlRel() {
 38+ $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
 39+ $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
 40+ $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
 41+ }
 42+
 43+ function testGetArchivePath() {
 44+ $this->assertEquals( '/testdir/archive', $this->file_hl0->getArchivePath() );
 45+ $this->assertEquals( '/testdir/archive/a/a2', $this->file_hl2->getArchivePath() );
 46+ $this->assertEquals( '/testdir/archive/!', $this->file_hl0->getArchivePath( '!' ) );
 47+ $this->assertEquals( '/testdir/archive/a/a2/!', $this->file_hl2->getArchivePath( '!' ) );
 48+ }
 49+
 50+ function testGetThumbPath() {
 51+ $this->assertEquals( '/testdir/thumb/Test!', $this->file_hl0->getThumbPath() );
 52+ $this->assertEquals( '/testdir/thumb/a/a2/Test!', $this->file_hl2->getThumbPath() );
 53+ $this->assertEquals( '/testdir/thumb/Test!/x', $this->file_hl0->getThumbPath( 'x' ) );
 54+ $this->assertEquals( '/testdir/thumb/a/a2/Test!/x', $this->file_hl2->getThumbPath( 'x' ) );
 55+ }
 56+
 57+ function testGetArchiveUrl() {
 58+ $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
 59+ $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
 60+ $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
 61+ $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
 62+ }
 63+
 64+ function testGetThumbUrl() {
 65+ $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
 66+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
 67+ $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
 68+ $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
 69+ }
 70+
 71+ function testGetArchiveVirtualUrl() {
 72+ $this->assertEquals( 'mwrepo:///public/archive', $this->file_hl0->getArchiveVirtualUrl() );
 73+ $this->assertEquals( 'mwrepo:///public/archive/a/a2', $this->file_hl2->getArchiveVirtualUrl() );
 74+ $this->assertEquals( 'mwrepo:///public/archive/%21', $this->file_hl0->getArchiveVirtualUrl( '!' ) );
 75+ $this->assertEquals( 'mwrepo:///public/archive/a/a2/%21', $this->file_hl2->getArchiveVirtualUrl( '!' ) );
 76+ }
 77+
 78+ function testGetThumbVirtualUrl() {
 79+ $this->assertEquals( 'mwrepo:///public/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
 80+ $this->assertEquals( 'mwrepo:///public/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
 81+ $this->assertEquals( 'mwrepo:///public/thumb/Test%21/%21', $this->file_hl0->getThumbVirtualUrl( '!' ) );
 82+ $this->assertEquals( 'mwrepo:///public/thumb/a/a2/Test%21/%21', $this->file_hl2->getThumbVirtualUrl( '!' ) );
 83+ }
 84+
 85+ function testGetUrl() {
 86+ $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
 87+ $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
 88+ }
 89+}
 90+
 91+?>
Property changes on: trunk/phase3/tests/LocalFileTest.php
___________________________________________________________________
Added: svn:eol-style
192 + native
Index: trunk/phase3/includes/filerepo/FSRepo.php
@@ -318,7 +318,7 @@
319319
320320 /**
321321 * Get a relative path including trailing slash, e.g. f/fa/
322 - * If the repo is not hashed, returns a slash
 322+ * If the repo is not hashed, returns an empty string
323323 */
324324 function getHashPath( $name ) {
325325 if ( $this->isHashed() ) {
@@ -329,7 +329,7 @@
330330 }
331331 return $path;
332332 } else {
333 - return '/';
 333+ return '';
334334 }
335335 }
336336
Index: trunk/phase3/includes/filerepo/File.php
@@ -669,8 +669,10 @@
670670 /** Get the path of the archive directory, or a particular file if $suffix is specified */
671671 function getArchivePath( $suffix = false ) {
672672 $path = $this->repo->getZonePath('public') . '/archive/' . $this->getHashPath();
673 - if ( $suffix !== false ) {
674 - $path .= '/' . $suffix;
 673+ if ( $suffix === false ) {
 674+ $path = substr( $path, 0, -1 );
 675+ } else {
 676+ $path .= $suffix;
675677 }
676678 return $path;
677679 }
@@ -687,8 +689,10 @@
688690 /** Get the URL of the archive directory, or a particular file if $suffix is specified */
689691 function getArchiveUrl( $suffix = false ) {
690692 $path = $this->repo->getZoneUrl('public') . '/archive/' . $this->getHashPath();
691 - if ( $suffix !== false ) {
692 - $path .= '/' . urlencode( $suffix );
 693+ if ( $suffix === false ) {
 694+ $path = substr( $path, 0, -1 );
 695+ } else {
 696+ $path .= urlencode( $suffix );
693697 }
694698 return $path;
695699 }
@@ -705,15 +709,17 @@
706710 /** Get the virtual URL for an archive file or directory */
707711 function getArchiveVirtualUrl( $suffix = false ) {
708712 $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
709 - if ( $suffix !== false ) {
710 - $path .= '/' . urlencode( $suffix );
 713+ if ( $suffix === false ) {
 714+ $path = substr( $path, 0, -1 );
 715+ } else {
 716+ $path .= urlencode( $suffix );
711717 }
712718 return $path;
713719 }
714720
715721 /** Get the virtual URL for a thumbnail file or directory */
716722 function getThumbVirtualUrl( $suffix = false ) {
717 - $path = $this->repo->getVirtualUrl() . '/public/thumb/' . $this->getHashPath();
 723+ $path = $this->repo->getVirtualUrl() . '/public/thumb/' . $this->getUrlRel();
718724 if ( $suffix !== false ) {
719725 $path .= '/' . urlencode( $suffix );
720726 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r22919Merged revisions 22878-22918 via svnmerge from...david00:00, 12 June 2007

Status & tagging log