Merge "Improve sorting on SpecialWanted*-Pages"
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / SwiftFileBackendTest.php
1 <?php
2
3 /**
4 * @group FileRepo
5 * @group FileBackend
6 * @group medium
7 *
8 * @covers SwiftFileBackend
9 * @covers SwiftFileBackendDirList
10 * @covers SwiftFileBackendFileList
11 * @covers SwiftFileBackendList
12 */
13 class SwiftFileBackendTest extends MediaWikiTestCase {
14 /** @var TestingAccessWrapper Proxy to SwiftFileBackend */
15 private $backend;
16
17 protected function setUp() {
18 parent::setUp();
19
20 $this->backend = TestingAccessWrapper::newFromObject(
21 new SwiftFileBackend( [
22 'name' => 'local-swift-testing',
23 'class' => 'SwiftFileBackend',
24 'wikiId' => 'unit-testing',
25 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ),
26 'swiftAuthUrl' => 'http://127.0.0.1:8080/auth', // unused
27 'swiftUser' => 'test:tester',
28 'swiftKey' => 'testing',
29 'swiftTempUrlKey' => 'b3968d0207b54ece87cccc06515a89d4' // unused
30 ] )
31 );
32 }
33
34 /**
35 * @dataProvider provider_testSanitizeHdrs
36 */
37 public function testSanitizeHdrs( $raw, $sanitized ) {
38 $hdrs = $this->backend->sanitizeHdrs( [ 'headers' => $raw ] );
39
40 $this->assertEquals( $hdrs, $sanitized, 'sanitizeHdrs() has expected result' );
41 }
42
43 public static function provider_testSanitizeHdrs() {
44 return [
45 [
46 [
47 'content-length' => 345,
48 'content-type' => 'image+bitmap/jpeg',
49 'content-disposition' => 'inline',
50 'content-duration' => 35.6363,
51 'content-Custom' => 'hello',
52 'x-content-custom' => 'hello'
53 ],
54 [
55 'content-disposition' => 'inline',
56 'content-duration' => 35.6363,
57 'content-custom' => 'hello',
58 'x-content-custom' => 'hello'
59 ]
60 ],
61 [
62 [
63 'content-length' => 345,
64 'content-type' => 'image+bitmap/jpeg',
65 'content-Disposition' => 'inline; filename=xxx; ' . str_repeat( 'o', 1024 ),
66 'content-duration' => 35.6363,
67 'content-custom' => 'hello',
68 'x-content-custom' => 'hello'
69 ],
70 [
71 'content-disposition' => 'inline;filename=xxx',
72 'content-duration' => 35.6363,
73 'content-custom' => 'hello',
74 'x-content-custom' => 'hello'
75 ]
76 ],
77 [
78 [
79 'content-length' => 345,
80 'content-type' => 'image+bitmap/jpeg',
81 'content-disposition' => 'filename=' . str_repeat( 'o', 1024 ) . ';inline',
82 'content-duration' => 35.6363,
83 'content-custom' => 'hello',
84 'x-content-custom' => 'hello'
85 ],
86 [
87 'content-disposition' => '',
88 'content-duration' => 35.6363,
89 'content-custom' => 'hello',
90 'x-content-custom' => 'hello'
91 ]
92 ]
93 ];
94 }
95
96 /**
97 * @dataProvider provider_testGetMetadataHeaders
98 */
99 public function testGetMetadataHeaders( $raw, $sanitized ) {
100 $hdrs = $this->backend->getMetadataHeaders( $raw );
101
102 $this->assertEquals( $hdrs, $sanitized, 'getMetadataHeaders() has expected result' );
103 }
104
105 public static function provider_testGetMetadataHeaders() {
106 return [
107 [
108 [
109 'content-length' => 345,
110 'content-custom' => 'hello',
111 'x-content-custom' => 'hello',
112 'x-object-meta-custom' => 5,
113 'x-object-meta-sha1Base36' => 'a3deadfg...',
114 ],
115 [
116 'x-object-meta-custom' => 5,
117 'x-object-meta-sha1base36' => 'a3deadfg...',
118 ]
119 ]
120 ];
121 }
122
123 /**
124 * @dataProvider provider_testGetMetadata
125 */
126 public function testGetMetadata( $raw, $sanitized ) {
127 $hdrs = $this->backend->getMetadata( $raw );
128
129 $this->assertEquals( $hdrs, $sanitized, 'getMetadata() has expected result' );
130 }
131
132 public static function provider_testGetMetadata() {
133 return [
134 [
135 [
136 'content-length' => 345,
137 'content-custom' => 'hello',
138 'x-content-custom' => 'hello',
139 'x-object-meta-custom' => 5,
140 'x-object-meta-sha1Base36' => 'a3deadfg...',
141 ],
142 [
143 'custom' => 5,
144 'sha1base36' => 'a3deadfg...',
145 ]
146 ]
147 ];
148 }
149 }