MediaWiki  1.33.0
LocalFileTest.php
Go to the documentation of this file.
1 <?php
2 
9 
11  private $repo_hl0;
13  private $repo_hl2;
15  private $repo_lc;
17  private $file_hl0;
19  private $file_hl2;
21  private $file_lc;
22 
23  protected function setUp() {
24  parent::setUp();
25 
26  $this->setMwGlobals( 'wgCapitalLinks', true );
27 
28  $info = [
29  'name' => 'test',
30  'directory' => '/testdir',
31  'url' => '/testurl',
32  'hashLevels' => 2,
33  'transformVia404' => false,
34  'backend' => new FSFileBackend( [
35  'name' => 'local-backend',
36  'wikiId' => wfWikiID(),
37  'containerPaths' => [
38  'cont1' => "/testdir/local-backend/tempimages/cont1",
39  'cont2' => "/testdir/local-backend/tempimages/cont2"
40  ]
41  ] )
42  ];
43  $this->repo_hl0 = new LocalRepo( [ 'hashLevels' => 0 ] + $info );
44  $this->repo_hl2 = new LocalRepo( [ 'hashLevels' => 2 ] + $info );
45  $this->repo_lc = new LocalRepo( [ 'initialCapital' => false ] + $info );
46  $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
47  $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
48  $this->file_lc = $this->repo_lc->newFile( 'test!' );
49  }
50 
54  public function testGetHashPath() {
55  $this->assertEquals( '', $this->file_hl0->getHashPath() );
56  $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
57  $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
58  }
59 
63  public function testGetRel() {
64  $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
65  $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
66  $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
67  }
68 
72  public function testGetUrlRel() {
73  $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
74  $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
75  $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
76  }
77 
81  public function testGetArchivePath() {
82  $this->assertEquals(
83  'mwstore://local-backend/test-public/archive',
84  $this->file_hl0->getArchivePath()
85  );
86  $this->assertEquals(
87  'mwstore://local-backend/test-public/archive/a/a2',
88  $this->file_hl2->getArchivePath()
89  );
90  $this->assertEquals(
91  'mwstore://local-backend/test-public/archive/!',
92  $this->file_hl0->getArchivePath( '!' )
93  );
94  $this->assertEquals(
95  'mwstore://local-backend/test-public/archive/a/a2/!',
96  $this->file_hl2->getArchivePath( '!' )
97  );
98  }
99 
103  public function testGetThumbPath() {
104  $this->assertEquals(
105  'mwstore://local-backend/test-thumb/Test!',
106  $this->file_hl0->getThumbPath()
107  );
108  $this->assertEquals(
109  'mwstore://local-backend/test-thumb/a/a2/Test!',
110  $this->file_hl2->getThumbPath()
111  );
112  $this->assertEquals(
113  'mwstore://local-backend/test-thumb/Test!/x',
114  $this->file_hl0->getThumbPath( 'x' )
115  );
116  $this->assertEquals(
117  'mwstore://local-backend/test-thumb/a/a2/Test!/x',
118  $this->file_hl2->getThumbPath( 'x' )
119  );
120  }
121 
125  public function testGetArchiveUrl() {
126  $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
127  $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
128  $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
129  $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
130  }
131 
135  public function testGetThumbUrl() {
136  $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
137  $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
138  $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
139  $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
140  }
141 
145  public function testGetArchiveVirtualUrl() {
146  $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
147  $this->assertEquals(
148  'mwrepo://test/public/archive/a/a2',
149  $this->file_hl2->getArchiveVirtualUrl()
150  );
151  $this->assertEquals(
152  'mwrepo://test/public/archive/%21',
153  $this->file_hl0->getArchiveVirtualUrl( '!' )
154  );
155  $this->assertEquals(
156  'mwrepo://test/public/archive/a/a2/%21',
157  $this->file_hl2->getArchiveVirtualUrl( '!' )
158  );
159  }
160 
164  public function testGetThumbVirtualUrl() {
165  $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
166  $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
167  $this->assertEquals(
168  'mwrepo://test/thumb/Test%21/%21',
169  $this->file_hl0->getThumbVirtualUrl( '!' )
170  );
171  $this->assertEquals(
172  'mwrepo://test/thumb/a/a2/Test%21/%21',
173  $this->file_hl2->getThumbVirtualUrl( '!' )
174  );
175  }
176 
180  public function testGetUrl() {
181  $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
182  $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
183  }
184 
188  public function testWfLocalFile() {
189  $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
190  $this->assertThat(
191  $file,
192  $this->isInstanceOf( LocalFile::class ),
193  'wfLocalFile() returns LocalFile for valid Titles'
194  );
195  }
196 }
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
LocalFileTest\testGetArchiveVirtualUrl
testGetArchiveVirtualUrl()
File::getArchiveVirtualUrl.
Definition: LocalFileTest.php:145
LocalFileTest\$repo_hl2
LocalRepo $repo_hl2
Definition: LocalFileTest.php:13
LocalFileTest\testGetUrlRel
testGetUrlRel()
File::getUrlRel.
Definition: LocalFileTest.php:72
LocalFileTest\testGetRel
testGetRel()
File::getRel.
Definition: LocalFileTest.php:63
LocalFileTest\$file_hl2
File $file_hl2
Definition: LocalFileTest.php:19
LocalFileTest\$file_lc
File $file_lc
Definition: LocalFileTest.php:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
LocalFileTest\$file_hl0
File $file_hl0
Definition: LocalFileTest.php:17
LocalFileTest\testGetThumbPath
testGetThumbPath()
File::getThumbPath.
Definition: LocalFileTest.php:103
LocalFileTest\testGetArchivePath
testGetArchivePath()
File::getArchivePath.
Definition: LocalFileTest.php:81
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:52
LocalFileTest\testWfLocalFile
testWfLocalFile()
wfLocalFile
Definition: LocalFileTest.php:188
LocalFileTest\testGetThumbUrl
testGetThumbUrl()
File::getThumbUrl.
Definition: LocalFileTest.php:135
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
LocalFileTest
These tests should work regardless of $wgCapitalLinks.
Definition: LocalFileTest.php:8
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
LocalFileTest\testGetUrl
testGetUrl()
File::getUrl.
Definition: LocalFileTest.php:180
LocalFileTest\$repo_hl0
LocalRepo $repo_hl0
Definition: LocalFileTest.php:11
LocalFileTest\setUp
setUp()
Definition: LocalFileTest.php:23
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2602
LocalFileTest\testGetArchiveUrl
testGetArchiveUrl()
File::getArchiveUrl.
Definition: LocalFileTest.php:125
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
LocalFileTest\$repo_lc
LocalRepo $repo_lc
Definition: LocalFileTest.php:15
LocalFileTest\testGetHashPath
testGetHashPath()
File::getHashPath.
Definition: LocalFileTest.php:54
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
LocalFileTest\testGetThumbVirtualUrl
testGetThumbVirtualUrl()
File::getThumbVirtualUrl.
Definition: LocalFileTest.php:164
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:2688
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:36