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 |
1 | 92 | + native |
Index: trunk/phase3/includes/filerepo/FSRepo.php |
— | — | @@ -318,7 +318,7 @@ |
319 | 319 | |
320 | 320 | /** |
321 | 321 | * 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 |
323 | 323 | */ |
324 | 324 | function getHashPath( $name ) { |
325 | 325 | if ( $this->isHashed() ) { |
— | — | @@ -329,7 +329,7 @@ |
330 | 330 | } |
331 | 331 | return $path; |
332 | 332 | } else { |
333 | | - return '/'; |
| 333 | + return ''; |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
Index: trunk/phase3/includes/filerepo/File.php |
— | — | @@ -669,8 +669,10 @@ |
670 | 670 | /** Get the path of the archive directory, or a particular file if $suffix is specified */ |
671 | 671 | function getArchivePath( $suffix = false ) { |
672 | 672 | $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; |
675 | 677 | } |
676 | 678 | return $path; |
677 | 679 | } |
— | — | @@ -687,8 +689,10 @@ |
688 | 690 | /** Get the URL of the archive directory, or a particular file if $suffix is specified */ |
689 | 691 | function getArchiveUrl( $suffix = false ) { |
690 | 692 | $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 ); |
693 | 697 | } |
694 | 698 | return $path; |
695 | 699 | } |
— | — | @@ -705,15 +709,17 @@ |
706 | 710 | /** Get the virtual URL for an archive file or directory */ |
707 | 711 | function getArchiveVirtualUrl( $suffix = false ) { |
708 | 712 | $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 ); |
711 | 717 | } |
712 | 718 | return $path; |
713 | 719 | } |
714 | 720 | |
715 | 721 | /** Get the virtual URL for a thumbnail file or directory */ |
716 | 722 | function getThumbVirtualUrl( $suffix = false ) { |
717 | | - $path = $this->repo->getVirtualUrl() . '/public/thumb/' . $this->getHashPath(); |
| 723 | + $path = $this->repo->getVirtualUrl() . '/public/thumb/' . $this->getUrlRel(); |
718 | 724 | if ( $suffix !== false ) { |
719 | 725 | $path .= '/' . urlencode( $suffix ); |
720 | 726 | } |