MediaWiki  REL1_31
SwiftFileBackendTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
17  private $backend;
18 
19  protected function setUp() {
20  parent::setUp();
21 
22  $this->backend = TestingAccessWrapper::newFromObject(
23  new SwiftFileBackend( [
24  'name' => 'local-swift-testing',
25  'class' => SwiftFileBackend::class,
26  'wikiId' => 'unit-testing',
27  'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ),
28  'swiftAuthUrl' => 'http://127.0.0.1:8080/auth', // unused
29  'swiftUser' => 'test:tester',
30  'swiftKey' => 'testing',
31  'swiftTempUrlKey' => 'b3968d0207b54ece87cccc06515a89d4' // unused
32  ] )
33  );
34  }
35 
39  public function testSanitizeHdrsStrict( $raw, $sanitized ) {
40  $hdrs = $this->backend->sanitizeHdrsStrict( [ 'headers' => $raw ] );
41 
42  $this->assertEquals( $hdrs, $sanitized, 'sanitizeHdrsStrict() has expected result' );
43  }
44 
45  public static function provider_testSanitizeHdrsStrict() {
46  return [
47  [
48  [
49  'content-length' => 345,
50  'content-type' => 'image+bitmap/jpeg',
51  'content-disposition' => 'inline',
52  'content-duration' => 35.6363,
53  'content-Custom' => 'hello',
54  'x-content-custom' => 'hello'
55  ],
56  [
57  'content-disposition' => 'inline',
58  'content-duration' => 35.6363,
59  'content-custom' => 'hello',
60  'x-content-custom' => 'hello'
61  ]
62  ],
63  [
64  [
65  'content-length' => 345,
66  'content-type' => 'image+bitmap/jpeg',
67  'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
68  'content-duration' => 35.6363,
69  'content-custom' => 'hello',
70  'x-content-custom' => 'hello'
71  ],
72  [
73  'content-disposition' => 'inline;filename=xxx',
74  'content-duration' => 35.6363,
75  'content-custom' => 'hello',
76  'x-content-custom' => 'hello'
77  ]
78  ],
79  [
80  [
81  'content-length' => 345,
82  'content-type' => 'image+bitmap/jpeg',
83  'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
84  'content-duration' => 35.6363,
85  'content-custom' => 'hello',
86  'x-content-custom' => 'hello'
87  ],
88  [
89  'content-disposition' => '',
90  'content-duration' => 35.6363,
91  'content-custom' => 'hello',
92  'x-content-custom' => 'hello'
93  ]
94  ]
95  ];
96  }
97 
101  public function testSanitizeHdrs( $raw, $sanitized ) {
102  $hdrs = $this->backend->sanitizeHdrs( [ 'headers' => $raw ] );
103 
104  $this->assertEquals( $hdrs, $sanitized, 'sanitizeHdrs() has expected result' );
105  }
106 
107  public static function provider_testSanitizeHdrs() {
108  return [
109  [
110  [
111  'content-length' => 345,
112  'content-type' => 'image+bitmap/jpeg',
113  'content-disposition' => 'inline',
114  'content-duration' => 35.6363,
115  'content-Custom' => 'hello',
116  'x-content-custom' => 'hello'
117  ],
118  [
119  'content-type' => 'image+bitmap/jpeg',
120  'content-disposition' => 'inline',
121  'content-duration' => 35.6363,
122  'content-custom' => 'hello',
123  'x-content-custom' => 'hello'
124  ]
125  ],
126  [
127  [
128  'content-length' => 345,
129  'content-type' => 'image+bitmap/jpeg',
130  'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
131  'content-duration' => 35.6363,
132  'content-custom' => 'hello',
133  'x-content-custom' => 'hello'
134  ],
135  [
136  'content-type' => 'image+bitmap/jpeg',
137  'content-disposition' => 'inline;filename=xxx',
138  'content-duration' => 35.6363,
139  'content-custom' => 'hello',
140  'x-content-custom' => 'hello'
141  ]
142  ],
143  [
144  [
145  'content-length' => 345,
146  'content-type' => 'image+bitmap/jpeg',
147  'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
148  'content-duration' => 35.6363,
149  'content-custom' => 'hello',
150  'x-content-custom' => 'hello'
151  ],
152  [
153  'content-type' => 'image+bitmap/jpeg',
154  'content-disposition' => '',
155  'content-duration' => 35.6363,
156  'content-custom' => 'hello',
157  'x-content-custom' => 'hello'
158  ]
159  ]
160  ];
161  }
162 
166  public function testGetMetadataHeaders( $raw, $sanitized ) {
167  $hdrs = $this->backend->getMetadataHeaders( $raw );
168 
169  $this->assertEquals( $hdrs, $sanitized, 'getMetadataHeaders() has expected result' );
170  }
171 
172  public static function provider_testGetMetadataHeaders() {
173  return [
174  [
175  [
176  'content-length' => 345,
177  'content-custom' => 'hello',
178  'x-content-custom' => 'hello',
179  'x-object-meta-custom' => 5,
180  'x-object-meta-sha1Base36' => 'a3deadfg...',
181  ],
182  [
183  'x-object-meta-custom' => 5,
184  'x-object-meta-sha1base36' => 'a3deadfg...',
185  ]
186  ]
187  ];
188  }
189 
193  public function testGetMetadata( $raw, $sanitized ) {
194  $hdrs = $this->backend->getMetadata( $raw );
195 
196  $this->assertEquals( $hdrs, $sanitized, 'getMetadata() has expected result' );
197  }
198 
199  public static function provider_testGetMetadata() {
200  return [
201  [
202  [
203  'content-length' => 345,
204  'content-custom' => 'hello',
205  'x-content-custom' => 'hello',
206  'x-object-meta-custom' => 5,
207  'x-object-meta-sha1Base36' => 'a3deadfg...',
208  ],
209  [
210  'custom' => 5,
211  'sha1base36' => 'a3deadfg...',
212  ]
213  ]
214  ];
215  }
216 }
SwiftFileBackendTest\provider_testGetMetadataHeaders
static provider_testGetMetadataHeaders()
Definition: SwiftFileBackendTest.php:172
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
SwiftFileBackendTest\setUp
setUp()
Definition: SwiftFileBackendTest.php:19
LockManagerGroup\singleton
static singleton( $domain=false)
Definition: LockManagerGroup.php:52
SwiftFileBackendTest\$backend
TestingAccessWrapper $backend
Proxy to SwiftFileBackend.
Definition: SwiftFileBackendTest.php:17
SwiftFileBackendTest\provider_testSanitizeHdrsStrict
static provider_testSanitizeHdrsStrict()
Definition: SwiftFileBackendTest.php:45
SwiftFileBackendTest
FileRepo FileBackend medium.
Definition: SwiftFileBackendTest.php:15
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:37
SwiftFileBackend
Class for an OpenStack Swift (or Ceph RGW) based file backend.
Definition: SwiftFileBackend.php:34
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
SwiftFileBackendTest\testSanitizeHdrs
testSanitizeHdrs( $raw, $sanitized)
provider_testSanitizeHdrs
Definition: SwiftFileBackendTest.php:101
SwiftFileBackendTest\testGetMetadataHeaders
testGetMetadataHeaders( $raw, $sanitized)
provider_testGetMetadataHeaders
Definition: SwiftFileBackendTest.php:166
SwiftFileBackendTest\provider_testGetMetadata
static provider_testGetMetadata()
Definition: SwiftFileBackendTest.php:199
SwiftFileBackendTest\provider_testSanitizeHdrs
static provider_testSanitizeHdrs()
Definition: SwiftFileBackendTest.php:107
SwiftFileBackendTest\testGetMetadata
testGetMetadata( $raw, $sanitized)
provider_testGetMetadata
Definition: SwiftFileBackendTest.php:193
SwiftFileBackendTest\testSanitizeHdrsStrict
testSanitizeHdrsStrict( $raw, $sanitized)
provider_testSanitizeHdrsStrict
Definition: SwiftFileBackendTest.php:39
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:56