MediaWiki  1.30.2
LocalFileTest.php
Go to the documentation of this file.
1 <?php
2 
9 
10  protected function setUp() {
11  parent::setUp();
12 
13  $this->setMwGlobals( 'wgCapitalLinks', true );
14 
15  $info = [
16  'name' => 'test',
17  'directory' => '/testdir',
18  'url' => '/testurl',
19  'hashLevels' => 2,
20  'transformVia404' => false,
21  'backend' => new FSFileBackend( [
22  'name' => 'local-backend',
23  'wikiId' => wfWikiID(),
24  'containerPaths' => [
25  'cont1' => "/testdir/local-backend/tempimages/cont1",
26  'cont2' => "/testdir/local-backend/tempimages/cont2"
27  ]
28  ] )
29  ];
30  $this->repo_hl0 = new LocalRepo( [ 'hashLevels' => 0 ] + $info );
31  $this->repo_hl2 = new LocalRepo( [ 'hashLevels' => 2 ] + $info );
32  $this->repo_lc = new LocalRepo( [ 'initialCapital' => false ] + $info );
33  $this->file_hl0 = $this->repo_hl0->newFile( 'test!' );
34  $this->file_hl2 = $this->repo_hl2->newFile( 'test!' );
35  $this->file_lc = $this->repo_lc->newFile( 'test!' );
36  }
37 
41  public function testGetHashPath() {
42  $this->assertEquals( '', $this->file_hl0->getHashPath() );
43  $this->assertEquals( 'a/a2/', $this->file_hl2->getHashPath() );
44  $this->assertEquals( 'c/c4/', $this->file_lc->getHashPath() );
45  }
46 
50  public function testGetRel() {
51  $this->assertEquals( 'Test!', $this->file_hl0->getRel() );
52  $this->assertEquals( 'a/a2/Test!', $this->file_hl2->getRel() );
53  $this->assertEquals( 'c/c4/test!', $this->file_lc->getRel() );
54  }
55 
59  public function testGetUrlRel() {
60  $this->assertEquals( 'Test%21', $this->file_hl0->getUrlRel() );
61  $this->assertEquals( 'a/a2/Test%21', $this->file_hl2->getUrlRel() );
62  $this->assertEquals( 'c/c4/test%21', $this->file_lc->getUrlRel() );
63  }
64 
68  public function testGetArchivePath() {
69  $this->assertEquals(
70  'mwstore://local-backend/test-public/archive',
71  $this->file_hl0->getArchivePath()
72  );
73  $this->assertEquals(
74  'mwstore://local-backend/test-public/archive/a/a2',
75  $this->file_hl2->getArchivePath()
76  );
77  $this->assertEquals(
78  'mwstore://local-backend/test-public/archive/!',
79  $this->file_hl0->getArchivePath( '!' )
80  );
81  $this->assertEquals(
82  'mwstore://local-backend/test-public/archive/a/a2/!',
83  $this->file_hl2->getArchivePath( '!' )
84  );
85  }
86 
90  public function testGetThumbPath() {
91  $this->assertEquals(
92  'mwstore://local-backend/test-thumb/Test!',
93  $this->file_hl0->getThumbPath()
94  );
95  $this->assertEquals(
96  'mwstore://local-backend/test-thumb/a/a2/Test!',
97  $this->file_hl2->getThumbPath()
98  );
99  $this->assertEquals(
100  'mwstore://local-backend/test-thumb/Test!/x',
101  $this->file_hl0->getThumbPath( 'x' )
102  );
103  $this->assertEquals(
104  'mwstore://local-backend/test-thumb/a/a2/Test!/x',
105  $this->file_hl2->getThumbPath( 'x' )
106  );
107  }
108 
112  public function testGetArchiveUrl() {
113  $this->assertEquals( '/testurl/archive', $this->file_hl0->getArchiveUrl() );
114  $this->assertEquals( '/testurl/archive/a/a2', $this->file_hl2->getArchiveUrl() );
115  $this->assertEquals( '/testurl/archive/%21', $this->file_hl0->getArchiveUrl( '!' ) );
116  $this->assertEquals( '/testurl/archive/a/a2/%21', $this->file_hl2->getArchiveUrl( '!' ) );
117  }
118 
122  public function testGetThumbUrl() {
123  $this->assertEquals( '/testurl/thumb/Test%21', $this->file_hl0->getThumbUrl() );
124  $this->assertEquals( '/testurl/thumb/a/a2/Test%21', $this->file_hl2->getThumbUrl() );
125  $this->assertEquals( '/testurl/thumb/Test%21/x', $this->file_hl0->getThumbUrl( 'x' ) );
126  $this->assertEquals( '/testurl/thumb/a/a2/Test%21/x', $this->file_hl2->getThumbUrl( 'x' ) );
127  }
128 
132  public function testGetArchiveVirtualUrl() {
133  $this->assertEquals( 'mwrepo://test/public/archive', $this->file_hl0->getArchiveVirtualUrl() );
134  $this->assertEquals(
135  'mwrepo://test/public/archive/a/a2',
136  $this->file_hl2->getArchiveVirtualUrl()
137  );
138  $this->assertEquals(
139  'mwrepo://test/public/archive/%21',
140  $this->file_hl0->getArchiveVirtualUrl( '!' )
141  );
142  $this->assertEquals(
143  'mwrepo://test/public/archive/a/a2/%21',
144  $this->file_hl2->getArchiveVirtualUrl( '!' )
145  );
146  }
147 
151  public function testGetThumbVirtualUrl() {
152  $this->assertEquals( 'mwrepo://test/thumb/Test%21', $this->file_hl0->getThumbVirtualUrl() );
153  $this->assertEquals( 'mwrepo://test/thumb/a/a2/Test%21', $this->file_hl2->getThumbVirtualUrl() );
154  $this->assertEquals(
155  'mwrepo://test/thumb/Test%21/%21',
156  $this->file_hl0->getThumbVirtualUrl( '!' )
157  );
158  $this->assertEquals(
159  'mwrepo://test/thumb/a/a2/Test%21/%21',
160  $this->file_hl2->getThumbVirtualUrl( '!' )
161  );
162  }
163 
167  public function testGetUrl() {
168  $this->assertEquals( '/testurl/Test%21', $this->file_hl0->getUrl() );
169  $this->assertEquals( '/testurl/a/a2/Test%21', $this->file_hl2->getUrl() );
170  }
171 
175  public function testWfLocalFile() {
176  $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" );
177  $this->assertThat(
178  $file,
179  $this->isInstanceOf( 'LocalFile' ),
180  'wfLocalFile() returns LocalFile for valid Titles'
181  );
182  }
183 }
LocalFileTest\testGetArchiveVirtualUrl
testGetArchiveVirtualUrl()
File::getArchiveVirtualUrl.
Definition: LocalFileTest.php:132
LocalFileTest\testGetUrlRel
testGetUrlRel()
File::getUrlRel.
Definition: LocalFileTest.php:59
LocalFileTest\testGetRel
testGetRel()
File::getRel.
Definition: LocalFileTest.php:50
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\testGetThumbPath
testGetThumbPath()
File::getThumbPath.
Definition: LocalFileTest.php:90
LocalFileTest\testGetArchivePath
testGetArchivePath()
File::getArchivePath.
Definition: LocalFileTest.php:68
LocalFileTest\testWfLocalFile
testWfLocalFile()
wfLocalFile
Definition: LocalFileTest.php:175
LocalFileTest\testGetThumbUrl
testGetThumbUrl()
File::getThumbUrl.
Definition: LocalFileTest.php:122
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:672
LocalFileTest
These tests should work regardless of $wgCapitalLinks.
Definition: LocalFileTest.php:8
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
LocalFileTest\testGetUrl
testGetUrl()
File::getUrl.
Definition: LocalFileTest.php:167
LocalFileTest\setUp
setUp()
Definition: LocalFileTest.php:10
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2807
LocalFileTest\testGetArchiveUrl
testGetArchiveUrl()
File::getArchiveUrl.
Definition: LocalFileTest.php:112
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
LocalFileTest\testGetHashPath
testGetHashPath()
File::getHashPath.
Definition: LocalFileTest.php:41
LocalFileTest\testGetThumbVirtualUrl
testGetThumbVirtualUrl()
File::getThumbVirtualUrl.
Definition: LocalFileTest.php:151
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:2908
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:35