Merge "FauxRequest: don’t override getValues()"
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / SwiftFileBackendTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * @group FileRepo
7 * @group FileBackend
8 * @group medium
9 *
10 * @covers SwiftFileBackend
11 * @covers SwiftFileBackendDirList
12 * @covers SwiftFileBackendFileList
13 * @covers SwiftFileBackendList
14 */
15 class SwiftFileBackendTest extends MediaWikiTestCase {
16 /** @var TestingAccessWrapper|SwiftFileBackend */
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
36 /**
37 * @covers SwiftFileBackend::extractMutableContentHeaders
38 * @dataProvider provider_testExtractPostableContentHeaders
39 */
40 public function testExtractPostableContentHeaders( $raw, $sanitized ) {
41 $hdrs = $this->backend->extractMutableContentHeaders( $raw );
42
43 $this->assertEquals( $hdrs, $sanitized, 'Correct extractPostableContentHeaders() result' );
44 }
45
46 public static function provider_testExtractPostableContentHeaders() {
47 return [
48 [
49 [
50 'content-length' => 345,
51 'content-type' => 'image+bitmap/jpeg',
52 'content-disposition' => 'inline',
53 'content-duration' => 35.6363,
54 'content-Custom' => 'hello',
55 'x-content-custom' => 'hello'
56 ],
57 [
58 'content-type' => 'image+bitmap/jpeg',
59 'content-disposition' => 'inline',
60 'content-duration' => 35.6363,
61 'content-custom' => 'hello',
62 'x-content-custom' => 'hello'
63 ]
64 ],
65 [
66 [
67 'content-length' => 345,
68 'content-type' => 'image+bitmap/jpeg',
69 'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
70 'content-duration' => 35.6363,
71 'content-custom' => 'hello',
72 'x-content-custom' => 'hello'
73 ],
74 [
75 'content-type' => 'image+bitmap/jpeg',
76 'content-disposition' => 'inline;filename=xxx',
77 'content-duration' => 35.6363,
78 'content-custom' => 'hello',
79 'x-content-custom' => 'hello'
80 ]
81 ],
82 [
83 [
84 'content-length' => 345,
85 'content-type' => 'image+bitmap/jpeg',
86 'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
87 'content-duration' => 35.6363,
88 'content-custom' => 'hello',
89 'x-content-custom' => 'hello'
90 ],
91 [
92 'content-type' => 'image+bitmap/jpeg',
93 'content-disposition' => '',
94 'content-duration' => 35.6363,
95 'content-custom' => 'hello',
96 'x-content-custom' => 'hello'
97 ]
98 ]
99 ];
100 }
101
102 /**
103 * @covers SwiftFileBackend::extractMetadataHeaders
104 * @dataProvider provider_testGetMetadataHeaders
105 */
106 public function testGetMetadataHeaders( $raw, $sanitized ) {
107 $hdrs = $this->backend->extractMetadataHeaders( $raw );
108
109 $this->assertEquals( $hdrs, $sanitized, 'getMetadataHeaders() has expected result' );
110 }
111
112 public static function provider_testGetMetadataHeaders() {
113 return [
114 [
115 [
116 'content-length' => 345,
117 'content-custom' => 'hello',
118 'x-content-custom' => 'hello',
119 'x-object-meta-custom' => 5,
120 'x-object-meta-sha1Base36' => 'a3deadfg...',
121 ],
122 [
123 'x-object-meta-custom' => 5,
124 'x-object-meta-sha1base36' => 'a3deadfg...',
125 ]
126 ]
127 ];
128 }
129
130 /**
131 * @covers SwiftFileBackend::getMetadataFromHeaders
132 * @dataProvider provider_testGetMetadata
133 */
134 public function testGetMetadata( $raw, $sanitized ) {
135 $hdrs = $this->backend->getMetadataFromHeaders( $raw );
136
137 $this->assertEquals( $hdrs, $sanitized, 'getMetadata() has expected result' );
138 }
139
140 public static function provider_testGetMetadata() {
141 return [
142 [
143 [
144 'content-length' => 345,
145 'content-custom' => 'hello',
146 'x-content-custom' => 'hello',
147 'x-object-meta-custom' => 5,
148 'x-object-meta-sha1Base36' => 'a3deadfg...',
149 ],
150 [
151 'custom' => 5,
152 'sha1base36' => 'a3deadfg...',
153 ]
154 ]
155 ];
156 }
157 }